Skip to content

Commit 9cc331b

Browse files
committed
Move tests to elasticsearch test framework
Closes #46.
1 parent 04f15cd commit 9cc331b

File tree

6 files changed

+223
-28
lines changed

6 files changed

+223
-28
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/.idea
55
/target
66
.DS_Store
7+
.local-execution-hints.log
78
*.iml
89
/.settings
910
/.project

pom.xml

+124-11
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@
3131
</parent>
3232

3333
<properties>
34-
<elasticsearch.version>0.90.4</elasticsearch.version>
34+
<elasticsearch.version>0.90.10</elasticsearch.version>
35+
<lucene.version>4.6.0</lucene.version>
36+
<tests.output>onerror</tests.output>
37+
<tests.jvms>1</tests.jvms>
38+
<tests.shuffle>true</tests.shuffle>
39+
<tests.output>onerror</tests.output>
40+
<tests.client.ratio></tests.client.ratio>
41+
<tests.jvm.argline></tests.jvm.argline>
42+
<es.logger.level>INFO</es.logger.level>
3543
</properties>
3644

3745
<repositories>
@@ -42,13 +50,28 @@
4250
</repositories>
4351

4452
<dependencies>
53+
<dependency>
54+
<groupId>org.apache.lucene</groupId>
55+
<artifactId>lucene-test-framework</artifactId>
56+
<version>${lucene.version}</version>
57+
<scope>test</scope>
58+
</dependency>
59+
4560
<dependency>
4661
<groupId>org.elasticsearch</groupId>
4762
<artifactId>elasticsearch</artifactId>
4863
<version>${elasticsearch.version}</version>
4964
<scope>compile</scope>
5065
</dependency>
5166

67+
<dependency>
68+
<groupId>org.elasticsearch</groupId>
69+
<artifactId>elasticsearch</artifactId>
70+
<version>${elasticsearch.version}</version>
71+
<type>test-jar</type>
72+
<scope>test</scope>
73+
</dependency>
74+
5275
<dependency>
5376
<groupId>com.amazonaws</groupId>
5477
<artifactId>aws-java-sdk</artifactId>
@@ -87,13 +110,6 @@
87110
<version>1.4</version>
88111
</dependency>
89112

90-
<dependency>
91-
<groupId>junit</groupId>
92-
<artifactId>junit</artifactId>
93-
<version>4.11</version>
94-
<scope>test</scope>
95-
</dependency>
96-
97113
<dependency>
98114
<groupId>org.hamcrest</groupId>
99115
<artifactId>hamcrest-core</artifactId>
@@ -107,6 +123,15 @@
107123
<version>1.3.RC2</version>
108124
<scope>test</scope>
109125
</dependency>
126+
127+
<dependency>
128+
<groupId>log4j</groupId>
129+
<artifactId>log4j</artifactId>
130+
<version>1.2.17</version>
131+
<scope>test</scope>
132+
<optional>true</optional>
133+
</dependency>
134+
110135
</dependencies>
111136

112137
<build>
@@ -120,14 +145,102 @@
120145
<target>1.6</target>
121146
</configuration>
122147
</plugin>
148+
<plugin>
149+
<groupId>com.carrotsearch.randomizedtesting</groupId>
150+
<artifactId>junit4-maven-plugin</artifactId>
151+
<version>2.0.14</version>
152+
<executions>
153+
<execution>
154+
<id>tests</id>
155+
<phase>test</phase>
156+
<goals>
157+
<goal>junit4</goal>
158+
</goals>
159+
<configuration>
160+
<heartbeat>20</heartbeat>
161+
<jvmOutputAction>pipe,warn</jvmOutputAction>
162+
<leaveTemporary>true</leaveTemporary>
163+
<listeners>
164+
<report-ant-xml mavenExtensions="true"
165+
dir="${project.build.directory}/surefire-reports"/>
166+
<report-text
167+
showThrowable="true"
168+
showStackTraces="true"
169+
showOutput="${tests.output}"
170+
showStatusOk="false"
171+
showStatusError="true"
172+
showStatusFailure="true"
173+
showStatusIgnored="true"
174+
showSuiteSummary="true"
175+
timestamps="false"/>
176+
<report-execution-times file="${basedir}/.local-execution-hints.log"/>
177+
</listeners>
178+
<assertions>
179+
<enable/>
180+
</assertions>
181+
<parallelism>${tests.jvms}</parallelism>
182+
<balancers>
183+
<execution-times>
184+
<fileset dir="${basedir}" includes=".local-execution-hints.log"/>
185+
</execution-times>
186+
</balancers>
187+
<includes>
188+
<include>**/*Tests.class</include>
189+
<include>**/*Test.class</include>
190+
</includes>
191+
<excludes>
192+
<exclude>**/Abstract*.class</exclude>
193+
<exclude>**/*StressTest.class</exclude>
194+
</excludes>
195+
<argLine>
196+
${tests.jvm.argline}
197+
</argLine>
198+
<jvmArgs>
199+
<param>-Xmx512m</param>
200+
<param>-Xss256k</param>
201+
<param>-XX:MaxDirectMemorySize=512m</param>
202+
<param>-Des.logger.prefix=</param>
203+
</jvmArgs>
204+
<shuffleOnSlave>${tests.shuffle}</shuffleOnSlave>
205+
<sysouts>${tests.verbose}</sysouts>
206+
<seed>${tests.seed}</seed>
207+
<haltOnFailure>${tests.failfast}</haltOnFailure>
208+
<systemProperties>
209+
<!-- RandomizedTesting library system properties -->
210+
<tests.jvm.argline>${tests.jvm.argline}</tests.jvm.argline>
211+
<tests.iters>${tests.iters}</tests.iters>
212+
<tests.maxfailures>${tests.maxfailures}</tests.maxfailures>
213+
<tests.failfast>${tests.failfast}</tests.failfast>
214+
<tests.class>${tests.class}</tests.class>
215+
<tests.method>${tests.method}</tests.method>
216+
<tests.nightly>${tests.nightly}</tests.nightly>
217+
<tests.badapples>${tests.badapples}</tests.badapples>
218+
<tests.weekly>${tests.weekly}</tests.weekly>
219+
<tests.slow>${tests.slow}</tests.slow>
220+
<tests.aws>${tests.aws}</tests.aws>
221+
<tests.awaitsfix>${tests.awaitsfix}</tests.awaitsfix>
222+
<tests.slow>${tests.slow}</tests.slow>
223+
<tests.timeoutSuite>${tests.timeoutSuite}</tests.timeoutSuite>
224+
<tests.showSuccess>${tests.showSuccess}</tests.showSuccess>
225+
<tests.integration>${tests.integration}</tests.integration>
226+
<tests.cluster_seed>${tests.cluster_seed}</tests.cluster_seed>
227+
<tests.client.ratio>${tests.client.ratio}</tests.client.ratio>
228+
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
229+
<es.node.mode>${es.node.mode}</es.node.mode>
230+
<es.config>${es.config}</es.config>
231+
<es.logger.level>${es.logger.level}</es.logger.level>
232+
<java.awt.headless>true</java.awt.headless>
233+
</systemProperties>
234+
</configuration>
235+
</execution>
236+
</executions>
237+
</plugin>
123238
<plugin>
124239
<groupId>org.apache.maven.plugins</groupId>
125240
<artifactId>maven-surefire-plugin</artifactId>
126241
<version>2.11</version>
127242
<configuration>
128-
<includes>
129-
<include>**/*Tests.java</include>
130-
</includes>
243+
<skip>true</skip>
131244
</configuration>
132245
</plugin>
133246
<plugin>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Licensed to Elasticsearch (the "Author") under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. Author licenses this
6+
* file to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. 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.cloud.aws;
21+
22+
import com.carrotsearch.randomizedtesting.annotations.TestGroup;
23+
import org.elasticsearch.test.ElasticsearchIntegrationTest;
24+
25+
import java.lang.annotation.Documented;
26+
import java.lang.annotation.Inherited;
27+
import java.lang.annotation.Retention;
28+
import java.lang.annotation.RetentionPolicy;
29+
30+
/**
31+
*
32+
*/
33+
public abstract class AbstractAwsTest extends ElasticsearchIntegrationTest {
34+
35+
/**
36+
* Annotation for tests that require AWS to run. AWS tests are disabled by default.
37+
* <p/>
38+
* To enable test add -Dtests.aws=true -Des.config=/path/to/elasticsearch.yml
39+
* <p/>
40+
* The elasticsearch.yml file should contain the following keys
41+
* <pre>
42+
* cloud:
43+
* aws:
44+
* access_key: AKVAIQBF2RECL7FJWGJQ
45+
* secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
46+
* region: "us-west"
47+
*
48+
* discovery:
49+
# type: ec2
50+
* </pre>
51+
*/
52+
@Documented
53+
@Inherited
54+
@Retention(RetentionPolicy.RUNTIME)
55+
@TestGroup(enabled = false, sysProperty = SYSPROP_AWS)
56+
public @interface AwsTest {
57+
}
58+
59+
/**
60+
*/
61+
public static final String SYSPROP_AWS = "tests.aws";
62+
63+
}

src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryITest.java

+17-8
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,31 @@
2020
package org.elasticsearch.discovery.ec2;
2121

2222

23-
import org.elasticsearch.node.NodeBuilder;
24-
import org.junit.Ignore;
23+
import org.elasticsearch.cloud.aws.AbstractAwsTest;
24+
import org.elasticsearch.cloud.aws.AbstractAwsTest.AwsTest;
25+
import org.elasticsearch.common.settings.Settings;
26+
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
27+
import org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
2528
import org.junit.Test;
2629

30+
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
31+
2732
/**
2833
* Just an empty Node Start test to check eveything if fine when
2934
* starting.
30-
* This test is marked as ignored.
31-
* If you want to run your own test, please modify first test/resources/elasticsearch.yml file
32-
* with your own AWS credentials
35+
* This test requires AWS to run.
3336
*/
34-
public class Ec2DiscoveryITest {
37+
@AwsTest
38+
@ClusterScope(scope = Scope.TEST, numNodes = 0)
39+
public class Ec2DiscoveryITest extends AbstractAwsTest {
3540

36-
@Test @Ignore
41+
@Test
3742
public void testStart() {
38-
NodeBuilder.nodeBuilder().node();
43+
Settings nodeSettings = settingsBuilder()
44+
.put("cloud.enabled", true)
45+
.put("discovery.type", "ec2")
46+
.build();
47+
cluster().startNode(nodeSettings);
3948
}
4049

4150
}

src/test/resources/elasticsearch.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Replace this access_key / secret_key with your own if you want
2-
# to run tests
3-
cloud:
4-
aws:
5-
access_key: AKVAIQBF2RECL7FJWGJQ
6-
secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
7-
8-
discovery:
9-
type: ec2
1+
# Replace this access_key / secret_key and bucket name with your own if you want
2+
# to run tests.
3+
#cloud:
4+
# aws:
5+
# access_key: AKVAIQBF2RECL7FJWGJQ
6+
# secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
7+
#
8+
#discovery:
9+
# type: ec2
1010

src/test/resources/log4j.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
es.logger.level=INFO
2+
log4j.rootLogger=${es.logger.level}, out
3+
4+
log4j.appender.out=org.apache.log4j.ConsoleAppender
5+
log4j.appender.out.layout=org.apache.log4j.PatternLayout
6+
log4j.appender.out.layout.conversionPattern=[%d{ISO8601}][%-5p][%-25c] %m%n
7+
log4j.logger.org.elasticsearch.snapshots=TRACE
8+
log4j.logger.org.elasticsearch.index.snapshots=TRACE
9+
log4j.logger.com.amazonaws=INFO

0 commit comments

Comments
 (0)