From f1e80b7f9c9afb2e3037715ea50b551f6517dc02 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 7 Aug 2015 14:14:33 +0200 Subject: [PATCH] Add basic tests for sharded JAR this commit adds a simple integration test that starts a node from a shaded jar, indexes a doc and retrieves it. It also has some basic unittests that try to load shaded classes and ensure that their counterpart is not in the classpath. Closes #12711 --- .../resources/forbidden/all-signatures.txt | 11 -- .../third-party-shaded-signatures.txt | 11 ++ .../third-party-unshaded-signatures.txt | 11 ++ qa/pom.xml | 182 +---------------- qa/smoke-test-plugins/pom.xml | 184 ++++++++++++++++++ qa/smoke-test-shaded/pom.xml | 38 ++++ .../elasticsearch/shaded/test/ShadedIT.java | 54 +++++ .../elasticsearch/shaded/test/ShadedTest.java | 49 +++++ 8 files changed, 348 insertions(+), 192 deletions(-) create mode 100644 qa/smoke-test-shaded/pom.xml create mode 100644 qa/smoke-test-shaded/src/test/java/org/elasticsearch/shaded/test/ShadedIT.java create mode 100644 qa/smoke-test-shaded/src/test/java/org/elasticsearch/shaded/test/ShadedTest.java diff --git a/dev-tools/src/main/resources/forbidden/all-signatures.txt b/dev-tools/src/main/resources/forbidden/all-signatures.txt index b03cd14731f..642310519c8 100644 --- a/dev-tools/src/main/resources/forbidden/all-signatures.txt +++ b/dev-tools/src/main/resources/forbidden/all-signatures.txt @@ -46,17 +46,6 @@ java.nio.file.FileSystems#getDefault() @ use PathUtils.getDefault instead. java.nio.file.Files#createTempDirectory(java.lang.String,java.nio.file.attribute.FileAttribute[]) java.nio.file.Files#createTempFile(java.lang.String,java.lang.String,java.nio.file.attribute.FileAttribute[]) -@defaultMessage Constructing a DateTime without a time zone is dangerous -org.joda.time.DateTime#() -org.joda.time.DateTime#(long) -org.joda.time.DateTime#(int, int, int, int, int) -org.joda.time.DateTime#(int, int, int, int, int, int) -org.joda.time.DateTime#(int, int, int, int, int, int, int) -org.joda.time.DateTime#now() -org.joda.time.DateTimeZone#getDefault() - -com.google.common.collect.Iterators#emptyIterator() @ Use Collections.emptyIterator instead - @defaultMessage Don't use java serialization - this can break BWC without noticing it java.io.ObjectOutputStream java.io.ObjectOutput diff --git a/dev-tools/src/main/resources/forbidden/third-party-shaded-signatures.txt b/dev-tools/src/main/resources/forbidden/third-party-shaded-signatures.txt index 798265d8ad9..db1cd6f83be 100644 --- a/dev-tools/src/main/resources/forbidden/third-party-shaded-signatures.txt +++ b/dev-tools/src/main/resources/forbidden/third-party-shaded-signatures.txt @@ -20,3 +20,14 @@ org.elasticsearch.common.primitives.Longs#compare(long,long) @defaultMessage unsafe encoders/decoders have problems in the lzf compress library. Use variants of encode/decode functions which take Encoder/Decoder. org.elasticsearch.common.compress.lzf.impl.UnsafeChunkDecoder#() org.elasticsearch.common.compress.lzf.util.ChunkDecoderFactory#optimalInstance() + +@defaultMessage Constructing a DateTime without a time zone is dangerous +org.elasticsearch.joda.time.DateTime#() +org.elasticsearch.joda.time.DateTime#(long) +org.elasticsearch.joda.time.DateTime#(int, int, int, int, int) +org.elasticsearch.joda.time.DateTime#(int, int, int, int, int, int) +org.elasticsearch.joda.time.DateTime#(int, int, int, int, int, int, int) +org.elasticsearch.joda.time.DateTime#now() +org.elasticsearch.joda.time.DateTimeZone#getDefault() + +org.elasticsearch.common.collect.Iterators#emptyIterator() @ Use Collections.emptyIterator instead diff --git a/dev-tools/src/main/resources/forbidden/third-party-unshaded-signatures.txt b/dev-tools/src/main/resources/forbidden/third-party-unshaded-signatures.txt index 379951e8c3a..9979f8c221a 100644 --- a/dev-tools/src/main/resources/forbidden/third-party-unshaded-signatures.txt +++ b/dev-tools/src/main/resources/forbidden/third-party-unshaded-signatures.txt @@ -58,3 +58,14 @@ com.ning.compress.lzf.LZFOutputStream#(java.io.OutputStream) com.ning.compress.lzf.LZFOutputStream#(java.io.OutputStream, com.ning.compress.BufferRecycler) com.ning.compress.lzf.LZFUncompressor#(com.ning.compress.DataHandler) com.ning.compress.lzf.LZFUncompressor#(com.ning.compress.DataHandler, com.ning.compress.BufferRecycler) + +@defaultMessage Constructing a DateTime without a time zone is dangerous +org.joda.time.DateTime#() +org.joda.time.DateTime#(long) +org.joda.time.DateTime#(int, int, int, int, int) +org.joda.time.DateTime#(int, int, int, int, int, int) +org.joda.time.DateTime#(int, int, int, int, int, int, int) +org.joda.time.DateTime#now() +org.joda.time.DateTimeZone#getDefault() + +com.google.common.collect.Iterators#emptyIterator() @ Use Collections.emptyIterator instead \ No newline at end of file diff --git a/qa/pom.xml b/qa/pom.xml index a5d68c1beaf..c31dc04b456 100644 --- a/qa/pom.xml +++ b/qa/pom.xml @@ -33,188 +33,7 @@ lucene-test-framework test - - org.elasticsearch - elasticsearch - test-jar - test - - - - org.elasticsearch - elasticsearch - provided - - - org.apache.lucene - lucene-core - provided - - - org.apache.lucene - lucene-backward-codecs - provided - - - org.apache.lucene - lucene-analyzers-common - provided - - - org.apache.lucene - lucene-queries - provided - - - org.apache.lucene - lucene-memory - provided - - - org.apache.lucene - lucene-highlighter - provided - - - org.apache.lucene - lucene-queryparser - provided - - - org.apache.lucene - lucene-suggest - provided - - - org.apache.lucene - lucene-join - provided - - - org.apache.lucene - lucene-spatial - provided - - - org.apache.lucene - lucene-expressions - provided - - - com.spatial4j - spatial4j - provided - - - com.vividsolutions - jts - provided - - - com.github.spullara.mustache.java - compiler - provided - - - com.google.guava - guava - provided - - - com.carrotsearch - hppc - provided - - - joda-time - joda-time - provided - - - org.joda - joda-convert - provided - - - com.fasterxml.jackson.core - jackson-core - provided - - - com.fasterxml.jackson.dataformat - jackson-dataformat-smile - provided - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - provided - - - com.fasterxml.jackson.dataformat - jackson-dataformat-cbor - provided - - - io.netty - netty - provided - - - com.ning - compress-lzf - provided - - - com.tdunning - t-digest - provided - - - org.apache.commons - commons-lang3 - provided - - - commons-cli - commons-cli - provided - - - org.codehaus.groovy - groovy-all - indy - provided - - - log4j - log4j - provided - - - log4j - apache-log4j-extras - provided - - - org.slf4j - slf4j-api - provided - - - net.java.dev.jna - jna - provided - - - - - - org.apache.httpcomponents - httpclient - test - @@ -316,5 +135,6 @@ smoke-test-plugins + smoke-test-shaded diff --git a/qa/smoke-test-plugins/pom.xml b/qa/smoke-test-plugins/pom.xml index 489608b4ff3..4a02c591306 100644 --- a/qa/smoke-test-plugins/pom.xml +++ b/qa/smoke-test-plugins/pom.xml @@ -31,6 +31,190 @@ smoke_test_plugins false + + + org.elasticsearch + elasticsearch + test-jar + test + + + + + org.elasticsearch + elasticsearch + provided + + + org.apache.lucene + lucene-core + provided + + + org.apache.lucene + lucene-backward-codecs + provided + + + org.apache.lucene + lucene-analyzers-common + provided + + + org.apache.lucene + lucene-queries + provided + + + org.apache.lucene + lucene-memory + provided + + + org.apache.lucene + lucene-highlighter + provided + + + org.apache.lucene + lucene-queryparser + provided + + + org.apache.lucene + lucene-suggest + provided + + + org.apache.lucene + lucene-join + provided + + + org.apache.lucene + lucene-spatial + provided + + + org.apache.lucene + lucene-expressions + provided + + + com.spatial4j + spatial4j + provided + + + com.vividsolutions + jts + provided + + + com.github.spullara.mustache.java + compiler + provided + + + com.google.guava + guava + provided + + + com.carrotsearch + hppc + provided + + + joda-time + joda-time + provided + + + org.joda + joda-convert + provided + + + com.fasterxml.jackson.core + jackson-core + provided + + + com.fasterxml.jackson.dataformat + jackson-dataformat-smile + provided + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + provided + + + com.fasterxml.jackson.dataformat + jackson-dataformat-cbor + provided + + + io.netty + netty + provided + + + com.ning + compress-lzf + provided + + + com.tdunning + t-digest + provided + + + org.apache.commons + commons-lang3 + provided + + + commons-cli + commons-cli + provided + + + org.codehaus.groovy + groovy-all + indy + provided + + + log4j + log4j + provided + + + log4j + apache-log4j-extras + provided + + + org.slf4j + slf4j-api + provided + + + net.java.dev.jna + jna + provided + + + + + + org.apache.httpcomponents + httpclient + test + + diff --git a/qa/smoke-test-shaded/pom.xml b/qa/smoke-test-shaded/pom.xml new file mode 100644 index 00000000000..0f701d06034 --- /dev/null +++ b/qa/smoke-test-shaded/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + + org.elasticsearch.qa + elasticsearch-qa + 2.0.0-beta1-SNAPSHOT + + + smoke-test-shaded + QA: Smoke Test Shaded Jar + Runs a simple + + + shaded + + + + + org.elasticsearch.distribution.shaded + elasticsearch + 2.0.0-beta1-SNAPSHOT + + + org.hamcrest + hamcrest-all + test + + + org.apache.lucene + lucene-test-framework + test + + + diff --git a/qa/smoke-test-shaded/src/test/java/org/elasticsearch/shaded/test/ShadedIT.java b/qa/smoke-test-shaded/src/test/java/org/elasticsearch/shaded/test/ShadedIT.java new file mode 100644 index 00000000000..13a6804ab20 --- /dev/null +++ b/qa/smoke-test-shaded/src/test/java/org/elasticsearch/shaded/test/ShadedIT.java @@ -0,0 +1,54 @@ +/* + * 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.shaded.test; + +import org.apache.lucene.util.LuceneTestCase; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.common.logging.ESLoggerFactory; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.node.Node; +import org.elasticsearch.node.NodeBuilder; + +import java.nio.file.Path; + +/** + */ +public class ShadedIT extends LuceneTestCase { + + public void testStartShadedNode() { + ESLoggerFactory.getRootLogger().setLevel("ERROR"); + Path data = createTempDir(); + Settings settings = Settings.builder() + .put("path.home", data.toAbsolutePath().toString()) + .put("node.mode", "local") + .put("http.enabled", "false") + .build(); + NodeBuilder builder = NodeBuilder.nodeBuilder().data(true).settings(settings).loadConfigSettings(false).local(true); + try (Node node = builder.node()) { + Client client = node.client(); + client.admin().indices().prepareCreate("test").get(); + client.prepareIndex("test", "foo").setSource("{ \"field\" : \"value\" }").get(); + client.admin().indices().prepareRefresh().get(); + SearchResponse response = client.prepareSearch("test").get(); + assertEquals(response.getHits().getTotalHits(), 1l); + } + + } +} diff --git a/qa/smoke-test-shaded/src/test/java/org/elasticsearch/shaded/test/ShadedTest.java b/qa/smoke-test-shaded/src/test/java/org/elasticsearch/shaded/test/ShadedTest.java new file mode 100644 index 00000000000..d2d8c2422be --- /dev/null +++ b/qa/smoke-test-shaded/src/test/java/org/elasticsearch/shaded/test/ShadedTest.java @@ -0,0 +1,49 @@ +/* + * 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.shaded.test; + +import org.apache.lucene.util.LuceneTestCase; +import org.junit.Test; + +/** + */ +public class ShadedTest extends LuceneTestCase { + + @Test + public void testLoadShadedClasses() throws ClassNotFoundException { + Class.forName("org.elasticsearch.common.collect.ImmutableList"); + Class.forName("org.elasticsearch.common.joda.time.DateTime"); + Class.forName("org.elasticsearch.common.util.concurrent.jsr166e.LongAdder"); + } + + @Test(expected = ClassNotFoundException.class) + public void testGuavaIsNotOnTheCP() throws ClassNotFoundException { + Class.forName("com.google.common.collect.ImmutableList"); + } + + @Test(expected = ClassNotFoundException.class) + public void testJodaIsNotOnTheCP() throws ClassNotFoundException { + Class.forName("org.joda.time.DateTime"); + } + + @Test(expected = ClassNotFoundException.class) + public void testjsr166eIsNotOnTheCP() throws ClassNotFoundException { + Class.forName("com.twitter.jsr166e.LongAdder"); + } +}