kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | ae86723b0d851a7b832472777caaddf1e05d1f9e2c190fbd508023244b560495 |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2016-04-26 16:11 +02:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2016-04-26 16:11 +02:00 |
| Parents | ced5ba920359, 28340c9afa42 |
21 files changed
modified changelog/README.md +1 −0
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | - [improvement] JAVA-1113: Support Cassandra 3.4 LIKE operator in QueryBuilder. |
| 16 | 16 | - [improvement] JAVA-1086: Support Cassandra 3.2 CAST function in QueryBuilder. |
| 17 | 17 | - [bug] JAVA-1095: Check protocol version for custom payload before sending the query. |
| 18 | +- [improvement] JAVA-1133: Add OSGi headers to cassandra-driver-extras. | |
| 18 | 19 | |
| 19 | 20 | Merged from 2.1 branch: |
| 20 | 21 |
modified driver-core/pom.xml +15 −1
| @@ -136,6 +136,20 @@ | ||
| 136 | 136 | <scope>test</scope> |
| 137 | 137 | </dependency> |
| 138 | 138 | |
| 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 | + | |
| 139 | 153 | </dependencies> |
| 140 | 154 | |
| 141 | 155 | <build> |
| @@ -173,7 +187,7 @@ | ||
| 173 | 187 | <Bundle-SymbolicName>com.datastax.driver.core</Bundle-SymbolicName> |
| 174 | 188 | <Bundle-Version>${project.version}</Bundle-Version> |
| 175 | 189 | <_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> | |
| 177 | 191 | </instructions> |
| 178 | 192 | <supportedProjectTypes> |
| 179 | 193 | <supportedProjectType>jar</supportedProjectType> |
modified driver-examples/osgi/README.md +14 −9
| @@ -3,28 +3,33 @@ | ||
| 3 | 3 | A simple example application that demonstrates using the Java Driver in |
| 4 | 4 | an OSGi service. |
| 5 | 5 | |
| 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. | |
| 8 | 8 | |
| 9 | 9 | ## Usage |
| 10 | 10 | |
| 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: | |
| 12 | 12 | |
| 13 | - mvn integration-test -P short | |
| 13 | + mvn verify -P short | |
| 14 | 14 | |
| 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 | |
| 16 | 16 | this group. |
| 17 | 17 | |
| 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. | |
| 19 | 23 | |
| 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 | |
| 21 | 27 | be activated and used in an OSGi container. It also verifies that |
| 22 | 28 | driver-core can be used in an OSGi container in the following |
| 23 | 29 | configurations: |
| 24 | 30 | |
| 25 | 31 | 1. Default (default classifier with all dependencies) |
| 26 | 32 | 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 | |
| 29 | 33 | 5. Guava 17 |
| 30 | 34 | 6. Guava 18 |
| 35 | +7. Guava 19 |
modified driver-examples/osgi/pom.xml +71 −28
| @@ -23,6 +23,7 @@ | ||
| 23 | 23 | <artifactId>cassandra-driver-examples-parent</artifactId> |
| 24 | 24 | <version>3.0.1-SNAPSHOT</version> |
| 25 | 25 | </parent> |
| 26 | + | |
| 26 | 27 | <artifactId>cassandra-driver-examples-osgi</artifactId> |
| 27 | 28 | <packaging>bundle</packaging> |
| 28 | 29 | <name>DataStax Java Driver for Apache Cassandra Examples - OSGi</name> |
| @@ -30,19 +31,41 @@ | ||
| 30 | 31 | <url>https://github.com/datastax/java-driver</url> |
| 31 | 32 | |
| 32 | 33 | <properties> |
| 34 | + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | |
| 33 | 35 | <felix.version>4.6.0</felix.version> |
| 36 | + <!-- more recent version require JDK7+ --> | |
| 34 | 37 | <pax-exam.version>3.6.0</pax-exam.version> |
| 35 | 38 | <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> | |
| 36 | 46 | <main.basedir>${project.parent.parent.basedir}</main.basedir> |
| 37 | 47 | </properties> |
| 38 | 48 | |
| 39 | 49 | <dependencies> |
| 50 | + | |
| 40 | 51 | <dependency> |
| 41 | 52 | <groupId>com.datastax.cassandra</groupId> |
| 42 | 53 | <artifactId>cassandra-driver-core</artifactId> |
| 43 | 54 | <version>${project.parent.version}</version> |
| 44 | 55 | </dependency> |
| 45 | 56 | |
| 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 | + | |
| 46 | 69 | <dependency> |
| 47 | 70 | <groupId>org.apache.felix</groupId> |
| 48 | 71 | <artifactId>org.apache.felix.framework</artifactId> |
| @@ -131,16 +154,46 @@ | ||
| 131 | 154 | <artifactId>logback-core</artifactId> |
| 132 | 155 | <version>${logback.version}</version> |
| 133 | 156 | </dependency> |
| 157 | + | |
| 134 | 158 | </dependencies> |
| 135 | 159 | |
| 136 | 160 | <build> |
| 161 | + | |
| 137 | 162 | <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 | + | |
| 138 | 182 | <plugin> |
| 139 | 183 | <groupId>org.apache.maven.plugins</groupId> |
| 140 | 184 | <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> | |
| 142 | 194 | <executions> |
| 143 | 195 | <execution> |
| 196 | + <id>default</id> | |
| 144 | 197 | <goals> |
| 145 | 198 | <goal>integration-test</goal> |
| 146 | 199 | <goal>verify</goal> |
| @@ -148,6 +201,7 @@ | ||
| 148 | 201 | </execution> |
| 149 | 202 | </executions> |
| 150 | 203 | </plugin> |
| 204 | + | |
| 151 | 205 | <plugin> |
| 152 | 206 | <groupId>org.apache.felix</groupId> |
| 153 | 207 | <artifactId>maven-bundle-plugin</artifactId> |
| @@ -160,6 +214,7 @@ | ||
| 160 | 214 | <Export-Package>com.datastax.driver.osgi.api,!com.datastax.driver.osgi.impl</Export-Package> |
| 161 | 215 | <Bundle-Activator>com.datastax.driver.osgi.impl.Activator</Bundle-Activator> |
| 162 | 216 | <_include>-osgi.bnd</_include> |
| 217 | + <Import-Package><![CDATA[com.google.common*;version="[16.0.1,20)",*]]></Import-Package> | |
| 163 | 218 | </instructions> |
| 164 | 219 | <supportedProjectTypes> |
| 165 | 220 | <supportedProjectType>jar</supportedProjectType> |
| @@ -177,41 +232,29 @@ | ||
| 177 | 232 | </execution> |
| 178 | 233 | </executions> |
| 179 | 234 | </plugin> |
| 235 | + | |
| 180 | 236 | </plugins> |
| 237 | + | |
| 181 | 238 | </build> |
| 182 | 239 | |
| 183 | 240 | <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 | + | |
| 184 | 250 | <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> | |
| 188 | 252 | <properties> |
| 189 | - <env>default</env> | |
| 253 | + <test.groups>unit,short,long</test.groups> | |
| 254 | + <test.skip>false</test.skip> | |
| 190 | 255 | </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> | |
| 214 | 256 | </profile> |
| 257 | + | |
| 215 | 258 | </profiles> |
| 216 | 259 | |
| 217 | 260 | <licenses> |
modified driver-examples/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxMessage.java +59 −14
| @@ -15,15 +15,41 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.osgi.api; |
| 17 | 17 | |
| 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; | |
| 19 | 24 | |
| 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) | |
| 20 | 32 | public class MailboxMessage { |
| 33 | + | |
| 34 | + public static final String TABLE = "mailbox"; | |
| 35 | + | |
| 36 | + @PartitionKey | |
| 21 | 37 | private String recipient; |
| 22 | - private Date date; | |
| 38 | + | |
| 39 | + @ClusteringColumn | |
| 40 | + @Column(name = "time", codec = SimpleTimestampCodec.class) | |
| 41 | + private long date; | |
| 42 | + | |
| 43 | + @Column | |
| 23 | 44 | private String sender; |
| 45 | + | |
| 46 | + @Column | |
| 24 | 47 | private String body; |
| 25 | 48 | |
| 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) { | |
| 27 | 53 | this.recipient = recipient; |
| 28 | 54 | this.date = date; |
| 29 | 55 | this.sender = sender; |
| @@ -34,28 +60,47 @@ | ||
| 34 | 60 | return recipient; |
| 35 | 61 | } |
| 36 | 62 | |
| 37 | - public Date getDate() { | |
| 63 | + public void setRecipient(String recipient) { | |
| 64 | + this.recipient = recipient; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public long getDate() { | |
| 38 | 68 | return date; |
| 39 | 69 | } |
| 40 | 70 | |
| 71 | + public void setDate(long date) { | |
| 72 | + this.date = date; | |
| 73 | + } | |
| 74 | + | |
| 41 | 75 | public String getSender() { |
| 42 | 76 | return sender; |
| 43 | 77 | } |
| 44 | 78 | |
| 79 | + public void setSender(String sender) { | |
| 80 | + this.sender = sender; | |
| 81 | + } | |
| 82 | + | |
| 45 | 83 | public String getBody() { |
| 46 | 84 | return body; |
| 47 | 85 | } |
| 48 | 86 | |
| 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 | + | |
| 49 | 102 | @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); | |
| 60 | 105 | } |
| 61 | 106 | } |
modified driver-examples/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxService.java +3 −6
| @@ -15,9 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.osgi.api; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.UUID; | |
| 20 | - | |
| 21 | 18 | public interface MailboxService { |
| 22 | 19 | |
| 23 | 20 | /** |
| @@ -26,15 +23,15 @@ | ||
| 26 | 23 | * @param recipient User whose mailbox is being read. |
| 27 | 24 | * @return All messages in the mailbox. |
| 28 | 25 | */ |
| 29 | - public Collection<MailboxMessage> getMessages(String recipient) throws MailboxException; | |
| 26 | + public Iterable<MailboxMessage> getMessages(String recipient) throws MailboxException; | |
| 30 | 27 | |
| 31 | 28 | /** |
| 32 | 29 | * Stores the given message in the appropriate mailbox. |
| 33 | 30 | * |
| 34 | 31 | * @param message Message to send. |
| 35 | - * @return UUID generated for the message. | |
| 32 | + * @return The timestamp generated for the message (milliseconds since the Epoch). | |
| 36 | 33 | */ |
| 37 | - public UUID sendMessage(MailboxMessage message) throws MailboxException; | |
| 34 | + public long sendMessage(MailboxMessage message) throws MailboxException; | |
| 38 | 35 | |
| 39 | 36 | /** |
| 40 | 37 | * Deletes all mail for the given recipient. |
modified driver-examples/osgi/src/main/java/com/datastax/driver/osgi/impl/Activator.java +40 −3
| @@ -16,13 +16,19 @@ | ||
| 16 | 16 | package com.datastax.driver.osgi.impl; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.Cluster; |
| 19 | +import com.datastax.driver.core.CodecRegistry; | |
| 20 | +import com.datastax.driver.core.Metadata; | |
| 19 | 21 | import com.datastax.driver.core.Session; |
| 22 | +import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 23 | +import com.datastax.driver.extras.codecs.date.SimpleTimestampCodec; | |
| 20 | 24 | import com.datastax.driver.osgi.api.MailboxService; |
| 21 | 25 | import org.osgi.framework.BundleActivator; |
| 22 | 26 | import org.osgi.framework.BundleContext; |
| 23 | 27 | |
| 24 | 28 | import java.util.Hashtable; |
| 25 | 29 | |
| 30 | +import static com.datastax.driver.osgi.api.MailboxMessage.TABLE; | |
| 31 | + | |
| 26 | 32 | public class Activator implements BundleActivator { |
| 27 | 33 | |
| 28 | 34 | private Cluster cluster; |
| @@ -39,9 +45,29 @@ | ||
| 39 | 45 | if (keyspace == null) { |
| 40 | 46 | keyspace = "mailbox"; |
| 41 | 47 | } |
| 42 | - | |
| 43 | - cluster = Cluster.builder().addContactPoints(contactPoints).build(); | |
| 44 | - Session session = cluster.connect(); | |
| 48 | + keyspace = Metadata.quote(keyspace); | |
| 49 | + | |
| 50 | + cluster = Cluster.builder() | |
| 51 | + .addContactPoints(contactPoints) | |
| 52 | + .withCodecRegistry(new CodecRegistry().register(SimpleTimestampCodec.instance)) | |
| 53 | + .build(); | |
| 54 | + | |
| 55 | + Session session; | |
| 56 | + try { | |
| 57 | + session = cluster.connect(keyspace); | |
| 58 | + } catch (InvalidQueryException e) { | |
| 59 | + // Create the schema if it does not exist. | |
| 60 | + session = cluster.connect(); | |
| 61 | + session.execute("CREATE KEYSPACE " + keyspace + | |
| 62 | + " with replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}"); | |
| 63 | + session.execute("CREATE TABLE " + keyspace + "." + TABLE + " (" + | |
| 64 | + "recipient text," + | |
| 65 | + "time timestamp," + | |
| 66 | + "sender text," + | |
| 67 | + "body text," + | |
| 68 | + "PRIMARY KEY (recipient, time))"); | |
| 69 | + session.execute("USE " + keyspace); | |
| 70 | + } | |
| 45 | 71 | |
| 46 | 72 | MailboxImpl mailbox = new MailboxImpl(session, keyspace); |
| 47 | 73 | mailbox.init(); |
| @@ -53,6 +79,17 @@ | ||
| 53 | 79 | public void stop(BundleContext context) throws Exception { |
| 54 | 80 | if (cluster != null) { |
| 55 | 81 | cluster.close(); |
| 82 | + /* | |
| 83 | + Allow Netty ThreadDeathWatcher to terminate; | |
| 84 | + unfortunately we can't explicitly call ThreadDeathWatcher.awaitInactivity() | |
| 85 | + because Netty could be shaded. | |
| 86 | + If this thread isn't terminated when this bundle is closed, | |
| 87 | + we could get exceptions such as this one: | |
| 88 | + Exception in thread "threadDeathWatcher-2-1" java.lang.NoClassDefFoundError: xxx | |
| 89 | + Caused by: java.lang.ClassNotFoundException: Unable to load class 'xxx' because the bundle wiring for xxx is no longer valid. | |
| 90 | + Although ugly, they are harmless and can be safely ignored. | |
| 91 | + */ | |
| 92 | + Thread.sleep(1000); | |
| 56 | 93 | } |
| 57 | 94 | } |
| 58 | 95 | } |
modified driver-examples/osgi/src/main/java/com/datastax/driver/osgi/impl/MailboxImpl.java +17 −56
| @@ -15,24 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.osgi.impl; |
| 17 | 17 | |
| 18 | -import com.datastax.driver.core.*; | |
| 19 | -import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 20 | -import com.datastax.driver.core.utils.UUIDs; | |
| 18 | +import com.datastax.driver.core.BoundStatement; | |
| 19 | +import com.datastax.driver.core.PreparedStatement; | |
| 20 | +import com.datastax.driver.core.Session; | |
| 21 | +import com.datastax.driver.mapping.Mapper; | |
| 22 | +import com.datastax.driver.mapping.MappingManager; | |
| 21 | 23 | import com.datastax.driver.osgi.api.MailboxException; |
| 22 | 24 | import com.datastax.driver.osgi.api.MailboxMessage; |
| 23 | 25 | import com.datastax.driver.osgi.api.MailboxService; |
| 24 | 26 | |
| 25 | -import java.util.ArrayList; | |
| 26 | -import java.util.Collection; | |
| 27 | -import java.util.Date; | |
| 28 | -import java.util.UUID; | |
| 29 | - | |
| 30 | 27 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 28 | +import static com.datastax.driver.osgi.api.MailboxMessage.TABLE; | |
| 31 | 29 | |
| 32 | 30 | public class MailboxImpl implements MailboxService { |
| 33 | 31 | |
| 34 | - private static final String TABLE = "mailbox"; | |
| 35 | - | |
| 36 | 32 | private final Session session; |
| 37 | 33 | |
| 38 | 34 | private final String keyspace; |
| @@ -41,10 +37,10 @@ | ||
| 41 | 37 | |
| 42 | 38 | private PreparedStatement retrieveStatement; |
| 43 | 39 | |
| 44 | - private PreparedStatement insertStatement; | |
| 45 | - | |
| 46 | 40 | private PreparedStatement deleteStatement; |
| 47 | 41 | |
| 42 | + private Mapper<MailboxMessage> mapper; | |
| 43 | + | |
| 48 | 44 | public MailboxImpl(Session session, String keyspace) { |
| 49 | 45 | this.session = session; |
| 50 | 46 | this.keyspace = keyspace; |
| @@ -54,71 +50,36 @@ | ||
| 54 | 50 | if (initialized) |
| 55 | 51 | return; |
| 56 | 52 | |
| 57 | - // Create the schema if it does not exist. | |
| 58 | - try { | |
| 59 | - session.execute("USE " + keyspace); | |
| 60 | - } catch (InvalidQueryException e) { | |
| 61 | - session.execute("CREATE KEYSPACE " + keyspace + | |
| 62 | - " with replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}"); | |
| 63 | - | |
| 64 | - session.execute("CREATE TABLE " + keyspace + "." + TABLE + " (" + | |
| 65 | - "recipient text," + | |
| 66 | - "time timeuuid," + | |
| 67 | - "sender text," + | |
| 68 | - "body text," + | |
| 69 | - "PRIMARY KEY (recipient, time))"); | |
| 70 | - } | |
| 71 | - | |
| 72 | 53 | retrieveStatement = session.prepare(select() |
| 73 | 54 | .from(keyspace, TABLE) |
| 74 | 55 | .where(eq("recipient", bindMarker()))); |
| 75 | 56 | |
| 76 | - insertStatement = session.prepare(insertInto(keyspace, TABLE) | |
| 77 | - .value("recipient", bindMarker()) | |
| 78 | - .value("time", bindMarker()) | |
| 79 | - .value("sender", bindMarker()) | |
| 80 | - .value("body", bindMarker())); | |
| 81 | - | |
| 82 | 57 | deleteStatement = session.prepare(delete().from(keyspace, TABLE) |
| 83 | 58 | .where(eq("recipient", bindMarker()))); |
| 84 | 59 | |
| 60 | + MappingManager mappingManager = new MappingManager(session); | |
| 61 | + | |
| 62 | + mapper = mappingManager.mapper(MailboxMessage.class); | |
| 63 | + | |
| 85 | 64 | initialized = true; |
| 86 | 65 | } |
| 87 | 66 | |
| 88 | 67 | @Override |
| 89 | - public Collection<MailboxMessage> getMessages(String recipient) throws MailboxException { | |
| 68 | + public Iterable<MailboxMessage> getMessages(String recipient) throws MailboxException { | |
| 90 | 69 | try { |
| 91 | 70 | BoundStatement statement = new BoundStatement(retrieveStatement); |
| 92 | 71 | statement.setString(0, recipient); |
| 93 | - ResultSet result = session.execute(statement); | |
| 94 | - | |
| 95 | - Collection<MailboxMessage> messages = new ArrayList<MailboxMessage>(); | |
| 96 | - for (Row input : result) { | |
| 97 | - Date date = new Date(UUIDs.unixTimestamp(input.getUUID("time"))); | |
| 98 | - messages.add(new MailboxMessage(input.getString("recipient"), | |
| 99 | - date, | |
| 100 | - input.getString("sender"), | |
| 101 | - input.getString("body"))); | |
| 102 | - } | |
| 103 | - return messages; | |
| 72 | + return mapper.map(session.execute(statement)); | |
| 104 | 73 | } catch (Exception e) { |
| 105 | 74 | throw new MailboxException(e); |
| 106 | 75 | } |
| 107 | 76 | } |
| 108 | 77 | |
| 109 | 78 | @Override |
| 110 | - public UUID sendMessage(MailboxMessage message) throws MailboxException { | |
| 79 | + public long sendMessage(MailboxMessage message) throws MailboxException { | |
| 111 | 80 | try { |
| 112 | - UUID time = UUIDs.startOf(message.getDate().getTime()); | |
| 113 | - | |
| 114 | - BoundStatement statement = new BoundStatement(insertStatement); | |
| 115 | - statement.setString(0, message.getRecipient()); | |
| 116 | - statement.setUUID(1, time); | |
| 117 | - statement.setString(2, message.getSender()); | |
| 118 | - statement.setString(3, message.getBody()); | |
| 119 | - | |
| 120 | - session.execute(statement); | |
| 121 | - return time; | |
| 81 | + mapper.save(message); | |
| 82 | + return message.getDate(); | |
| 122 | 83 | } catch (Exception e) { |
| 123 | 84 | throw new MailboxException(e); |
| 124 | 85 | } |
modified driver-examples/osgi/src/test/java/com/datastax/driver/osgi/BundleOptions.java +8 −0
| @@ -36,6 +36,14 @@ | ||
| 36 | 36 | return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-core/target/cassandra-driver-core-" + projectVersion() + classifier + ".jar"); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | + public static UrlProvisionOption mappingBundle() { | |
| 40 | + return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-mapping/target/cassandra-driver-mapping-" + projectVersion() + ".jar"); | |
| 41 | + } | |
| 42 | + | |
| 43 | + public static UrlProvisionOption extrasBundle() { | |
| 44 | + return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-extras/target/cassandra-driver-extras-" + projectVersion() + ".jar"); | |
| 45 | + } | |
| 46 | + | |
| 39 | 47 | public static MavenArtifactProvisionOption guavaBundle() { |
| 40 | 48 | return mavenBundle("com.google.guava", "guava", "16.0.1"); |
| 41 | 49 | } |
deleted driver-examples/osgi/src/test/java/com/datastax/driver/osgi/GuavaSanityCheckNegativeIT.java +0 −100
| @@ -1,100 +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.datastax.driver.core.Cluster; | |
| 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 | -import static org.testng.Assert.assertTrue; | |
| 28 | -import static org.testng.Assert.fail; | |
| 29 | - | |
| 30 | -/** | |
| 31 | - * This test is no longer valid since the driver bundle has the following new requirement | |
| 32 | - * for Guava: {@code [16.0.1,19)}. | |
| 33 | - */ | |
| 34 | -@Listeners({PaxExam.class}) | |
| 35 | -@Test(groups = "short", enabled = false) | |
| 36 | -public class GuavaSanityCheckNegativeIT { | |
| 37 | - | |
| 38 | - @Configuration | |
| 39 | - public Option[] guava14_0_1Config() { | |
| 40 | - return options( | |
| 41 | - driverBundle(), | |
| 42 | - nettyBundles(), | |
| 43 | - guavaBundle().version("14.0.1"), | |
| 44 | - defaultOptions() | |
| 45 | - ); | |
| 46 | - } | |
| 47 | - | |
| 48 | - @Configuration | |
| 49 | - public Option[] guava15Config() { | |
| 50 | - return options( | |
| 51 | - driverBundle(), | |
| 52 | - nettyBundles(), | |
| 53 | - guavaBundle().version("15.0"), | |
| 54 | - defaultOptions() | |
| 55 | - ); | |
| 56 | - } | |
| 57 | - | |
| 58 | - @Configuration | |
| 59 | - public Option[] guava16Config() { | |
| 60 | - return options( | |
| 61 | - driverBundle(), | |
| 62 | - nettyBundles(), | |
| 63 | - guavaBundle().version("16.0"), | |
| 64 | - defaultOptions() | |
| 65 | - ); | |
| 66 | - } | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * <p> | |
| 70 | - * Validates that the driver is able to detect that the guava library in the classpath is | |
| 71 | - * less than version 16.01 and throws an {@link IllegalStateException} in this case and | |
| 72 | - * is raised as the cause of an {@link ExceptionInInitializerError} since the failure | |
| 73 | - * occurs at static initialization. | |
| 74 | - * </p> | |
| 75 | - * <p/> | |
| 76 | - * The following configurations are tried (defined via methods with the @Configuration annotation): | |
| 77 | - * <ol> | |
| 78 | - * <li>With Guava 14.0.1</li> | |
| 79 | - * <li>With Guava 15.0</li> | |
| 80 | - * <li>With Guava 16.0</li> | |
| 81 | - * </ol> | |
| 82 | - * | |
| 83 | - * @test_category packaging | |
| 84 | - * @expected_result An {@link IllegalStateException} is thrown. | |
| 85 | - * @jira_ticket JAVA-961 | |
| 86 | - * @since 3.0.0-beta1 | |
| 87 | - */ | |
| 88 | - public void should_raise_guava_version_error_if_lt_16_0_1() throws Throwable { | |
| 89 | - try { | |
| 90 | - Cluster.builder(); | |
| 91 | - fail("Expected an IllegalStateException for Guava version incompatibility"); | |
| 92 | - } catch (ExceptionInInitializerError e) { | |
| 93 | - try { | |
| 94 | - throw e.getCause(); | |
| 95 | - } catch (IllegalStateException ise) { | |
| 96 | - assertTrue(ise.getMessage().contains("Detected Guava issue #1635")); | |
| 97 | - } | |
| 98 | - } | |
| 99 | - } | |
| 100 | -} |
added driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceDefaultIT.java +57 −0
| @@ -0,0 +1,57 @@ | ||
| 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 MailboxServiceDefaultIT extends MailboxServiceTests { | |
| 30 | + | |
| 31 | + @Configuration | |
| 32 | + public Option[] defaultConfig() { | |
| 33 | + return options( | |
| 34 | + defaultOptions(), | |
| 35 | + nettyBundles(), | |
| 36 | + guavaBundle(), | |
| 37 | + driverBundle(), | |
| 38 | + extrasBundle(), | |
| 39 | + mappingBundle(), | |
| 40 | + mailboxBundle() | |
| 41 | + ); | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver with | |
| 46 | + * default configuration (driver with all of its regular dependencies). | |
| 47 | + * | |
| 48 | + * @test_category packaging | |
| 49 | + * @expected_result Can create, retrieve and delete data using the mailbox service. | |
| 50 | + * @jira_ticket JAVA-620 | |
| 51 | + * @since 2.0.10, 2.1.5 | |
| 52 | + */ | |
| 53 | + @Test(groups = "short") | |
| 54 | + public void test_default() throws MailboxException { | |
| 55 | + checkService(); | |
| 56 | + } | |
| 57 | +} |
added driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceGuava17IT.java +57 −0
| @@ -0,0 +1,57 @@ | ||
| 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 MailboxServiceGuava17IT extends MailboxServiceTests { | |
| 30 | + | |
| 31 | + @Configuration | |
| 32 | + public Option[] guava17Config() { | |
| 33 | + return options( | |
| 34 | + defaultOptions(), | |
| 35 | + nettyBundles(), | |
| 36 | + guavaBundle().version("17.0"), | |
| 37 | + driverBundle(), | |
| 38 | + mappingBundle(), | |
| 39 | + extrasBundle(), | |
| 40 | + mailboxBundle() | |
| 41 | + ); | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver with | |
| 46 | + * Guava 17 explicitly enforced. | |
| 47 | + * | |
| 48 | + * @test_category packaging | |
| 49 | + * @expected_result Can create, retrieve and delete data using the mailbox service. | |
| 50 | + * @jira_ticket JAVA-620 | |
| 51 | + * @since 2.0.10, 2.1.5 | |
| 52 | + */ | |
| 53 | + @Test(groups = "short") | |
| 54 | + public void test_guava_17() throws MailboxException { | |
| 55 | + checkService(); | |
| 56 | + } | |
| 57 | +} |
added driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceGuava18IT.java +57 −0
| @@ -0,0 +1,57 @@ | ||
| 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 MailboxServiceGuava18IT extends MailboxServiceTests { | |
| 30 | + | |
| 31 | + @Configuration | |
| 32 | + public Option[] guava18Config() { | |
| 33 | + return options( | |
| 34 | + defaultOptions(), | |
| 35 | + nettyBundles(), | |
| 36 | + guavaBundle().version("18.0"), | |
| 37 | + driverBundle(), | |
| 38 | + extrasBundle(), | |
| 39 | + mappingBundle(), | |
| 40 | + mailboxBundle() | |
| 41 | + ); | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver with | |
| 46 | + * Guava 18 explicitly enforced. | |
| 47 | + * | |
| 48 | + * @test_category packaging | |
| 49 | + * @expected_result Can create, retrieve and delete data using the mailbox service. | |
| 50 | + * @jira_ticket JAVA-620 | |
| 51 | + * @since 2.0.10, 2.1.5 | |
| 52 | + */ | |
| 53 | + @Test(groups = "short") | |
| 54 | + public void test_guava_18() throws MailboxException { | |
| 55 | + checkService(); | |
| 56 | + } | |
| 57 | +} |
added driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceGuava19IT.java +57 −0
| @@ -0,0 +1,57 @@ | ||
| 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 MailboxServiceGuava19IT extends MailboxServiceTests { | |
| 30 | + | |
| 31 | + @Configuration | |
| 32 | + public Option[] guava19Config() { | |
| 33 | + return options( | |
| 34 | + defaultOptions(), | |
| 35 | + nettyBundles(), | |
| 36 | + guavaBundle().version("19.0"), | |
| 37 | + driverBundle(), | |
| 38 | + extrasBundle(), | |
| 39 | + mappingBundle(), | |
| 40 | + mailboxBundle() | |
| 41 | + ); | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver with | |
| 46 | + * Guava 19 explicitly enforced. | |
| 47 | + * | |
| 48 | + * @test_category packaging | |
| 49 | + * @expected_result Can create, retrieve and delete data using the mailbox service. | |
| 50 | + * @jira_ticket JAVA-620 | |
| 51 | + * @since 2.0.10, 2.1.5 | |
| 52 | + */ | |
| 53 | + @Test(groups = "short") | |
| 54 | + public void test_guava_19() throws MailboxException { | |
| 55 | + checkService(); | |
| 56 | + } | |
| 57 | +} |
deleted driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceIT.java +0 −124
| @@ -1,124 +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.datastax.driver.osgi.api.MailboxException; | |
| 19 | -import com.datastax.driver.osgi.api.MailboxMessage; | |
| 20 | -import com.datastax.driver.osgi.api.MailboxService; | |
| 21 | -import org.ops4j.pax.exam.Configuration; | |
| 22 | -import org.ops4j.pax.exam.Option; | |
| 23 | -import org.ops4j.pax.exam.testng.listener.PaxExam; | |
| 24 | -import org.testng.annotations.Listeners; | |
| 25 | -import org.testng.annotations.Test; | |
| 26 | - | |
| 27 | -import javax.inject.Inject; | |
| 28 | -import java.util.ArrayList; | |
| 29 | -import java.util.Collection; | |
| 30 | -import java.util.GregorianCalendar; | |
| 31 | - | |
| 32 | -import static com.datastax.driver.osgi.BundleOptions.*; | |
| 33 | -import static org.ops4j.pax.exam.CoreOptions.options; | |
| 34 | -import static org.testng.Assert.assertEquals; | |
| 35 | - | |
| 36 | -@Listeners({CCMBridgeListener.class, PaxExam.class}) | |
| 37 | -@Test(groups = "short") | |
| 38 | -public class MailboxServiceIT { | |
| 39 | - @Inject | |
| 40 | - MailboxService service; | |
| 41 | - | |
| 42 | - @Configuration | |
| 43 | - public Option[] shadedConfig() { | |
| 44 | - return options( | |
| 45 | - driverBundle(true), | |
| 46 | - mailboxBundle(), | |
| 47 | - guavaBundle(), | |
| 48 | - defaultOptions() | |
| 49 | - ); | |
| 50 | - } | |
| 51 | - | |
| 52 | - @Configuration | |
| 53 | - public Option[] defaultConfig() { | |
| 54 | - return options( | |
| 55 | - driverBundle(), | |
| 56 | - mailboxBundle(), | |
| 57 | - guavaBundle(), | |
| 58 | - nettyBundles(), | |
| 59 | - defaultOptions() | |
| 60 | - ); | |
| 61 | - } | |
| 62 | - | |
| 63 | - @Configuration | |
| 64 | - public Option[] guava17Config() { | |
| 65 | - return options( | |
| 66 | - driverBundle(), | |
| 67 | - mailboxBundle(), | |
| 68 | - nettyBundles(), | |
| 69 | - guavaBundle().version("17.0"), | |
| 70 | - defaultOptions() | |
| 71 | - ); | |
| 72 | - } | |
| 73 | - | |
| 74 | - @Configuration | |
| 75 | - public Option[] guava18Config() { | |
| 76 | - return options( | |
| 77 | - driverBundle(), | |
| 78 | - mailboxBundle(), | |
| 79 | - nettyBundles(), | |
| 80 | - guavaBundle().version("18.0"), | |
| 81 | - defaultOptions() | |
| 82 | - ); | |
| 83 | - } | |
| 84 | - | |
| 85 | - /** | |
| 86 | - * <p> | |
| 87 | - * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver. Ensures that | |
| 88 | - * queries can be made through the service with the current given configuration. | |
| 89 | - * </p> | |
| 90 | - * <p/> | |
| 91 | - * The following configurations are tried (defined via methods with the @Configuration annotation): | |
| 92 | - * <ol> | |
| 93 | - * <li>Default bundle (Driver with all of it's dependencies)</li> | |
| 94 | - * <li>Shaded bundle (Driver with netty shaded)</li> | |
| 95 | - * <li>With Guava 16.0.1</li> | |
| 96 | - * <li>With Guava 17</li> | |
| 97 | - * <li>With Guava 18</li> | |
| 98 | - * </ol> | |
| 99 | - * | |
| 100 | - * @test_category packaging | |
| 101 | - * @expected_result Can create, retrieve and delete data using the mailbox service. | |
| 102 | - * @jira_ticket JAVA-620 | |
| 103 | - * @since 2.0.10, 2.1.5 | |
| 104 | - */ | |
| 105 | - public void service_api_functional() throws MailboxException { | |
| 106 | - // Insert some data into mailbox for a particular user. | |
| 107 | - String recipient = "user@datastax.com"; | |
| 108 | - | |
| 109 | - try { | |
| 110 | - Collection<MailboxMessage> inMessages = new ArrayList<MailboxMessage>(); | |
| 111 | - for (int i = 0; i < 30; i++) { | |
| 112 | - MailboxMessage message = new MailboxMessage(recipient, new GregorianCalendar(2015, 1, i).getTime(), recipient, "" + i); | |
| 113 | - inMessages.add(message); | |
| 114 | - service.sendMessage(message); | |
| 115 | - } | |
| 116 | - | |
| 117 | - Collection<MailboxMessage> messages = service.getMessages(recipient); | |
| 118 | - | |
| 119 | - assertEquals(messages, inMessages); | |
| 120 | - } finally { | |
| 121 | - service.clearMailbox(recipient); | |
| 122 | - } | |
| 123 | - } | |
| 124 | -} |
added driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceShadedIT.java +56 −0
| @@ -0,0 +1,56 @@ | ||
| 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 MailboxServiceShadedIT extends MailboxServiceTests { | |
| 30 | + | |
| 31 | + @Configuration | |
| 32 | + public Option[] shadedConfig() { | |
| 33 | + return options( | |
| 34 | + defaultOptions(), | |
| 35 | + guavaBundle(), | |
| 36 | + extrasBundle(), | |
| 37 | + mappingBundle(), | |
| 38 | + driverBundle(true), | |
| 39 | + mailboxBundle() | |
| 40 | + ); | |
| 41 | + } | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver with | |
| 45 | + * shaded configuration (driver with Netty shaded). | |
| 46 | + * | |
| 47 | + * @test_category packaging | |
| 48 | + * @expected_result Can create, retrieve and delete data using the mailbox service. | |
| 49 | + * @jira_ticket JAVA-620 | |
| 50 | + * @since 2.0.10, 2.1.5 | |
| 51 | + */ | |
| 52 | + @Test(groups = "short") | |
| 53 | + public void test_shaded() throws MailboxException { | |
| 54 | + checkService(); | |
| 55 | + } | |
| 56 | +} |
added driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceTests.java +81 −0
| @@ -0,0 +1,81 @@ | ||
| 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 com.datastax.driver.osgi.api.MailboxMessage; | |
| 20 | +import com.datastax.driver.osgi.api.MailboxService; | |
| 21 | +import org.osgi.framework.Bundle; | |
| 22 | +import org.osgi.framework.BundleContext; | |
| 23 | +import org.slf4j.Logger; | |
| 24 | +import org.slf4j.LoggerFactory; | |
| 25 | + | |
| 26 | +import javax.inject.Inject; | |
| 27 | +import java.util.ArrayList; | |
| 28 | +import java.util.Collection; | |
| 29 | +import java.util.GregorianCalendar; | |
| 30 | + | |
| 31 | +import static org.testng.Assert.assertEquals; | |
| 32 | + | |
| 33 | +public abstract class MailboxServiceTests { | |
| 34 | + | |
| 35 | + private static final Logger LOGGER = LoggerFactory.getLogger(MailboxServiceTests.class); | |
| 36 | + | |
| 37 | + @Inject | |
| 38 | + MailboxService service; | |
| 39 | + | |
| 40 | + @Inject | |
| 41 | + BundleContext bundleContext; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * <p> | |
| 45 | + * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver. Ensures that | |
| 46 | + * queries can be made through the service with the current given configuration. | |
| 47 | + * </p> | |
| 48 | + * <p/> | |
| 49 | + * The following configurations are tried (defined via methods with the @Configuration annotation): | |
| 50 | + * <ol> | |
| 51 | + * <li>Default bundle (Driver with all of it's dependencies and Guava 16.0.1)</li> | |
| 52 | + * <li>Shaded bundle (Driver with netty shaded and Guava 16.0.1)</li> | |
| 53 | + * <li>With Guava 17</li> | |
| 54 | + * <li>With Guava 18</li> | |
| 55 | + * <li>With Guava 19</li> | |
| 56 | + * </ol> | |
| 57 | + */ | |
| 58 | + protected void checkService() throws MailboxException { | |
| 59 | + if (LOGGER.isDebugEnabled()) { | |
| 60 | + for (Bundle bundle : bundleContext.getBundles()) { | |
| 61 | + LOGGER.debug("Loaded bundle: {} {}", bundle.getSymbolicName(), bundle.getVersion()); | |
| 62 | + } | |
| 63 | + } | |
| 64 | + // Insert some data into mailbox for a particular user. | |
| 65 | + String recipient = "user@datastax.com"; | |
| 66 | + try { | |
| 67 | + Collection<MailboxMessage> inMessages = new ArrayList<MailboxMessage>(); | |
| 68 | + for (int i = 0; i < 30; i++) { | |
| 69 | + MailboxMessage message = new MailboxMessage(recipient, new GregorianCalendar(2015, 1, i).getTimeInMillis(), recipient, "" + i); | |
| 70 | + inMessages.add(message); | |
| 71 | + service.sendMessage(message); | |
| 72 | + } | |
| 73 | + | |
| 74 | + Iterable<MailboxMessage> messages = service.getMessages(recipient); | |
| 75 | + | |
| 76 | + assertEquals(messages, inMessages); | |
| 77 | + } finally { | |
| 78 | + service.clearMailbox(recipient); | |
| 79 | + } | |
| 80 | + } | |
| 81 | +} |
modified driver-examples/osgi/src/test/resources/logback.xml +26 −3
| @@ -16,12 +16,35 @@ | ||
| 16 | 16 | |
| 17 | 17 | --> |
| 18 | 18 | <configuration> |
| 19 | + | |
| 19 | 20 | <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> | |
| 21 | + <encoder> | |
| 22 | + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | |
| 23 | + </encoder> | |
| 23 | 24 | </appender> |
| 25 | + | |
| 24 | 26 | <root level="INFO"> |
| 25 | 27 | <appender-ref ref="STDOUT"/> |
| 26 | 28 | </root> |
| 29 | + | |
| 30 | + <!-- debug Pax Exam --> | |
| 31 | + <!--<logger name="org.ops4j.pax" level="DEBUG" additivity="false">--> | |
| 32 | + <!--<appender-ref ref="STDOUT"/>--> | |
| 33 | + <!--</logger>--> | |
| 34 | + | |
| 35 | + <!-- print loaded bundles --> | |
| 36 | + <!--<logger name="com.datastax.driver.osgi.MailboxServiceTests" level="DEBUG" additivity="false">--> | |
| 37 | + <!--<appender-ref ref="STDOUT"/>--> | |
| 38 | + <!--</logger>--> | |
| 39 | + | |
| 40 | + <!-- this guy is a bit too verbose --> | |
| 41 | + <logger name="org.ops4j.pax.exam.nat.internal.NativeTestContainer" level="WARN" additivity="false"> | |
| 42 | + <appender-ref ref="STDOUT"/> | |
| 43 | + </logger> | |
| 44 | + | |
| 45 | + <!-- this one too --> | |
| 46 | + <logger name="com.jcabi.manifests.Manifests" level="WARN" additivity="false"> | |
| 47 | + <appender-ref ref="STDOUT"/> | |
| 48 | + </logger> | |
| 49 | + | |
| 27 | 50 | </configuration> |
modified driver-extras/pom.xml +16 −1
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | <modelVersion>4.0.0</modelVersion> |
| 25 | 25 | |
| 26 | 26 | <artifactId>cassandra-driver-extras</artifactId> |
| 27 | - | |
| 27 | + <packaging>bundle</packaging> | |
| 28 | 28 | <name>DataStax Java Driver for Apache Cassandra - Extras</name> |
| 29 | 29 | <description>Extended functionality for the Java driver.</description> |
| 30 | 30 | <url>https://github.com/datastax/java-driver</url> |
| @@ -120,6 +120,20 @@ | ||
| 120 | 120 | <scope>test</scope> |
| 121 | 121 | </dependency> |
| 122 | 122 | |
| 123 | + <dependency> | |
| 124 | + <groupId>log4j</groupId> | |
| 125 | + <artifactId>log4j</artifactId> | |
| 126 | + <version>${log4j.version}</version> | |
| 127 | + <scope>test</scope> | |
| 128 | + </dependency> | |
| 129 | + | |
| 130 | + <dependency> | |
| 131 | + <groupId>org.slf4j</groupId> | |
| 132 | + <artifactId>slf4j-log4j12</artifactId> | |
| 133 | + <version>${slf4j-log4j12.version}</version> | |
| 134 | + <scope>test</scope> | |
| 135 | + </dependency> | |
| 136 | + | |
| 123 | 137 | </dependencies> |
| 124 | 138 | |
| 125 | 139 | <build> |
| @@ -216,6 +230,7 @@ | ||
| 216 | 230 | <Bundle-SymbolicName>com.datastax.driver.extras</Bundle-SymbolicName> |
| 217 | 231 | <Bundle-Version>${project.version}</Bundle-Version> |
| 218 | 232 | <_include>-osgi.bnd</_include> |
| 233 | + <Import-Package><![CDATA[com.google.common*;version="[16.0.1,20)",*]]></Import-Package> | |
| 219 | 234 | </instructions> |
| 220 | 235 | <supportedProjectTypes> |
| 221 | 236 | <supportedProjectType>jar</supportedProjectType> |
modified driver-mapping/pom.xml +16 −0
| @@ -94,6 +94,21 @@ | ||
| 94 | 94 | <version>4.1</version> |
| 95 | 95 | </dependency> |
| 96 | 96 | --> |
| 97 | + | |
| 98 | + <dependency> | |
| 99 | + <groupId>log4j</groupId> | |
| 100 | + <artifactId>log4j</artifactId> | |
| 101 | + <version>${log4j.version}</version> | |
| 102 | + <scope>test</scope> | |
| 103 | + </dependency> | |
| 104 | + | |
| 105 | + <dependency> | |
| 106 | + <groupId>org.slf4j</groupId> | |
| 107 | + <artifactId>slf4j-log4j12</artifactId> | |
| 108 | + <version>${slf4j-log4j12.version}</version> | |
| 109 | + <scope>test</scope> | |
| 110 | + </dependency> | |
| 111 | + | |
| 97 | 112 | </dependencies> |
| 98 | 113 | |
| 99 | 114 | <build> |
| @@ -117,6 +132,7 @@ | ||
| 117 | 132 | <Bundle-SymbolicName>com.datastax.driver.mapping</Bundle-SymbolicName> |
| 118 | 133 | <Bundle-Version>${project.version}</Bundle-Version> |
| 119 | 134 | <_include>-osgi.bnd</_include> |
| 135 | + <Import-Package><![CDATA[com.google.common*;version="[16.0.1,20)",*]]></Import-Package> | |
| 120 | 136 | </instructions> |
| 121 | 137 | <supportedProjectTypes> |
| 122 | 138 | <supportedProjectType>jar</supportedProjectType> |
modified pom.xml +0 −16
| @@ -74,22 +74,6 @@ | ||
| 74 | 74 | <javadoc.opts/> |
| 75 | 75 | </properties> |
| 76 | 76 | |
| 77 | - <dependencies> | |
| 78 | - <dependency> | |
| 79 | - <groupId>log4j</groupId> | |
| 80 | - <artifactId>log4j</artifactId> | |
| 81 | - <version>${log4j.version}</version> | |
| 82 | - <scope>test</scope> | |
| 83 | - </dependency> | |
| 84 | - | |
| 85 | - <dependency> | |
| 86 | - <groupId>org.slf4j</groupId> | |
| 87 | - <artifactId>slf4j-log4j12</artifactId> | |
| 88 | - <version>${slf4j-log4j12.version}</version> | |
| 89 | - <scope>test</scope> | |
| 90 | - </dependency> | |
| 91 | - </dependencies> | |
| 92 | - | |
| 93 | 77 | <profiles> |
| 94 | 78 | <profile> |
| 95 | 79 | <id>default</id> |