Skip to content

Commit 1e63f86

Browse files
committed
Refactor integration tests
Launching nodes are now controlled by the test case as we need a fine control here. Add a test for minimum_master_nodes. Related to #15.
1 parent 4a353ba commit 1e63f86

File tree

7 files changed

+134
-36
lines changed

7 files changed

+134
-36
lines changed

pom.xml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ governing permissions and limitations under the License. -->
4646
<elasticsearch.version>1.2.1</elasticsearch.version>
4747
<lucene.version>4.8.1</lucene.version>
4848
<tests.output>onerror</tests.output>
49-
<tests.jvms>1</tests.jvms>
5049
<tests.shuffle>true</tests.shuffle>
5150
<tests.output>onerror</tests.output>
5251
<tests.client.ratio></tests.client.ratio>
@@ -56,6 +55,18 @@ governing permissions and limitations under the License. -->
5655
</properties>
5756

5857
<dependencies>
58+
<dependency>
59+
<groupId>org.hamcrest</groupId>
60+
<artifactId>hamcrest-core</artifactId>
61+
<version>1.3.RC2</version>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.hamcrest</groupId>
66+
<artifactId>hamcrest-library</artifactId>
67+
<version>1.3.RC2</version>
68+
<scope>test</scope>
69+
</dependency>
5970
<dependency>
6071
<groupId>org.apache.lucene</groupId>
6172
<artifactId>lucene-test-framework</artifactId>
@@ -86,18 +97,6 @@ governing permissions and limitations under the License. -->
8697
<type>test-jar</type>
8798
<scope>test</scope>
8899
</dependency>
89-
<dependency>
90-
<groupId>org.hamcrest</groupId>
91-
<artifactId>hamcrest-core</artifactId>
92-
<version>1.3.RC2</version>
93-
<scope>test</scope>
94-
</dependency>
95-
<dependency>
96-
<groupId>org.hamcrest</groupId>
97-
<artifactId>hamcrest-library</artifactId>
98-
<version>1.3.RC2</version>
99-
<scope>test</scope>
100-
</dependency>
101100
</dependencies>
102101

103102
<build>
@@ -157,7 +156,7 @@ governing permissions and limitations under the License. -->
157156
<assertions>
158157
<enable/>
159158
</assertions>
160-
<parallelism>${tests.jvms}</parallelism>
159+
<parallelism>1</parallelism>
161160
<balancers>
162161
<execution-times>
163162
<fileset dir="${basedir}" includes=".local-execution-hints.log"/>
@@ -204,8 +203,6 @@ governing permissions and limitations under the License. -->
204203
<tests.integration>${tests.integration}</tests.integration>
205204
<tests.cluster_seed>${tests.cluster_seed}</tests.cluster_seed>
206205
<tests.client.ratio>${tests.client.ratio}</tests.client.ratio>
207-
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
208-
<es.node.mode>${es.node.mode}</es.node.mode>
209206
<es.config>${es.config}</es.config>
210207
<es.logger.level>${es.logger.level}</es.logger.level>
211208
<java.awt.headless>true</java.awt.headless>

src/main/java/org/elasticsearch/discovery/azure/AzureUnicastHostsProvider.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.elasticsearch.common.transport.TransportAddress;
3333
import org.elasticsearch.common.unit.TimeValue;
3434
import org.elasticsearch.discovery.zen.ping.unicast.UnicastHostsProvider;
35-
import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing;
3635
import org.elasticsearch.transport.TransportService;
3736

3837
import java.io.IOException;
@@ -139,10 +138,8 @@ public List<DiscoveryNode> buildDynamicNodes() {
139138
} else {
140139
TransportAddress[] addresses = transportService.addressesFromString(networkAddress);
141140
// we only limit to 1 addresses, makes no sense to ping 100 ports
142-
for (int i = 0; (i < addresses.length && i < UnicastZenPing.LIMIT_PORTS_COUNT); i++) {
143-
logger.trace("adding {}, transport_address {}", networkAddress, addresses[i]);
144-
cachedDiscoNodes.add(new DiscoveryNode("#cloud-" + instance.getName() + "-" + i, addresses[i], Version.CURRENT));
145-
}
141+
logger.trace("adding {}, transport_address {}", networkAddress, addresses[0]);
142+
cachedDiscoNodes.add(new DiscoveryNode("#cloud-" + instance.getName(), addresses[0], Version.CURRENT));
146143
}
147144

148145
}

src/test/java/org/elasticsearch/azure/itest/AzureSimpleITest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
@ElasticsearchIntegrationTest.ClusterScope(
3737
scope = ElasticsearchIntegrationTest.Scope.TEST,
3838
numDataNodes = 1,
39+
numClientNodes = 0,
3940
transportClientRatio = 0.0)
4041
public class AzureSimpleITest extends AbstractAzureTest {
4142

src/test/java/org/elasticsearch/discovery/azure/AbstractAzureComputeServiceTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,22 @@ protected void checkNumberOfNodes(int expected) {
4141
assertEquals(expected, nodeInfos.getNodes().length);
4242
}
4343

44-
@Override
45-
protected Settings nodeSettings(int nodeOrdinal) {
44+
protected Settings settingsBuilder() {
4645
ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
46+
.put("discovery.type", "azure")
4747
.put("cloud.azure.api.impl", mock)
4848
// We add a fake subscription_id to start mock compute service
4949
.put("cloud.azure.subscription_id", "fake")
50-
.put("cloud.azure.refresh_interval", "5s");
51-
builder.put(super.nodeSettings(nodeOrdinal));
50+
.put("cloud.azure.refresh_interval", "5s")
51+
.put("cloud.azure.keystore", "dummy")
52+
.put("cloud.azure.password", "dummy")
53+
.put("cloud.azure.service_name", "dummy")
54+
.put("cloud.azure.refresh_interval", "5s")
55+
// Make the tests run faster
56+
.put("discovery.zen.join.timeout", "100ms")
57+
.put("discovery.zen.ping.timeout", "10ms")
58+
.put("discovery.initial_state_timeout", "300ms");
59+
5260
return builder.build();
5361
}
5462
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.discovery.azure;
21+
22+
import org.elasticsearch.common.settings.ImmutableSettings;
23+
import org.elasticsearch.common.settings.Settings;
24+
import org.elasticsearch.discovery.MasterNotDiscoveredException;
25+
import org.elasticsearch.test.ElasticsearchIntegrationTest;
26+
import org.junit.Test;
27+
28+
import static org.hamcrest.Matchers.notNullValue;
29+
import static org.hamcrest.Matchers.nullValue;
30+
31+
/**
32+
* Reported issue in #15
33+
* (https://github.com/elasticsearch/elasticsearch-cloud-azure/issues/15)
34+
*/
35+
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST,
36+
numDataNodes = 0,
37+
transportClientRatio = 0.0,
38+
numClientNodes = 0)
39+
public class AzureMinimumMasterNodesTest extends AbstractAzureComputeServiceTest {
40+
41+
public AzureMinimumMasterNodesTest() {
42+
super(AzureComputeServiceTwoNodesMock.class);
43+
}
44+
45+
@Override
46+
protected final Settings settingsBuilder() {
47+
ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
48+
.put("discovery.zen.minimum_master_nodes", 2)
49+
.put(super.settingsBuilder());
50+
return builder.build();
51+
}
52+
53+
@Test
54+
public void simpleOnlyMasterNodeElection() {
55+
logger.info("--> start data node / non master node");
56+
cluster().startNode(settingsBuilder());
57+
try {
58+
assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("100ms").execute().actionGet().getState().nodes().masterNodeId(), nullValue());
59+
fail("should not be able to find master");
60+
} catch (MasterNotDiscoveredException e) {
61+
// all is well, no master elected
62+
}
63+
logger.info("--> start another node");
64+
cluster().startNode(settingsBuilder());
65+
assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("1s").execute().actionGet().getState().nodes().masterNodeId(), notNullValue());
66+
67+
logger.info("--> stop master node");
68+
cluster().stopCurrentMasterNode();
69+
70+
try {
71+
assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("1s").execute().actionGet().getState().nodes().masterNodeId(), nullValue());
72+
fail("should not be able to find master");
73+
} catch (MasterNotDiscoveredException e) {
74+
// all is well, no master elected
75+
}
76+
77+
logger.info("--> start another node");
78+
cluster().startNode(settingsBuilder());
79+
assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("1s").execute().actionGet().getState().nodes().masterNodeId(), notNullValue());
80+
}
81+
}

src/test/java/org/elasticsearch/discovery/azure/AzureSimpleTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import org.elasticsearch.test.ElasticsearchIntegrationTest;
2323
import org.junit.Test;
2424

25-
@ElasticsearchIntegrationTest.ClusterScope(
26-
scope = ElasticsearchIntegrationTest.Scope.TEST,
27-
numDataNodes = 1,
28-
transportClientRatio = 0.0)
25+
import static org.hamcrest.Matchers.notNullValue;
26+
27+
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST,
28+
numDataNodes = 0,
29+
transportClientRatio = 0.0,
30+
numClientNodes = 0)
2931
public class AzureSimpleTest extends AbstractAzureComputeServiceTest {
3032

3133
public AzureSimpleTest() {
@@ -34,9 +36,11 @@ public AzureSimpleTest() {
3436

3537
@Test
3638
public void one_node_should_run() {
37-
// We expect having 2 nodes as part of the cluster, let's test that
38-
checkNumberOfNodes(1);
39-
39+
logger.info("--> start one node");
40+
cluster().startNode(settingsBuilder());
41+
assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("1s").execute().actionGet().getState().nodes().masterNodeId(), notNullValue());
4042

43+
// We expect having 1 node as part of the cluster, let's test that
44+
checkNumberOfNodes(1);
4145
}
4246
}

src/test/java/org/elasticsearch/discovery/azure/AzureTwoStartedNodesTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import org.elasticsearch.test.ElasticsearchIntegrationTest;
2323
import org.junit.Test;
2424

25-
@ElasticsearchIntegrationTest.ClusterScope(
26-
scope = ElasticsearchIntegrationTest.Scope.TEST,
27-
numDataNodes = 2,
28-
transportClientRatio = 0.0)
25+
import static org.hamcrest.Matchers.notNullValue;
26+
27+
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST,
28+
numDataNodes = 0,
29+
transportClientRatio = 0.0,
30+
numClientNodes = 0)
2931
public class AzureTwoStartedNodesTest extends AbstractAzureComputeServiceTest {
3032

3133
public AzureTwoStartedNodesTest() {
@@ -34,6 +36,14 @@ public AzureTwoStartedNodesTest() {
3436

3537
@Test
3638
public void two_nodes_should_run() {
39+
logger.info("--> start first node");
40+
cluster().startNode(settingsBuilder());
41+
assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("1s").execute().actionGet().getState().nodes().masterNodeId(), notNullValue());
42+
43+
logger.info("--> start another node");
44+
cluster().startNode(settingsBuilder());
45+
assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("1s").execute().actionGet().getState().nodes().masterNodeId(), notNullValue());
46+
3747
// We expect having 2 nodes as part of the cluster, let's test that
3848
checkNumberOfNodes(2);
3949
}

0 commit comments

Comments
 (0)