MINOR: guard against calls to exit in QuorumTestHarness tests (#11457)

Author: Colin P. Mccabe <cmccabe@confluent.io>

Reviewers: José Armando García Sancio <jsancio@users.noreply.github.com>, Sherzod Mamadaliev <mamadaliev@yahoo.com>

Closes #11457 from cmccabe/guard_against_exit
This commit is contained in:
Colin P. Mccabe 2021-11-24 12:38:27 -07:00 committed by José Armando García Sancio
parent e8b53caab4
commit 0f967828e1
1 changed files with 23 additions and 1 deletions

View File

@ -32,7 +32,7 @@ import org.apache.kafka.common.metrics.Metrics
import org.apache.kafka.common.{TopicPartition, Uuid}
import org.apache.kafka.common.security.JaasUtils
import org.apache.kafka.common.security.auth.SecurityProtocol
import org.apache.kafka.common.utils.Time
import org.apache.kafka.common.utils.{Exit, Time}
import org.apache.kafka.metadata.MetadataRecordSerde
import org.apache.kafka.raft.RaftConfig.{AddressSpec, InetAddressSpec}
import org.apache.kafka.server.common.ApiMessageAndVersion
@ -162,6 +162,26 @@ abstract class QuorumTestHarness extends Logging {
// That way you control the initialization order.
@BeforeEach
def setUp(testInfo: TestInfo): Unit = {
Exit.setExitProcedure((code, message) => {
try {
throw new RuntimeException(s"exit(${code}, ${message}) called!")
} catch {
case e: Throwable => error("test error", e)
throw e
} finally {
tearDown()
}
})
Exit.setHaltProcedure((code, message) => {
try {
throw new RuntimeException(s"halt(${code}, ${message}) called!")
} catch {
case e: Throwable => error("test error", e)
throw e
} finally {
tearDown()
}
})
val name = if (testInfo.getTestMethod().isPresent()) {
testInfo.getTestMethod().get().toString()
} else {
@ -296,6 +316,8 @@ abstract class QuorumTestHarness extends Logging {
@AfterEach
def tearDown(): Unit = {
Exit.resetExitProcedure()
Exit.resetHaltProcedure()
if (implementation != null) {
implementation.shutdown()
}