You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ar...@apache.org on 2018/03/03 18:47:13 UTC

[07/17] drill git commit: DRILL-6198: OpenTSDB unit tests fail when Lilith client is running

DRILL-6198: OpenTSDB unit tests fail when Lilith client is running

closes #1142


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/4bd3cc29
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/4bd3cc29
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/4bd3cc29

Branch: refs/heads/master
Commit: 4bd3cc2995ab7bd94ca5f5a8838b0d02fb396c3e
Parents: 57e5ab2
Author: Volodymyr Vysotskyi <vv...@gmail.com>
Authored: Thu Mar 1 14:52:28 2018 +0200
Committer: Arina Ielchiieva <ar...@gmail.com>
Committed: Sat Mar 3 19:47:41 2018 +0200

----------------------------------------------------------------------
 .../store/openTSDB/TestOpenTSDBPlugin.java      | 41 +++++++++++++++++---
 1 file changed, 35 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/4bd3cc29/contrib/storage-opentsdb/src/test/java/org/apache/drill/store/openTSDB/TestOpenTSDBPlugin.java
----------------------------------------------------------------------
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 27ca09c..0c1fb5e 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
@@ -21,13 +21,18 @@ import com.github.tomakehurst.wiremock.junit.WireMockRule;
 import org.apache.drill.PlanTestBase;
 import org.apache.drill.common.exceptions.UserRemoteException;
 import org.apache.drill.exec.store.StoragePluginRegistry;
-import org.apache.drill.exec.store.openTSDB.OpenTSDBStoragePlugin;
 import org.apache.drill.exec.store.openTSDB.OpenTSDBStoragePluginConfig;
 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;
@@ -50,18 +55,19 @@ import static org.apache.drill.store.openTSDB.TestDataHolder.SAMPLE_DATA_FOR_POS
 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);
 
-  protected static OpenTSDBStoragePlugin storagePlugin;
-  protected static OpenTSDBStoragePluginConfig storagePluginConfig;
+  private static int portNumber;
 
   @Rule
-  public WireMockRule wireMockRule = new WireMockRule(10000);
+  public WireMockRule wireMockRule = new WireMockRule(portNumber);
 
   @BeforeClass
   public static void setup() throws Exception {
+    portNumber = getFreePortNumber(10_000, 200);
     final StoragePluginRegistry pluginRegistry = getDrillbitContext().getStorage();
-    storagePlugin = (OpenTSDBStoragePlugin) pluginRegistry.getPlugin(OpenTSDBStoragePluginConfig.NAME);
-    storagePluginConfig = storagePlugin.getConfig();
+    OpenTSDBStoragePluginConfig storagePluginConfig =
+        new OpenTSDBStoragePluginConfig(String.format("http://localhost:%s", portNumber));
     storagePluginConfig.setEnabled(true);
     pluginRegistry.createOrUpdate(OpenTSDBStoragePluginConfig.NAME, storagePluginConfig, true);
   }
@@ -185,4 +191,27 @@ public class TestOpenTSDBPlugin extends PlanTestBase {
     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));
+  }
 }