From commits-return-5530-apmail-drill-commits-archive=drill.apache.org@drill.apache.org Sat Mar 3 18:47:08 2018 Return-Path: X-Original-To: apmail-drill-commits-archive@www.apache.org Delivered-To: apmail-drill-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4C75818889 for ; Sat, 3 Mar 2018 18:47:08 +0000 (UTC) Received: (qmail 62672 invoked by uid 500); 3 Mar 2018 18:47:08 -0000 Delivered-To: apmail-drill-commits-archive@drill.apache.org Received: (qmail 62558 invoked by uid 500); 3 Mar 2018 18:47:08 -0000 Mailing-List: contact commits-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: commits@drill.apache.org Delivered-To: mailing list commits@drill.apache.org Received: (qmail 62392 invoked by uid 99); 3 Mar 2018 18:47:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Mar 2018 18:47:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 97F7AF4E05; Sat, 3 Mar 2018 18:47:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: arina@apache.org To: commits@drill.apache.org Date: Sat, 03 Mar 2018 18:47:13 -0000 Message-Id: <34b76696c032450f9c91885d7cffe468@git.apache.org> In-Reply-To: <2e31d07b350c44db856024707f3d6367@git.apache.org> References: <2e31d07b350c44db856024707f3d6367@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Thu Mar 1 14:52:28 2018 +0200 Committer: Arina Ielchiieva 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)); + } }