();
-
- File dataDir = new File("./target/es/data");
- if(dataDir.exists()) {
- FileSystemUtils.deleteRecursively(dataDir, true);
- }
- }
-
- @After
- public void tearDown() {
- // Cleaning nodes after test
- for (Node node : nodes) {
- node.close();
- }
- }
-
- protected Client getTransportClient() {
- // Create a TransportClient on node 1 and 2
- Settings settings = ImmutableSettings.settingsBuilder()
- .put("cluster.name", "azure")
- .put("transport.tcp.connect_timeout", "1s")
- .build();
-
- TransportClient client = new TransportClient(settings);
-
- for (Node node : nodes) {
- NettyTransport nettyTransport = ((InternalNode) node).injector().getInstance(NettyTransport.class);
- TransportAddress transportAddress = nettyTransport.boundAddress().publishAddress();
- client.addTransportAddress(transportAddress);
- }
-
- return client;
- }
-
- protected Client getNodeClient() {
- for (Node node : nodes) {
- return node.client();
- }
-
- return null;
- }
-
- protected void checkNumberOfNodes(int expected, boolean fail) {
- NodesInfoResponse nodeInfos = null;
-
- try {
- nodeInfos = getTransportClient().admin().cluster().prepareNodesInfo().execute().actionGet();
- } catch (NoNodeAvailableException e) {
- // If we can't build a Transport Client, we are may be not connected to any network
- // Let's try a Node Client
- nodeInfos = getNodeClient().admin().cluster().prepareNodesInfo().execute().actionGet();
- }
-
- Assert.assertNotNull(nodeInfos);
- Assert.assertNotNull(nodeInfos.getNodes());
-
- if (fail) {
- Assert.assertEquals(expected, nodeInfos.getNodes().length);
- } else {
- if (nodeInfos.getNodes().length != expected) {
- logger.warn("expected {} node(s) but found {}. Could be due to no local IP address available.",
- expected, nodeInfos.getNodes().length);
- }
- }
- }
-
- protected void checkNumberOfNodes(int expected) {
- checkNumberOfNodes(expected, true);
- }
-
- protected void nodeBuilder() {
- ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
- //.put("gateway.type", "local")
- .put("path.data", "./target/es/data")
- .put("path.logs", "./target/es/logs")
- .put("path.work", "./target/es/work")
-// .put("discovery.zen.ping.timeout", "500ms")
-// .put("discovery.zen.fd.ping_retries",1)
-// .put("discovery.zen.fd.ping_timeout", "500ms")
-// .put("discovery.initial_state_timeout", "5s")
-// .put("transport.tcp.connect_timeout", "1s")
- .put("cloud.azure.api.impl", mock)
- .put("cloud.azure.refresh_interval", "5s")
- .put("node.name", (nodes.size()+1) + "#" + mock.getSimpleName());
- Node node = NodeBuilder.nodeBuilder().settings(builder).node();
- nodes.add(node);
- }
-}
diff --git a/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureTest.java b/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureTest.java
new file mode 100644
index 0000000000000..58c69ebba7636
--- /dev/null
+++ b/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to Elasticsearch (the "Author") under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. Author licenses this
+ * file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.elasticsearch.cloud.azure;
+
+import com.carrotsearch.randomizedtesting.annotations.TestGroup;
+import org.elasticsearch.test.ElasticsearchIntegrationTest;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ *
+ */
+public abstract class AbstractAzureTest extends ElasticsearchIntegrationTest {
+
+ /**
+ * Annotation for tests that require Azure to run. Azure tests are disabled by default.
+ *
+ * To enable test add -Dtests.azure=true -Des.config=/path/to/elasticsearch.yml
+ *
+ * The elasticsearch.yml file should contain the following keys
+ *
+ cloud:
+ azure:
+ keystore: FULLPATH-TO-YOUR-KEYSTORE
+ password: YOUR-PASSWORD
+ subscription_id: YOUR-AZURE-SUBSCRIPTION-ID
+ service_name: YOUR-AZURE-SERVICE-NAME
+
+ discovery:
+ type: azure
+ *
+ */
+ @Documented
+ @Inherited
+ @Retention(RetentionPolicy.RUNTIME)
+ @TestGroup(enabled = false, sysProperty = SYSPROP_AZURE)
+ public @interface AzureTest {
+ }
+
+ /**
+ */
+ public static final String SYSPROP_AZURE = "tests.azure";
+
+}
diff --git a/src/test/java/org/elasticsearch/discovery/azure/AbstractAzureComputeServiceTest.java b/src/test/java/org/elasticsearch/discovery/azure/AbstractAzureComputeServiceTest.java
new file mode 100644
index 0000000000000..c6586dfe1fc5a
--- /dev/null
+++ b/src/test/java/org/elasticsearch/discovery/azure/AbstractAzureComputeServiceTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to ElasticSearch under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. ElasticSearch licenses this
+ * file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.elasticsearch.discovery.azure;
+
+import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
+import org.elasticsearch.cloud.azure.AbstractAzureTest;
+import org.elasticsearch.cloud.azure.AzureComputeService;
+import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.settings.Settings;
+
+public abstract class AbstractAzureComputeServiceTest extends AbstractAzureTest {
+
+ private Class extends AzureComputeService> mock;
+
+ public AbstractAzureComputeServiceTest(Class extends AzureComputeService> mock) {
+ // We want to inject the Azure API Mock
+ this.mock = mock;
+ }
+
+ protected void checkNumberOfNodes(int expected) {
+ NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().execute().actionGet();
+ assertNotNull(nodeInfos);
+ assertNotNull(nodeInfos.getNodes());
+ assertEquals(expected, nodeInfos.getNodes().length);
+ }
+
+ @Override
+ protected Settings nodeSettings(int nodeOrdinal) {
+ ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
+ .put("cloud.azure.api.impl", mock)
+ // We add a fake subscription_id to start mock compute service
+ .put("cloud.azure.subscription_id", "fake")
+ .put("cloud.azure.refresh_interval", "5s");
+
+ return builder.build();
+ }
+}
diff --git a/src/test/java/org/elasticsearch/azure/test/AzureComputeServiceAbstractMock.java b/src/test/java/org/elasticsearch/discovery/azure/AzureComputeServiceAbstractMock.java
similarity index 92%
rename from src/test/java/org/elasticsearch/azure/test/AzureComputeServiceAbstractMock.java
rename to src/test/java/org/elasticsearch/discovery/azure/AzureComputeServiceAbstractMock.java
index b04524fec989c..142923f58534e 100644
--- a/src/test/java/org/elasticsearch/azure/test/AzureComputeServiceAbstractMock.java
+++ b/src/test/java/org/elasticsearch/discovery/azure/AzureComputeServiceAbstractMock.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.elasticsearch.azure.test;
+package org.elasticsearch.discovery.azure;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.cloud.azure.AzureComputeService;
@@ -32,6 +32,7 @@ public abstract class AzureComputeServiceAbstractMock extends AbstractLifecycleC
protected AzureComputeServiceAbstractMock(Settings settings) {
super(settings);
+ logger.debug("starting Azure Mock [{}]", this.getClass().getSimpleName());
}
@Override
diff --git a/src/test/java/org/elasticsearch/azure/test/AzureComputeServiceSimpleMock.java b/src/test/java/org/elasticsearch/discovery/azure/AzureComputeServiceSimpleMock.java
similarity index 94%
rename from src/test/java/org/elasticsearch/azure/test/AzureComputeServiceSimpleMock.java
rename to src/test/java/org/elasticsearch/discovery/azure/AzureComputeServiceSimpleMock.java
index f3cac7a940f89..c1b79e39c4b68 100644
--- a/src/test/java/org/elasticsearch/azure/test/AzureComputeServiceSimpleMock.java
+++ b/src/test/java/org/elasticsearch/discovery/azure/AzureComputeServiceSimpleMock.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.elasticsearch.azure.test;
+package org.elasticsearch.discovery.azure;
import org.elasticsearch.cloud.azure.Instance;
import org.elasticsearch.common.inject.Inject;
@@ -34,7 +34,6 @@ public class AzureComputeServiceSimpleMock extends AzureComputeServiceAbstractMo
@Inject
protected AzureComputeServiceSimpleMock(Settings settings) {
super(settings);
- logger.debug("starting Azure Mock");
}
@Override
diff --git a/src/test/java/org/elasticsearch/azure/test/AzureComputeServiceTwoNodesMock.java b/src/test/java/org/elasticsearch/discovery/azure/AzureComputeServiceTwoNodesMock.java
similarity index 95%
rename from src/test/java/org/elasticsearch/azure/test/AzureComputeServiceTwoNodesMock.java
rename to src/test/java/org/elasticsearch/discovery/azure/AzureComputeServiceTwoNodesMock.java
index d94efc13f5435..8a60528846ac3 100644
--- a/src/test/java/org/elasticsearch/azure/test/AzureComputeServiceTwoNodesMock.java
+++ b/src/test/java/org/elasticsearch/discovery/azure/AzureComputeServiceTwoNodesMock.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.elasticsearch.azure.test;
+package org.elasticsearch.discovery.azure;
import org.elasticsearch.cloud.azure.Instance;
import org.elasticsearch.common.inject.Inject;
@@ -34,7 +34,6 @@ public class AzureComputeServiceTwoNodesMock extends AzureComputeServiceAbstract
@Inject
protected AzureComputeServiceTwoNodesMock(Settings settings) {
super(settings);
- logger.debug("starting Azure Mock");
}
@Override
diff --git a/src/test/java/org/elasticsearch/azure/test/AzureInstanceXmlParserTest.java b/src/test/java/org/elasticsearch/discovery/azure/AzureInstanceXmlParserTest.java
similarity index 98%
rename from src/test/java/org/elasticsearch/azure/test/AzureInstanceXmlParserTest.java
rename to src/test/java/org/elasticsearch/discovery/azure/AzureInstanceXmlParserTest.java
index d99e3edc74b41..dfe358d3254ea 100644
--- a/src/test/java/org/elasticsearch/azure/test/AzureInstanceXmlParserTest.java
+++ b/src/test/java/org/elasticsearch/discovery/azure/AzureInstanceXmlParserTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.elasticsearch.azure.test;
+package org.elasticsearch.discovery.azure;
import org.elasticsearch.cloud.azure.AzureComputeServiceImpl;
import org.elasticsearch.cloud.azure.Instance;
diff --git a/src/test/java/org/elasticsearch/azure/test/AzureSimpleTest.java b/src/test/java/org/elasticsearch/discovery/azure/AzureSimpleTest.java
similarity index 76%
rename from src/test/java/org/elasticsearch/azure/test/AzureSimpleTest.java
rename to src/test/java/org/elasticsearch/discovery/azure/AzureSimpleTest.java
index 2fee19dac90ef..6bd7130300db1 100644
--- a/src/test/java/org/elasticsearch/azure/test/AzureSimpleTest.java
+++ b/src/test/java/org/elasticsearch/discovery/azure/AzureSimpleTest.java
@@ -16,11 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.elasticsearch.azure.test;
+package org.elasticsearch.discovery.azure;
+import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Test;
-public class AzureSimpleTest extends AzureAbstractTest {
+@ElasticsearchIntegrationTest.ClusterScope(
+ scope = ElasticsearchIntegrationTest.Scope.TEST,
+ numNodes = 1,
+ transportClientRatio = 0.0)
+public class AzureSimpleTest extends AbstractAzureComputeServiceTest {
public AzureSimpleTest() {
super(AzureComputeServiceSimpleMock.class);
@@ -28,10 +33,9 @@ public AzureSimpleTest() {
@Test
public void one_node_should_run() {
- // Then we start our node for tests
- nodeBuilder();
-
// We expect having 2 nodes as part of the cluster, let's test that
checkNumberOfNodes(1);
+
+
}
}
diff --git a/src/test/java/org/elasticsearch/azure/test/AzureTwoStartedNodesTest.java b/src/test/java/org/elasticsearch/discovery/azure/AzureTwoStartedNodesTest.java
similarity index 73%
rename from src/test/java/org/elasticsearch/azure/test/AzureTwoStartedNodesTest.java
rename to src/test/java/org/elasticsearch/discovery/azure/AzureTwoStartedNodesTest.java
index ae1e3ac8febdf..a806f5e63cd13 100644
--- a/src/test/java/org/elasticsearch/azure/test/AzureTwoStartedNodesTest.java
+++ b/src/test/java/org/elasticsearch/discovery/azure/AzureTwoStartedNodesTest.java
@@ -16,11 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.elasticsearch.azure.test;
+package org.elasticsearch.discovery.azure;
+import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Test;
-public class AzureTwoStartedNodesTest extends AzureAbstractTest {
+@ElasticsearchIntegrationTest.ClusterScope(
+ scope = ElasticsearchIntegrationTest.Scope.TEST,
+ numNodes = 2,
+ transportClientRatio = 0.0)
+public class AzureTwoStartedNodesTest extends AbstractAzureComputeServiceTest {
public AzureTwoStartedNodesTest() {
super(AzureComputeServiceTwoNodesMock.class);
@@ -28,11 +33,7 @@ public AzureTwoStartedNodesTest() {
@Test
public void two_nodes_should_run() {
- // Then we start our node for tests
- nodeBuilder();
- nodeBuilder();
-
// We expect having 2 nodes as part of the cluster, let's test that
- checkNumberOfNodes(2, false);
+ checkNumberOfNodes(2);
}
}
diff --git a/src/test/resources/elasticsearch.yml b/src/test/resources/elasticsearch.yml
index 82583a481cb5e..07536b8c77b7c 100644
--- a/src/test/resources/elasticsearch.yml
+++ b/src/test/resources/elasticsearch.yml
@@ -8,9 +8,7 @@
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
-
- cluster.name: azure
-
+#
# Azure discovery allows to use Azure API in order to perform discovery.
#
# You have to install the cloud-azure plugin for enabling the Azure discovery.
@@ -18,13 +16,15 @@
# See
# for more information.
#
-# See
+# See
# for a step-by-step tutorial.
- cloud:
- azure:
- keystore: FULLPATH-TO-YOUR-KEYSTORE
- password: YOUR-PASSWORD
- subscription_id: YOUR-AZURE-SUBSCRIPTION-ID
- service_name: YOUR-AZURE-SERVICE-NAME
- discovery:
- type: azure
+#
+# cloud:
+# azure:
+# keystore: FULLPATH-TO-YOUR-KEYSTORE
+# password: YOUR-PASSWORD
+# subscription_id: YOUR-AZURE-SUBSCRIPTION-ID
+# service_name: YOUR-AZURE-SERVICE-NAME
+#
+# discovery:
+# type: azure