Repository: kafka
Updated Branches:
  refs/heads/trunk ef9551297 -> 31cc8885e


MINOR: Improve assert in ControllerFailoverTest

It sometimes fails in Jenkins like:

```text
java.lang.AssertionError: IllegalStateException was not thrown
        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.Assert.assertTrue(Assert.java:41)
        at 
kafka.controller.ControllerFailoverTest.testHandleIllegalStateException(ControllerFailoverTest.scala:86)
```

I ran it locally 100 times with no failure.

Author: Ismael Juma <[email protected]>

Reviewers: Rajini Sivaram <[email protected]>

Closes #3176 from ijuma/improve-controller-failover-assert


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/31cc8885
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/31cc8885
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/31cc8885

Branch: refs/heads/trunk
Commit: 31cc8885e4cfc35d97291b5d9eece6f3793f2538
Parents: ef95512
Author: Ismael Juma <[email protected]>
Authored: Wed May 31 10:22:10 2017 +0100
Committer: Ismael Juma <[email protected]>
Committed: Wed May 31 10:22:17 2017 +0100

----------------------------------------------------------------------
 .../unit/kafka/controller/ControllerFailoverTest.scala | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/31cc8885/core/src/test/scala/unit/kafka/controller/ControllerFailoverTest.scala
----------------------------------------------------------------------
diff --git 
a/core/src/test/scala/unit/kafka/controller/ControllerFailoverTest.scala 
b/core/src/test/scala/unit/kafka/controller/ControllerFailoverTest.scala
index 7a91bef..c17ec6a 100644
--- a/core/src/test/scala/unit/kafka/controller/ControllerFailoverTest.scala
+++ b/core/src/test/scala/unit/kafka/controller/ControllerFailoverTest.scala
@@ -68,13 +68,11 @@ class ControllerFailoverTest extends KafkaServerTestHarness 
with Logging {
 
     // Wait until we have verified that we have resigned
     val latch = new CountDownLatch(1)
-    @volatile var expectedExceptionThrown = false
-    @volatile var unexpectedExceptionThrown: Option[Throwable] = None
+    @volatile var exceptionThrown: Option[Throwable] = None
     val illegalStateEvent = 
ControllerTestUtils.createMockControllerEvent(ControllerState.BrokerChange, { 
() =>
       try initialController.handleIllegalState(new 
IllegalStateException("Thrown for test purposes"))
       catch {
-        case _: IllegalStateException => expectedExceptionThrown = true
-        case t: Throwable => unexpectedExceptionThrown = Some(t)
+        case t: Throwable => exceptionThrown = Some(t)
       }
       latch.await()
     })
@@ -83,12 +81,13 @@ class ControllerFailoverTest extends KafkaServerTestHarness 
with Logging {
     TestUtils.waitUntilTrue(() => !initialController.kafkaScheduler.isStarted, 
"Scheduler was not shutdown")
     TestUtils.waitUntilTrue(() => !initialController.isActive, "Controller did 
not become inactive")
     latch.countDown()
-    assertTrue("IllegalStateException was not thrown", expectedExceptionThrown)
-    assertEquals("Unexpected exception thrown", None, 
unexpectedExceptionThrown)
+    assertTrue("handleIllegalState did not throw an exception", 
exceptionThrown.isDefined)
+    assertTrue(s"handleIllegalState should throw an IllegalStateException, but 
$exceptionThrown was thrown",
+      exceptionThrown.get.isInstanceOf[IllegalStateException])
 
     TestUtils.waitUntilTrue(() => {
       servers.exists { server =>
-        server.kafkaController.isActive && server.kafkaController.epoch > 
initialController.epoch
+        server.kafkaController.isActive && server.kafkaController.epoch > 
initialEpoch
       }
     }, "Failed to find controller")
 

Reply via email to