You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2018/03/22 16:07:57 UTC

[incubator-pulsar] branch master updated: Null checks in MockedPulsarServiceBaseTest (#1420)

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

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 9bc5518  Null checks in MockedPulsarServiceBaseTest (#1420)
9bc5518 is described below

commit 9bc5518062da1fec23f4bfdb19e65f31fc0d8210
Author: Ivan Kelly <iv...@apache.org>
AuthorDate: Thu Mar 22 17:07:54 2018 +0100

    Null checks in MockedPulsarServiceBaseTest (#1420)
    
    If initialization fails, any of the members could be null. If we try
    to do cleanup on null members we get a NullPointerException, which
    obscures the original error that caused the member to be null in the
    first place.
---
 .../broker/auth/MockedPulsarServiceBaseTest.java   | 23 ++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockedPulsarServiceBaseTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockedPulsarServiceBaseTest.java
index 02055ac..66b6f6a 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockedPulsarServiceBaseTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/MockedPulsarServiceBaseTest.java
@@ -136,15 +136,26 @@ public abstract class MockedPulsarServiceBaseTest {
 
     protected final void internalCleanup() throws Exception {
         try {
-            admin.close();
-            // There are some test cases where pulsarClient is not initialized.
+            // if init fails, some of these could be null, and if so would throw
+            // an NPE in shutdown, obscuring the real error
+            if (admin != null) {
+                admin.close();
+            }
             if (pulsarClient != null) {
                 pulsarClient.close();
             }
-            pulsar.close();
-            mockBookKeeper.reallyShutdow();
-            mockZookKeeper.shutdown();
-            sameThreadOrderedSafeExecutor.shutdown();
+            if (pulsar != null) {
+                pulsar.close();
+            }
+            if (mockBookKeeper != null) {
+                mockBookKeeper.reallyShutdow();
+            }
+            if (mockZookKeeper != null) {
+                mockZookKeeper.shutdown();
+            }
+            if (sameThreadOrderedSafeExecutor != null) {
+                sameThreadOrderedSafeExecutor.shutdown();
+            }
         } catch (Exception e) {
             log.warn("Failed to clean up mocked pulsar service:", e);
             throw e;

-- 
To stop receiving notification emails like this one, please contact
mmerli@apache.org.