Skip to content

Commit 278c3bc

Browse files
adutraolim7t
authored andcommitted
JAVA-1200: Upgrade LZ4 to 1.3.0. (scylladb#698)
This commit also introduces a new OSGi test to validate that it can be used in an OSGi environment. As this new test relies on system properties that might be present or not, this commit switches the Pax Exam container from "native" to "forked", because native containers are not confined enough to isolate system properties correctly.
1 parent 37c39c7 commit 278c3bc

7 files changed

Lines changed: 134 additions & 10 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [bug] JAVA-1139: ConnectionException.getMessage() throws NPE if address is null.
1414
- [bug] JAVA-1202: Handle null rpc_address when checking schema agreement.
1515
- [improvement] JAVA-1198: Document that BoundStatement is not thread-safe.
16+
- [improvement] JAVA-1200: Upgrade LZ4 to 1.3.0.
1617

1718

1819
### 3.0.2

driver-tests/osgi/pom.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<felix.version>4.6.0</felix.version>
3535
<!-- more recent version require JDK7+ -->
3636
<pax-exam.version>3.6.0</pax-exam.version>
37+
<url.version>2.4.0</url.version>
3738
<logback.version>1.1.3</logback.version>
3839
<test.groups>none</test.groups>
3940
<!--
@@ -71,6 +72,12 @@
7172
<version>${felix.version}</version>
7273
</dependency>
7374

75+
<dependency>
76+
<groupId>org.slf4j</groupId>
77+
<artifactId>slf4j-api</artifactId>
78+
<version>1.7.5</version>
79+
</dependency>
80+
7481
<dependency>
7582
<groupId>com.datastax.cassandra</groupId>
7683
<artifactId>cassandra-driver-core</artifactId>
@@ -95,7 +102,7 @@
95102

96103
<dependency>
97104
<groupId>org.ops4j.pax.exam</groupId>
98-
<artifactId>pax-exam-container-native</artifactId>
105+
<artifactId>pax-exam-container-forked</artifactId>
99106
<version>${pax-exam.version}</version>
100107
<scope>test</scope>
101108
</dependency>
@@ -107,6 +114,13 @@
107114
<scope>test</scope>
108115
</dependency>
109116

117+
<dependency>
118+
<groupId>org.ops4j.pax.url</groupId>
119+
<artifactId>pax-url-reference</artifactId>
120+
<version>${url.version}</version>
121+
<scope>test</scope>
122+
</dependency>
123+
110124
<dependency>
111125
<groupId>javax.transaction</groupId>
112126
<artifactId>jta</artifactId>
@@ -146,12 +160,14 @@
146160
<groupId>ch.qos.logback</groupId>
147161
<artifactId>logback-classic</artifactId>
148162
<version>${logback.version}</version>
163+
<scope>test</scope>
149164
</dependency>
150165

151166
<dependency>
152167
<groupId>ch.qos.logback</groupId>
153168
<artifactId>logback-core</artifactId>
154169
<version>${logback.version}</version>
170+
<scope>test</scope>
155171
</dependency>
156172

157173
</dependencies>

driver-tests/osgi/src/main/java/com/datastax/driver/osgi/impl/Activator.java

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,73 @@
1515
*/
1616
package com.datastax.driver.osgi.impl;
1717

18-
import com.datastax.driver.core.Cluster;
19-
import com.datastax.driver.core.CodecRegistry;
20-
import com.datastax.driver.core.Metadata;
21-
import com.datastax.driver.core.Session;
18+
import com.datastax.driver.core.*;
2219
import com.datastax.driver.core.exceptions.InvalidQueryException;
20+
import com.datastax.driver.core.policies.PercentileSpeculativeExecutionPolicy;
2321
import com.datastax.driver.extras.codecs.date.SimpleTimestampCodec;
2422
import com.datastax.driver.osgi.api.MailboxService;
2523
import org.osgi.framework.BundleActivator;
2624
import org.osgi.framework.BundleContext;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
2727

2828
import java.util.Hashtable;
2929

30+
import static com.datastax.driver.core.ProtocolOptions.Compression.LZ4;
3031
import static com.datastax.driver.osgi.api.MailboxMessage.TABLE;
3132

3233
public class Activator implements BundleActivator {
3334

35+
private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
36+
3437
private Cluster cluster;
3538

3639
@Override
3740
public void start(BundleContext context) throws Exception {
41+
42+
VersionNumber ver = VersionNumber.parse(context.getProperty("cassandra.version"));
43+
LOGGER.info("C* version: {}", ver);
44+
3845
String contactPointsStr = context.getProperty("cassandra.contactpoints");
3946
if (contactPointsStr == null) {
4047
contactPointsStr = "127.0.0.1";
4148
}
49+
LOGGER.info("Contact points: {}", contactPointsStr);
4250
String[] contactPoints = contactPointsStr.split(",");
4351

4452
String keyspace = context.getProperty("cassandra.keyspace");
4553
if (keyspace == null) {
4654
keyspace = "mailbox";
4755
}
56+
LOGGER.info("Keyspace: {}", keyspace);
4857
keyspace = Metadata.quote(keyspace);
4958

50-
cluster = Cluster.builder()
59+
Cluster.Builder builder = Cluster.builder()
5160
.addContactPoints(contactPoints)
52-
.withCodecRegistry(new CodecRegistry().register(SimpleTimestampCodec.instance))
53-
.build();
61+
.withCodecRegistry(new CodecRegistry().register(SimpleTimestampCodec.instance));
62+
63+
String compression = context.getProperty("cassandra.compression");
64+
if (compression != null) {
65+
if (ver.getMajor() < 2 && compression.equals(LZ4.name())) {
66+
LOGGER.warn("Requested LZ4 compression but C* version is not compatible, disabling");
67+
} else {
68+
LOGGER.info("Compression: {}", compression);
69+
builder.withCompression(ProtocolOptions.Compression.valueOf(compression));
70+
}
71+
} else {
72+
LOGGER.info("Compression: NONE");
73+
}
74+
75+
String usePercentileSpeculativeExecutionPolicy = context.getProperty("cassandra.usePercentileSpeculativeExecutionPolicy");
76+
if ("true".equals(usePercentileSpeculativeExecutionPolicy)) {
77+
PerHostPercentileTracker perHostPercentileTracker = PerHostPercentileTracker.builderWithHighestTrackableLatencyMillis(15000).build();
78+
builder.withSpeculativeExecutionPolicy(new PercentileSpeculativeExecutionPolicy(perHostPercentileTracker, 99, 1));
79+
LOGGER.info("Use PercentileSpeculativeExecutionPolicy: YES");
80+
} else {
81+
LOGGER.info("Use PercentileSpeculativeExecutionPolicy: NO");
82+
}
83+
84+
cluster = builder.build();
5485

5586
Session session;
5687
try {
@@ -73,6 +104,7 @@ public void start(BundleContext context) throws Exception {
73104
mailbox.init();
74105

75106
context.registerService(MailboxService.class.getName(), mailbox, new Hashtable<String, String>());
107+
LOGGER.info("Mailbox Service successfully initialized");
76108
}
77109

78110
@Override

driver-tests/osgi/src/test/java/com/datastax/driver/osgi/BundleOptions.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.datastax.driver.osgi;
1717

18+
import com.datastax.driver.core.CCMBridge;
19+
import com.datastax.driver.core.ProtocolOptions;
1820
import com.datastax.driver.core.TestUtils;
1921
import org.ops4j.pax.exam.Option;
2022
import org.ops4j.pax.exam.options.CompositeOption;
@@ -48,6 +50,19 @@ public static MavenArtifactProvisionOption guavaBundle() {
4850
return mavenBundle("com.google.guava", "guava", "16.0.1");
4951
}
5052

53+
public static CompositeOption lz4Bundle() {
54+
return new CompositeOption() {
55+
56+
@Override
57+
public Option[] getOptions() {
58+
return options(
59+
systemProperty("cassandra.compression").value(ProtocolOptions.Compression.LZ4.name()),
60+
mavenBundle("net.jpountz.lz4", "lz4", "1.3.0")
61+
);
62+
}
63+
};
64+
}
65+
5166
public static CompositeOption nettyBundles() {
5267
final String nettyVersion = "4.0.33.Final";
5368
return new CompositeOption() {
@@ -78,12 +93,14 @@ public Option[] getOptions() {
7893
// Delegate javax.security.cert to the parent classloader. javax.security.cert.X509Certificate is used in
7994
// io.netty.util.internal.EmptyArrays, but not directly by the driver.
8095
bootDelegationPackage("javax.security.cert"),
96+
systemProperty("cassandra.version").value(CCMBridge.getCassandraVersion()),
8197
systemProperty("cassandra.contactpoints").value(TestUtils.IP_PREFIX + 1),
8298
systemProperty("logback.configurationFile").value("file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"),
8399
mavenBundle("org.slf4j", "slf4j-api", "1.7.5"),
84100
mavenBundle("ch.qos.logback", "logback-classic", "1.1.3"),
85101
mavenBundle("ch.qos.logback", "logback-core", "1.1.3"),
86102
mavenBundle("io.dropwizard.metrics", "metrics-core", "3.1.2"),
103+
mavenBundle("org.testng", "testng", "6.8.8"),
87104
systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation",
88105
"org.junit.runner.notification", "com.jcabi.manifests")
89106
);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.datastax.driver.osgi.api.MailboxException;
19+
import org.ops4j.pax.exam.Configuration;
20+
import org.ops4j.pax.exam.Option;
21+
import org.ops4j.pax.exam.testng.listener.PaxExam;
22+
import org.testng.annotations.Listeners;
23+
import org.testng.annotations.Test;
24+
25+
import static com.datastax.driver.osgi.BundleOptions.*;
26+
import static org.ops4j.pax.exam.CoreOptions.options;
27+
28+
@Listeners({CCMBridgeListener.class, PaxExam.class})
29+
public class MailboxServiceLZ4IT extends MailboxServiceTests {
30+
31+
@Configuration
32+
public Option[] lz4Config() {
33+
return options(
34+
defaultOptions(),
35+
lz4Bundle(),
36+
nettyBundles(),
37+
guavaBundle(),
38+
extrasBundle(),
39+
mappingBundle(),
40+
driverBundle(),
41+
mailboxBundle()
42+
);
43+
}
44+
45+
/**
46+
* Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver with
47+
* LZ4 compression activated.
48+
*
49+
* @test_category packaging
50+
* @expected_result Can create, retrieve and delete data using the mailbox service.
51+
* @jira_ticket JAVA-1200
52+
* @since 3.1.0
53+
*/
54+
@Test(groups = "short")
55+
public void test_lz4() throws MailboxException {
56+
checkService();
57+
}
58+
}

manual/compression/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Maven dependency:
2727
<dependency>
2828
<groupId>net.jpountz.lz4</groupId>
2929
<artifactId>lz4</artifactId>
30-
<version>1.2.0</version>
30+
<version>1.3.0</version>
3131
</dependency>
3232
```
3333

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<netty.version>4.0.37.Final</netty.version>
5555
<metrics.version>3.1.2</metrics.version>
5656
<snappy.version>1.0.5</snappy.version>
57-
<lz4.version>1.2.0</lz4.version>
57+
<lz4.version>1.3.0</lz4.version>
5858
<hdr.version>2.1.4</hdr.version>
5959
<!-- driver-extras module -->
6060
<jackson.version>2.6.3</jackson.version>

0 commit comments

Comments
 (0)