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 2018/12/21 17:59:46 UTC

[GitHub] arina-ielchiieva closed pull request #1581: DRILL-6919: Fix compilation error in TestGracefulShutdown class for mapr profile

arina-ielchiieva closed pull request #1581: DRILL-6919: Fix compilation error in TestGracefulShutdown class for mapr profile
URL: https://github.com/apache/drill/pull/1581
 
 
   

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/contrib/storage-opentsdb/src/test/java/org/apache/drill/store/openTSDB/TestOpenTSDBPlugin.java b/contrib/storage-opentsdb/src/test/java/org/apache/drill/store/openTSDB/TestOpenTSDBPlugin.java
index 0c1fb5ef5ab..bcff4d6029d 100644
--- a/contrib/storage-opentsdb/src/test/java/org/apache/drill/store/openTSDB/TestOpenTSDBPlugin.java
+++ b/contrib/storage-opentsdb/src/test/java/org/apache/drill/store/openTSDB/TestOpenTSDBPlugin.java
@@ -22,17 +22,12 @@
 import org.apache.drill.common.exceptions.UserRemoteException;
 import org.apache.drill.exec.store.StoragePluginRegistry;
 import org.apache.drill.exec.store.openTSDB.OpenTSDBStoragePluginConfig;
+import org.apache.drill.test.QueryTestUtil;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.net.BindException;
-import java.net.ServerSocket;
 
 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
 import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
@@ -55,7 +50,6 @@
 import static org.apache.drill.store.openTSDB.TestDataHolder.SAMPLE_DATA_FOR_POST_REQUEST_WITH_TAGS;
 
 public class TestOpenTSDBPlugin extends PlanTestBase {
-  private static final Logger logger = LoggerFactory.getLogger(TestOpenTSDBPlugin.class);
 
   private static int portNumber;
 
@@ -64,7 +58,7 @@
 
   @BeforeClass
   public static void setup() throws Exception {
-    portNumber = getFreePortNumber(10_000, 200);
+    portNumber = QueryTestUtil.getFreePortNumber(10_000, 200);
     final StoragePluginRegistry pluginRegistry = getDrillbitContext().getStorage();
     OpenTSDBStoragePluginConfig storagePluginConfig =
         new OpenTSDBStoragePluginConfig(String.format("http://localhost:%s", portNumber));
@@ -191,27 +185,4 @@ public void testDescribe() throws Exception {
     test("describe `warp.speed.test`");
     Assert.assertEquals(1, testSql("show tables"));
   }
-
-  /**
-   * Checks that port with specified number is free and returns it.
-   * Otherwise, increases port number and checks until free port is found
-   * or the number of attempts is reached specified numberOfAttempts
-   *
-   * @param portNumber     initial port number
-   * @param numberOfAttempts max number of attempts to find port with greater number
-   * @return free port number
-   * @throws BindException if free port was not found and all attempts were used.
-   */
-  private static int getFreePortNumber(int portNumber, int numberOfAttempts) throws IOException {
-    for (int i = portNumber; i <= portNumber + numberOfAttempts; i++) {
-      try (ServerSocket socket = new ServerSocket(i)) {
-        return socket.getLocalPort();
-      } catch (BindException e) {
-        logger.warn("Port {} is already in use.", i);
-      }
-    }
-
-    throw new BindException(String.format("Free port could not be found in the range [%s-%s].\n" +
-        "Please release any of used ports in this range.", portNumber, portNumber + numberOfAttempts));
-  }
 }
diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/QueryTestUtil.java b/exec/java-exec/src/test/java/org/apache/drill/test/QueryTestUtil.java
index 2c89694aa51..79ac60610c4 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/test/QueryTestUtil.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/test/QueryTestUtil.java
@@ -17,6 +17,9 @@
  */
 package org.apache.drill.test;
 
+import java.io.IOException;
+import java.net.BindException;
+import java.net.ServerSocket;
 import java.util.List;
 import java.util.Properties;
 import java.util.regex.Matcher;
@@ -41,11 +44,15 @@
 import org.apache.drill.exec.server.options.OptionValue;
 import org.apache.drill.exec.server.options.SystemOptionManager;
 import org.apache.drill.exec.util.VectorUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Utilities useful for tests that issue SQL queries.
  */
 public class QueryTestUtil {
+  private static final Logger logger = LoggerFactory.getLogger(QueryTestUtil.class);
+
   /**
    * Constructor. All methods are static.
    */
@@ -286,4 +293,26 @@ public static void restoreScalarReplacementOption(final Drillbit drillbit, final
     drillbitContext.getCompiler().flushCache();
   }
 
+  /**
+   * Checks that port with specified number is free and returns it.
+   * Otherwise, increases port number and checks until free port is found
+   * or the number of attempts is reached specified numberOfAttempts
+   *
+   * @param portNumber     initial port number
+   * @param numberOfAttempts max number of attempts to find port with greater number
+   * @return free port number
+   * @throws BindException if free port was not found and all attempts were used.
+   */
+  public static int getFreePortNumber(int portNumber, int numberOfAttempts) throws IOException {
+    for (int i = portNumber; i <= portNumber + numberOfAttempts; i++) {
+      try (ServerSocket socket = new ServerSocket(i)) {
+        return socket.getLocalPort();
+      } catch (BindException e) {
+        logger.warn("Port {} is already in use.", i);
+      }
+    }
+
+    throw new BindException(String.format("Free port could not be found in the range [%s-%s].\n" +
+        "Please release any of used ports in this range.", portNumber, portNumber + numberOfAttempts));
+  }
 }
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 9d649ba4521..94180e2cbc3 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
@@ -21,7 +21,6 @@
 import org.apache.drill.exec.ExecConstants;
 import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
 import org.apache.drill.exec.server.Drillbit;
-import org.apache.hadoop.net.ServerSocketUtil;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Rule;
@@ -184,8 +183,8 @@ public void gracefulShutdownThreadShouldBeInitializedBeforeClosingDrillbit() thr
     Drillbit drillbit = null;
     Drillbit drillbitWithSamePort = null;
 
-    int userPort = ServerSocketUtil.getPort(31170, 300);
-    int bitPort = ServerSocketUtil.getPort(31180, 300);
+    int userPort = QueryTestUtil.getFreePortNumber(31170, 300);
+    int bitPort = QueryTestUtil.getFreePortNumber(31180, 300);
     ClusterFixtureBuilder fixtureBuilder = ClusterFixture.bareBuilder(dirTestWatcher).withLocalZk()
         .configProperty(ExecConstants.INITIAL_USER_PORT, userPort)
         .configProperty(ExecConstants.INITIAL_BIT_PORT, bitPort);


 

----------------------------------------------------------------
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