aboutsummaryrefslogtreecommitdiff
path: root/exec/java-exec/src/test/java/org/apache/drill/test/TestGracefulShutdown.java
diff options
context:
space:
mode:
Diffstat (limited to 'exec/java-exec/src/test/java/org/apache/drill/test/TestGracefulShutdown.java')
-rw-r--r--exec/java-exec/src/test/java/org/apache/drill/test/TestGracefulShutdown.java42
1 files changed, 42 insertions, 0 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 a433237c5..d74f1e691 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
@@ -17,11 +17,13 @@
*/
package org.apache.drill.test;
+import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.drill.categories.SlowTest;
import org.apache.drill.common.exceptions.UserException;
import org.apache.drill.exec.ExecConstants;
import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.server.rest.WebServer;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -30,17 +32,21 @@ import org.junit.experimental.categories.Category;
import org.junit.rules.TestRule;
import java.io.BufferedWriter;
+import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
+import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Path;
import java.util.Collection;
import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@Category({SlowTest.class})
@@ -205,6 +211,42 @@ public class TestGracefulShutdown extends BaseTestQuery {
}
}
+ @Test // DRILL-7056
+ public void testDrillbitTempDir() throws Exception {
+ File originalDrillbitTempDir = null;
+ ClusterFixtureBuilder fixtureBuilder = ClusterFixture.bareBuilder(dirTestWatcher).withLocalZk()
+ .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 twinDrillbitOnSamePort = 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
+ Drillbit originalDrillbit = fixture.drillbit();
+ assertNotNull("First drillbit instance should be initialized", originalDrillbit);
+ originalDrillbitTempDir = getWebServerTempDirPath(originalDrillbit);
+ assertTrue("First drillbit instance should have a temporary Javascript dir initialized", originalDrillbitTempDir.exists());
+ try {
+ twinDrillbitOnSamePort.run();
+ fail("Invocation of 'twinDrillbitOnSamePort.run()' should throw UserException");
+ } catch (UserException userEx) {
+ assertThat(userEx.getMessage(), containsString("RESOURCE ERROR: Drillbit could not bind to port"));
+ }
+ }
+ // Verify deletion
+ assertFalse("First drillbit instance should have a temporary Javascript dir deleted", originalDrillbitTempDir.exists());
+ }
+
+ private static File getWebServerTempDirPath(Drillbit drillbit) throws IllegalAccessException {
+ Field webServerField = FieldUtils.getField(drillbit.getClass(), "webServer", true);
+ WebServer webServerHandle = (WebServer) FieldUtils.readField(webServerField, drillbit, true);
+ File webServerTempDirPath = webServerHandle.getOrCreateTmpJavaScriptDir();
+ return webServerTempDirPath;
+ }
+
private static boolean waitAndAssertDrillbitCount(ClusterFixture cluster, int zkRefresh) throws InterruptedException {
while (true) {