This is an automated email from the ASF dual-hosted git repository.

dajac pushed a commit to branch 3.1-test
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/3.1-test by this push:
     new d0d09d6  MINOR: guard against calls to exit in QuorumTestHarness tests 
(#11457)
d0d09d6 is described below

commit d0d09d6f316af509489a11ff6ec65f9f9fed9cea
Author: Colin P. Mccabe <[email protected]>
AuthorDate: Wed Nov 24 12:38:27 2021 -0700

    MINOR: guard against calls to exit in QuorumTestHarness tests (#11457)
    
    Author: Colin P. Mccabe <[email protected]>
    
    Reviewers: José Armando García Sancio <[email protected]>, 
Sherzod Mamadaliev <[email protected]>
    
    Closes #11457 from cmccabe/guard_against_exit
---
 .../kafka/server/QuorumTestHarness.scala           | 24 +++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git 
a/core/src/test/scala/integration/kafka/server/QuorumTestHarness.scala 
b/core/src/test/scala/integration/kafka/server/QuorumTestHarness.scala
index 9c9fb72..c520ffb 100755
--- a/core/src/test/scala/integration/kafka/server/QuorumTestHarness.scala
+++ b/core/src/test/scala/integration/kafka/server/QuorumTestHarness.scala
@@ -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()
     }

Reply via email to