Elffuss BraidHub

kikocis/java-driver public

JAVA-961: Raise an excepiton when an older version of guava is found.
Changesetafa9ec7b29c756253e08fecf26868feff7090fe517d343406c75f7979cdf1d61
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-10-22 18:57 -05:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-11-05 14:10 -06:00
Parents08758edd9a11

Browse the files at this changeset

10 files changed

modified changelog/README.md +2 −0
@@ -6,6 +6,8 @@
66 - [improvement] Update metrics to the latest version (JAVA-968)
77 - [improvement] Improve error handling for when a non-type 1 UUID is given to bind() on a timeuuid column (JAVA-965)
88 - [improvement] Pass the authenticator name from the server to the auth provider (JAVA-885)
9+- [improvement] Raise an exception when an older version of guava (<16.01) is found (JAVA-961)
10+
911
1012 ### 3.0.0-alpha4
1113
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +5 −0
@@ -66,6 +66,11 @@
6666
6767 private static final Logger logger = LoggerFactory.getLogger(Cluster.class);
6868
69+ static {
70+ // Perform sanity checks to inform user of possible environment misconfiguration.
71+ SanityChecks.check();
72+ }
73+
6974 @VisibleForTesting
7075 static final int NEW_NODE_DELAY_SECONDS = SystemProperties.getInt("com.datastax.driver.NEW_NODE_DELAY_SECONDS", 1);
7176 private static final int NON_BLOCKING_EXECUTOR_SIZE = SystemProperties.getInt("com.datastax.driver.NON_BLOCKING_EXECUTOR_SIZE",
added driver-core/src/main/java/com/datastax/driver/core/SanityChecks.java +69 −0
@@ -0,0 +1,69 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.core;
17+
18+import java.lang.reflect.ParameterizedType;
19+import java.lang.reflect.Type;
20+import java.util.Map;
21+
22+import com.google.common.reflect.TypeToken;
23+
24+class SanityChecks {
25+
26+ /**
27+ * Performs a series of runtime checks to ensure the environment does not have any
28+ * incompatible libraries or configurations. Depending on the severity of an
29+ * incompatibility an {@link IllegalStateException} may be thrown or an ERROR or
30+ * WARNING is logged.
31+ *
32+ * @throws IllegalStateException If an environment incompatibility is detected.
33+ * @see #checkGuava
34+ */
35+ static void check() {
36+ checkGuava();
37+ }
38+
39+ /**
40+ * Detects if a version of guava older than 16.01 is present by attempting to create
41+ * a {@link TypeToken} instance for <code>Map&lt;String,String&gt;</code> and ensures that the
42+ * value type argument is of instance {@link String}. If using an older version of guava
43+ * this will resolve to {@link Object} instead. In this case an {@link IllegalStateException}
44+ * is thrown.
45+ *
46+ * @throws IllegalStateException if version of guava less than 16.01 is detected.
47+ */
48+ static void checkGuava() {
49+ boolean resolved = false;
50+ TypeToken<Map<String,String>> mapOfString = CodecUtils.mapOf(String.class, String.class);
51+ Type type = mapOfString.getType();
52+ if(type instanceof ParameterizedType) {
53+ ParameterizedType pType = (ParameterizedType)type;
54+ Type[] types = pType.getActualTypeArguments();
55+ if(types.length == 2) {
56+ TypeToken valueType = TypeToken.of(types[1]);
57+ resolved = valueType.getRawType().equals(String.class);
58+ }
59+ }
60+
61+ if(!resolved) {
62+ throw new IllegalStateException(
63+ "Detected Guava issue #1635 which indicates that a version of Guava less than 16.01 is in use. "
64+ + "This introduces codec resolution issues and potentially other incompatibility issues in the driver. "
65+ + "Please upgrade to Guava 16.01 or later.");
66+ }
67+ }
68+
69+}
modified driver-examples/osgi/pom.xml +13 −14
@@ -31,6 +31,7 @@
3131 <properties>
3232 <felix.version>4.6.0</felix.version>
3333 <pax-exam.version>3.6.0</pax-exam.version>
34+ <logback.version>1.1.3</logback.version>
3435 <main.basedir>${project.parent.parent.basedir}</main.basedir>
3536 </properties>
3637
@@ -90,20 +91,6 @@
9091 <scope>test</scope>
9192 </dependency>
9293
93- <dependency>
94- <groupId>log4j</groupId>
95- <artifactId>log4j</artifactId>
96- <version>${log4j.version}</version>
97- <scope>test</scope>
98- </dependency>
99-
100- <dependency>
101- <groupId>org.slf4j</groupId>
102- <artifactId>slf4j-log4j12</artifactId>
103- <version>${slf4j-log4j12.version}</version>
104- <scope>test</scope>
105- </dependency>
106-
10794 <dependency>
10895 <groupId>com.jcabi</groupId>
10996 <artifactId>jcabi-manifests</artifactId>
@@ -131,6 +118,18 @@
131118 <version>1.3</version>
132119 <scope>test</scope>
133120 </dependency>
121+
122+ <dependency>
123+ <groupId>ch.qos.logback</groupId>
124+ <artifactId>logback-classic</artifactId>
125+ <version>${logback.version}</version>
126+ </dependency>
127+
128+ <dependency>
129+ <groupId>ch.qos.logback</groupId>
130+ <artifactId>logback-core</artifactId>
131+ <version>${logback.version}</version>
132+ </dependency>
134133 </dependencies>
135134
136135 <build>
added driver-examples/osgi/src/test/java/com/datastax/driver/osgi/BundleOptions.java +86 −0
@@ -0,0 +1,86 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.osgi;
17+
18+import org.ops4j.pax.exam.Option;
19+import org.ops4j.pax.exam.options.CompositeOption;
20+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
21+import org.ops4j.pax.exam.options.UrlProvisionOption;
22+import org.ops4j.pax.exam.util.PathUtils;
23+
24+import static org.ops4j.pax.exam.CoreOptions.bundle;
25+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
26+import static org.ops4j.pax.exam.CoreOptions.options;
27+import static org.ops4j.pax.exam.CoreOptions.systemPackages;
28+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
29+
30+import com.datastax.driver.core.CCMBridge;
31+
32+import static com.datastax.driver.osgi.VersionProvider.projectVersion;
33+
34+public class BundleOptions {
35+
36+ public static UrlProvisionOption driverBundle() {
37+ return driverBundle(false);
38+ }
39+
40+ public static UrlProvisionOption driverBundle(boolean useShaded) {
41+ String classifier = useShaded ? "-shaded" : "";
42+ return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-core/target/cassandra-driver-core-" + projectVersion() + classifier + ".jar");
43+ }
44+
45+ public static MavenArtifactProvisionOption guavaBundle() {
46+ return mavenBundle("com.google.guava", "guava", "16.0.1");
47+ }
48+
49+ public static CompositeOption nettyBundles() {
50+ final String nettyVersion = "4.0.27.Final";
51+ return new CompositeOption() {
52+
53+ @Override public Option[] getOptions() {
54+ return options(
55+ mavenBundle("io.netty", "netty-buffer", nettyVersion),
56+ mavenBundle("io.netty", "netty-codec", nettyVersion),
57+ mavenBundle("io.netty", "netty-common", nettyVersion),
58+ mavenBundle("io.netty", "netty-handler", nettyVersion),
59+ mavenBundle("io.netty", "netty-transport", nettyVersion)
60+ );
61+ }
62+ };
63+ }
64+
65+ public static UrlProvisionOption mailboxBundle() {
66+ return bundle("reference:file:" + PathUtils.getBaseDir() + "/target/classes");
67+ }
68+
69+ public static CompositeOption defaultOptions() {
70+ return new CompositeOption() {
71+
72+ @Override public Option[] getOptions() {
73+ return options(
74+ systemProperty("cassandra.contactpoints").value(CCMBridge.IP_PREFIX + 1),
75+ systemProperty("logback.configurationFile").value("file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"),
76+ mavenBundle("org.slf4j", "slf4j-api", "1.7.5"),
77+ mavenBundle("ch.qos.logback", "logback-classic", "1.1.3"),
78+ mavenBundle("ch.qos.logback", "logback-core", "1.1.3"),
79+ mavenBundle("io.dropwizard.metrics", "metrics-core", "3.1.2"),
80+ systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation",
81+ "org.junit.runner.notification", "com.jcabi.manifests")
82+ );
83+ }
84+ };
85+ }
86+}
added driver-examples/osgi/src/test/java/com/datastax/driver/osgi/GuavaSanityCheckNegativeIT.java +102 −0
@@ -0,0 +1,102 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.osgi;
17+
18+import org.ops4j.pax.exam.Configuration;
19+import org.ops4j.pax.exam.Option;
20+import org.ops4j.pax.exam.testng.listener.PaxExam;
21+import org.testng.annotations.Listeners;
22+import org.testng.annotations.Test;
23+
24+import static org.ops4j.pax.exam.CoreOptions.options;
25+import static org.testng.Assert.assertTrue;
26+import static org.testng.Assert.fail;
27+
28+import com.datastax.driver.core.Cluster;
29+
30+import static com.datastax.driver.osgi.BundleOptions.defaultOptions;
31+import static com.datastax.driver.osgi.BundleOptions.driverBundle;
32+import static com.datastax.driver.osgi.BundleOptions.guavaBundle;
33+import static com.datastax.driver.osgi.BundleOptions.nettyBundles;
34+
35+@Listeners({PaxExam.class})
36+@Test(groups="short")
37+public class GuavaSanityCheckNegativeIT {
38+
39+ @Configuration
40+ public Option[] guava14_0_1Config() {
41+ return options(
42+ driverBundle(),
43+ nettyBundles(),
44+ guavaBundle().version("14.0.1"),
45+ defaultOptions()
46+ );
47+ }
48+
49+ @Configuration
50+ public Option[] guava15Config() {
51+ return options(
52+ driverBundle(),
53+ nettyBundles(),
54+ guavaBundle().version("15.0"),
55+ defaultOptions()
56+ );
57+ }
58+
59+ @Configuration
60+ public Option[] guava16Config() {
61+ return options(
62+ driverBundle(),
63+ nettyBundles(),
64+ guavaBundle().version("16.0"),
65+ defaultOptions()
66+ );
67+ }
68+
69+ /**
70+ * <p>
71+ * Validates that the driver is able to detect that the guava library in the classpath is
72+ * less than version 16.01 and throws an {@link IllegalStateException} in this case and
73+ * is raised as the cause of an {@link ExceptionInInitializerError} since the failure
74+ * occurs at static initialization.
75+ * </p>
76+ *
77+ * The following configurations are tried (defined via methods with the @Configuration annotation):
78+ * <ol>
79+ * <li>With Guava 14.0.1</li>
80+ * <li>With Guava 15.0</li>
81+ * <li>With Guava 16.0</li>
82+ * </ol>
83+ *
84+ * @test_category packaging
85+ * @expected_result An {@link IllegalStateException} is thrown.
86+ * @jira_ticket JAVA-961
87+ * @since 3.0.0-beta1
88+ */
89+ public void should_raise_guava_version_error_if_lt_16_0_1() throws Throwable {
90+ try {
91+ Cluster.builder();
92+ fail("Expected an IllegalStateException for Guava version incompatibility");
93+ }
94+ catch(ExceptionInInitializerError e) {
95+ try {
96+ throw e.getCause();
97+ } catch(IllegalStateException ise) {
98+ assertTrue(ise.getMessage().contains("Detected Guava issue #1635"));
99+ }
100+ }
101+ }
102+}
modified driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceIT.java +7 −54
@@ -22,78 +22,29 @@
2222 import javax.inject.Inject;
2323 import org.ops4j.pax.exam.Configuration;
2424 import org.ops4j.pax.exam.Option;
25-import org.ops4j.pax.exam.options.CompositeOption;
26-import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
27-import org.ops4j.pax.exam.options.UrlProvisionOption;
2825 import org.ops4j.pax.exam.testng.listener.PaxExam;
2926 import org.testng.annotations.Listeners;
3027 import org.testng.annotations.Test;
3128
32-import static org.ops4j.pax.exam.CoreOptions.*;
29+import static org.ops4j.pax.exam.CoreOptions.options;
3330 import static org.testng.Assert.assertEquals;
3431
35-import com.datastax.driver.core.CCMBridge;
3632 import com.datastax.driver.osgi.api.MailboxException;
3733 import com.datastax.driver.osgi.api.MailboxMessage;
3834 import com.datastax.driver.osgi.api.MailboxService;
3935
40-import static com.datastax.driver.osgi.VersionProvider.projectVersion;
36+import static com.datastax.driver.osgi.BundleOptions.*;
4137
4238 @Listeners({CCMBridgeListener.class, PaxExam.class})
4339 @Test(groups="short")
4440 public class MailboxServiceIT {
4541 @Inject MailboxService service;
4642
47- private UrlProvisionOption driverBundle() {
48- return driverBundle(false);
49- }
50-
51- private UrlProvisionOption driverBundle(boolean useShaded) {
52- String classifier = useShaded ? "-shaded" : "";
53- return bundle("reference:file:../../driver-core/target/cassandra-driver-core-" + projectVersion() + classifier + ".jar");
54- }
55-
56- private MavenArtifactProvisionOption guavaBundle() {
57- return mavenBundle("com.google.guava", "guava", "16.0.1");
58- }
59-
60- private CompositeOption nettyBundles() {
61- final String nettyVersion = "4.0.27.Final";
62- return new CompositeOption() {
63-
64- @Override public Option[] getOptions() {
65- return options(
66- mavenBundle("io.netty", "netty-buffer", nettyVersion),
67- mavenBundle("io.netty", "netty-codec", nettyVersion),
68- mavenBundle("io.netty", "netty-common", nettyVersion),
69- mavenBundle("io.netty", "netty-handler", nettyVersion),
70- mavenBundle("io.netty", "netty-transport", nettyVersion)
71- );
72- }
73- };
74- }
75-
76- private CompositeOption defaultOptions() {
77- return new CompositeOption() {
78-
79- @Override public Option[] getOptions() {
80- return options(
81- systemProperty("cassandra.contactpoints").value(CCMBridge.IP_PREFIX + 1),
82- bundle("reference:file:target/classes"),
83- mavenBundle("com.codahale.metrics", "metrics-core", "3.0.2"),
84- mavenBundle("org.slf4j", "slf4j-api", "1.7.5"),
85- mavenBundle("org.slf4j", "slf4j-simple", "1.7.5").noStart(),
86- systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation",
87- "org.junit.runner.notification", "com.jcabi.manifests")
88- );
89- }
90- };
91- }
92-
9343 @Configuration
9444 public Option[] shadedConfig() {
9545 return options(
9646 driverBundle(true),
47+ mailboxBundle(),
9748 guavaBundle(),
9849 defaultOptions()
9950 );
@@ -103,6 +54,7 @@
10354 public Option[] defaultConfig() {
10455 return options(
10556 driverBundle(),
57+ mailboxBundle(),
10658 guavaBundle(),
10759 nettyBundles(),
10860 defaultOptions()
@@ -113,6 +65,7 @@
11365 public Option[] guava17Config() {
11466 return options(
11567 driverBundle(),
68+ mailboxBundle(),
11669 nettyBundles(),
11770 guavaBundle().version("17.0"),
11871 defaultOptions()
@@ -123,6 +76,7 @@
12376 public Option[] guava18Config() {
12477 return options(
12578 driverBundle(),
79+ mailboxBundle(),
12680 nettyBundles(),
12781 guavaBundle().version("18.0"),
12882 defaultOptions()
@@ -139,8 +93,7 @@
13993 * <ol>
14094 * <li>Default bundle (Driver with all of it's dependencies)</li>
14195 * <li>Shaded bundle (Driver with netty shaded)</li>
142- * <li>With Guava 15</li>
143- * <li>With Guava 16</li>
96+ * <li>With Guava 16.0.1</li>
14497 * <li>With Guava 17</li>
14598 * <li>With Guava 18</li>
14699 * </ol>
added driver-examples/osgi/src/test/resources/exam.properties +18 −0
@@ -0,0 +1,18 @@
1+#
2+# Copyright (C) 2012-2015 DataStax Inc.
3+#
4+# Licensed under the Apache License, Version 2.0 (the "License");
5+# you may not use this file except in compliance with the License.
6+# You may obtain a copy of the License at
7+#
8+# http://www.apache.org/licenses/LICENSE-2.0
9+#
10+# Unless required by applicable law or agreed to in writing, software
11+# distributed under the License is distributed on an "AS IS" BASIS,
12+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+# See the License for the specific language governing permissions and
14+# limitations under the License.
15+#
16+
17+pax.exam.system=test
18+pax.exam.logging=none
No newline at the end of the file
deleted driver-examples/osgi/src/test/resources/log4j.properties +0 −28
@@ -1,28 +0,0 @@
1-#
2-# Copyright (C) 2012-2015 DataStax Inc.
3-#
4-# Licensed under the Apache License, Version 2.0 (the "License");
5-# you may not use this file except in compliance with the License.
6-# You may obtain a copy of the License at
7-#
8-# http://www.apache.org/licenses/LICENSE-2.0
9-#
10-# Unless required by applicable law or agreed to in writing, software
11-# distributed under the License is distributed on an "AS IS" BASIS,
12-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-# See the License for the specific language governing permissions and
14-# limitations under the License.
15-#
16-
17-# Set root logger level to DEBUG and its only appender to A1.
18-log4j.rootLogger=INFO, A1
19-
20-# Scassandra's info log is a bit verbose
21-log4j.logger.org.scassandra=WARN
22-
23-# A1 is set to be a ConsoleAppender.
24-log4j.appender.A1=org.apache.log4j.ConsoleAppender
25-
26-# A1 uses PatternLayout.
27-log4j.appender.A1.layout=org.apache.log4j.PatternLayout
28-log4j.appender.A1.layout.ConversionPattern=\ %-6r [%t] %-5p %c %x - %m%n
added driver-examples/osgi/src/test/resources/logback.xml +27 −0
@@ -0,0 +1,27 @@
1+<!--
2+
3+ Copyright (C) 2012-2015 DataStax Inc.
4+
5+ Licensed under the Apache License, Version 2.0 (the "License");
6+ you may not use this file except in compliance with the License.
7+ You may obtain a copy of the License at
8+
9+ http://www.apache.org/licenses/LICENSE-2.0
10+
11+ Unless required by applicable law or agreed to in writing, software
12+ distributed under the License is distributed on an "AS IS" BASIS,
13+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ See the License for the specific language governing permissions and
15+ limitations under the License.
16+
17+-->
18+<configuration>
19+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
20+ <layout class="ch.qos.logback.classic.PatternLayout">
21+ <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
22+ </layout>
23+ </appender>
24+ <root level="INFO">
25+ <appender-ref ref="STDOUT" />
26+ </root>
27+</configuration>
No newline at the end of the file