Skip to content

Commit ee070f3

Browse files
[test] use randomized runner in packaging tests (#32109)
Use the randomized runner from the test framework and add some basic logging to make the packaging tests behave more similarly to how we use junit in the rest of the project
1 parent dade5bb commit ee070f3

File tree

3 files changed

+67
-18
lines changed

3 files changed

+67
-18
lines changed

qa/vagrant/build.gradle

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ plugins {
2828

2929
dependencies {
3030
compile "junit:junit:${versions.junit}"
31-
compile "org.hamcrest:hamcrest-core:${versions.hamcrest}"
32-
compile "org.hamcrest:hamcrest-library:${versions.hamcrest}"
31+
compile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
32+
compile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
3333

3434
compile "org.apache.httpcomponents:httpcore:${versions.httpcore}"
3535
compile "org.apache.httpcomponents:httpclient:${versions.httpclient}"
@@ -81,15 +81,23 @@ tasks.dependencyLicenses.enabled = false
8181
tasks.dependenciesInfo.enabled = false
8282

8383
tasks.thirdPartyAudit.excludes = [
84-
//commons-logging optional dependencies
84+
// commons-logging optional dependencies
8585
'org.apache.avalon.framework.logger.Logger',
8686
'org.apache.log.Hierarchy',
8787
'org.apache.log.Logger',
8888
'org.apache.log4j.Category',
8989
'org.apache.log4j.Level',
9090
'org.apache.log4j.Logger',
9191
'org.apache.log4j.Priority',
92-
//commons-logging provided dependencies
92+
// commons-logging provided dependencies
9393
'javax.servlet.ServletContextEvent',
94-
'javax.servlet.ServletContextListener'
94+
'javax.servlet.ServletContextListener',
95+
// from randomized testing
96+
'org.apache.tools.ant.BuildException',
97+
'org.apache.tools.ant.DirectoryScanner',
98+
'org.apache.tools.ant.Task',
99+
'org.apache.tools.ant.types.FileSet',
100+
'org.easymock.EasyMock',
101+
'org.easymock.IArgumentMatcher',
102+
'org.jmock.core.Constraint'
95103
]

qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.packaging.test;
2121

22+
import com.carrotsearch.randomizedtesting.annotations.TestCaseOrdering;
2223
import org.apache.http.client.fluent.Request;
2324
import org.elasticsearch.packaging.util.Archives;
2425
import org.elasticsearch.packaging.util.Platforms;
@@ -27,9 +28,6 @@
2728
import org.elasticsearch.packaging.util.Shell.Result;
2829
import org.junit.Before;
2930
import org.junit.BeforeClass;
30-
import org.junit.FixMethodOrder;
31-
import org.junit.Test;
32-
import org.junit.runners.MethodSorters;
3331

3432
import org.elasticsearch.packaging.util.Distribution;
3533
import org.elasticsearch.packaging.util.Installation;
@@ -67,8 +65,8 @@
6765
* Tests that apply to the archive distributions (tar, zip). To add a case for a distribution, subclass and
6866
* override {@link ArchiveTestCase#distribution()}. These tests should be the same across all archive distributions
6967
*/
70-
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
71-
public abstract class ArchiveTestCase {
68+
@TestCaseOrdering(TestCaseOrdering.AlphabeticOrder.class)
69+
public abstract class ArchiveTestCase extends PackagingTestCase {
7270

7371
private static Installation installation;
7472

@@ -86,13 +84,11 @@ public void onlyCompatibleDistributions() {
8684
assumeTrue("only compatible distributions", distribution().packaging.compatible);
8785
}
8886

89-
@Test
9087
public void test10Install() {
9188
installation = installArchive(distribution());
9289
verifyArchiveInstallation(installation, distribution());
9390
}
9491

95-
@Test
9692
public void test20PluginsListWithNoPlugins() {
9793
assumeThat(installation, is(notNullValue()));
9894

@@ -103,7 +99,6 @@ public void test20PluginsListWithNoPlugins() {
10399
assertThat(r.stdout, isEmptyString());
104100
}
105101

106-
@Test
107102
public void test30AbortWhenJavaMissing() {
108103
assumeThat(installation, is(notNullValue()));
109104

@@ -146,7 +141,6 @@ public void test30AbortWhenJavaMissing() {
146141
});
147142
}
148143

149-
@Test
150144
public void test40CreateKeystoreManually() {
151145
assumeThat(installation, is(notNullValue()));
152146

@@ -180,7 +174,6 @@ public void test40CreateKeystoreManually() {
180174
});
181175
}
182176

183-
@Test
184177
public void test50StartAndStop() throws IOException {
185178
assumeThat(installation, is(notNullValue()));
186179

@@ -198,7 +191,6 @@ public void test50StartAndStop() throws IOException {
198191
Archives.stopElasticsearch(installation);
199192
}
200193

201-
@Test
202194
public void test60AutoCreateKeystore() {
203195
assumeThat(installation, is(notNullValue()));
204196

@@ -218,7 +210,6 @@ public void test60AutoCreateKeystore() {
218210
});
219211
}
220212

221-
@Test
222213
public void test70CustomPathConfAndJvmOptions() throws IOException {
223214
assumeThat(installation, is(notNullValue()));
224215

@@ -268,7 +259,6 @@ public void test70CustomPathConfAndJvmOptions() throws IOException {
268259
}
269260
}
270261

271-
@Test
272262
public void test80RelativePathConf() throws IOException {
273263
assumeThat(installation, is(notNullValue()));
274264

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.packaging.test;
21+
22+
import com.carrotsearch.randomizedtesting.JUnit3MethodProvider;
23+
import com.carrotsearch.randomizedtesting.RandomizedRunner;
24+
import com.carrotsearch.randomizedtesting.annotations.TestMethodProviders;
25+
import org.apache.commons.logging.Log;
26+
import org.apache.commons.logging.LogFactory;
27+
import org.junit.Before;
28+
import org.junit.Rule;
29+
import org.junit.rules.TestName;
30+
import org.junit.runner.RunWith;
31+
32+
@RunWith(RandomizedRunner.class)
33+
@TestMethodProviders({
34+
JUnit3MethodProvider.class
35+
})
36+
/**
37+
* Class that all packaging test cases should inherit from. This makes working with the packaging tests more similar to what we're
38+
* familiar with from {@link org.elasticsearch.test.ESTestCase} without having to apply its behavior that's not relevant here
39+
*/
40+
public abstract class PackagingTestCase {
41+
42+
protected final Log logger = LogFactory.getLog(getClass());
43+
44+
@Rule
45+
public final TestName testNameRule = new TestName();
46+
47+
@Before
48+
public void logTestNameBefore() {
49+
logger.info("[" + testNameRule.getMethodName() + "]: before test");
50+
}
51+
}

0 commit comments

Comments
 (0)