You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by da...@apache.org on 2022/01/11 09:16:43 UTC

[kafka] branch 3.1 updated: MINOR: guard against calls to exit in QuorumTestHarness tests (#11457)

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

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


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

commit 34ed961de0925d8d92ddaeab899d57d47084536d
Author: Colin P. Mccabe <cm...@confluent.io>
AuthorDate: Wed Nov 24 12:38:27 2021 -0700

    MINOR: guard against calls to exit in QuorumTestHarness tests (#11457)
    
    Author: Colin P. Mccabe <cm...@confluent.io>
    
    Reviewers: José Armando García Sancio <js...@users.noreply.github.com>, Sherzod Mamadaliev <ma...@yahoo.com>
    
    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()
     }