From a569a8c1b7cbb13ec0b2f23ee434caa332508781 Mon Sep 17 00:00:00 2001 From: Andy Bristol Date: Mon, 16 Jul 2018 12:03:58 -0700 Subject: [PATCH 1/4] [test] use randomized runner in packaging tests 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 --- qa/vagrant/build.gradle | 18 +++--- .../packaging/test/ArchiveTestCase.java | 16 +---- .../packaging/test/PackagingTestCase.java | 58 +++++++++++++++++++ 3 files changed, 72 insertions(+), 20 deletions(-) create mode 100644 qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java diff --git a/qa/vagrant/build.gradle b/qa/vagrant/build.gradle index 704136eb4cf27..a2c15770ee441 100644 --- a/qa/vagrant/build.gradle +++ b/qa/vagrant/build.gradle @@ -28,8 +28,7 @@ plugins { dependencies { compile "junit:junit:${versions.junit}" - compile "org.hamcrest:hamcrest-core:${versions.hamcrest}" - compile "org.hamcrest:hamcrest-library:${versions.hamcrest}" + compile "org.hamcrest:hamcrest-all:${versions.hamcrest}" compile "org.apache.httpcomponents:httpcore:${versions.httpcore}" compile "org.apache.httpcomponents:httpclient:${versions.httpclient}" @@ -37,6 +36,7 @@ dependencies { compile "commons-codec:commons-codec:${versions.commonscodec}" compile "commons-logging:commons-logging:${versions.commonslogging}" + compile "org.elasticsearch.test:framework:${version}" compile project(':libs:core') // pulls in the jar built by this project and its dependencies @@ -85,11 +85,15 @@ tasks.thirdPartyAudit.excludes = [ 'org.apache.avalon.framework.logger.Logger', 'org.apache.log.Hierarchy', 'org.apache.log.Logger', - 'org.apache.log4j.Category', - 'org.apache.log4j.Level', - 'org.apache.log4j.Logger', - 'org.apache.log4j.Priority', //commons-logging provided dependencies 'javax.servlet.ServletContextEvent', - 'javax.servlet.ServletContextListener' + 'javax.servlet.ServletContextListener', + // brought in from test framework + 'org.apache.tools.ant.BuildException', + 'org.apache.tools.ant.DirectoryScanner', + 'org.apache.tools.ant.Task', + 'org.apache.tools.ant.types.FileSet', + 'org.easymock.EasyMock', + 'org.easymock.IArgumentMatcher', + 'org.jmock.core.Constraint' ] diff --git a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java index df5e8cf995d86..3aada7837d8ae 100644 --- a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java +++ b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java @@ -19,6 +19,7 @@ package org.elasticsearch.packaging.test; +import com.carrotsearch.randomizedtesting.annotations.TestCaseOrdering; import org.apache.http.client.fluent.Request; import org.elasticsearch.packaging.util.Archives; import org.elasticsearch.packaging.util.Platforms; @@ -27,9 +28,6 @@ import org.elasticsearch.packaging.util.Shell.Result; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; import org.elasticsearch.packaging.util.Distribution; import org.elasticsearch.packaging.util.Installation; @@ -67,8 +65,8 @@ * Tests that apply to the archive distributions (tar, zip). To add a case for a distribution, subclass and * override {@link ArchiveTestCase#distribution()}. These tests should be the same across all archive distributions */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public abstract class ArchiveTestCase { +@TestCaseOrdering(TestCaseOrdering.AlphabeticOrder.class) +public abstract class ArchiveTestCase extends PackagingTestCase { private static Installation installation; @@ -86,13 +84,11 @@ public void onlyCompatibleDistributions() { assumeTrue("only compatible distributions", distribution().packaging.compatible); } - @Test public void test10Install() { installation = installArchive(distribution()); verifyArchiveInstallation(installation, distribution()); } - @Test public void test20PluginsListWithNoPlugins() { assumeThat(installation, is(notNullValue())); @@ -103,7 +99,6 @@ public void test20PluginsListWithNoPlugins() { assertThat(r.stdout, isEmptyString()); } - @Test public void test30AbortWhenJavaMissing() { assumeThat(installation, is(notNullValue())); @@ -146,7 +141,6 @@ public void test30AbortWhenJavaMissing() { }); } - @Test public void test40CreateKeystoreManually() { assumeThat(installation, is(notNullValue())); @@ -180,7 +174,6 @@ public void test40CreateKeystoreManually() { }); } - @Test public void test50StartAndStop() throws IOException { assumeThat(installation, is(notNullValue())); @@ -198,7 +191,6 @@ public void test50StartAndStop() throws IOException { Archives.stopElasticsearch(installation); } - @Test public void test60AutoCreateKeystore() { assumeThat(installation, is(notNullValue())); @@ -218,7 +210,6 @@ public void test60AutoCreateKeystore() { }); } - @Test public void test70CustomPathConfAndJvmOptions() throws IOException { assumeThat(installation, is(notNullValue())); @@ -268,7 +259,6 @@ public void test70CustomPathConfAndJvmOptions() throws IOException { } } - @Test public void test80RelativePathConf() throws IOException { assumeThat(installation, is(notNullValue())); diff --git a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java new file mode 100644 index 0000000000000..13b9f1b922ebf --- /dev/null +++ b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java @@ -0,0 +1,58 @@ +/* + * 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.packaging.test; + +import com.carrotsearch.randomizedtesting.RandomizedRunner; +import com.carrotsearch.randomizedtesting.annotations.TestMethodProviders; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.lucene.util.LuceneJUnit3MethodProvider; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TestName; +import org.junit.runner.RunWith; + +@RunWith(RandomizedRunner.class) +@TestMethodProviders({ + LuceneJUnit3MethodProvider.class +}) +/** + * Class that all packaging test cases should inherit from. This makes working with the packaging tests more similar to what we're + * familiar with from {@link org.elasticsearch.test.ESTestCase} without having to apply its behavior that's not relevant here + */ +public abstract class PackagingTestCase { + + protected final Log logger = LogFactory.getLog(getClass()); + + @Rule + public final TestName testNameRule = new TestName(); + + @Before + public void logTestNameBefore() { + logger.info("[" + testNameRule.getMethodName() + "]: before test"); + } + + @After + public void logTestnameAfter() { + logger.info("[" + testNameRule.getMethodName() + "]: after test"); + } + +} From 568b7dd90bbdab5f8d0fc021e82724b4a762b592 Mon Sep 17 00:00:00 2001 From: Andy Bristol Date: Tue, 17 Jul 2018 11:58:47 -0700 Subject: [PATCH 2/4] use randomizedtesting directly --- qa/vagrant/build.gradle | 12 ++++++++---- .../packaging/test/PackagingTestCase.java | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/qa/vagrant/build.gradle b/qa/vagrant/build.gradle index a2c15770ee441..37190632b44bb 100644 --- a/qa/vagrant/build.gradle +++ b/qa/vagrant/build.gradle @@ -29,6 +29,7 @@ plugins { dependencies { compile "junit:junit:${versions.junit}" compile "org.hamcrest:hamcrest-all:${versions.hamcrest}" + compile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" compile "org.apache.httpcomponents:httpcore:${versions.httpcore}" compile "org.apache.httpcomponents:httpclient:${versions.httpclient}" @@ -36,7 +37,6 @@ dependencies { compile "commons-codec:commons-codec:${versions.commonscodec}" compile "commons-logging:commons-logging:${versions.commonslogging}" - compile "org.elasticsearch.test:framework:${version}" compile project(':libs:core') // pulls in the jar built by this project and its dependencies @@ -81,14 +81,18 @@ tasks.dependencyLicenses.enabled = false tasks.dependenciesInfo.enabled = false tasks.thirdPartyAudit.excludes = [ - //commons-logging optional dependencies + // commons-logging optional dependencies 'org.apache.avalon.framework.logger.Logger', 'org.apache.log.Hierarchy', 'org.apache.log.Logger', - //commons-logging provided dependencies + 'org.apache.log4j.Category', + 'org.apache.log4j.Level', + 'org.apache.log4j.Logger', + 'org.apache.log4j.Priority', + // commons-logging provided dependencies 'javax.servlet.ServletContextEvent', 'javax.servlet.ServletContextListener', - // brought in from test framework + // from randomized testing 'org.apache.tools.ant.BuildException', 'org.apache.tools.ant.DirectoryScanner', 'org.apache.tools.ant.Task', diff --git a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java index 13b9f1b922ebf..7f31e481bcbcb 100644 --- a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java +++ b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java @@ -19,11 +19,11 @@ package org.elasticsearch.packaging.test; +import com.carrotsearch.randomizedtesting.JUnit3MethodProvider; import com.carrotsearch.randomizedtesting.RandomizedRunner; import com.carrotsearch.randomizedtesting.annotations.TestMethodProviders; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.lucene.util.LuceneJUnit3MethodProvider; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -32,7 +32,7 @@ @RunWith(RandomizedRunner.class) @TestMethodProviders({ - LuceneJUnit3MethodProvider.class + JUnit3MethodProvider.class }) /** * Class that all packaging test cases should inherit from. This makes working with the packaging tests more similar to what we're From 5b7397a3245000939ceca9bed205be455e30fcbd Mon Sep 17 00:00:00 2001 From: Andy Bristol Date: Tue, 17 Jul 2018 15:14:05 -0700 Subject: [PATCH 3/4] log only before test, not after --- .../org/elasticsearch/packaging/test/PackagingTestCase.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java index 7f31e481bcbcb..336dc9722b32f 100644 --- a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java +++ b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java @@ -49,10 +49,4 @@ public abstract class PackagingTestCase { public void logTestNameBefore() { logger.info("[" + testNameRule.getMethodName() + "]: before test"); } - - @After - public void logTestnameAfter() { - logger.info("[" + testNameRule.getMethodName() + "]: after test"); - } - } From 9ec1584f244de77e13dd801afeff11a5a79b5490 Mon Sep 17 00:00:00 2001 From: Andy Bristol Date: Tue, 17 Jul 2018 17:53:29 -0700 Subject: [PATCH 4/4] checkstyle fixes --- .../java/org/elasticsearch/packaging/test/PackagingTestCase.java | 1 - 1 file changed, 1 deletion(-) diff --git a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java index 336dc9722b32f..77644b70f28e1 100644 --- a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java +++ b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackagingTestCase.java @@ -24,7 +24,6 @@ import com.carrotsearch.randomizedtesting.annotations.TestMethodProviders; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.rules.TestName;