Elffuss BraidHub

kikocis/java-driver public

Fix OSGi tests and simplify bundle version management
Changesetb68536f98e4a8377c9a2854e746c9cef1487d541f56d8f08caa53c910263d216
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2017-02-27 17:58 +01:00
CommitterAlexandre Dutra <alexandre.dutra@datastax.com> · 2017-02-28 17:31 +01:00
Parents5c67c2133880

Browse the files at this changeset

3 files changed

modified driver-tests/osgi/pom.xml +14 −15
@@ -24,7 +24,7 @@
2424 </parent>
2525
2626 <artifactId>cassandra-driver-tests-osgi</artifactId>
27- <packaging>bundle</packaging>
27+ <packaging>jar</packaging>
2828 <name>DataStax Java Driver for Apache Cassandra Tests - OSGi</name>
2929 <description>A test for the DataStax Java Driver in an OSGi container.</description>
3030 <url>https://github.com/datastax/java-driver</url>
@@ -36,6 +36,7 @@
3636 <pax-exam.version>3.6.0</pax-exam.version>
3737 <url.version>2.4.0</url.version>
3838 <logback.version>1.1.3</logback.version>
39+ <slf4j.version>1.7.5</slf4j.version>
3940 <test.groups>none</test.groups>
4041 <!--
4142 Skip tests by default, short or long profile is required to run tests in this module
@@ -75,7 +76,7 @@
7576 <dependency>
7677 <groupId>org.slf4j</groupId>
7778 <artifactId>slf4j-api</artifactId>
78- <version>1.7.5</version>
79+ <version>${slf4j.version}</version>
7980 </dependency>
8081
8182 <dependency>
@@ -128,13 +129,6 @@
128129 <scope>test</scope>
129130 </dependency>
130131
131- <dependency>
132- <groupId>com.jcabi</groupId>
133- <artifactId>jcabi-manifests</artifactId>
134- <version>1.1</version>
135- <scope>test</scope>
136- </dependency>
137-
138132 <dependency>
139133 <groupId>javax.servlet</groupId>
140134 <artifactId>javax.servlet-api</artifactId>
@@ -203,6 +197,16 @@
203197 <groups>${test.groups}</groups>
204198 <systemPropertyVariables>
205199 <cassandra.version>${cassandra.version}</cassandra.version>
200+ <!-- pull in declared version properties, this ensures we test with the same versions used by the driver -->
201+ <guava.version>${guava.version}</guava.version>
202+ <lz4.version>${lz4.version}</lz4.version>
203+ <snappy.version>${snappy.version}</snappy.version>
204+ <hdr.version>${hdr.version}</hdr.version>
205+ <netty.version>${netty.version}</netty.version>
206+ <slf4j.version>${slf4j.version}</slf4j.version>
207+ <logback.version>${logback.version}</logback.version>
208+ <metrics.version>${metrics.version}</metrics.version>
209+ <testng.version>${testng.version}</testng.version>
206210 <ipprefix>${ipprefix}</ipprefix>
207211 </systemPropertyVariables>
208212 </configuration>
@@ -229,13 +233,8 @@
229233 <Export-Package>com.datastax.driver.osgi.api,!com.datastax.driver.osgi.impl</Export-Package>
230234 <Bundle-Activator>com.datastax.driver.osgi.impl.Activator</Bundle-Activator>
231235 <_include>-osgi.bnd</_include>
232- <Import-Package><![CDATA[com.google.common*;version="[16.0.1,20)",*]]></Import-Package>
236+ <Import-Package><![CDATA[com.google.common.*;version="[16.0.1,20)",*]]></Import-Package>
233237 </instructions>
234- <supportedProjectTypes>
235- <supportedProjectType>jar</supportedProjectType>
236- <supportedProjectType>bundle</supportedProjectType>
237- <supportedProjectType>pom</supportedProjectType>
238- </supportedProjectTypes>
239238 </configuration>
240239 <executions>
241240 <execution>
modified driver-tests/osgi/src/test/java/com/datastax/driver/osgi/BundleOptions.java +46 −12
@@ -16,6 +16,7 @@
1616 package com.datastax.driver.osgi;
1717
1818 import com.datastax.driver.core.CCMBridge;
19+import com.datastax.driver.core.Cluster;
1920 import com.datastax.driver.core.ProtocolOptions;
2021 import com.datastax.driver.core.TestUtils;
2122 import org.ops4j.pax.exam.Option;
@@ -24,7 +25,6 @@
2425 import org.ops4j.pax.exam.options.UrlProvisionOption;
2526 import org.ops4j.pax.exam.util.PathUtils;
2627
27-import static com.datastax.driver.osgi.VersionProvider.projectVersion;
2828 import static org.ops4j.pax.exam.CoreOptions.*;
2929
3030 public class BundleOptions {
@@ -35,19 +35,19 @@
3535
3636 public static UrlProvisionOption driverBundle(boolean useShaded) {
3737 String classifier = useShaded ? "-shaded" : "";
38- return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-core/target/cassandra-driver-core-" + projectVersion() + classifier + ".jar");
38+ return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-core/target/cassandra-driver-core-" + Cluster.getDriverVersion() + classifier + ".jar");
3939 }
4040
4141 public static UrlProvisionOption mappingBundle() {
42- return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-mapping/target/cassandra-driver-mapping-" + projectVersion() + ".jar");
42+ return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-mapping/target/cassandra-driver-mapping-" + Cluster.getDriverVersion() + ".jar");
4343 }
4444
4545 public static UrlProvisionOption extrasBundle() {
46- return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-extras/target/cassandra-driver-extras-" + projectVersion() + ".jar");
46+ return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-extras/target/cassandra-driver-extras-" + Cluster.getDriverVersion() + ".jar");
4747 }
4848
4949 public static MavenArtifactProvisionOption guavaBundle() {
50- return mavenBundle("com.google.guava", "guava", "16.0.1");
50+ return mavenBundle("com.google.guava", "guava", getVersion("guava.version"));
5151 }
5252
5353 public static CompositeOption lz4Bundle() {
@@ -57,14 +57,40 @@
5757 public Option[] getOptions() {
5858 return options(
5959 systemProperty("cassandra.compression").value(ProtocolOptions.Compression.LZ4.name()),
60- mavenBundle("net.jpountz.lz4", "lz4", "1.3.0")
60+ mavenBundle("net.jpountz.lz4", "lz4", getVersion("lz4.version"))
61+ );
62+ }
63+ };
64+ }
65+
66+ public static CompositeOption snappyBundle() {
67+ return new CompositeOption() {
68+
69+ @Override
70+ public Option[] getOptions() {
71+ return options(
72+ systemProperty("cassandra.compression").value(ProtocolOptions.Compression.SNAPPY.name()),
73+ mavenBundle("org.xerial.snappy", "snappy-java", getVersion("snappy.version"))
74+ );
75+ }
76+ };
77+ }
78+
79+ public static CompositeOption hdrHistogramBundle() {
80+ return new CompositeOption() {
81+
82+ @Override
83+ public Option[] getOptions() {
84+ return options(
85+ systemProperty("cassandra.usePercentileSpeculativeExecutionPolicy").value("true"),
86+ mavenBundle("org.hdrhistogram", "HdrHistogram", getVersion("hdr.version"))
6187 );
6288 }
6389 };
6490 }
6591
6692 public static CompositeOption nettyBundles() {
67- final String nettyVersion = "4.0.33.Final";
93+ final String nettyVersion = getVersion("netty.version");
6894 return new CompositeOption() {
6995
7096 @Override
@@ -96,15 +122,23 @@
96122 systemProperty("cassandra.version").value(CCMBridge.getGlobalCassandraVersion().toString()),
97123 systemProperty("cassandra.contactpoints").value(TestUtils.IP_PREFIX + 1),
98124 systemProperty("logback.configurationFile").value("file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"),
99- mavenBundle("org.slf4j", "slf4j-api", "1.7.5"),
100- mavenBundle("ch.qos.logback", "logback-classic", "1.1.3"),
101- mavenBundle("ch.qos.logback", "logback-core", "1.1.3"),
102- mavenBundle("io.dropwizard.metrics", "metrics-core", "3.1.2"),
103- mavenBundle("org.testng", "testng", "6.8.8"),
125+ mavenBundle("org.slf4j", "slf4j-api", getVersion("slf4j.version")),
126+ mavenBundle("ch.qos.logback", "logback-classic", getVersion("logback.version")),
127+ mavenBundle("ch.qos.logback", "logback-core", getVersion("logback.version")),
128+ mavenBundle("io.dropwizard.metrics", "metrics-core", getVersion("metrics.version")),
129+ mavenBundle("org.testng", "testng", getVersion("testng.version")),
104130 systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation",
105131 "org.junit.runner.notification", "com.jcabi.manifests")
106132 );
107133 }
108134 };
109135 }
136+
137+ private static String getVersion(String propertyName) {
138+ String value = System.getProperty(propertyName);
139+ if (value == null) {
140+ throw new IllegalArgumentException(propertyName + " system property is not set.");
141+ }
142+ return value;
143+ }
110144 }
deleted driver-tests/osgi/src/test/java/com/datastax/driver/osgi/VersionProvider.java +0 −59
@@ -1,59 +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-package com.datastax.driver.osgi;
17-
18-import com.jcabi.manifests.Manifests;
19-
20-import java.util.regex.Matcher;
21-import java.util.regex.Pattern;
22-
23-/**
24- * Attempts to resolve the project version from the Bundle manifest. If not present, will throw RuntimeException
25- * on initialization. If this happens, try building with 'mvn compile' to generate the Bundle manifest.
26- * <p/>
27- * In IntelliJ you can have compile run after make by right clicking on 'compile' in the 'Maven Projects' tool window.
28- */
29-public class VersionProvider {
30-
31- private static final Pattern versionPattern = Pattern.compile(("(\\d+.\\d+\\.\\d+)(.*)"));
32-
33- private static final String PROJECT_VERSION;
34-
35- static {
36- String bundleName = Manifests.read("Bundle-SymbolicName");
37- if (bundleName.equals("com.datastax.driver.osgi")) {
38- String bundleVersion = Manifests.read("Bundle-Version");
39- Matcher matcher = versionPattern.matcher(bundleVersion);
40- if (matcher.matches()) {
41- String majorVersion = matcher.group(1);
42- // Replace all instances of '.' after the main version with '-' to properly
43- // resolve the correct version.
44- String rest = matcher.group(2).replaceAll("\\.", "-");
45- PROJECT_VERSION = majorVersion + rest;
46- } else {
47- // This should never happen, but if we are using a non X.Y.Z version number
48- // we'll just back off to the bundle version.
49- PROJECT_VERSION = bundleVersion;
50- }
51- } else {
52- throw new RuntimeException("Couldn't resolve bundle manifest (try building with mvn compile)");
53- }
54- }
55-
56- public static String projectVersion() {
57- return PROJECT_VERSION;
58- }
59-}