You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2019/01/04 06:54:06 UTC

[GitHub] gparai closed pull request #1589: DRILL-6936: TestGracefulShutdown.gracefulShutdownThreadShouldBeInitia…

gparai closed pull request #1589: DRILL-6936: TestGracefulShutdown.gracefulShutdownThreadShouldBeInitia…
URL: https://github.com/apache/drill/pull/1589
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 94180e2cbc3..a433237c5db 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 void testRestApiShutdown() throws Exception {
   }
 
   @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 @@ private static void setupFile(int file_num) throws Exception {
       fail(e.getMessage());
     }
   }
+
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services