Skip to content

Commit 959049e

Browse files
Alexandre Dutraolim7t
authored andcommitted
JAVA-1133: Add OSGi headers to cassandra-driver-extras.
The problem was simply due to the fact that this module had a packaging type of jar instead of bundle. This commit also improves OSGi tests in driver-examples/osgi: 1) Included driver-mapping and driver-extras as a dependency. Tests now also validate that these modules are fully operational when accessed from within an OSGi container. 2) Split tests in different classes for a better reporting (different test names for each configuration) 3) Added Guava 19 as a supported Guava version for all bundles (driver-core, driver-mapping, driver-extras and driver-osgi). Tests in driver-examples/osgi now also test a configuration including Guava 19.0 explicitly. 4) Removed log4j dependency from parent pom. This can lead to multiple bindings on the classpath if some submodules (e.g. osgi) use a different logging backend. 5) Updated logback configuration file in osgi module. 6) Added project.reporting.outputEncoding Maven property in osgi pom file (Failsafe plugin requires it). 7) Deleted GuavaSanityCheckNegativeIT.
1 parent c19f7a9 commit 959049e

21 files changed

Lines changed: 650 additions & 360 deletions

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [improvement] JAVA-1113: Support Cassandra 3.4 LIKE operator in QueryBuilder.
1616
- [improvement] JAVA-1086: Support Cassandra 3.2 CAST function in QueryBuilder.
1717
- [bug] JAVA-1095: Check protocol version for custom payload before sending the query.
18+
- [improvement] JAVA-1133: Add OSGi headers to cassandra-driver-extras.
1819

1920
Merged from 2.1 branch:
2021

driver-core/pom.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@
136136
<scope>test</scope>
137137
</dependency>
138138

139+
<dependency>
140+
<groupId>log4j</groupId>
141+
<artifactId>log4j</artifactId>
142+
<version>${log4j.version}</version>
143+
<scope>test</scope>
144+
</dependency>
145+
146+
<dependency>
147+
<groupId>org.slf4j</groupId>
148+
<artifactId>slf4j-log4j12</artifactId>
149+
<version>${slf4j-log4j12.version}</version>
150+
<scope>test</scope>
151+
</dependency>
152+
139153
</dependencies>
140154

141155
<build>
@@ -173,7 +187,7 @@
173187
<Bundle-SymbolicName>com.datastax.driver.core</Bundle-SymbolicName>
174188
<Bundle-Version>${project.version}</Bundle-Version>
175189
<_include>-osgi.bnd</_include>
176-
<Import-Package><![CDATA[com.google.common*;version="[16.0.1,19)",*]]></Import-Package>
190+
<Import-Package><![CDATA[com.google.common*;version="[16.0.1,20)",*]]></Import-Package>
177191
</instructions>
178192
<supportedProjectTypes>
179193
<supportedProjectType>jar</supportedProjectType>

driver-examples/osgi/README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,33 @@
33
A simple example application that demonstrates using the Java Driver in
44
an OSGi service.
55

6-
MailboxService is an activated service that uses Cassandra to
7-
persist a Mailbox by email address.
6+
`MailboxService` is an OSGi service that uses Cassandra to
7+
store messages that can be retrieved by email address.
88

99
## Usage
1010

11-
To build the bundle and run tests execute the following maven task::
11+
To build the bundle and run tests, execute the following Maven goal:
1212

13-
mvn integration-test -P short
13+
mvn verify -P short
1414

15-
The short profile needs to be activated since the tests run under
15+
The "short" profile needs to be activated since the tests run under
1616
this group.
1717

18-
After which the bundle jar will be present in the target/ directory.
18+
Note: tests will try to load the jars of 3 dependent modules:
19+
`driver-core`, `driver-mapping` and `driver-extras`.
20+
For this to succeed, you need to run `mvn package`
21+
first for these modules and make sure the jars are present
22+
in each module's `target/` subdirectory.
1923

20-
The project includes an integration test that verifies the service can
24+
Once `mvn verify` completes, the bundle jar will be present in the `target/` directory.
25+
26+
The project includes integration tests that verify the service can
2127
be activated and used in an OSGi container. It also verifies that
2228
driver-core can be used in an OSGi container in the following
2329
configurations:
2430

2531
1. Default (default classifier with all dependencies)
2632
2. Netty-Shaded (shaded classifier with all depedencies w/o Netty)
27-
3. Guava 15 (default classifier with Guava 15.0)
28-
4. Guava 16
2933
5. Guava 17
3034
6. Guava 18
35+
7. Guava 19

driver-examples/osgi/pom.xml

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,49 @@
2323
<artifactId>cassandra-driver-examples-parent</artifactId>
2424
<version>3.0.1-SNAPSHOT</version>
2525
</parent>
26+
2627
<artifactId>cassandra-driver-examples-osgi</artifactId>
2728
<packaging>bundle</packaging>
2829
<name>DataStax Java Driver for Apache Cassandra Examples - OSGi</name>
2930
<description>An example of using DataStax Java Driver in an OSGi container.</description>
3031
<url>https://github.com/datastax/java-driver</url>
3132

3233
<properties>
34+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
3335
<felix.version>4.6.0</felix.version>
36+
<!-- more recent version require JDK7+ -->
3437
<pax-exam.version>3.6.0</pax-exam.version>
3538
<logback.version>1.1.3</logback.version>
39+
<test.groups>none</test.groups>
40+
<!--
41+
Skip tests by default, short or long profile is required to run tests in this module
42+
since pax-exam will throw exception if it encounters a
43+
test with no matching methods.
44+
-->
45+
<test.skip>true</test.skip>
3646
<main.basedir>${project.parent.parent.basedir}</main.basedir>
3747
</properties>
3848

3949
<dependencies>
50+
4051
<dependency>
4152
<groupId>com.datastax.cassandra</groupId>
4253
<artifactId>cassandra-driver-core</artifactId>
4354
<version>${project.parent.version}</version>
4455
</dependency>
4556

57+
<dependency>
58+
<groupId>com.datastax.cassandra</groupId>
59+
<artifactId>cassandra-driver-mapping</artifactId>
60+
<version>${project.parent.version}</version>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>com.datastax.cassandra</groupId>
65+
<artifactId>cassandra-driver-extras</artifactId>
66+
<version>${project.parent.version}</version>
67+
</dependency>
68+
4669
<dependency>
4770
<groupId>org.apache.felix</groupId>
4871
<artifactId>org.apache.felix.framework</artifactId>
@@ -131,23 +154,54 @@
131154
<artifactId>logback-core</artifactId>
132155
<version>${logback.version}</version>
133156
</dependency>
157+
134158
</dependencies>
135159

136160
<build>
161+
137162
<plugins>
163+
164+
<!--
165+
this project has no unit tests;
166+
this plugin is declared just so that Maven properties
167+
get automatically passed to tests run with IntelliJ
168+
-->
169+
<plugin>
170+
<groupId>org.apache.maven.plugins</groupId>
171+
<artifactId>maven-surefire-plugin</artifactId>
172+
<version>2.18.1</version>
173+
<configuration>
174+
<skip>true</skip>
175+
<systemPropertyVariables>
176+
<cassandra.version>${cassandra.version}</cassandra.version>
177+
<ipprefix>${ipprefix}</ipprefix>
178+
</systemPropertyVariables>
179+
</configuration>
180+
</plugin>
181+
138182
<plugin>
139183
<groupId>org.apache.maven.plugins</groupId>
140184
<artifactId>maven-failsafe-plugin</artifactId>
141-
<version>2.16</version>
185+
<version>2.18.1</version>
186+
<configuration>
187+
<skip>${test.skip}</skip>
188+
<groups>${test.groups}</groups>
189+
<systemPropertyVariables>
190+
<cassandra.version>${cassandra.version}</cassandra.version>
191+
<ipprefix>${ipprefix}</ipprefix>
192+
</systemPropertyVariables>
193+
</configuration>
142194
<executions>
143195
<execution>
196+
<id>default</id>
144197
<goals>
145198
<goal>integration-test</goal>
146199
<goal>verify</goal>
147200
</goals>
148201
</execution>
149202
</executions>
150203
</plugin>
204+
151205
<plugin>
152206
<groupId>org.apache.felix</groupId>
153207
<artifactId>maven-bundle-plugin</artifactId>
@@ -160,6 +214,7 @@
160214
<Export-Package>com.datastax.driver.osgi.api,!com.datastax.driver.osgi.impl</Export-Package>
161215
<Bundle-Activator>com.datastax.driver.osgi.impl.Activator</Bundle-Activator>
162216
<_include>-osgi.bnd</_include>
217+
<Import-Package><![CDATA[com.google.common*;version="[16.0.1,20)",*]]></Import-Package>
163218
</instructions>
164219
<supportedProjectTypes>
165220
<supportedProjectType>jar</supportedProjectType>
@@ -177,41 +232,29 @@
177232
</execution>
178233
</executions>
179234
</plugin>
235+
180236
</plugins>
237+
181238
</build>
182239

183240
<profiles>
241+
242+
<profile>
243+
<id>short</id>
244+
<properties>
245+
<test.groups>unit,short</test.groups>
246+
<test.skip>false</test.skip>
247+
</properties>
248+
</profile>
249+
184250
<profile>
185-
<!-- Skip test by default, short or long is required to run unit tests since pax-exam will throw exception if it encounters a
186-
test with no matching methods. -->
187-
<id>default</id>
251+
<id>long</id>
188252
<properties>
189-
<env>default</env>
253+
<test.groups>unit,short,long</test.groups>
254+
<test.skip>false</test.skip>
190255
</properties>
191-
<activation>
192-
<activeByDefault>true</activeByDefault>
193-
</activation>
194-
<build>
195-
<plugins>
196-
<plugin>
197-
<groupId>org.apache.maven.plugins</groupId>
198-
<artifactId>maven-surefire-plugin</artifactId>
199-
<version>2.16</version>
200-
<configuration>
201-
<skip>true</skip>
202-
</configuration>
203-
</plugin>
204-
<plugin>
205-
<groupId>org.apache.maven.plugins</groupId>
206-
<artifactId>maven-failsafe-plugin</artifactId>
207-
<version>2.16</version>
208-
<configuration>
209-
<skip>true</skip>
210-
</configuration>
211-
</plugin>
212-
</plugins>
213-
</build>
214256
</profile>
257+
215258
</profiles>
216259

217260
<licenses>

driver-examples/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxMessage.java

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,41 @@
1515
*/
1616
package com.datastax.driver.osgi.api;
1717

18-
import java.util.Date;
18+
import com.datastax.driver.extras.codecs.date.SimpleTimestampCodec;
19+
import com.datastax.driver.mapping.annotations.ClusteringColumn;
20+
import com.datastax.driver.mapping.annotations.Column;
21+
import com.datastax.driver.mapping.annotations.PartitionKey;
22+
import com.datastax.driver.mapping.annotations.Table;
23+
import com.google.common.base.Objects;
1924

25+
import static com.datastax.driver.osgi.api.MailboxMessage.TABLE;
26+
27+
/**
28+
* A mailbox message entity mapped to the table <code>{@value #TABLE}</code>.
29+
*/
30+
@SuppressWarnings("unused")
31+
@Table(name = TABLE)
2032
public class MailboxMessage {
33+
34+
public static final String TABLE = "mailbox";
35+
36+
@PartitionKey
2137
private String recipient;
22-
private Date date;
38+
39+
@ClusteringColumn
40+
@Column(name = "time", codec = SimpleTimestampCodec.class)
41+
private long date;
42+
43+
@Column
2344
private String sender;
45+
46+
@Column
2447
private String body;
2548

26-
public MailboxMessage(String recipient, Date date, String sender, String body) {
49+
public MailboxMessage() {
50+
}
51+
52+
public MailboxMessage(String recipient, long date, String sender, String body) {
2753
this.recipient = recipient;
2854
this.date = date;
2955
this.sender = sender;
@@ -34,28 +60,47 @@ public String getRecipient() {
3460
return recipient;
3561
}
3662

37-
public Date getDate() {
63+
public void setRecipient(String recipient) {
64+
this.recipient = recipient;
65+
}
66+
67+
public long getDate() {
3868
return date;
3969
}
4070

71+
public void setDate(long date) {
72+
this.date = date;
73+
}
74+
4175
public String getSender() {
4276
return sender;
4377
}
4478

79+
public void setSender(String sender) {
80+
this.sender = sender;
81+
}
82+
4583
public String getBody() {
4684
return body;
4785
}
4886

87+
public void setBody(String body) {
88+
this.body = body;
89+
}
90+
91+
@Override
92+
public boolean equals(Object o) {
93+
if (this == o) return true;
94+
if (o == null || getClass() != o.getClass()) return false;
95+
MailboxMessage that = (MailboxMessage) o;
96+
return date == that.date &&
97+
Objects.equal(recipient, that.recipient) &&
98+
Objects.equal(sender, that.sender) &&
99+
Objects.equal(body, that.body);
100+
}
101+
49102
@Override
50-
public boolean equals(Object that) {
51-
if (that instanceof MailboxMessage) {
52-
MailboxMessage thatM = (MailboxMessage) that;
53-
return recipient.equals(thatM.getRecipient()) &&
54-
date.equals(thatM.getDate()) &&
55-
sender.equals(thatM.getSender()) &&
56-
body.equals(thatM.getBody());
57-
} else {
58-
return false;
59-
}
103+
public int hashCode() {
104+
return Objects.hashCode(recipient, date, sender, body);
60105
}
61106
}

driver-examples/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxService.java

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

18-
import java.util.Collection;
19-
import java.util.UUID;
20-
2118
public interface MailboxService {
2219

2320
/**
@@ -26,15 +23,15 @@ public interface MailboxService {
2623
* @param recipient User whose mailbox is being read.
2724
* @return All messages in the mailbox.
2825
*/
29-
public Collection<MailboxMessage> getMessages(String recipient) throws MailboxException;
26+
public Iterable<MailboxMessage> getMessages(String recipient) throws MailboxException;
3027

3128
/**
3229
* Stores the given message in the appropriate mailbox.
3330
*
3431
* @param message Message to send.
35-
* @return UUID generated for the message.
32+
* @return The timestamp generated for the message (milliseconds since the Epoch).
3633
*/
37-
public UUID sendMessage(MailboxMessage message) throws MailboxException;
34+
public long sendMessage(MailboxMessage message) throws MailboxException;
3835

3936
/**
4037
* Deletes all mail for the given recipient.

0 commit comments

Comments
 (0)