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

gparai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git

commit d96bea54b96b01ffe9bb19c76bfc158784f26ffc
Author: Igor Guzenko <[email protected]>
AuthorDate: Fri Dec 28 21:04:42 2018 +0200

    DRILL-6936: 
TestGracefulShutdown.gracefulShutdownThreadShouldBeInitializedBeforeClosingDrillbit
 fails if loopback address is set in hosts
    closes #1589
---
 .../apache/drill/test/TestGracefulShutdown.java    | 46 +++++++++-------------
 1 file changed, 18 insertions(+), 28 deletions(-)

diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/test/TestGracefulShutdown.java 
b/exec/java-exec/src/test/java/org/apache/drill/test/TestGracefulShutdown.java
index 94180e2..a433237 100644
--- 
a/exec/java-exec/src/test/java/org/apache/drill/test/TestGracefulShutdown.java
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/test/TestGracefulShutdown.java
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 package org.apache.drill.test;
+
 import org.apache.drill.categories.SlowTest;
 import org.apache.drill.common.exceptions.UserException;
 import org.apache.drill.exec.ExecConstants;
@@ -179,40 +180,28 @@ public class TestGracefulShutdown extends BaseTestQuery {
   }
 
   @Test // DRILL-6912
-  public void gracefulShutdownThreadShouldBeInitializedBeforeClosingDrillbit() 
throws Exception {
-    Drillbit drillbit = null;
-    Drillbit drillbitWithSamePort = null;
-
-    int userPort = QueryTestUtil.getFreePortNumber(31170, 300);
-    int bitPort = QueryTestUtil.getFreePortNumber(31180, 300);
+  public void testDrillbitWithSamePortContainsShutdownThread() throws 
Exception {
     ClusterFixtureBuilder fixtureBuilder = 
ClusterFixture.bareBuilder(dirTestWatcher).withLocalZk()
-        .configProperty(ExecConstants.INITIAL_USER_PORT, userPort)
-        .configProperty(ExecConstants.INITIAL_BIT_PORT, bitPort);
-    try (ClusterFixture clusterFixture = fixtureBuilder.build()) {
-      drillbit = clusterFixture.drillbit();
-
-      // creating another drillbit instance using same config
-      drillbitWithSamePort = new Drillbit(clusterFixture.config(), 
fixtureBuilder.configBuilder().getDefinitions(),
-          clusterFixture.serviceSet());
-
+        .configProperty(ExecConstants.ALLOW_LOOPBACK_ADDRESS_BINDING, true)
+        .configProperty(ExecConstants.INITIAL_USER_PORT, 
QueryTestUtil.getFreePortNumber(31170, 300))
+        .configProperty(ExecConstants.INITIAL_BIT_PORT, 
QueryTestUtil.getFreePortNumber(31180, 300));
+
+    try (ClusterFixture fixture = fixtureBuilder.build();
+         Drillbit drillbitWithSamePort = new Drillbit(fixture.config(),
+             fixtureBuilder.configBuilder().getDefinitions(), 
fixture.serviceSet())) {
+      // Assert preconditions :
+      //      1. First drillbit instance should be started normally
+      //      2. Second instance startup should fail, because ports are 
occupied by the first one
+      assertNotNull("First drillbit instance should be initialized", 
fixture.drillbit());
       try {
         drillbitWithSamePort.run();
-        fail("drillbitWithSamePort.run() should throw UserException");
+        fail("Invocation of 'drillbitWithSamePort.run()' should throw 
UserException");
       } catch (UserException e) {
-        // it's expected that second drillbit can't be started because port is 
busy
         assertThat(e.getMessage(), containsString("RESOURCE ERROR: Drillbit 
could not bind to port"));
+        // Ensure that drillbit with failed startup may be safely closed
+        assertNotNull("Drillbit.gracefulShutdownThread shouldn't be null, 
otherwise close() may throw NPE (if so, check suppressed exception).",
+            drillbitWithSamePort.getGracefulShutdownThread());
       }
-    } finally {
-      // preconditions
-      assertNotNull(drillbit);
-      assertNotNull(drillbitWithSamePort);
-      assertNotNull("gracefulShutdownThread should be initialized, otherwise 
NPE will be thrown from close()",
-          drillbit.getGracefulShutdownThread());
-      // main test case
-      assertNotNull("gracefulShutdownThread should be initialized, otherwise 
NPE will be thrown from close()",
-          drillbitWithSamePort.getGracefulShutdownThread());
-      drillbit.close();
-      drillbitWithSamePort.close();
     }
   }
 
@@ -245,4 +234,5 @@ public class TestGracefulShutdown extends BaseTestQuery {
       fail(e.getMessage());
     }
   }
+
 }

Reply via email to