diff options
author | Igor Guzenko <ihor.huzenko.igs@gmail.com> | 2018-12-28 21:04:42 +0200 |
---|---|---|
committer | Gautam Parai <gparai@apache.org> | 2019-01-03 16:35:30 -0800 |
commit | d96bea54b96b01ffe9bb19c76bfc158784f26ffc (patch) | |
tree | f2d3865d7d2678657b3c00259b41353a9b98ea59 | |
parent | 8a56fe6002451b26a21c776a8f9882a5b1b48243 (diff) |
DRILL-6936: TestGracefulShutdown.gracefulShutdownThreadShouldBeInitializedBeforeClosingDrillbit fails if loopback address is set in hosts
closes #1589
-rw-r--r-- | exec/java-exec/src/test/java/org/apache/drill/test/TestGracefulShutdown.java | 46 |
1 files 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 94180e2cb..a433237c5 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()); } } + } |