kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 9f05ad615f60134bafd7c0d6435c08dd3b696affa2a0f053d85d401204b8e7d3 |
|---|---|
| Author | Alexandre Dutra <adutra@users.noreply.github.com> · 2016-05-02 17:27 +02:00 |
| Committer | Alexandre Dutra <adutra@users.noreply.github.com> · 2016-05-02 17:27 +02:00 |
| Parents | 0e48b8881002, d0403d53e0ee |
73 files changed
modified README.md +2 −0
| @@ -37,8 +37,10 @@ | ||
| 37 | 37 | |
| 38 | 38 | - driver-core: the core layer. |
| 39 | 39 | - driver-mapping: the object mapper. |
| 40 | +- driver-extras: optional features for the Java driver. | |
| 40 | 41 | - driver-examples: example applications using the other modules which are |
| 41 | 42 | only meant for demonstration purposes. |
| 43 | +- driver-tests: tests for the java-driver. | |
| 42 | 44 | |
| 43 | 45 | **Useful links:** |
| 44 | 46 |
modified changelog/README.md +2 −0
| @@ -20,6 +20,8 @@ | ||
| 20 | 20 | - [bug] JAVA-1046: (Dynamic)CompositeTypes need to be parsed as string literal, not blob. |
| 21 | 21 | - [improvement] JAVA-1164: Clarify documentation on Host.listenAddress and broadcastAddress. |
| 22 | 22 | - [improvement] JAVA-1171: Add Host method to determine if DSE Graph is enabled. |
| 23 | +- [improvement]: JAVA-1069: Bootstrap driver-examples module. | |
| 24 | +- [documentation] JAVA-1150: Add example and FAQ entry about ByteBuffer/BLOB. | |
| 23 | 25 | |
| 24 | 26 | Merged from 2.1 branch: |
| 25 | 27 |
added driver-examples/README.md +10 −0
| @@ -0,0 +1,10 @@ | ||
| 1 | +# DataStax Java Driver for Apache Cassandra - Examples | |
| 2 | + | |
| 3 | +This module contains examples of how to use the DataStax Java driver for | |
| 4 | +Apache Cassandra. | |
| 5 | + | |
| 6 | +## Usage | |
| 7 | + | |
| 8 | +Unless otherwise stated, all examples assume that you have a single-node Cassandra 3.0 cluster | |
| 9 | +listening on localhost:9042. | |
| 10 | + |
deleted driver-examples/osgi/README.md +0 −35
| @@ -1,35 +0,0 @@ | ||
| 1 | -# OSGi Example | |
| 2 | - | |
| 3 | -A simple example application that demonstrates using the Java Driver in | |
| 4 | -an OSGi service. | |
| 5 | - | |
| 6 | -`MailboxService` is an OSGi service that uses Cassandra to | |
| 7 | -store messages that can be retrieved by email address. | |
| 8 | - | |
| 9 | -## Usage | |
| 10 | - | |
| 11 | -To build the bundle and run tests, execute the following Maven goal: | |
| 12 | - | |
| 13 | - mvn verify -P short | |
| 14 | - | |
| 15 | -The "short" profile needs to be activated since the tests run under | |
| 16 | -this group. | |
| 17 | - | |
| 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. | |
| 23 | - | |
| 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 | |
| 27 | -be activated and used in an OSGi container. It also verifies that | |
| 28 | -driver-core can be used in an OSGi container in the following | |
| 29 | -configurations: | |
| 30 | - | |
| 31 | -1. Default (default classifier with all dependencies) | |
| 32 | -2. Netty-Shaded (shaded classifier with all depedencies w/o Netty) | |
| 33 | -5. Guava 17 | |
| 34 | -6. Guava 18 | |
| 35 | -7. Guava 19 |
deleted driver-examples/osgi/pom.xml +0 −283
| @@ -1,283 +0,0 @@ | ||
| 1 | -<!-- | |
| 2 | - | |
| 3 | - Copyright (C) 2012-2015 DataStax Inc. | |
| 4 | - | |
| 5 | - Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | - you may not use this file except in compliance with the License. | |
| 7 | - You may obtain a copy of the License at | |
| 8 | - | |
| 9 | - http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | - | |
| 11 | - Unless required by applicable law or agreed to in writing, software | |
| 12 | - distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | - See the License for the specific language governing permissions and | |
| 15 | - limitations under the License. | |
| 16 | - | |
| 17 | ---> | |
| 18 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 19 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| 20 | - <modelVersion>4.0.0</modelVersion> | |
| 21 | - <parent> | |
| 22 | - <groupId>com.datastax.cassandra</groupId> | |
| 23 | - <artifactId>cassandra-driver-examples-parent</artifactId> | |
| 24 | - <version>3.0.1-SNAPSHOT</version> | |
| 25 | - </parent> | |
| 26 | - | |
| 27 | - <artifactId>cassandra-driver-examples-osgi</artifactId> | |
| 28 | - <packaging>bundle</packaging> | |
| 29 | - <name>DataStax Java Driver for Apache Cassandra Examples - OSGi</name> | |
| 30 | - <description>An example of using DataStax Java Driver in an OSGi container.</description> | |
| 31 | - <url>https://github.com/datastax/java-driver</url> | |
| 32 | - | |
| 33 | - <properties> | |
| 34 | - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | |
| 35 | - <felix.version>4.6.0</felix.version> | |
| 36 | - <!-- more recent version require JDK7+ --> | |
| 37 | - <pax-exam.version>3.6.0</pax-exam.version> | |
| 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> | |
| 46 | - <main.basedir>${project.parent.parent.basedir}</main.basedir> | |
| 47 | - </properties> | |
| 48 | - | |
| 49 | - <dependencies> | |
| 50 | - | |
| 51 | - <dependency> | |
| 52 | - <groupId>com.datastax.cassandra</groupId> | |
| 53 | - <artifactId>cassandra-driver-core</artifactId> | |
| 54 | - <version>${project.parent.version}</version> | |
| 55 | - </dependency> | |
| 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 | - | |
| 69 | - <dependency> | |
| 70 | - <groupId>org.apache.felix</groupId> | |
| 71 | - <artifactId>org.apache.felix.framework</artifactId> | |
| 72 | - <version>${felix.version}</version> | |
| 73 | - </dependency> | |
| 74 | - | |
| 75 | - <dependency> | |
| 76 | - <groupId>com.datastax.cassandra</groupId> | |
| 77 | - <artifactId>cassandra-driver-core</artifactId> | |
| 78 | - <version>${project.parent.version}</version> | |
| 79 | - <type>test-jar</type> | |
| 80 | - <scope>test</scope> | |
| 81 | - </dependency> | |
| 82 | - | |
| 83 | - <dependency> | |
| 84 | - <groupId>org.ops4j.pax.exam</groupId> | |
| 85 | - <artifactId>pax-exam</artifactId> | |
| 86 | - <version>${pax-exam.version}</version> | |
| 87 | - <scope>test</scope> | |
| 88 | - </dependency> | |
| 89 | - | |
| 90 | - <dependency> | |
| 91 | - <groupId>org.ops4j.pax.exam</groupId> | |
| 92 | - <artifactId>pax-exam-testng</artifactId> | |
| 93 | - <version>${pax-exam.version}</version> | |
| 94 | - <scope>test</scope> | |
| 95 | - </dependency> | |
| 96 | - | |
| 97 | - <dependency> | |
| 98 | - <groupId>org.ops4j.pax.exam</groupId> | |
| 99 | - <artifactId>pax-exam-container-native</artifactId> | |
| 100 | - <version>${pax-exam.version}</version> | |
| 101 | - <scope>test</scope> | |
| 102 | - </dependency> | |
| 103 | - | |
| 104 | - <dependency> | |
| 105 | - <groupId>org.ops4j.pax.exam</groupId> | |
| 106 | - <artifactId>pax-exam-link-mvn</artifactId> | |
| 107 | - <version>${pax-exam.version}</version> | |
| 108 | - <scope>test</scope> | |
| 109 | - </dependency> | |
| 110 | - | |
| 111 | - <dependency> | |
| 112 | - <groupId>javax.transaction</groupId> | |
| 113 | - <artifactId>jta</artifactId> | |
| 114 | - <version>1.1</version> | |
| 115 | - <scope>test</scope> | |
| 116 | - </dependency> | |
| 117 | - | |
| 118 | - <dependency> | |
| 119 | - <groupId>com.jcabi</groupId> | |
| 120 | - <artifactId>jcabi-manifests</artifactId> | |
| 121 | - <version>1.1</version> | |
| 122 | - <scope>test</scope> | |
| 123 | - </dependency> | |
| 124 | - | |
| 125 | - <dependency> | |
| 126 | - <groupId>javax.servlet</groupId> | |
| 127 | - <artifactId>javax.servlet-api</artifactId> | |
| 128 | - <version>3.1.0</version> | |
| 129 | - <scope>test</scope> | |
| 130 | - </dependency> | |
| 131 | - | |
| 132 | - <dependency> | |
| 133 | - <groupId>javax.inject</groupId> | |
| 134 | - <artifactId>javax.inject</artifactId> | |
| 135 | - <version>1</version> | |
| 136 | - <scope>test</scope> | |
| 137 | - </dependency> | |
| 138 | - | |
| 139 | - <dependency> | |
| 140 | - <groupId>org.apache.commons</groupId> | |
| 141 | - <artifactId>commons-exec</artifactId> | |
| 142 | - <version>1.3</version> | |
| 143 | - <scope>test</scope> | |
| 144 | - </dependency> | |
| 145 | - | |
| 146 | - <dependency> | |
| 147 | - <groupId>ch.qos.logback</groupId> | |
| 148 | - <artifactId>logback-classic</artifactId> | |
| 149 | - <version>${logback.version}</version> | |
| 150 | - </dependency> | |
| 151 | - | |
| 152 | - <dependency> | |
| 153 | - <groupId>ch.qos.logback</groupId> | |
| 154 | - <artifactId>logback-core</artifactId> | |
| 155 | - <version>${logback.version}</version> | |
| 156 | - </dependency> | |
| 157 | - | |
| 158 | - </dependencies> | |
| 159 | - | |
| 160 | - <build> | |
| 161 | - | |
| 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 | - | |
| 182 | - <plugin> | |
| 183 | - <groupId>org.apache.maven.plugins</groupId> | |
| 184 | - <artifactId>maven-failsafe-plugin</artifactId> | |
| 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> | |
| 194 | - <executions> | |
| 195 | - <execution> | |
| 196 | - <id>default</id> | |
| 197 | - <goals> | |
| 198 | - <goal>integration-test</goal> | |
| 199 | - <goal>verify</goal> | |
| 200 | - </goals> | |
| 201 | - </execution> | |
| 202 | - </executions> | |
| 203 | - </plugin> | |
| 204 | - | |
| 205 | - <plugin> | |
| 206 | - <groupId>org.apache.felix</groupId> | |
| 207 | - <artifactId>maven-bundle-plugin</artifactId> | |
| 208 | - <extensions>true</extensions> | |
| 209 | - <version>2.4.0</version> | |
| 210 | - <configuration> | |
| 211 | - <instructions> | |
| 212 | - <Bundle-SymbolicName>com.datastax.driver.osgi</Bundle-SymbolicName> | |
| 213 | - <Bundle-Version>${project.version}</Bundle-Version> | |
| 214 | - <Export-Package>com.datastax.driver.osgi.api,!com.datastax.driver.osgi.impl</Export-Package> | |
| 215 | - <Bundle-Activator>com.datastax.driver.osgi.impl.Activator</Bundle-Activator> | |
| 216 | - <_include>-osgi.bnd</_include> | |
| 217 | - <Import-Package><![CDATA[com.google.common*;version="[16.0.1,20)",*]]></Import-Package> | |
| 218 | - </instructions> | |
| 219 | - <supportedProjectTypes> | |
| 220 | - <supportedProjectType>jar</supportedProjectType> | |
| 221 | - <supportedProjectType>bundle</supportedProjectType> | |
| 222 | - <supportedProjectType>pom</supportedProjectType> | |
| 223 | - </supportedProjectTypes> | |
| 224 | - </configuration> | |
| 225 | - <executions> | |
| 226 | - <execution> | |
| 227 | - <id>bundle-manifest</id> | |
| 228 | - <phase>compile</phase> | |
| 229 | - <goals> | |
| 230 | - <goal>manifest</goal> | |
| 231 | - </goals> | |
| 232 | - </execution> | |
| 233 | - </executions> | |
| 234 | - </plugin> | |
| 235 | - | |
| 236 | - </plugins> | |
| 237 | - | |
| 238 | - </build> | |
| 239 | - | |
| 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 | - | |
| 250 | - <profile> | |
| 251 | - <id>long</id> | |
| 252 | - <properties> | |
| 253 | - <test.groups>unit,short,long</test.groups> | |
| 254 | - <test.skip>false</test.skip> | |
| 255 | - </properties> | |
| 256 | - </profile> | |
| 257 | - | |
| 258 | - </profiles> | |
| 259 | - | |
| 260 | - <licenses> | |
| 261 | - <license> | |
| 262 | - <name>Apache 2</name> | |
| 263 | - <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | |
| 264 | - <distribution>repo</distribution> | |
| 265 | - <comments>Apache License Version 2.0</comments> | |
| 266 | - </license> | |
| 267 | - </licenses> | |
| 268 | - | |
| 269 | - <scm> | |
| 270 | - <connection>scm:git:git@github.com:datastax/java-driver.git</connection> | |
| 271 | - <developerConnection>scm:git:git@github.com:datastax/java-driver.git</developerConnection> | |
| 272 | - <url>https://github.com/datastax/java-driver</url> | |
| 273 | - <tag>HEAD</tag> | |
| 274 | - </scm> | |
| 275 | - | |
| 276 | - <developers> | |
| 277 | - <developer> | |
| 278 | - <name>Various</name> | |
| 279 | - <organization>DataStax</organization> | |
| 280 | - </developer> | |
| 281 | - </developers> | |
| 282 | -</project> | |
| 283 | - |
deleted driver-examples/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxException.java +0 −23
| @@ -1,23 +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.api; | |
| 17 | - | |
| 18 | -public class MailboxException extends Exception { | |
| 19 | - | |
| 20 | - public MailboxException(Throwable cause) { | |
| 21 | - super("Failure interacting with Mailbox", cause); | |
| 22 | - } | |
| 23 | -} |
deleted driver-examples/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxMessage.java +0 −106
| @@ -1,106 +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.api; | |
| 17 | - | |
| 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; | |
| 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) | |
| 32 | -public class MailboxMessage { | |
| 33 | - | |
| 34 | - public static final String TABLE = "mailbox"; | |
| 35 | - | |
| 36 | - @PartitionKey | |
| 37 | - private String recipient; | |
| 38 | - | |
| 39 | - @ClusteringColumn | |
| 40 | - @Column(name = "time", codec = SimpleTimestampCodec.class) | |
| 41 | - private long date; | |
| 42 | - | |
| 43 | - @Column | |
| 44 | - private String sender; | |
| 45 | - | |
| 46 | - @Column | |
| 47 | - private String body; | |
| 48 | - | |
| 49 | - public MailboxMessage() { | |
| 50 | - } | |
| 51 | - | |
| 52 | - public MailboxMessage(String recipient, long date, String sender, String body) { | |
| 53 | - this.recipient = recipient; | |
| 54 | - this.date = date; | |
| 55 | - this.sender = sender; | |
| 56 | - this.body = body; | |
| 57 | - } | |
| 58 | - | |
| 59 | - public String getRecipient() { | |
| 60 | - return recipient; | |
| 61 | - } | |
| 62 | - | |
| 63 | - public void setRecipient(String recipient) { | |
| 64 | - this.recipient = recipient; | |
| 65 | - } | |
| 66 | - | |
| 67 | - public long getDate() { | |
| 68 | - return date; | |
| 69 | - } | |
| 70 | - | |
| 71 | - public void setDate(long date) { | |
| 72 | - this.date = date; | |
| 73 | - } | |
| 74 | - | |
| 75 | - public String getSender() { | |
| 76 | - return sender; | |
| 77 | - } | |
| 78 | - | |
| 79 | - public void setSender(String sender) { | |
| 80 | - this.sender = sender; | |
| 81 | - } | |
| 82 | - | |
| 83 | - public String getBody() { | |
| 84 | - return body; | |
| 85 | - } | |
| 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 | - | |
| 102 | - @Override | |
| 103 | - public int hashCode() { | |
| 104 | - return Objects.hashCode(recipient, date, sender, body); | |
| 105 | - } | |
| 106 | -} |
deleted driver-examples/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxService.java +0 −42
| @@ -1,42 +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.api; | |
| 17 | - | |
| 18 | -public interface MailboxService { | |
| 19 | - | |
| 20 | - /** | |
| 21 | - * Retrieve all messages for a given recipient. | |
| 22 | - * | |
| 23 | - * @param recipient User whose mailbox is being read. | |
| 24 | - * @return All messages in the mailbox. | |
| 25 | - */ | |
| 26 | - public Iterable<MailboxMessage> getMessages(String recipient) throws MailboxException; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * Stores the given message in the appropriate mailbox. | |
| 30 | - * | |
| 31 | - * @param message Message to send. | |
| 32 | - * @return The timestamp generated for the message (milliseconds since the Epoch). | |
| 33 | - */ | |
| 34 | - public long sendMessage(MailboxMessage message) throws MailboxException; | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * Deletes all mail for the given recipient. | |
| 38 | - * | |
| 39 | - * @param recipient User whose mailbox will be cleared. | |
| 40 | - */ | |
| 41 | - public void clearMailbox(String recipient) throws MailboxException; | |
| 42 | -} |
deleted driver-examples/osgi/src/main/java/com/datastax/driver/osgi/impl/Activator.java +0 −95
| @@ -1,95 +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.impl; | |
| 17 | - | |
| 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; | |
| 22 | -import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 23 | -import com.datastax.driver.extras.codecs.date.SimpleTimestampCodec; | |
| 24 | -import com.datastax.driver.osgi.api.MailboxService; | |
| 25 | -import org.osgi.framework.BundleActivator; | |
| 26 | -import org.osgi.framework.BundleContext; | |
| 27 | - | |
| 28 | -import java.util.Hashtable; | |
| 29 | - | |
| 30 | -import static com.datastax.driver.osgi.api.MailboxMessage.TABLE; | |
| 31 | - | |
| 32 | -public class Activator implements BundleActivator { | |
| 33 | - | |
| 34 | - private Cluster cluster; | |
| 35 | - | |
| 36 | - @Override | |
| 37 | - public void start(BundleContext context) throws Exception { | |
| 38 | - String contactPointsStr = context.getProperty("cassandra.contactpoints"); | |
| 39 | - if (contactPointsStr == null) { | |
| 40 | - contactPointsStr = "127.0.0.1"; | |
| 41 | - } | |
| 42 | - String[] contactPoints = contactPointsStr.split(","); | |
| 43 | - | |
| 44 | - String keyspace = context.getProperty("cassandra.keyspace"); | |
| 45 | - if (keyspace == null) { | |
| 46 | - keyspace = "mailbox"; | |
| 47 | - } | |
| 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 | - } | |
| 71 | - | |
| 72 | - MailboxImpl mailbox = new MailboxImpl(session, keyspace); | |
| 73 | - mailbox.init(); | |
| 74 | - | |
| 75 | - context.registerService(MailboxService.class.getName(), mailbox, new Hashtable<String, String>()); | |
| 76 | - } | |
| 77 | - | |
| 78 | - @Override | |
| 79 | - public void stop(BundleContext context) throws Exception { | |
| 80 | - if (cluster != null) { | |
| 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); | |
| 93 | - } | |
| 94 | - } | |
| 95 | -} |
deleted driver-examples/osgi/src/main/java/com/datastax/driver/osgi/impl/MailboxImpl.java +0 −98
| @@ -1,98 +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.impl; | |
| 17 | - | |
| 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; | |
| 23 | -import com.datastax.driver.osgi.api.MailboxException; | |
| 24 | -import com.datastax.driver.osgi.api.MailboxMessage; | |
| 25 | -import com.datastax.driver.osgi.api.MailboxService; | |
| 26 | - | |
| 27 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 28 | -import static com.datastax.driver.osgi.api.MailboxMessage.TABLE; | |
| 29 | - | |
| 30 | -public class MailboxImpl implements MailboxService { | |
| 31 | - | |
| 32 | - private final Session session; | |
| 33 | - | |
| 34 | - private final String keyspace; | |
| 35 | - | |
| 36 | - private volatile boolean initialized = false; | |
| 37 | - | |
| 38 | - private PreparedStatement retrieveStatement; | |
| 39 | - | |
| 40 | - private PreparedStatement deleteStatement; | |
| 41 | - | |
| 42 | - private Mapper<MailboxMessage> mapper; | |
| 43 | - | |
| 44 | - public MailboxImpl(Session session, String keyspace) { | |
| 45 | - this.session = session; | |
| 46 | - this.keyspace = keyspace; | |
| 47 | - } | |
| 48 | - | |
| 49 | - public synchronized void init() { | |
| 50 | - if (initialized) | |
| 51 | - return; | |
| 52 | - | |
| 53 | - retrieveStatement = session.prepare(select() | |
| 54 | - .from(keyspace, TABLE) | |
| 55 | - .where(eq("recipient", bindMarker()))); | |
| 56 | - | |
| 57 | - deleteStatement = session.prepare(delete().from(keyspace, TABLE) | |
| 58 | - .where(eq("recipient", bindMarker()))); | |
| 59 | - | |
| 60 | - MappingManager mappingManager = new MappingManager(session); | |
| 61 | - | |
| 62 | - mapper = mappingManager.mapper(MailboxMessage.class); | |
| 63 | - | |
| 64 | - initialized = true; | |
| 65 | - } | |
| 66 | - | |
| 67 | - @Override | |
| 68 | - public Iterable<MailboxMessage> getMessages(String recipient) throws MailboxException { | |
| 69 | - try { | |
| 70 | - BoundStatement statement = new BoundStatement(retrieveStatement); | |
| 71 | - statement.setString(0, recipient); | |
| 72 | - return mapper.map(session.execute(statement)); | |
| 73 | - } catch (Exception e) { | |
| 74 | - throw new MailboxException(e); | |
| 75 | - } | |
| 76 | - } | |
| 77 | - | |
| 78 | - @Override | |
| 79 | - public long sendMessage(MailboxMessage message) throws MailboxException { | |
| 80 | - try { | |
| 81 | - mapper.save(message); | |
| 82 | - return message.getDate(); | |
| 83 | - } catch (Exception e) { | |
| 84 | - throw new MailboxException(e); | |
| 85 | - } | |
| 86 | - } | |
| 87 | - | |
| 88 | - @Override | |
| 89 | - public void clearMailbox(String recipient) throws MailboxException { | |
| 90 | - try { | |
| 91 | - BoundStatement statement = new BoundStatement(deleteStatement); | |
| 92 | - statement.setString(0, recipient); | |
| 93 | - session.execute(statement); | |
| 94 | - } catch (Exception e) { | |
| 95 | - throw new MailboxException(e); | |
| 96 | - } | |
| 97 | - } | |
| 98 | -} |
deleted driver-examples/osgi/src/test/java/com/datastax/driver/osgi/BundleOptions.java +0 −93
| @@ -1,93 +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.TestUtils; | |
| 19 | -import org.ops4j.pax.exam.Option; | |
| 20 | -import org.ops4j.pax.exam.options.CompositeOption; | |
| 21 | -import org.ops4j.pax.exam.options.MavenArtifactProvisionOption; | |
| 22 | -import org.ops4j.pax.exam.options.UrlProvisionOption; | |
| 23 | -import org.ops4j.pax.exam.util.PathUtils; | |
| 24 | - | |
| 25 | -import static com.datastax.driver.osgi.VersionProvider.projectVersion; | |
| 26 | -import static org.ops4j.pax.exam.CoreOptions.*; | |
| 27 | - | |
| 28 | -public class BundleOptions { | |
| 29 | - | |
| 30 | - public static UrlProvisionOption driverBundle() { | |
| 31 | - return driverBundle(false); | |
| 32 | - } | |
| 33 | - | |
| 34 | - public static UrlProvisionOption driverBundle(boolean useShaded) { | |
| 35 | - String classifier = useShaded ? "-shaded" : ""; | |
| 36 | - return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-core/target/cassandra-driver-core-" + projectVersion() + classifier + ".jar"); | |
| 37 | - } | |
| 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 | - | |
| 47 | - public static MavenArtifactProvisionOption guavaBundle() { | |
| 48 | - return mavenBundle("com.google.guava", "guava", "16.0.1"); | |
| 49 | - } | |
| 50 | - | |
| 51 | - public static CompositeOption nettyBundles() { | |
| 52 | - final String nettyVersion = "4.0.33.Final"; | |
| 53 | - return new CompositeOption() { | |
| 54 | - | |
| 55 | - @Override | |
| 56 | - public Option[] getOptions() { | |
| 57 | - return options( | |
| 58 | - mavenBundle("io.netty", "netty-buffer", nettyVersion), | |
| 59 | - mavenBundle("io.netty", "netty-codec", nettyVersion), | |
| 60 | - mavenBundle("io.netty", "netty-common", nettyVersion), | |
| 61 | - mavenBundle("io.netty", "netty-handler", nettyVersion), | |
| 62 | - mavenBundle("io.netty", "netty-transport", nettyVersion) | |
| 63 | - ); | |
| 64 | - } | |
| 65 | - }; | |
| 66 | - } | |
| 67 | - | |
| 68 | - public static UrlProvisionOption mailboxBundle() { | |
| 69 | - return bundle("reference:file:" + PathUtils.getBaseDir() + "/target/classes"); | |
| 70 | - } | |
| 71 | - | |
| 72 | - public static CompositeOption defaultOptions() { | |
| 73 | - return new CompositeOption() { | |
| 74 | - | |
| 75 | - @Override | |
| 76 | - public Option[] getOptions() { | |
| 77 | - return options( | |
| 78 | - // Delegate javax.security.cert to the parent classloader. javax.security.cert.X509Certificate is used in | |
| 79 | - // io.netty.util.internal.EmptyArrays, but not directly by the driver. | |
| 80 | - bootDelegationPackage("javax.security.cert"), | |
| 81 | - systemProperty("cassandra.contactpoints").value(TestUtils.IP_PREFIX + 1), | |
| 82 | - systemProperty("logback.configurationFile").value("file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"), | |
| 83 | - mavenBundle("org.slf4j", "slf4j-api", "1.7.5"), | |
| 84 | - mavenBundle("ch.qos.logback", "logback-classic", "1.1.3"), | |
| 85 | - mavenBundle("ch.qos.logback", "logback-core", "1.1.3"), | |
| 86 | - mavenBundle("io.dropwizard.metrics", "metrics-core", "3.1.2"), | |
| 87 | - systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation", | |
| 88 | - "org.junit.runner.notification", "com.jcabi.manifests") | |
| 89 | - ); | |
| 90 | - } | |
| 91 | - }; | |
| 92 | - } | |
| 93 | -} |
deleted driver-examples/osgi/src/test/java/com/datastax/driver/osgi/CCMBridgeListener.java +0 −65
| @@ -1,65 +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.CCMBridge; | |
| 19 | -import org.testng.ITestContext; | |
| 20 | -import org.testng.ITestListener; | |
| 21 | -import org.testng.ITestResult; | |
| 22 | - | |
| 23 | -/** | |
| 24 | - * A listener that fires up a single node CCM instance on test class start and tears it | |
| 25 | - * down on test class end. | |
| 26 | - * <p/> | |
| 27 | - * This is needed for tests that use Pax-Exam since it runs some methods in the OSGi container | |
| 28 | - * which we do not want. | |
| 29 | - */ | |
| 30 | -public class CCMBridgeListener implements ITestListener { | |
| 31 | - | |
| 32 | - private CCMBridge ccm; | |
| 33 | - | |
| 34 | - @Override | |
| 35 | - public void onStart(ITestContext context) { | |
| 36 | - ccm = CCMBridge.builder().withNodes(1).withBinaryPort(9042).build(); | |
| 37 | - } | |
| 38 | - | |
| 39 | - @Override | |
| 40 | - public void onFinish(ITestContext context) { | |
| 41 | - if (ccm != null) { | |
| 42 | - ccm.remove(); | |
| 43 | - } | |
| 44 | - } | |
| 45 | - | |
| 46 | - @Override | |
| 47 | - public void onTestStart(ITestResult result) { | |
| 48 | - } | |
| 49 | - | |
| 50 | - @Override | |
| 51 | - public void onTestSuccess(ITestResult result) { | |
| 52 | - } | |
| 53 | - | |
| 54 | - @Override | |
| 55 | - public void onTestFailure(ITestResult result) { | |
| 56 | - } | |
| 57 | - | |
| 58 | - @Override | |
| 59 | - public void onTestSkipped(ITestResult result) { | |
| 60 | - } | |
| 61 | - | |
| 62 | - @Override | |
| 63 | - public void onTestFailedButWithinSuccessPercentage(ITestResult result) { | |
| 64 | - } | |
| 65 | -} |
deleted driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceDefaultIT.java +0 −57
| @@ -1,57 +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 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 | -} |
deleted driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceGuava17IT.java +0 −57
| @@ -1,57 +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 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 | -} |
deleted driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceGuava18IT.java +0 −57
| @@ -1,57 +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 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 | -} |
deleted driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceGuava19IT.java +0 −57
| @@ -1,57 +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 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/MailboxServiceShadedIT.java +0 −56
| @@ -1,56 +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 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 | -} |
deleted driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceTests.java +0 −81
| @@ -1,81 +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.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 | -} |
deleted driver-examples/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 | -} |
deleted driver-examples/osgi/src/test/resources/exam.properties +0 −18
| @@ -1,18 +0,0 @@ | ||
| 1 | -# | |
| 2 | -# Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | -# | |
| 4 | -# Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | -# you may not use this file except in compliance with the License. | |
| 6 | -# You may obtain a copy of the License at | |
| 7 | -# | |
| 8 | -# http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | -# | |
| 10 | -# Unless required by applicable law or agreed to in writing, software | |
| 11 | -# distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | -# See the License for the specific language governing permissions and | |
| 14 | -# limitations under the License. | |
| 15 | -# | |
| 16 | - | |
| 17 | -pax.exam.system=test | |
| 18 | -pax.exam.logging=none | |
| No newline at the end of the file |
deleted driver-examples/osgi/src/test/resources/logback.xml +0 −50
| @@ -1,50 +0,0 @@ | ||
| 1 | -<!-- | |
| 2 | - | |
| 3 | - Copyright (C) 2012-2015 DataStax Inc. | |
| 4 | - | |
| 5 | - Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | - you may not use this file except in compliance with the License. | |
| 7 | - You may obtain a copy of the License at | |
| 8 | - | |
| 9 | - http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | - | |
| 11 | - Unless required by applicable law or agreed to in writing, software | |
| 12 | - distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | - See the License for the specific language governing permissions and | |
| 15 | - limitations under the License. | |
| 16 | - | |
| 17 | ---> | |
| 18 | -<configuration> | |
| 19 | - | |
| 20 | - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | |
| 21 | - <encoder> | |
| 22 | - <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | |
| 23 | - </encoder> | |
| 24 | - </appender> | |
| 25 | - | |
| 26 | - <root level="INFO"> | |
| 27 | - <appender-ref ref="STDOUT"/> | |
| 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 | - | |
| 50 | -</configuration> |
modified driver-examples/pom.xml +49 −30
| @@ -15,16 +15,18 @@ | ||
| 15 | 15 | limitations under the License. |
| 16 | 16 | |
| 17 | 17 | --> |
| 18 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| 19 | - <modelVersion>4.0.0</modelVersion> | |
| 18 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 20 | 20 | <parent> |
| 21 | - <groupId>com.datastax.cassandra</groupId> | |
| 22 | 21 | <artifactId>cassandra-driver-parent</artifactId> |
| 22 | + <groupId>com.datastax.cassandra</groupId> | |
| 23 | 23 | <version>3.0.1-SNAPSHOT</version> |
| 24 | 24 | </parent> |
| 25 | - <artifactId>cassandra-driver-examples-parent</artifactId> | |
| 26 | - <packaging>pom</packaging> | |
| 27 | - <name>DataStax Java Driver for Apache Cassandra Examples</name> | |
| 25 | + <modelVersion>4.0.0</modelVersion> | |
| 26 | + | |
| 27 | + <artifactId>cassandra-driver-examples</artifactId> | |
| 28 | + | |
| 29 | + <name>DataStax Java Driver for Apache Cassandra - Examples</name> | |
| 28 | 30 | <description>A collection of examples to demonstrate DataStax Java Driver for Apache Cassandra.</description> |
| 29 | 31 | <url>https://github.com/datastax/java-driver</url> |
| 30 | 32 | |
| @@ -32,36 +34,26 @@ | ||
| 32 | 34 | <main.basedir>${project.parent.basedir}</main.basedir> |
| 33 | 35 | </properties> |
| 34 | 36 | |
| 35 | - <modules> | |
| 36 | - <module>stress</module> | |
| 37 | - <module>osgi</module> | |
| 38 | - </modules> | |
| 37 | + <dependencies> | |
| 39 | 38 | |
| 40 | - <licenses> | |
| 41 | - <license> | |
| 42 | - <name>Apache 2</name> | |
| 43 | - <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | |
| 44 | - <distribution>repo</distribution> | |
| 45 | - <comments>Apache License Version 2.0</comments> | |
| 46 | - </license> | |
| 47 | - </licenses> | |
| 39 | + <dependency> | |
| 40 | + <groupId>com.datastax.cassandra</groupId> | |
| 41 | + <artifactId>cassandra-driver-core</artifactId> | |
| 42 | + <version>${project.parent.version}</version> | |
| 43 | + </dependency> | |
| 48 | 44 | |
| 49 | - <scm> | |
| 50 | - <connection>scm:git:git@github.com:datastax/java-driver.git</connection> | |
| 51 | - <developerConnection>scm:git:git@github.com:datastax/java-driver.git</developerConnection> | |
| 52 | - <url>https://github.com/datastax/java-driver</url> | |
| 53 | - <tag>HEAD</tag> | |
| 54 | - </scm> | |
| 45 | + <dependency> | |
| 46 | + <groupId>ch.qos.logback</groupId> | |
| 47 | + <artifactId>logback-classic</artifactId> | |
| 48 | + <version>1.1.3</version> | |
| 49 | + </dependency> | |
| 55 | 50 | |
| 56 | - <developers> | |
| 57 | - <developer> | |
| 58 | - <name>Various</name> | |
| 59 | - <organization>DataStax</organization> | |
| 60 | - </developer> | |
| 61 | - </developers> | |
| 51 | + </dependencies> | |
| 62 | 52 | |
| 63 | 53 | <build> |
| 54 | + | |
| 64 | 55 | <plugins> |
| 56 | + | |
| 65 | 57 | <plugin> |
| 66 | 58 | <groupId>org.apache.maven.plugins</groupId> |
| 67 | 59 | <artifactId>maven-install-plugin</artifactId> |
| @@ -70,6 +62,7 @@ | ||
| 70 | 62 | <skip>true</skip> |
| 71 | 63 | </configuration> |
| 72 | 64 | </plugin> |
| 65 | + | |
| 73 | 66 | <plugin> |
| 74 | 67 | <groupId>org.apache.maven.plugins</groupId> |
| 75 | 68 | <artifactId>maven-deploy-plugin</artifactId> |
| @@ -78,6 +71,32 @@ | ||
| 78 | 71 | <skip>true</skip> |
| 79 | 72 | </configuration> |
| 80 | 73 | </plugin> |
| 74 | + | |
| 81 | 75 | </plugins> |
| 76 | + | |
| 82 | 77 | </build> |
| 78 | + | |
| 79 | + <licenses> | |
| 80 | + <license> | |
| 81 | + <name>Apache 2</name> | |
| 82 | + <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | |
| 83 | + <distribution>repo</distribution> | |
| 84 | + <comments>Apache License Version 2.0</comments> | |
| 85 | + </license> | |
| 86 | + </licenses> | |
| 87 | + | |
| 88 | + <scm> | |
| 89 | + <connection>scm:git:git@github.com:datastax/java-driver.git</connection> | |
| 90 | + <developerConnection>scm:git:git@github.com:datastax/java-driver.git</developerConnection> | |
| 91 | + <url>https://github.com/datastax/java-driver</url> | |
| 92 | + <tag>HEAD</tag> | |
| 93 | + </scm> | |
| 94 | + | |
| 95 | + <developers> | |
| 96 | + <developer> | |
| 97 | + <name>Various</name> | |
| 98 | + <organization>DataStax</organization> | |
| 99 | + </developer> | |
| 100 | + </developers> | |
| 101 | + | |
| 83 | 102 | </project> |
added driver-examples/src/main/java/com/datastax/driver/examples/basic/CreateAndPopulateKeyspace.java +166 −0
| @@ -0,0 +1,166 @@ | ||
| 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.examples.basic; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.Cluster; | |
| 19 | +import com.datastax.driver.core.ResultSet; | |
| 20 | +import com.datastax.driver.core.Row; | |
| 21 | +import com.datastax.driver.core.Session; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * Creates a keyspace and tables, and loads some data into them. | |
| 25 | + * <p/> | |
| 26 | + * Preconditions: | |
| 27 | + * - a Cassandra cluster is running and accessible through the contacts points identified by CONTACT_POINTS and PORT. | |
| 28 | + * <p/> | |
| 29 | + * Side effects: | |
| 30 | + * - creates a new keyspace "simplex" in the cluster. It a keyspace with this name already exists, it will be reused; | |
| 31 | + * - creates two tables "simplex.songs" and "simplex.playlists". If they exist already, they will be reused; | |
| 32 | + * - inserts a row in each table. | |
| 33 | + * | |
| 34 | + * @see <a href="http://datastax.github.io/java-driver/manual/">Java driver online manual</a> | |
| 35 | + */ | |
| 36 | +public class CreateAndPopulateKeyspace { | |
| 37 | + | |
| 38 | + static String[] CONTACT_POINTS = {"127.0.0.1"}; | |
| 39 | + static int PORT = 9042; | |
| 40 | + | |
| 41 | + public static void main(String[] args) { | |
| 42 | + | |
| 43 | + CreateAndPopulateKeyspace client = new CreateAndPopulateKeyspace(); | |
| 44 | + | |
| 45 | + try { | |
| 46 | + | |
| 47 | + client.connect(CONTACT_POINTS, PORT); | |
| 48 | + client.createSchema(); | |
| 49 | + client.loadData(); | |
| 50 | + client.querySchema(); | |
| 51 | + | |
| 52 | + } finally { | |
| 53 | + client.close(); | |
| 54 | + } | |
| 55 | + } | |
| 56 | + | |
| 57 | + private Cluster cluster; | |
| 58 | + | |
| 59 | + private Session session; | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Initiates a connection to the cluster | |
| 63 | + * specified by the given contact point. | |
| 64 | + * | |
| 65 | + * @param contactPoints the contact points to use. | |
| 66 | + * @param port the port to use. | |
| 67 | + */ | |
| 68 | + public void connect(String[] contactPoints, int port) { | |
| 69 | + | |
| 70 | + cluster = Cluster.builder() | |
| 71 | + .addContactPoints(contactPoints).withPort(port) | |
| 72 | + .build(); | |
| 73 | + | |
| 74 | + System.out.printf("Connected to cluster: %s%n", cluster.getMetadata().getClusterName()); | |
| 75 | + | |
| 76 | + session = cluster.connect(); | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * Creates the schema (keyspace) and tables | |
| 81 | + * for this example. | |
| 82 | + */ | |
| 83 | + public void createSchema() { | |
| 84 | + | |
| 85 | + session.execute("CREATE KEYSPACE IF NOT EXISTS simplex WITH replication " + | |
| 86 | + "= {'class':'SimpleStrategy', 'replication_factor':1};"); | |
| 87 | + | |
| 88 | + session.execute( | |
| 89 | + "CREATE TABLE IF NOT EXISTS simplex.songs (" + | |
| 90 | + "id uuid PRIMARY KEY," + | |
| 91 | + "title text," + | |
| 92 | + "album text," + | |
| 93 | + "artist text," + | |
| 94 | + "tags set<text>," + | |
| 95 | + "data blob" + | |
| 96 | + ");"); | |
| 97 | + | |
| 98 | + session.execute( | |
| 99 | + "CREATE TABLE IF NOT EXISTS simplex.playlists (" + | |
| 100 | + "id uuid," + | |
| 101 | + "title text," + | |
| 102 | + "album text, " + | |
| 103 | + "artist text," + | |
| 104 | + "song_id uuid," + | |
| 105 | + "PRIMARY KEY (id, title, album, artist)" + | |
| 106 | + ");"); | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * Inserts data into the tables. | |
| 111 | + */ | |
| 112 | + public void loadData() { | |
| 113 | + | |
| 114 | + session.execute( | |
| 115 | + "INSERT INTO simplex.songs (id, title, album, artist, tags) " + | |
| 116 | + "VALUES (" + | |
| 117 | + "756716f7-2e54-4715-9f00-91dcbea6cf50," + | |
| 118 | + "'La Petite Tonkinoise'," + | |
| 119 | + "'Bye Bye Blackbird'," + | |
| 120 | + "'Joséphine Baker'," + | |
| 121 | + "{'jazz', '2013'})" + | |
| 122 | + ";"); | |
| 123 | + | |
| 124 | + session.execute( | |
| 125 | + "INSERT INTO simplex.playlists (id, song_id, title, album, artist) " + | |
| 126 | + "VALUES (" + | |
| 127 | + "2cc9ccb7-6221-4ccb-8387-f22b6a1b354d," + | |
| 128 | + "756716f7-2e54-4715-9f00-91dcbea6cf50," + | |
| 129 | + "'La Petite Tonkinoise'," + | |
| 130 | + "'Bye Bye Blackbird'," + | |
| 131 | + "'Joséphine Baker'" + | |
| 132 | + ");"); | |
| 133 | + } | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * Queries and displays data. | |
| 137 | + */ | |
| 138 | + public void querySchema() { | |
| 139 | + | |
| 140 | + ResultSet results = session.execute( | |
| 141 | + "SELECT * FROM simplex.playlists " + | |
| 142 | + "WHERE id = 2cc9ccb7-6221-4ccb-8387-f22b6a1b354d;"); | |
| 143 | + | |
| 144 | + System.out.printf("%-30s\t%-20s\t%-20s%n", "title", "album", "artist"); | |
| 145 | + System.out.println("-------------------------------+-----------------------+--------------------"); | |
| 146 | + | |
| 147 | + for (Row row : results) { | |
| 148 | + | |
| 149 | + System.out.printf("%-30s\t%-20s\t%-20s%n", | |
| 150 | + row.getString("title"), | |
| 151 | + row.getString("album"), | |
| 152 | + row.getString("artist")); | |
| 153 | + | |
| 154 | + } | |
| 155 | + | |
| 156 | + } | |
| 157 | + | |
| 158 | + /** | |
| 159 | + * Closes the session and the cluster. | |
| 160 | + */ | |
| 161 | + public void close() { | |
| 162 | + session.close(); | |
| 163 | + cluster.close(); | |
| 164 | + } | |
| 165 | + | |
| 166 | +} |
added driver-examples/src/main/java/com/datastax/driver/examples/basic/ReadCassandraVersion.java +72 −0
| @@ -0,0 +1,72 @@ | ||
| 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.examples.basic; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.Cluster; | |
| 19 | +import com.datastax.driver.core.ResultSet; | |
| 20 | +import com.datastax.driver.core.Row; | |
| 21 | +import com.datastax.driver.core.Session; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * Connects to a Cassandra cluster and extracts basic information from it. | |
| 25 | + * <p/> | |
| 26 | + * Preconditions: | |
| 27 | + * - a Cassandra cluster is running and accessible through the contacts points identified by CONTACT_POINTS and PORT. | |
| 28 | + * <p/> | |
| 29 | + * Side effects: none. | |
| 30 | + * | |
| 31 | + * @see <a href="http://datastax.github.io/java-driver/manual/">Java driver online manual</a> | |
| 32 | + */ | |
| 33 | +public class ReadCassandraVersion { | |
| 34 | + | |
| 35 | + static String[] CONTACT_POINTS = {"127.0.0.1"}; | |
| 36 | + static int PORT = 9042; | |
| 37 | + | |
| 38 | + public static void main(String[] args) { | |
| 39 | + | |
| 40 | + Cluster cluster = null; | |
| 41 | + try { | |
| 42 | + // The Cluster object is the main entry point of the driver. | |
| 43 | + // It holds the known state of the actual Cassandra cluster (notably the Metadata). | |
| 44 | + // This class is thread-safe, you should create a single instance (per target Cassandra cluster), and share | |
| 45 | + // it throughout your application. | |
| 46 | + cluster = Cluster.builder() | |
| 47 | + .addContactPoints(CONTACT_POINTS).withPort(PORT) | |
| 48 | + .build(); | |
| 49 | + | |
| 50 | + // The Session is what you use to execute queries. Likewise, it is thread-safe and should be reused. | |
| 51 | + Session session = cluster.connect(); | |
| 52 | + | |
| 53 | + // We use execute to send a query to Cassandra. This returns a ResultSet, which is essentially a collection | |
| 54 | + // of Row objects. | |
| 55 | + ResultSet rs = session.execute("select release_version from system.local"); | |
| 56 | + // Extract the first row (which is the only one in this case). | |
| 57 | + Row row = rs.one(); | |
| 58 | + | |
| 59 | + // Extract the value of the first (and only) column from the row. | |
| 60 | + String releaseVersion = row.getString("release_version"); | |
| 61 | + System.out.printf("Cassandra version is: %s%n", releaseVersion); | |
| 62 | + | |
| 63 | + } finally { | |
| 64 | + // Close the cluster after we’re done with it. This will also close any session that was created from this | |
| 65 | + // cluster. | |
| 66 | + // This step is important because it frees underlying resources (TCP connections, thread pools...). In a | |
| 67 | + // real application, you would typically do this at shutdown (for example, when undeploying your webapp). | |
| 68 | + if (cluster != null) | |
| 69 | + cluster.close(); | |
| 70 | + } | |
| 71 | + } | |
| 72 | +} |
added driver-examples/src/main/java/com/datastax/driver/examples/basic/ReadTopologyAndSchemaMetadata.java +64 −0
| @@ -0,0 +1,64 @@ | ||
| 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.examples.basic; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * Gathers information about a Cassandra cluster's topology (which nodes belong to the cluster) and schema (what | |
| 22 | + * keyspaces, tables, etc. exist in this cluster). | |
| 23 | + * <p/> | |
| 24 | + * Preconditions: | |
| 25 | + * - a Cassandra cluster is running and accessible through the contacts points identified by CONTACT_POINTS and PORT. | |
| 26 | + * <p/> | |
| 27 | + * Side effects: none. | |
| 28 | + * | |
| 29 | + * @see <a href="http://datastax.github.io/java-driver/manual/">Java driver online manual</a> | |
| 30 | + */ | |
| 31 | +public class ReadTopologyAndSchemaMetadata { | |
| 32 | + | |
| 33 | + static String[] CONTACT_POINTS = {"127.0.0.1"}; | |
| 34 | + static int PORT = 9042; | |
| 35 | + | |
| 36 | + public static void main(String[] args) { | |
| 37 | + | |
| 38 | + Cluster cluster = null; | |
| 39 | + try { | |
| 40 | + cluster = Cluster.builder() | |
| 41 | + .addContactPoints(CONTACT_POINTS).withPort(PORT) | |
| 42 | + .build(); | |
| 43 | + | |
| 44 | + Metadata metadata = cluster.getMetadata(); | |
| 45 | + System.out.printf("Connected to cluster: %s%n", metadata.getClusterName()); | |
| 46 | + | |
| 47 | + for (Host host : metadata.getAllHosts()) { | |
| 48 | + System.out.printf("Datatacenter: %s; Host: %s; Rack: %s%n", | |
| 49 | + host.getDatacenter(), host.getAddress(), host.getRack()); | |
| 50 | + } | |
| 51 | + | |
| 52 | + for (KeyspaceMetadata keyspace : metadata.getKeyspaces()) { | |
| 53 | + for (TableMetadata table : keyspace.getTables()) { | |
| 54 | + System.out.printf("Keyspace: %s; Table: %s%n", | |
| 55 | + keyspace.getName(), table.getName()); | |
| 56 | + } | |
| 57 | + } | |
| 58 | + | |
| 59 | + } finally { | |
| 60 | + if (cluster != null) | |
| 61 | + cluster.close(); | |
| 62 | + } | |
| 63 | + } | |
| 64 | +} |
added driver-examples/src/main/java/com/datastax/driver/examples/datatypes/Blobs.java +253 −0
| @@ -0,0 +1,253 @@ | ||
| 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.examples.datatypes; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.utils.Bytes; | |
| 20 | +import com.google.common.collect.ImmutableMap; | |
| 21 | + | |
| 22 | +import java.io.*; | |
| 23 | +import java.nio.ByteBuffer; | |
| 24 | +import java.nio.channels.FileChannel; | |
| 25 | +import java.util.Map; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * Inserts and retrieves values in BLOB columns. | |
| 29 | + * <p/> | |
| 30 | + * By default, the Java driver maps this type to {@link java.nio.ByteBuffer}. The ByteBuffer API is a bit tricky to use | |
| 31 | + * at times, so we will show common pitfalls as well. We strongly recommend that you read the {@link java.nio.Buffer} | |
| 32 | + * and {@link ByteBuffer} API docs and become familiar with the capacity, limit and position properties. | |
| 33 | + * <a href="http://tutorials.jenkov.com/java-nio/buffers.html">This tutorial</a> might also help. | |
| 34 | + * <p/> | |
| 35 | + * Preconditions: | |
| 36 | + * - a Cassandra cluster is running and accessible through the contacts points identified by CONTACT_POINTS and PORT; | |
| 37 | + * - FILE references an existing file. | |
| 38 | + * <p/> | |
| 39 | + * Side effects: | |
| 40 | + * - creates a new keyspace "examples" in the cluster. It a keyspace with this name already exists, it will be reused; | |
| 41 | + * - creates a table "examples.blobs". If it already exists, it will be reused; | |
| 42 | + * - inserts data in the table. | |
| 43 | + */ | |
| 44 | +public class Blobs { | |
| 45 | + | |
| 46 | + static String[] CONTACT_POINTS = {"127.0.0.1"}; | |
| 47 | + static int PORT = 9042; | |
| 48 | + | |
| 49 | + static File FILE = new File(Blobs.class.getResource("/cassandra_logo.png").getFile()); | |
| 50 | + | |
| 51 | + public static void main(String[] args) throws IOException { | |
| 52 | + Cluster cluster = null; | |
| 53 | + try { | |
| 54 | + cluster = Cluster.builder() | |
| 55 | + .addContactPoints(CONTACT_POINTS).withPort(PORT) | |
| 56 | + .build(); | |
| 57 | + Session session = cluster.connect(); | |
| 58 | + | |
| 59 | + createSchema(session); | |
| 60 | + allocateAndInsert(session); | |
| 61 | + retrieveSimpleColumn(session); | |
| 62 | + retrieveMapColumn(session); | |
| 63 | + insertConcurrent(session); | |
| 64 | + insertFromAndRetrieveToFile(session); | |
| 65 | + } finally { | |
| 66 | + if (cluster != null) cluster.close(); | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + private static void createSchema(Session session) { | |
| 71 | + session.execute("CREATE KEYSPACE IF NOT EXISTS examples " + | |
| 72 | + "WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); | |
| 73 | + session.execute("CREATE TABLE IF NOT EXISTS examples.blobs(k int PRIMARY KEY, b blob, m map<text, blob>)"); | |
| 74 | + } | |
| 75 | + | |
| 76 | + private static void allocateAndInsert(Session session) { | |
| 77 | + // One way to get a byte buffer is to allocate it and fill it yourself: | |
| 78 | + ByteBuffer buffer = ByteBuffer.allocate(16); | |
| 79 | + while (buffer.hasRemaining()) | |
| 80 | + buffer.put((byte) 0xFF); | |
| 81 | + | |
| 82 | + // Don't forget to flip! The driver expects a buffer that is ready for reading. That is, it will consider all | |
| 83 | + // the data between buffer.position() and buffer.limit(). | |
| 84 | + // Right now we are positioned at the end because we just finished writing, so if we passed the buffer as-is it | |
| 85 | + // would appear to be empty: | |
| 86 | + assert buffer.limit() - buffer.position() == 0; | |
| 87 | + | |
| 88 | + buffer.flip(); | |
| 89 | + // Now position is back to the beginning, so the driver will see all 16 bytes. | |
| 90 | + assert buffer.limit() - buffer.position() == 16; | |
| 91 | + | |
| 92 | + session.execute("INSERT INTO examples.blobs (k, b, m) VALUES (1, ?, ?)", | |
| 93 | + buffer, ImmutableMap.of("test", buffer)); | |
| 94 | + } | |
| 95 | + | |
| 96 | + private static void retrieveSimpleColumn(Session session) { | |
| 97 | + Row row = session.execute("SELECT b, m FROM examples.blobs WHERE k = 1").one(); | |
| 98 | + | |
| 99 | + ByteBuffer buffer = row.getBytes("b"); | |
| 100 | + | |
| 101 | + // The driver always returns buffers that are ready for reading. | |
| 102 | + assert buffer.limit() - buffer.position() == 16; | |
| 103 | + | |
| 104 | + // One way to read from the buffer is to use absolute getters. Do NOT start reading at index 0, as the buffer | |
| 105 | + // might start at a different position (we'll see an example of that later). | |
| 106 | + for (int i = buffer.position(); i < buffer.limit(); i++) { | |
| 107 | + byte b = buffer.get(i); | |
| 108 | + assert b == (byte) 0xFF; | |
| 109 | + } | |
| 110 | + | |
| 111 | + // Another way is to use relative getters. | |
| 112 | + while (buffer.hasRemaining()) { | |
| 113 | + byte b = buffer.get(); | |
| 114 | + assert b == (byte) 0xFF; | |
| 115 | + } | |
| 116 | + // Note that relative getters change the position, so when we're done reading we're at the end again. | |
| 117 | + assert buffer.position() == buffer.limit(); | |
| 118 | + | |
| 119 | + // Reset the position for the next operation. | |
| 120 | + buffer.flip(); | |
| 121 | + | |
| 122 | + // Yet another way is to convert the buffer to a byte array. Do NOT use buffer.array(), because it returns the | |
| 123 | + // buffer's *backing array*, which is not the same thing as its contents: | |
| 124 | + // - not all byte buffers have backing arrays | |
| 125 | + // - even then, the backing array might be larger than the buffer's contents | |
| 126 | + // | |
| 127 | + // The driver provides a utility method that handles those details for you: | |
| 128 | + byte[] array = Bytes.getArray(buffer); | |
| 129 | + assert array.length == 16; | |
| 130 | + for (byte b : array) { | |
| 131 | + assert b == (byte) 0xFF; | |
| 132 | + } | |
| 133 | + } | |
| 134 | + | |
| 135 | + private static void retrieveMapColumn(Session session) { | |
| 136 | + Row row = session.execute("SELECT b, m FROM examples.blobs WHERE k = 1").one(); | |
| 137 | + | |
| 138 | + // The map columns illustrates the pitfalls with position() and array(). | |
| 139 | + Map<String, ByteBuffer> m = row.getMap("m", String.class, ByteBuffer.class); | |
| 140 | + ByteBuffer buffer = m.get("test"); | |
| 141 | + | |
| 142 | + // We did get back a buffer that contains 16 bytes as expected. | |
| 143 | + assert buffer.limit() - buffer.position() == 16; | |
| 144 | + // However, it is not positioned at 0. And you can also see that its backing array contains more than 16 bytes. | |
| 145 | + // What happens is that the buffer is a "view" of the last 16 of a 32-byte array. | |
| 146 | + // This is an implementation detail and you shouldn't have to worry about it if you process the buffer correctly | |
| 147 | + // (don't iterate from 0, use Bytes.getArray()). | |
| 148 | + assert buffer.position() == 16; | |
| 149 | + assert buffer.array().length == 32; | |
| 150 | + } | |
| 151 | + | |
| 152 | + private static void insertConcurrent(Session session) { | |
| 153 | + PreparedStatement preparedStatement = session.prepare("INSERT INTO examples.blobs (k, b) VALUES (1, :b)"); | |
| 154 | + | |
| 155 | + // This is another convenient utility provided by the driver. It's useful for tests. | |
| 156 | + ByteBuffer buffer = Bytes.fromHexString("0xffffff"); | |
| 157 | + | |
| 158 | + // When you pass a byte buffer to a bound statement, it creates a shallow copy internally with the | |
| 159 | + // buffer.duplicate() method. | |
| 160 | + BoundStatement boundStatement = preparedStatement.bind(); | |
| 161 | + boundStatement.setBytes("b", buffer); | |
| 162 | + | |
| 163 | + // This means you can now move in the original buffer, without affecting the insertion if it happens later. | |
| 164 | + buffer.position(buffer.limit()); | |
| 165 | + | |
| 166 | + session.execute(boundStatement); | |
| 167 | + Row row = session.execute("SELECT b FROM examples.blobs WHERE k = 1").one(); | |
| 168 | + assert Bytes.toHexString(row.getBytes("b")).equals("0xffffff"); | |
| 169 | + | |
| 170 | + buffer.flip(); | |
| 171 | + | |
| 172 | + // HOWEVER duplicate() only performs a shallow copy. The two buffers still share the same contents. So if you | |
| 173 | + // modify the contents of the original buffer, this will affect another execution of the bound statement. | |
| 174 | + buffer.put(0, (byte) 0xaa); | |
| 175 | + session.execute(boundStatement); | |
| 176 | + row = session.execute("SELECT b FROM examples.blobs WHERE k = 1").one(); | |
| 177 | + assert Bytes.toHexString(row.getBytes("b")).equals("0xaaffff"); | |
| 178 | + | |
| 179 | + // This will also happen if you use the async API, e.g. create the bound statement, call executeAsync() on it | |
| 180 | + // and reuse the buffer immediately. | |
| 181 | + | |
| 182 | + // If you reuse buffers concurrently and want to avoid those issues, perform a deep copy of the buffer before | |
| 183 | + // passing it to the bound statement. | |
| 184 | + int startPosition = buffer.position(); | |
| 185 | + ByteBuffer buffer2 = ByteBuffer.allocate(buffer.limit() - startPosition); | |
| 186 | + buffer2.put(buffer); | |
| 187 | + buffer.position(startPosition); | |
| 188 | + buffer2.flip(); | |
| 189 | + boundStatement.setBytes("b", buffer2); | |
| 190 | + session.execute(boundStatement); | |
| 191 | + | |
| 192 | + // Note: unlike BoundStatement, SimpleStatement does not duplicate its arguments, so even the position will be | |
| 193 | + // affected if you change it before executing the statement. Again, resort to deep copies if required. | |
| 194 | + } | |
| 195 | + | |
| 196 | + private static void insertFromAndRetrieveToFile(Session session) throws IOException { | |
| 197 | + ByteBuffer buffer = readAll(FILE); | |
| 198 | + session.execute("INSERT INTO examples.blobs (k, b) VALUES (1, ?)", buffer); | |
| 199 | + | |
| 200 | + File tmpFile = File.createTempFile("blob", ".png"); | |
| 201 | + System.out.printf("Writing retrieved buffer to %s%n", tmpFile.getAbsoluteFile()); | |
| 202 | + | |
| 203 | + Row row = session.execute("SELECT b FROM examples.blobs WHERE k = 1").one(); | |
| 204 | + writeAll(row.getBytes("b"), tmpFile); | |
| 205 | + } | |
| 206 | + | |
| 207 | + // Note: | |
| 208 | + // - this is written with Java 6 APIs; if you're on a more recent version this can be improved (try-with-resources, | |
| 209 | + // new-new io...) | |
| 210 | + // - this reads the whole file in memory in one go. If your file does not fit in memory you should probably not | |
| 211 | + // insert it into Cassandra either ;) | |
| 212 | + private static ByteBuffer readAll(File file) throws IOException { | |
| 213 | + FileInputStream inputStream = null; | |
| 214 | + boolean threw = false; | |
| 215 | + try { | |
| 216 | + inputStream = new FileInputStream(file); | |
| 217 | + FileChannel channel = inputStream.getChannel(); | |
| 218 | + ByteBuffer buffer = ByteBuffer.allocate((int) channel.size()); | |
| 219 | + channel.read(buffer); | |
| 220 | + buffer.flip(); | |
| 221 | + return buffer; | |
| 222 | + } catch (IOException e) { | |
| 223 | + threw = true; | |
| 224 | + throw e; | |
| 225 | + } finally { | |
| 226 | + close(inputStream, threw); | |
| 227 | + } | |
| 228 | + } | |
| 229 | + | |
| 230 | + private static void writeAll(ByteBuffer buffer, File file) throws IOException { | |
| 231 | + FileOutputStream outputStream = null; | |
| 232 | + boolean threw = false; | |
| 233 | + try { | |
| 234 | + outputStream = new FileOutputStream(file); | |
| 235 | + FileChannel channel = outputStream.getChannel(); | |
| 236 | + channel.write(buffer); | |
| 237 | + } catch (IOException e) { | |
| 238 | + threw = true; | |
| 239 | + throw e; | |
| 240 | + } finally { | |
| 241 | + close(outputStream, threw); | |
| 242 | + } | |
| 243 | + } | |
| 244 | + | |
| 245 | + private static void close(Closeable inputStream, boolean threw) throws IOException { | |
| 246 | + if (inputStream != null) | |
| 247 | + try { | |
| 248 | + inputStream.close(); | |
| 249 | + } catch (IOException e) { | |
| 250 | + if (!threw) throw e; // else preserve original exception | |
| 251 | + } | |
| 252 | + } | |
| 253 | +} |
added driver-examples/src/main/resources/cassandra_logo.png +0 −0
Binary content is not shown. View the file.
added driver-examples/src/main/resources/logback.xml +39 −0
| @@ -0,0 +1,39 @@ | ||
| 1 | +<!-- | |
| 2 | + | |
| 3 | + Copyright (C) 2012-2015 DataStax Inc. | |
| 4 | + | |
| 5 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | + you may not use this file except in compliance with the License. | |
| 7 | + You may obtain a copy of the License at | |
| 8 | + | |
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | + | |
| 11 | + Unless required by applicable law or agreed to in writing, software | |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | + See the License for the specific language governing permissions and | |
| 15 | + limitations under the License. | |
| 16 | + | |
| 17 | +--> | |
| 18 | +<configuration> | |
| 19 | + | |
| 20 | + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | |
| 21 | + | |
| 22 | + <!-- encoders are assigned the type | |
| 23 | + ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | |
| 24 | + <encoder> | |
| 25 | + <pattern>%-5level - %msg%n</pattern> | |
| 26 | + </encoder> | |
| 27 | + | |
| 28 | + </appender> | |
| 29 | + | |
| 30 | + <!-- adjust the driver's log verbosity; see | |
| 31 | + http://datastax.github.io/java-driver/manual/logging/ | |
| 32 | + for more information --> | |
| 33 | + <logger name="com.datastax.driver.core" level="WARN"/> | |
| 34 | + | |
| 35 | + <root level="INFO"> | |
| 36 | + <appender-ref ref="STDOUT"/> | |
| 37 | + </root> | |
| 38 | + | |
| 39 | +</configuration> |
deleted driver-examples/stress/README.md +0 −25
| @@ -1,25 +0,0 @@ | ||
| 1 | -# Stress application | |
| 2 | - | |
| 3 | -A simple example application that uses the java driver to stress test | |
| 4 | -Cassandra. This also somewhat stress test the java driver as a result. | |
| 5 | - | |
| 6 | -Please note that this simple example is far from being a complete stress | |
| 7 | -application. In particular it currently supports a very limited number of | |
| 8 | -stress scenario. | |
| 9 | - | |
| 10 | -## Usage | |
| 11 | - | |
| 12 | -You will need to build the stress application fist: | |
| 13 | - | |
| 14 | - ./bin/build | |
| 15 | - | |
| 16 | -After which you can run it using for instance: | |
| 17 | - | |
| 18 | - ./bin/stress insert_prepared | |
| 19 | - | |
| 20 | -Of course, you will need to have at least one Cassandra node running (on | |
| 21 | -127.0.0.1 by default) for this to work. Please refer to: | |
| 22 | - | |
| 23 | - ./bin/stress -h | |
| 24 | - | |
| 25 | -for more details on the options available. |
deleted driver-examples/stress/bin/build +0 −36
| @@ -1,36 +0,0 @@ | ||
| 1 | -#!/bin/sh | |
| 2 | - | |
| 3 | -SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd ) | |
| 4 | -CURRENT_DIR=$( pwd ) | |
| 5 | - | |
| 6 | -LOG_FILE="$CURRENT_DIR/stress_build.log" | |
| 7 | -[ -f $LOG_FILE ] && rm $LOG_FILE | |
| 8 | - | |
| 9 | -echo "Building java driver ..." | |
| 10 | -echo "-- Driver build --\n" > $LOG_FILE | |
| 11 | - | |
| 12 | -cd $SCRIPT_DIR/../../.. | |
| 13 | -mvn clean install -Dmaven.test.skip=true >> $LOG_FILE 2>&1 | |
| 14 | -EXIT_CODE=$? | |
| 15 | -if [ $EXIT_CODE -ne 0 ]; | |
| 16 | -then | |
| 17 | - echo "Error building driver. See $LOG_FILE for details." 1>&2 | |
| 18 | - cd $CURRENT_DIR | |
| 19 | - exit $EXIT_CODE | |
| 20 | -fi | |
| 21 | - | |
| 22 | -echo "Building stress application ..." | |
| 23 | -echo "\n-- Stress build --\n" >> $LOG_FILE | |
| 24 | - | |
| 25 | -cd $SCRIPT_DIR/.. | |
| 26 | -mvn package assembly:single >> $LOG_FILE 2>&1 | |
| 27 | -EXIT_CODE=$? | |
| 28 | -if [ $EXIT_CODE -ne 0 ]; | |
| 29 | -then | |
| 30 | - echo "Error building stress application. See $LOG_FILE for details." 1>&2 | |
| 31 | - cd $CURRENT_DIR | |
| 32 | - exit $EXIT_CODE | |
| 33 | -fi | |
| 34 | - | |
| 35 | -cd $CURRENT_DIR | |
| 36 | -rm $LOG_FILE |
deleted driver-examples/stress/bin/stress +0 −30
| @@ -1,30 +0,0 @@ | ||
| 1 | -#!/bin/sh | |
| 2 | - | |
| 3 | -SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd ) | |
| 4 | -CURRENT_DIR=$( pwd ) | |
| 5 | - | |
| 6 | -# Use $JAVA_HOME if set | |
| 7 | -if [ -n "$JAVA_HOME" ]; then | |
| 8 | - JAVA="$JAVA_HOME/bin/java" | |
| 9 | -else | |
| 10 | - JAVA=java | |
| 11 | -fi | |
| 12 | - | |
| 13 | -if [ "x$STRESS_JAR" = "x" ]; then | |
| 14 | - | |
| 15 | - STRESS_JAR="$SCRIPT_DIR/../target/cassandra-driver-examples-stress-*-jar-with-dependencies.jar" | |
| 16 | - | |
| 17 | - if [ ! -f $STRESS_JAR ]; then | |
| 18 | - # Trash the version file in case there was some crap in it | |
| 19 | - RELATIVE_SCRIPT_DIR=`dirname $0` | |
| 20 | - echo "Stress application does not seem to be build, try $RELATIVE_SCRIPT_DIR/build first" 1>&2 | |
| 21 | - exit 1 | |
| 22 | - fi | |
| 23 | -else | |
| 24 | - if [ ! -f $STRESS_JAR ]; then | |
| 25 | - echo "Cannot find file $STRESS_JAR" 1>&2 | |
| 26 | - exit 1 | |
| 27 | - fi | |
| 28 | -fi | |
| 29 | - | |
| 30 | -"$JAVA" -Dlog4j.configuration="$SCRIPT_DIR/../conf/log4j.properties" -jar $STRESS_JAR $@ |
deleted driver-examples/stress/pom.xml +0 −109
| @@ -1,109 +0,0 @@ | ||
| 1 | -<!-- | |
| 2 | - | |
| 3 | - Copyright (C) 2012-2015 DataStax Inc. | |
| 4 | - | |
| 5 | - Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | - you may not use this file except in compliance with the License. | |
| 7 | - You may obtain a copy of the License at | |
| 8 | - | |
| 9 | - http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | - | |
| 11 | - Unless required by applicable law or agreed to in writing, software | |
| 12 | - distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | - See the License for the specific language governing permissions and | |
| 15 | - limitations under the License. | |
| 16 | - | |
| 17 | ---> | |
| 18 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| 19 | - <modelVersion>4.0.0</modelVersion> | |
| 20 | - <parent> | |
| 21 | - <groupId>com.datastax.cassandra</groupId> | |
| 22 | - <artifactId>cassandra-driver-examples-parent</artifactId> | |
| 23 | - <version>3.0.1-SNAPSHOT</version> | |
| 24 | - </parent> | |
| 25 | - <artifactId>cassandra-driver-examples-stress</artifactId> | |
| 26 | - <packaging>jar</packaging> | |
| 27 | - <name>DataStax Java Driver for Apache Cassandra Examples - Stress</name> | |
| 28 | - <description>A stress test example for DataStax Java Driver for Apache Cassandra.</description> | |
| 29 | - <url>https://github.com/datastax/java-driver</url> | |
| 30 | - | |
| 31 | - <properties> | |
| 32 | - <main.basedir>${project.parent.parent.basedir}</main.basedir> | |
| 33 | - </properties> | |
| 34 | - | |
| 35 | - <dependencies> | |
| 36 | - <dependency> | |
| 37 | - <groupId>com.datastax.cassandra</groupId> | |
| 38 | - <artifactId>cassandra-driver-core</artifactId> | |
| 39 | - <version>3.0.1-SNAPSHOT</version> | |
| 40 | - </dependency> | |
| 41 | - | |
| 42 | - <dependency> | |
| 43 | - <groupId>com.yammer.metrics</groupId> | |
| 44 | - <artifactId>metrics-core</artifactId> | |
| 45 | - <version>2.2.0</version> | |
| 46 | - </dependency> | |
| 47 | - | |
| 48 | - <dependency> | |
| 49 | - <groupId>net.sf.jopt-simple</groupId> | |
| 50 | - <artifactId>jopt-simple</artifactId> | |
| 51 | - <version>4.5</version> | |
| 52 | - </dependency> | |
| 53 | - | |
| 54 | - <dependency> | |
| 55 | - <groupId>log4j</groupId> | |
| 56 | - <artifactId>log4j</artifactId> | |
| 57 | - <version>1.2.17</version> | |
| 58 | - </dependency> | |
| 59 | - | |
| 60 | - <dependency> | |
| 61 | - <groupId>org.slf4j</groupId> | |
| 62 | - <artifactId>slf4j-log4j12</artifactId> | |
| 63 | - <version>1.7.5</version> | |
| 64 | - </dependency> | |
| 65 | - </dependencies> | |
| 66 | - | |
| 67 | - <build> | |
| 68 | - <plugins> | |
| 69 | - <plugin> | |
| 70 | - <artifactId>maven-assembly-plugin</artifactId> | |
| 71 | - <version>2.4</version> | |
| 72 | - <configuration> | |
| 73 | - <archive> | |
| 74 | - <manifest> | |
| 75 | - <mainClass>com.datastax.driver.stress.Stress</mainClass> | |
| 76 | - </manifest> | |
| 77 | - </archive> | |
| 78 | - <descriptorRefs> | |
| 79 | - <descriptorRef>jar-with-dependencies</descriptorRef> | |
| 80 | - </descriptorRefs> | |
| 81 | - </configuration> | |
| 82 | - </plugin> | |
| 83 | - </plugins> | |
| 84 | - </build> | |
| 85 | - | |
| 86 | - <licenses> | |
| 87 | - <license> | |
| 88 | - <name>Apache 2</name> | |
| 89 | - <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | |
| 90 | - <distribution>repo</distribution> | |
| 91 | - <comments>Apache License Version 2.0</comments> | |
| 92 | - </license> | |
| 93 | - </licenses> | |
| 94 | - | |
| 95 | - <scm> | |
| 96 | - <connection>scm:git:git@github.com:datastax/java-driver.git</connection> | |
| 97 | - <developerConnection>scm:git:git@github.com:datastax/java-driver.git</developerConnection> | |
| 98 | - <url>https://github.com/datastax/java-driver</url> | |
| 99 | - <tag>HEAD</tag> | |
| 100 | - </scm> | |
| 101 | - | |
| 102 | - <developers> | |
| 103 | - <developer> | |
| 104 | - <name>Various</name> | |
| 105 | - <organization>DataStax</organization> | |
| 106 | - </developer> | |
| 107 | - </developers> | |
| 108 | -</project> | |
| 109 | - |
deleted driver-examples/stress/src/main/java/com/datastax/driver/stress/AsynchronousConsumer.java +0 −98
| @@ -1,98 +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.stress; | |
| 17 | - | |
| 18 | -import com.datastax.driver.core.ResultSet; | |
| 19 | -import com.datastax.driver.core.ResultSetFuture; | |
| 20 | -import com.datastax.driver.core.Session; | |
| 21 | -import com.google.common.util.concurrent.FutureCallback; | |
| 22 | -import com.google.common.util.concurrent.Futures; | |
| 23 | - | |
| 24 | -import java.util.concurrent.CountDownLatch; | |
| 25 | -import java.util.concurrent.ExecutorService; | |
| 26 | -import java.util.concurrent.Executors; | |
| 27 | - | |
| 28 | -import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; | |
| 29 | - | |
| 30 | -public class AsynchronousConsumer implements Consumer { | |
| 31 | - | |
| 32 | - private static final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); | |
| 33 | - | |
| 34 | - private final CountDownLatch shutdownLatch = new CountDownLatch(1); | |
| 35 | - | |
| 36 | - private final Session session; | |
| 37 | - private final QueryGenerator requests; | |
| 38 | - private final Reporter reporter; | |
| 39 | - | |
| 40 | - public AsynchronousConsumer(Session session, | |
| 41 | - QueryGenerator requests, | |
| 42 | - Reporter reporter) { | |
| 43 | - this.session = session; | |
| 44 | - this.requests = requests; | |
| 45 | - this.reporter = reporter; | |
| 46 | - } | |
| 47 | - | |
| 48 | - @Override | |
| 49 | - public void start() { | |
| 50 | - executorService.execute(new Runnable() { | |
| 51 | - @Override | |
| 52 | - public void run() { | |
| 53 | - request(); | |
| 54 | - } | |
| 55 | - }); | |
| 56 | - } | |
| 57 | - | |
| 58 | - private void request() { | |
| 59 | - | |
| 60 | - if (!requests.hasNext()) { | |
| 61 | - shutdown(); | |
| 62 | - return; | |
| 63 | - } | |
| 64 | - | |
| 65 | - handle(requests.next()); | |
| 66 | - } | |
| 67 | - | |
| 68 | - @Override | |
| 69 | - public void join() { | |
| 70 | - awaitUninterruptibly(shutdownLatch); | |
| 71 | - } | |
| 72 | - | |
| 73 | - protected void handle(QueryGenerator.Request request) { | |
| 74 | - | |
| 75 | - final Reporter.Context ctx = reporter.newRequest(); | |
| 76 | - | |
| 77 | - ResultSetFuture resultSetFuture = request.executeAsync(session); | |
| 78 | - Futures.addCallback(resultSetFuture, new FutureCallback<ResultSet>() { | |
| 79 | - @Override | |
| 80 | - public void onSuccess(final ResultSet result) { | |
| 81 | - ctx.done(); | |
| 82 | - request(); | |
| 83 | - } | |
| 84 | - | |
| 85 | - @Override | |
| 86 | - public void onFailure(final Throwable t) { | |
| 87 | - // Could do better I suppose | |
| 88 | - System.err.println("Error during request: " + t); | |
| 89 | - ctx.done(); | |
| 90 | - request(); | |
| 91 | - } | |
| 92 | - }, executorService); | |
| 93 | - } | |
| 94 | - | |
| 95 | - protected void shutdown() { | |
| 96 | - shutdownLatch.countDown(); | |
| 97 | - } | |
| 98 | -} |
deleted driver-examples/stress/src/main/java/com/datastax/driver/stress/BlockingConsumer.java +0 −74
| @@ -1,74 +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.stress; | |
| 17 | - | |
| 18 | -import com.datastax.driver.core.Session; | |
| 19 | -import com.datastax.driver.core.exceptions.DriverException; | |
| 20 | -import com.google.common.util.concurrent.Uninterruptibles; | |
| 21 | - | |
| 22 | -public class BlockingConsumer implements Consumer { | |
| 23 | - | |
| 24 | - private final Runner runner = new Runner(); | |
| 25 | - | |
| 26 | - private final Session session; | |
| 27 | - private final QueryGenerator requests; | |
| 28 | - private final Reporter reporter; | |
| 29 | - | |
| 30 | - public BlockingConsumer(Session session, | |
| 31 | - QueryGenerator requests, | |
| 32 | - Reporter reporter) { | |
| 33 | - this.session = session; | |
| 34 | - this.requests = requests; | |
| 35 | - this.reporter = reporter; | |
| 36 | - this.runner.setDaemon(true); | |
| 37 | - } | |
| 38 | - | |
| 39 | - @Override | |
| 40 | - public void start() { | |
| 41 | - this.runner.start(); | |
| 42 | - } | |
| 43 | - | |
| 44 | - @Override | |
| 45 | - public void join() { | |
| 46 | - Uninterruptibles.joinUninterruptibly(this.runner); | |
| 47 | - } | |
| 48 | - | |
| 49 | - private class Runner extends Thread { | |
| 50 | - | |
| 51 | - public Runner() { | |
| 52 | - super("Consumer Threads"); | |
| 53 | - } | |
| 54 | - | |
| 55 | - @Override | |
| 56 | - public void run() { | |
| 57 | - try { | |
| 58 | - while (requests.hasNext()) | |
| 59 | - handle(requests.next()); | |
| 60 | - } catch (DriverException e) { | |
| 61 | - System.err.println("Error during query: " + e.getMessage()); | |
| 62 | - } | |
| 63 | - } | |
| 64 | - | |
| 65 | - protected void handle(QueryGenerator.Request request) { | |
| 66 | - Reporter.Context ctx = reporter.newRequest(); | |
| 67 | - try { | |
| 68 | - request.execute(session); | |
| 69 | - } finally { | |
| 70 | - ctx.done(); | |
| 71 | - } | |
| 72 | - } | |
| 73 | - } | |
| 74 | -} |
deleted driver-examples/stress/src/main/java/com/datastax/driver/stress/ConsistencyLevelConverter.java +0 −45
| @@ -1,45 +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.stress; | |
| 17 | - | |
| 18 | -import com.datastax.driver.core.ConsistencyLevel; | |
| 19 | -import joptsimple.ValueConverter; | |
| 20 | - | |
| 21 | -/** | |
| 22 | - * Created by Alram.Lechner on 03.03.2016. | |
| 23 | - */ | |
| 24 | -public class ConsistencyLevelConverter implements ValueConverter<ConsistencyLevel> { | |
| 25 | - | |
| 26 | - @Override | |
| 27 | - public ConsistencyLevel convert(String value) { | |
| 28 | - return ConsistencyLevel.valueOf(value); | |
| 29 | - } | |
| 30 | - | |
| 31 | - @Override | |
| 32 | - public Class<ConsistencyLevel> valueType() { | |
| 33 | - return ConsistencyLevel.class; | |
| 34 | - } | |
| 35 | - | |
| 36 | - @Override | |
| 37 | - public String valuePattern() { | |
| 38 | - StringBuilder pattern = new StringBuilder(); | |
| 39 | - for (ConsistencyLevel level : ConsistencyLevel.values()) { | |
| 40 | - pattern.append("(").append(level.name()).append(")|"); | |
| 41 | - } | |
| 42 | - pattern.setLength(pattern.length() - 1); | |
| 43 | - return pattern.toString(); | |
| 44 | - } | |
| 45 | -} |
deleted driver-examples/stress/src/main/java/com/datastax/driver/stress/Consumer.java +0 −23
| @@ -1,23 +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.stress; | |
| 17 | - | |
| 18 | -public interface Consumer { | |
| 19 | - | |
| 20 | - public void start(); | |
| 21 | - | |
| 22 | - public void join(); | |
| 23 | -} |
deleted driver-examples/stress/src/main/java/com/datastax/driver/stress/Generators.java +0 −227
| @@ -1,227 +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.stress; | |
| 17 | - | |
| 18 | -import com.datastax.driver.core.*; | |
| 19 | -import com.datastax.driver.core.exceptions.QueryValidationException; | |
| 20 | -import com.datastax.driver.core.utils.Bytes; | |
| 21 | -import joptsimple.OptionParser; | |
| 22 | -import joptsimple.OptionSet; | |
| 23 | - | |
| 24 | -import java.nio.ByteBuffer; | |
| 25 | -import java.util.Random; | |
| 26 | - | |
| 27 | -public class Generators { | |
| 28 | - private static ThreadLocal<Random> random = new ThreadLocal<Random>() { | |
| 29 | - @Override | |
| 30 | - protected Random initialValue() { | |
| 31 | - return new Random(); | |
| 32 | - } | |
| 33 | - }; | |
| 34 | - | |
| 35 | - private static ByteBuffer makeValue(final int valueSize) { | |
| 36 | - byte[] value = new byte[valueSize]; | |
| 37 | - random.get().nextBytes(value); | |
| 38 | - return ByteBuffer.wrap(value); | |
| 39 | - } | |
| 40 | - | |
| 41 | - private static abstract class AbstractGenerator extends QueryGenerator { | |
| 42 | - protected int iteration; | |
| 43 | - | |
| 44 | - protected AbstractGenerator(int iterations) { | |
| 45 | - super(iterations); | |
| 46 | - } | |
| 47 | - | |
| 48 | - @Override | |
| 49 | - public int currentIteration() { | |
| 50 | - return iteration; | |
| 51 | - } | |
| 52 | - | |
| 53 | - @Override | |
| 54 | - public boolean hasNext() { | |
| 55 | - return iterations == -1 || iteration < iterations; | |
| 56 | - } | |
| 57 | - | |
| 58 | - @Override | |
| 59 | - public void remove() { | |
| 60 | - throw new UnsupportedOperationException(); | |
| 61 | - } | |
| 62 | - } | |
| 63 | - | |
| 64 | - public static final QueryGenerator.Builder INSERTER = new QueryGenerator.Builder() { | |
| 65 | - | |
| 66 | - @Override | |
| 67 | - public String name() { | |
| 68 | - return "insert"; | |
| 69 | - } | |
| 70 | - | |
| 71 | - @Override | |
| 72 | - public OptionParser addOptions(OptionParser parser) { | |
| 73 | - String msg = "Simple insertion of CQL3 rows (using prepared statements unless the --no-prepare option is used). " | |
| 74 | - + "The inserted rows have a fixed set of columns but no clustering columns."; | |
| 75 | - parser.formatHelpWith(Stress.Help.formatFor(name(), msg)); | |
| 76 | - | |
| 77 | - parser.accepts("no-prepare", "Do no use prepared statement"); | |
| 78 | - parser.accepts("columns-per-row", "Number of columns per CQL3 row").withRequiredArg().ofType(Integer.class).defaultsTo(5); | |
| 79 | - parser.accepts("value-size", "The size in bytes for column values").withRequiredArg().ofType(Integer.class).defaultsTo(34); | |
| 80 | - parser.accepts("with-compact-storage", "Use COMPACT STORAGE on the table used"); | |
| 81 | - return parser; | |
| 82 | - } | |
| 83 | - | |
| 84 | - @Override | |
| 85 | - public void prepare(OptionSet options, Session session) { | |
| 86 | - | |
| 87 | - try { | |
| 88 | - session.execute("DROP KEYSPACE stress;"); | |
| 89 | - } catch (QueryValidationException e) { /* Fine, ignore */ } | |
| 90 | - | |
| 91 | - session.execute("CREATE KEYSPACE stress WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }"); | |
| 92 | - | |
| 93 | - session.execute("USE stress"); | |
| 94 | - | |
| 95 | - StringBuilder sb = new StringBuilder(); | |
| 96 | - sb.append("CREATE TABLE standard1 (key bigint PRIMARY KEY"); | |
| 97 | - for (int i = 0; i < (Integer) options.valueOf("columns-per-row"); ++i) | |
| 98 | - sb.append(", C").append(i).append(" blob"); | |
| 99 | - sb.append(')'); | |
| 100 | - | |
| 101 | - if (options.has("with-compact-storage")) | |
| 102 | - sb.append(" WITH COMPACT STORAGE"); | |
| 103 | - | |
| 104 | - session.execute(sb.toString()); | |
| 105 | - } | |
| 106 | - | |
| 107 | - @Override | |
| 108 | - public QueryGenerator create(int id, int iterations, OptionSet options, Session session) { | |
| 109 | - | |
| 110 | - return options.has("no-prepare") | |
| 111 | - ? createRegular(id, iterations, options, session) | |
| 112 | - : createPrepared(id, iterations, options, session); | |
| 113 | - } | |
| 114 | - | |
| 115 | - public QueryGenerator createRegular(int id, int iterations, OptionSet options, final Session session) { | |
| 116 | - final int valueSize = (Integer) options.valueOf("value-size"); | |
| 117 | - final int columnsPerRow = (Integer) options.valueOf("columns-per-row"); | |
| 118 | - final long prefix = (long) id << 32; | |
| 119 | - | |
| 120 | - return new AbstractGenerator(iterations) { | |
| 121 | - @Override | |
| 122 | - public QueryGenerator.Request next() { | |
| 123 | - StringBuilder sb = new StringBuilder(); | |
| 124 | - sb.append("UPDATE standard1 SET "); | |
| 125 | - for (int i = 0; i < columnsPerRow; ++i) { | |
| 126 | - if (i > 0) sb.append(", "); | |
| 127 | - sb.append('C').append(i).append("='").append(Bytes.toHexString(makeValue(valueSize))).append('\''); | |
| 128 | - } | |
| 129 | - sb.append(" WHERE key = ").append(prefix | iteration); | |
| 130 | - ++iteration; | |
| 131 | - return new QueryGenerator.Request.SimpleQuery(new SimpleStatement(sb.toString())); | |
| 132 | - } | |
| 133 | - }; | |
| 134 | - } | |
| 135 | - | |
| 136 | - public QueryGenerator createPrepared(int id, int iterations, OptionSet options, Session session) { | |
| 137 | - final int valueSize = (Integer) options.valueOf("value-size"); | |
| 138 | - final int columnsPerRow = (Integer) options.valueOf("columns-per-row"); | |
| 139 | - final long prefix = (long) id << 32; | |
| 140 | - | |
| 141 | - StringBuilder sb = new StringBuilder(); | |
| 142 | - sb.append("UPDATE standard1 SET "); | |
| 143 | - for (int i = 0; i < columnsPerRow; ++i) { | |
| 144 | - if (i > 0) sb.append(", "); | |
| 145 | - sb.append('C').append(i).append("=?"); | |
| 146 | - } | |
| 147 | - sb.append(" WHERE key = ?"); | |
| 148 | - | |
| 149 | - final PreparedStatement stmt = session.prepare(sb.toString()); | |
| 150 | - | |
| 151 | - return new AbstractGenerator(iterations) { | |
| 152 | - @Override | |
| 153 | - public QueryGenerator.Request next() { | |
| 154 | - BoundStatement b = stmt.bind(); | |
| 155 | - b.setLong("key", prefix | iteration); | |
| 156 | - for (int i = 0; i < columnsPerRow; ++i) | |
| 157 | - b.setBytes("c" + i, makeValue(valueSize)); | |
| 158 | - ++iteration; | |
| 159 | - return new QueryGenerator.Request.PreparedQuery(b); | |
| 160 | - } | |
| 161 | - }; | |
| 162 | - } | |
| 163 | - }; | |
| 164 | - | |
| 165 | - public static final QueryGenerator.Builder READER = new QueryGenerator.Builder() { | |
| 166 | - | |
| 167 | - @Override | |
| 168 | - public String name() { | |
| 169 | - return "read"; | |
| 170 | - } | |
| 171 | - | |
| 172 | - @Override | |
| 173 | - public OptionParser addOptions(OptionParser parser) { | |
| 174 | - String msg = "Read the rows inserted with the insert generator. Use prepared statements unless the --no-prepare option is used."; | |
| 175 | - parser.formatHelpWith(Stress.Help.formatFor(name(), msg)); | |
| 176 | - | |
| 177 | - parser.accepts("no-prepare", "Do no use prepared statement"); | |
| 178 | - return parser; | |
| 179 | - } | |
| 180 | - | |
| 181 | - @Override | |
| 182 | - public void prepare(OptionSet options, Session session) { | |
| 183 | - KeyspaceMetadata ks = session.getCluster().getMetadata().getKeyspace("stress"); | |
| 184 | - if (ks == null || ks.getTable("standard1") == null) { | |
| 185 | - System.err.println("There is nothing to reads, please run insert/insert_prepared first."); | |
| 186 | - System.exit(1); | |
| 187 | - } | |
| 188 | - | |
| 189 | - session.execute("USE stress"); | |
| 190 | - } | |
| 191 | - | |
| 192 | - @Override | |
| 193 | - public QueryGenerator create(int id, int iterations, OptionSet options, Session session) { | |
| 194 | - return options.has("no-prepare") | |
| 195 | - ? createRegular(id, iterations, session) | |
| 196 | - : createPrepared(id, iterations, session); | |
| 197 | - } | |
| 198 | - | |
| 199 | - public QueryGenerator createRegular(long id, int iterations, final Session session) { | |
| 200 | - final long prefix = (long) id << 32; | |
| 201 | - return new AbstractGenerator(iterations) { | |
| 202 | - @Override | |
| 203 | - public QueryGenerator.Request next() { | |
| 204 | - StringBuilder sb = new StringBuilder(); | |
| 205 | - sb.append("SELECT * FROM standard1 WHERE key = ").append(prefix | iteration); | |
| 206 | - ++iteration; | |
| 207 | - return new QueryGenerator.Request.SimpleQuery(new SimpleStatement(sb.toString())); | |
| 208 | - } | |
| 209 | - }; | |
| 210 | - } | |
| 211 | - | |
| 212 | - public QueryGenerator createPrepared(long id, int iterations, Session session) { | |
| 213 | - final long prefix = (long) id << 32; | |
| 214 | - final PreparedStatement stmt = session.prepare("SELECT * FROM standard1 WHERE key = ?"); | |
| 215 | - | |
| 216 | - return new AbstractGenerator(iterations) { | |
| 217 | - @Override | |
| 218 | - public QueryGenerator.Request next() { | |
| 219 | - BoundStatement bs = stmt.bind(); | |
| 220 | - bs.setLong("key", prefix | iteration); | |
| 221 | - ++iteration; | |
| 222 | - return new QueryGenerator.Request.PreparedQuery(bs); | |
| 223 | - } | |
| 224 | - }; | |
| 225 | - } | |
| 226 | - }; | |
| 227 | -} |
deleted driver-examples/stress/src/main/java/com/datastax/driver/stress/QueryGenerator.java +0 −92
| @@ -1,92 +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.stress; | |
| 17 | - | |
| 18 | -import com.datastax.driver.core.*; | |
| 19 | -import joptsimple.OptionParser; | |
| 20 | -import joptsimple.OptionSet; | |
| 21 | - | |
| 22 | -import java.util.Iterator; | |
| 23 | - | |
| 24 | -public abstract class QueryGenerator implements Iterator<QueryGenerator.Request> { | |
| 25 | - | |
| 26 | - protected final int iterations; | |
| 27 | - | |
| 28 | - protected QueryGenerator(int iterations) { | |
| 29 | - this.iterations = iterations; | |
| 30 | - } | |
| 31 | - | |
| 32 | - public abstract int currentIteration(); | |
| 33 | - | |
| 34 | - public int totalIterations() { | |
| 35 | - return iterations; | |
| 36 | - } | |
| 37 | - | |
| 38 | - public interface Builder { | |
| 39 | - public String name(); | |
| 40 | - | |
| 41 | - public OptionParser addOptions(OptionParser parser); | |
| 42 | - | |
| 43 | - public void prepare(OptionSet options, Session session); | |
| 44 | - | |
| 45 | - public QueryGenerator create(int id, int iterations, OptionSet options, Session session); | |
| 46 | - } | |
| 47 | - | |
| 48 | - public interface Request { | |
| 49 | - | |
| 50 | - public ResultSet execute(Session session); | |
| 51 | - | |
| 52 | - public ResultSetFuture executeAsync(Session session); | |
| 53 | - | |
| 54 | - public static class SimpleQuery implements Request { | |
| 55 | - | |
| 56 | - private final Statement statement; | |
| 57 | - | |
| 58 | - public SimpleQuery(Statement statement) { | |
| 59 | - this.statement = statement; | |
| 60 | - } | |
| 61 | - | |
| 62 | - @Override | |
| 63 | - public ResultSet execute(Session session) { | |
| 64 | - return session.execute(statement); | |
| 65 | - } | |
| 66 | - | |
| 67 | - @Override | |
| 68 | - public ResultSetFuture executeAsync(Session session) { | |
| 69 | - return session.executeAsync(statement); | |
| 70 | - } | |
| 71 | - } | |
| 72 | - | |
| 73 | - public static class PreparedQuery implements Request { | |
| 74 | - | |
| 75 | - private final BoundStatement query; | |
| 76 | - | |
| 77 | - public PreparedQuery(BoundStatement query) { | |
| 78 | - this.query = query; | |
| 79 | - } | |
| 80 | - | |
| 81 | - @Override | |
| 82 | - public ResultSet execute(Session session) { | |
| 83 | - return session.execute(query); | |
| 84 | - } | |
| 85 | - | |
| 86 | - @Override | |
| 87 | - public ResultSetFuture executeAsync(Session session) { | |
| 88 | - return session.executeAsync(query); | |
| 89 | - } | |
| 90 | - } | |
| 91 | - } | |
| 92 | -} |
deleted driver-examples/stress/src/main/java/com/datastax/driver/stress/Reporter.java +0 −281
| @@ -1,281 +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.stress; | |
| 17 | - | |
| 18 | -import com.yammer.metrics.Metrics; | |
| 19 | -import com.yammer.metrics.core.Meter; | |
| 20 | -import com.yammer.metrics.core.Timer; | |
| 21 | -import com.yammer.metrics.core.TimerContext; | |
| 22 | -import com.yammer.metrics.stats.Snapshot; | |
| 23 | - | |
| 24 | -import java.io.File; | |
| 25 | -import java.io.FileOutputStream; | |
| 26 | -import java.io.IOException; | |
| 27 | -import java.io.PrintStream; | |
| 28 | -import java.util.concurrent.Executors; | |
| 29 | -import java.util.concurrent.ScheduledExecutorService; | |
| 30 | -import java.util.concurrent.TimeUnit; | |
| 31 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 32 | - | |
| 33 | -public class Reporter implements Runnable { | |
| 34 | - | |
| 35 | - private Meter requests; | |
| 36 | - private Timer latencies; | |
| 37 | - | |
| 38 | - public Meter requestsMiddle; | |
| 39 | - public Timer latenciesMiddle; | |
| 40 | - | |
| 41 | - private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); | |
| 42 | - | |
| 43 | - private final File csvFile; | |
| 44 | - private final String header; | |
| 45 | - private final long period; | |
| 46 | - private final int consoleReportPeriod; | |
| 47 | - private final int iterations; | |
| 48 | - private final AtomicInteger requestsDone = new AtomicInteger(0); | |
| 49 | - | |
| 50 | - private final int middleLowBound; | |
| 51 | - private final int middleHighBound; | |
| 52 | - | |
| 53 | - private volatile double meanMiddleRate = -1.0; | |
| 54 | - | |
| 55 | - private long startTime; | |
| 56 | - private long lastOpCount; | |
| 57 | - | |
| 58 | - private PrintStream csv; | |
| 59 | - | |
| 60 | - private long lastConsoleOpCount; | |
| 61 | - private long lastConsoleTimestamp; | |
| 62 | - private int tickSinceLastConsoleReport; | |
| 63 | - | |
| 64 | - public Reporter(int consoleReportPeriod, String csvFileName, String[] args, int iterations) { | |
| 65 | - this(1, consoleReportPeriod, new File(csvFileName), formatHeader(args), iterations); | |
| 66 | - } | |
| 67 | - | |
| 68 | - private Reporter(int csvPeriod, int consolePeriod, File csvFile, String header, int iterations) { | |
| 69 | - this.period = csvPeriod; | |
| 70 | - this.consoleReportPeriod = consolePeriod / csvPeriod; | |
| 71 | - this.csvFile = csvFile; | |
| 72 | - this.header = header; | |
| 73 | - this.iterations = iterations; | |
| 74 | - | |
| 75 | - // Middle = exclude first and last 10% (note: if requests is -1, we'll end up with negative bounds, which will always exclude. It's fine if we never stop anyway) | |
| 76 | - this.middleLowBound = (int) (0.1 * iterations); | |
| 77 | - this.middleHighBound = (int) (0.9 * iterations); | |
| 78 | - } | |
| 79 | - | |
| 80 | - private static String formatHeader(String[] args) { | |
| 81 | - StringBuilder sb = new StringBuilder(); | |
| 82 | - sb.append("stress"); | |
| 83 | - for (String arg : args) | |
| 84 | - sb.append(' ').append(arg); | |
| 85 | - return sb.toString(); | |
| 86 | - } | |
| 87 | - | |
| 88 | - public void start() { | |
| 89 | - | |
| 90 | - this.requests = Metrics.newMeter(Reporter.class, "requests", "requests", TimeUnit.SECONDS); | |
| 91 | - this.latencies = Metrics.newTimer(Reporter.class, "latencies", TimeUnit.MILLISECONDS, TimeUnit.SECONDS); | |
| 92 | - this.startTime = System.currentTimeMillis(); | |
| 93 | - initConsole(); | |
| 94 | - initCSV(); | |
| 95 | - | |
| 96 | - this.executor.scheduleAtFixedRate(this, period, period, TimeUnit.SECONDS); | |
| 97 | - } | |
| 98 | - | |
| 99 | - public Context newRequest() { | |
| 100 | - int iteration = requestsDone.getAndIncrement(); | |
| 101 | - if (iteration >= middleLowBound) { | |
| 102 | - if (latenciesMiddle == null) { | |
| 103 | - synchronized (this) { | |
| 104 | - if (latenciesMiddle == null) { | |
| 105 | - latenciesMiddle = Metrics.newTimer(Reporter.class, "latencies_middle", TimeUnit.MILLISECONDS, TimeUnit.SECONDS); | |
| 106 | - requestsMiddle = Metrics.newMeter(Reporter.class, "requests_middle", "requests", TimeUnit.SECONDS); | |
| 107 | - } | |
| 108 | - } | |
| 109 | - } | |
| 110 | - if (iteration > middleHighBound) { | |
| 111 | - if (meanMiddleRate < 0) | |
| 112 | - meanMiddleRate = requestsMiddle.meanRate(); | |
| 113 | - | |
| 114 | - return new Context(this, latencies.time(), null); | |
| 115 | - } else { | |
| 116 | - return new Context(this, latencies.time(), latenciesMiddle.time()); | |
| 117 | - } | |
| 118 | - } else { | |
| 119 | - return new Context(this, latencies.time(), null); | |
| 120 | - } | |
| 121 | - } | |
| 122 | - | |
| 123 | - public void stop() { | |
| 124 | - executor.shutdown(); | |
| 125 | - | |
| 126 | - long tstamp = System.currentTimeMillis(); | |
| 127 | - long elapsed = TimeUnit.MILLISECONDS.toSeconds(tstamp - startTime); | |
| 128 | - Report lastReport = new Report(tstamp, elapsed, requests, latencies, lastOpCount); | |
| 129 | - | |
| 130 | - stopCSV(lastReport); | |
| 131 | - stopConsole(lastReport); | |
| 132 | - } | |
| 133 | - | |
| 134 | - @Override | |
| 135 | - public void run() { | |
| 136 | - report(); | |
| 137 | - } | |
| 138 | - | |
| 139 | - private void report() { | |
| 140 | - long tstamp = System.currentTimeMillis(); | |
| 141 | - long elapsed = TimeUnit.MILLISECONDS.toSeconds(tstamp - startTime); | |
| 142 | - | |
| 143 | - Report report = new Report(tstamp, elapsed, requests, latencies, lastOpCount); | |
| 144 | - lastOpCount = report.totalOps; | |
| 145 | - | |
| 146 | - reportToCSV(report); | |
| 147 | - reportToConsole(report); | |
| 148 | - } | |
| 149 | - | |
| 150 | - private void initCSV() { | |
| 151 | - if (csvFile.exists()) | |
| 152 | - if (!csvFile.delete()) | |
| 153 | - throw new RuntimeException("File " + csvFile + " already exists and cannot delete it"); | |
| 154 | - | |
| 155 | - try { | |
| 156 | - if (!csvFile.createNewFile()) | |
| 157 | - throw new RuntimeException("Unable to create report file " + csvFile); | |
| 158 | - | |
| 159 | - csv = new PrintStream(new FileOutputStream(csvFile)); | |
| 160 | - | |
| 161 | - csv.println("# " + header); | |
| 162 | - csv.println("# elapsed,total_ops,interval_rate,mean_rate,mean_latency,95th_latency,99th_latency,std_dev"); | |
| 163 | - | |
| 164 | - } catch (IOException e) { | |
| 165 | - throw new RuntimeException("Error creating report file " + csvFile, e); | |
| 166 | - } | |
| 167 | - } | |
| 168 | - | |
| 169 | - private void reportToCSV(Report report) { | |
| 170 | - csv.println(new StringBuilder() | |
| 171 | - .append(report.elapsed).append(',') | |
| 172 | - .append(report.totalOps).append(',') | |
| 173 | - .append(report.intervalRate).append(',') | |
| 174 | - .append(report.meanRate).append(',') | |
| 175 | - .append(report.meanLatency).append(',') | |
| 176 | - .append(report.latency95th).append(',') | |
| 177 | - .append(report.latency99th).append(',') | |
| 178 | - .append(report.stdDev)); | |
| 179 | - } | |
| 180 | - | |
| 181 | - private void stopCSV(Report lastReport) { | |
| 182 | - reportToCSV(lastReport); | |
| 183 | - } | |
| 184 | - | |
| 185 | - private void initConsole() { | |
| 186 | - this.lastConsoleTimestamp = startTime; | |
| 187 | - | |
| 188 | - System.out.println(" Time (s) | total ops | interval rate | mean rate | mean latency (ms) | 95th latency (ms) | 99th latency (ms) | std dev"); | |
| 189 | - System.out.println("--------------------------------------------------------------------------------------------------------------------------------"); | |
| 190 | - } | |
| 191 | - | |
| 192 | - private void reportToConsole(Report report) { | |
| 193 | - | |
| 194 | - if (++tickSinceLastConsoleReport < consoleReportPeriod) | |
| 195 | - return; | |
| 196 | - | |
| 197 | - printReportToConsole(report); | |
| 198 | - | |
| 199 | - tickSinceLastConsoleReport = 0; | |
| 200 | - lastConsoleTimestamp = report.timestamp; | |
| 201 | - lastConsoleOpCount = report.totalOps; | |
| 202 | - } | |
| 203 | - | |
| 204 | - private void printReportToConsole(Report report) { | |
| 205 | - long delay = report.timestamp - lastConsoleTimestamp; | |
| 206 | - double intervalRate = (((double) (report.totalOps - lastConsoleOpCount)) / delay) * 1000; | |
| 207 | - | |
| 208 | - String msg = String.format(" %8d | %12d | %13.2f | %12.2f | %17.3f | %17.3f | %17.3f | %9.3f", | |
| 209 | - report.elapsed, report.totalOps, intervalRate, report.meanRate, report.meanLatency, report.latency95th, report.latency99th, report.stdDev); | |
| 210 | - System.out.println(msg); | |
| 211 | - } | |
| 212 | - | |
| 213 | - private void stopConsole(Report lastReport) { | |
| 214 | - printReportToConsole(lastReport); | |
| 215 | - | |
| 216 | - if (latenciesMiddle == null) | |
| 217 | - return; | |
| 218 | - | |
| 219 | - Snapshot snapshot = latenciesMiddle.getSnapshot(); | |
| 220 | - | |
| 221 | - System.out.println(); | |
| 222 | - System.out.println("For the middle 80% of values:"); | |
| 223 | - System.out.println(String.format(" Mean rate (ops/sec): %10.1f", meanMiddleRate)); | |
| 224 | - System.out.println(String.format(" Mean latency (ms): %10.3f", latenciesMiddle.mean())); | |
| 225 | - System.out.println(String.format(" Median latency (ms): %10.3f", snapshot.getMedian())); | |
| 226 | - System.out.println(String.format(" 75th percentile latency (ms): %10.3f", snapshot.get75thPercentile())); | |
| 227 | - System.out.println(String.format(" 95th percentile latency (ms): %10.3f", snapshot.get95thPercentile())); | |
| 228 | - System.out.println(String.format(" 99th percentile latency (ms): %10.3f", snapshot.get99thPercentile())); | |
| 229 | - System.out.println(String.format(" Standard latency deviation: %10.3f", latenciesMiddle.stdDev())); | |
| 230 | - } | |
| 231 | - | |
| 232 | - private static class Report { | |
| 233 | - public final long timestamp; | |
| 234 | - public final long elapsed; | |
| 235 | - | |
| 236 | - public final long totalOps; | |
| 237 | - public final long intervalRate; | |
| 238 | - public final double meanRate; | |
| 239 | - | |
| 240 | - public final double meanLatency; | |
| 241 | - public final double latency95th; | |
| 242 | - public final double latency99th; | |
| 243 | - public final double stdDev; | |
| 244 | - | |
| 245 | - public Report(long timestamp, long elapsed, Meter meter, Timer timer, long lastOpCount) { | |
| 246 | - this.timestamp = timestamp; | |
| 247 | - this.elapsed = elapsed; | |
| 248 | - | |
| 249 | - this.totalOps = meter.count(); | |
| 250 | - this.intervalRate = totalOps - lastOpCount; | |
| 251 | - this.meanRate = meter.meanRate(); | |
| 252 | - | |
| 253 | - Snapshot snapshot = timer.getSnapshot(); | |
| 254 | - this.meanLatency = timer.mean(); | |
| 255 | - this.latency95th = snapshot.get95thPercentile(); | |
| 256 | - this.latency99th = snapshot.get99thPercentile(); | |
| 257 | - this.stdDev = timer.stdDev(); | |
| 258 | - } | |
| 259 | - } | |
| 260 | - | |
| 261 | - public static class Context { | |
| 262 | - private final Reporter reporter; | |
| 263 | - private final TimerContext context; | |
| 264 | - private final TimerContext contextMiddle; | |
| 265 | - | |
| 266 | - private Context(Reporter reporter, TimerContext context, TimerContext contextMiddle) { | |
| 267 | - this.reporter = reporter; | |
| 268 | - this.context = context; | |
| 269 | - this.contextMiddle = contextMiddle; | |
| 270 | - } | |
| 271 | - | |
| 272 | - public void done() { | |
| 273 | - context.stop(); | |
| 274 | - reporter.requests.mark(); | |
| 275 | - if (contextMiddle != null) { | |
| 276 | - contextMiddle.stop(); | |
| 277 | - reporter.requestsMiddle.mark(); | |
| 278 | - } | |
| 279 | - } | |
| 280 | - } | |
| 281 | -} |
deleted driver-examples/stress/src/main/java/com/datastax/driver/stress/Stress.java +0 −285
| @@ -1,285 +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.stress; | |
| 17 | - | |
| 18 | -import com.datastax.driver.core.*; | |
| 19 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 20 | -import joptsimple.*; | |
| 21 | -import org.apache.log4j.PropertyConfigurator; | |
| 22 | - | |
| 23 | -import java.io.IOException; | |
| 24 | -import java.util.HashMap; | |
| 25 | -import java.util.List; | |
| 26 | -import java.util.Map; | |
| 27 | - | |
| 28 | -/** | |
| 29 | - * A simple stress tool to demonstrate the use of the driver. | |
| 30 | - * <p/> | |
| 31 | - * Sample usage: | |
| 32 | - * stress insert -n 100000 | |
| 33 | - * stress read -n 10000 | |
| 34 | - */ | |
| 35 | -public class Stress { | |
| 36 | - | |
| 37 | - private static final Map<String, QueryGenerator.Builder> generators = new HashMap<String, QueryGenerator.Builder>(); | |
| 38 | - | |
| 39 | - static { | |
| 40 | - PropertyConfigurator.configure(System.getProperty("log4j.configuration", "./conf/log4j.properties")); | |
| 41 | - | |
| 42 | - QueryGenerator.Builder[] gs = new QueryGenerator.Builder[]{ | |
| 43 | - Generators.INSERTER, | |
| 44 | - Generators.READER | |
| 45 | - }; | |
| 46 | - | |
| 47 | - for (QueryGenerator.Builder b : gs) | |
| 48 | - register(b.name(), b); | |
| 49 | - } | |
| 50 | - | |
| 51 | - private static OptionParser defaultParser() { | |
| 52 | - OptionParser parser = new OptionParser() {{ | |
| 53 | - accepts("h", "Show this help message"); | |
| 54 | - accepts("n", "Number of requests to perform (default: unlimited)").withRequiredArg().ofType(Integer.class); | |
| 55 | - accepts("t", "Level of concurrency to use").withRequiredArg().ofType(Integer.class).defaultsTo(50); | |
| 56 | - accepts("async", "Make asynchronous requests instead of blocking ones"); | |
| 57 | - accepts("ip", "The hosts ip to connect to").withRequiredArg().ofType(String.class).defaultsTo("127.0.0.1"); | |
| 58 | - accepts("report-file", "The name of csv file to use for reporting results").withRequiredArg().ofType(String.class).defaultsTo("last.csv"); | |
| 59 | - accepts("print-delay", "The delay in seconds at which to report on the console").withRequiredArg().ofType(Integer.class).defaultsTo(5); | |
| 60 | - accepts("compression", "Use compression (SNAPPY)"); | |
| 61 | - accepts("connections-per-host", "The number of connections per hosts (default: based on the number of threads)").withRequiredArg().ofType(Integer.class); | |
| 62 | - accepts("consistency-level", "Consistency level").withRequiredArg().withValuesConvertedBy(new ConsistencyLevelConverter()) | |
| 63 | - .ofType(ConsistencyLevel.class).defaultsTo(ConsistencyLevel.LOCAL_ONE); | |
| 64 | - }}; | |
| 65 | - String msg = "Where <generator> can be one of " + generators.keySet() + '\n' | |
| 66 | - + "You can get more help on a particular generator with: stress <generator> -h"; | |
| 67 | - parser.formatHelpWith(Help.formatFor("<generator>", msg)); | |
| 68 | - return parser; | |
| 69 | - } | |
| 70 | - | |
| 71 | - public static void register(String name, QueryGenerator.Builder generator) { | |
| 72 | - if (generators.containsKey(name)) | |
| 73 | - throw new IllegalStateException("There is already a generator registered with the name " + name); | |
| 74 | - | |
| 75 | - generators.put(name, generator); | |
| 76 | - } | |
| 77 | - | |
| 78 | - private static class Stresser { | |
| 79 | - private final QueryGenerator.Builder genBuilder; | |
| 80 | - private final OptionParser parser; | |
| 81 | - private final OptionSet options; | |
| 82 | - | |
| 83 | - private Stresser(QueryGenerator.Builder genBuilder, OptionParser parser, OptionSet options) { | |
| 84 | - this.genBuilder = genBuilder; | |
| 85 | - this.parser = parser; | |
| 86 | - this.options = options; | |
| 87 | - } | |
| 88 | - | |
| 89 | - public static Stresser forCommandLineArguments(String[] args) { | |
| 90 | - OptionParser parser = defaultParser(); | |
| 91 | - | |
| 92 | - String generatorName = findPotentialGenerator(args); | |
| 93 | - if (generatorName == null) { | |
| 94 | - // Still parse the options to handle -h | |
| 95 | - OptionSet options = parseOptions(parser, args); | |
| 96 | - System.err.println("Missing generator, you need to provide a generator."); | |
| 97 | - printHelp(parser); | |
| 98 | - System.exit(1); | |
| 99 | - } | |
| 100 | - | |
| 101 | - if (!generators.containsKey(generatorName)) { | |
| 102 | - System.err.println(String.format("Unknown generator '%s'", generatorName)); | |
| 103 | - printHelp(parser); | |
| 104 | - System.exit(1); | |
| 105 | - } | |
| 106 | - | |
| 107 | - QueryGenerator.Builder genBuilder = generators.get(generatorName); | |
| 108 | - parser = genBuilder.addOptions(parser); | |
| 109 | - OptionSet options = parseOptions(parser, args); | |
| 110 | - | |
| 111 | - List<?> nonOpts = options.nonOptionArguments(); | |
| 112 | - if (nonOpts.size() > 1) { | |
| 113 | - System.err.println("Too many generators provided. Got " + nonOpts + " but only one generator supported."); | |
| 114 | - printHelp(parser); | |
| 115 | - System.exit(1); | |
| 116 | - } | |
| 117 | - | |
| 118 | - return new Stresser(genBuilder, parser, options); | |
| 119 | - } | |
| 120 | - | |
| 121 | - private static String findPotentialGenerator(String[] args) { | |
| 122 | - for (String arg : args) | |
| 123 | - if (!arg.startsWith("-")) | |
| 124 | - return arg; | |
| 125 | - | |
| 126 | - return null; | |
| 127 | - } | |
| 128 | - | |
| 129 | - private static OptionSet parseOptions(OptionParser parser, String[] args) { | |
| 130 | - try { | |
| 131 | - OptionSet options = parser.parse(args); | |
| 132 | - if (options.has("h")) { | |
| 133 | - printHelp(parser); | |
| 134 | - System.exit(0); | |
| 135 | - } | |
| 136 | - return options; | |
| 137 | - } catch (Exception e) { | |
| 138 | - System.err.println("Error parsing options: " + e.getMessage()); | |
| 139 | - printHelp(parser); | |
| 140 | - System.exit(1); | |
| 141 | - throw new AssertionError(); | |
| 142 | - } | |
| 143 | - } | |
| 144 | - | |
| 145 | - private static void printHelp(OptionParser parser) { | |
| 146 | - try { | |
| 147 | - parser.printHelpOn(System.out); | |
| 148 | - } catch (IOException e) { | |
| 149 | - throw new AssertionError(e); | |
| 150 | - } | |
| 151 | - } | |
| 152 | - | |
| 153 | - public OptionSet getOptions() { | |
| 154 | - return options; | |
| 155 | - } | |
| 156 | - | |
| 157 | - public void prepare(Session session) { | |
| 158 | - genBuilder.prepare(options, session); | |
| 159 | - } | |
| 160 | - | |
| 161 | - public QueryGenerator newGenerator(int id, Session session, int iterations) { | |
| 162 | - return genBuilder.create(id, iterations, options, session); | |
| 163 | - } | |
| 164 | - } | |
| 165 | - | |
| 166 | - public static class Help implements HelpFormatter { | |
| 167 | - | |
| 168 | - private final HelpFormatter defaultFormatter; | |
| 169 | - private final String generator; | |
| 170 | - private final String header; | |
| 171 | - | |
| 172 | - private Help(HelpFormatter defaultFormatter, String generator, String header) { | |
| 173 | - this.defaultFormatter = defaultFormatter; | |
| 174 | - this.generator = generator; | |
| 175 | - this.header = header; | |
| 176 | - } | |
| 177 | - | |
| 178 | - public static Help formatFor(String generator, String header) { | |
| 179 | - // It's a pain in the ass to get the real console width in JAVA so hardcode it. But it's the 21th | |
| 180 | - // century, we're not stuck at 80 characters anymore. | |
| 181 | - int width = 120; | |
| 182 | - return new Help(new BuiltinHelpFormatter(width, 4), generator, header); | |
| 183 | - } | |
| 184 | - | |
| 185 | - @Override | |
| 186 | - public String format(Map<String, ? extends OptionDescriptor> options) { | |
| 187 | - StringBuilder sb = new StringBuilder(); | |
| 188 | - | |
| 189 | - sb.append("Usage: stress ").append(generator).append(" [<option>]*").append("\n\n"); | |
| 190 | - sb.append(header).append("\n\n"); | |
| 191 | - sb.append(defaultFormatter.format(options)); | |
| 192 | - return sb.toString(); | |
| 193 | - } | |
| 194 | - } | |
| 195 | - | |
| 196 | - public static void main(String[] args) throws Exception { | |
| 197 | - | |
| 198 | - Stresser stresser = Stresser.forCommandLineArguments(args); | |
| 199 | - OptionSet options = stresser.getOptions(); | |
| 200 | - | |
| 201 | - int requests = options.has("n") ? (Integer) options.valueOf("n") : -1; | |
| 202 | - int concurrency = (Integer) options.valueOf("t"); | |
| 203 | - ConsistencyLevel consistencyLevel = (ConsistencyLevel) options.valueOf("consistency-level"); | |
| 204 | - | |
| 205 | - String reportFileName = (String) options.valueOf("report-file"); | |
| 206 | - | |
| 207 | - boolean async = options.has("async"); | |
| 208 | - | |
| 209 | - int iterations = (requests == -1 ? -1 : requests / concurrency); | |
| 210 | - | |
| 211 | - final int maxRequestsPerConnection = 128; | |
| 212 | - int maxConnections = options.has("connections-per-host") | |
| 213 | - ? (Integer) options.valueOf("connections-per-host") | |
| 214 | - : concurrency / maxRequestsPerConnection + 1; | |
| 215 | - | |
| 216 | - PoolingOptions pools = new PoolingOptions(); | |
| 217 | - pools.setNewConnectionThreshold(HostDistance.LOCAL, concurrency); | |
| 218 | - pools.setCoreConnectionsPerHost(HostDistance.LOCAL, maxConnections); | |
| 219 | - pools.setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnections); | |
| 220 | - pools.setCoreConnectionsPerHost(HostDistance.REMOTE, maxConnections); | |
| 221 | - pools.setMaxConnectionsPerHost(HostDistance.REMOTE, maxConnections); | |
| 222 | - | |
| 223 | - System.out.println("Initializing stress test:"); | |
| 224 | - System.out.println(" request count: " + (requests == -1 ? "unlimited" : requests)); | |
| 225 | - System.out.println(" concurrency: " + concurrency + " (" + iterations + " requests/thread)"); | |
| 226 | - System.out.println(" mode: " + (async ? "asynchronous" : "blocking")); | |
| 227 | - System.out.println(" per-host connections: " + maxConnections); | |
| 228 | - System.out.println(" compression: " + options.has("compression")); | |
| 229 | - System.out.println(" consistency-level: " + consistencyLevel.name()); | |
| 230 | - | |
| 231 | - try { | |
| 232 | - // Create session to hosts | |
| 233 | - Cluster cluster = new Cluster.Builder() | |
| 234 | - .addContactPoints(String.valueOf(options.valueOf("ip"))) | |
| 235 | - .withPoolingOptions(pools) | |
| 236 | - .withSocketOptions(new SocketOptions().setTcpNoDelay(true)) | |
| 237 | - .withQueryOptions(new QueryOptions().setConsistencyLevel(consistencyLevel)) | |
| 238 | - .build(); | |
| 239 | - | |
| 240 | - if (options.has("compression")) | |
| 241 | - cluster.getConfiguration().getProtocolOptions().setCompression(ProtocolOptions.Compression.SNAPPY); | |
| 242 | - | |
| 243 | - Session session = cluster.connect(); | |
| 244 | - | |
| 245 | - Metadata metadata = cluster.getMetadata(); | |
| 246 | - System.out.println(String.format("Connected to cluster '%s' on %s.", metadata.getClusterName(), metadata.getAllHosts())); | |
| 247 | - | |
| 248 | - System.out.println("Preparing test..."); | |
| 249 | - stresser.prepare(session); | |
| 250 | - | |
| 251 | - Reporter reporter = new Reporter((Integer) options.valueOf("print-delay"), reportFileName, args, requests); | |
| 252 | - | |
| 253 | - Consumer[] consumers = new Consumer[concurrency]; | |
| 254 | - for (int i = 0; i < concurrency; i++) { | |
| 255 | - QueryGenerator generator = stresser.newGenerator(i, session, iterations); | |
| 256 | - consumers[i] = async ? new AsynchronousConsumer(session, generator, reporter) : | |
| 257 | - new BlockingConsumer(session, generator, reporter); | |
| 258 | - } | |
| 259 | - | |
| 260 | - System.out.println("Starting to stress test..."); | |
| 261 | - System.out.println(); | |
| 262 | - | |
| 263 | - reporter.start(); | |
| 264 | - | |
| 265 | - for (Consumer consumer : consumers) | |
| 266 | - consumer.start(); | |
| 267 | - | |
| 268 | - for (Consumer consumer : consumers) | |
| 269 | - consumer.join(); | |
| 270 | - | |
| 271 | - reporter.stop(); | |
| 272 | - | |
| 273 | - System.out.println("Stress test successful."); | |
| 274 | - System.exit(0); | |
| 275 | - | |
| 276 | - } catch (NoHostAvailableException e) { | |
| 277 | - System.err.println("No alive hosts to use: " + e.getMessage()); | |
| 278 | - System.exit(1); | |
| 279 | - } catch (Exception e) { | |
| 280 | - System.err.println("Unexpected error: " + e.getMessage()); | |
| 281 | - e.printStackTrace(); | |
| 282 | - System.exit(1); | |
| 283 | - } | |
| 284 | - } | |
| 285 | -} |
added driver-tests/osgi/README.md +34 −0
| @@ -0,0 +1,34 @@ | ||
| 1 | +# OSGi Example | |
| 2 | + | |
| 3 | +A simple test for the Java Driver in an OSGi environment. | |
| 4 | + | |
| 5 | +`MailboxService` is an OSGi service that uses Cassandra to | |
| 6 | +store messages that can be retrieved by email address. | |
| 7 | + | |
| 8 | +## Usage | |
| 9 | + | |
| 10 | +To build the bundle and run tests, execute the following Maven goal: | |
| 11 | + | |
| 12 | + mvn verify -P short | |
| 13 | + | |
| 14 | +The "short" profile needs to be activated since the tests run under | |
| 15 | +this group. | |
| 16 | + | |
| 17 | +Note: tests will try to load the jars of 3 dependent modules: | |
| 18 | +`driver-core`, `driver-mapping` and `driver-extras`. | |
| 19 | +For this to succeed, you need to run `mvn package` | |
| 20 | +first for these modules and make sure the jars are present | |
| 21 | +in each module's `target/` subdirectory. | |
| 22 | + | |
| 23 | +Once `mvn verify` completes, the bundle jar will be present in the `target/` directory. | |
| 24 | + | |
| 25 | +The project includes integration tests that verify the service can | |
| 26 | +be activated and used in an OSGi container. It also verifies that | |
| 27 | +the Java driver can be used in an OSGi container in the following | |
| 28 | +configurations: | |
| 29 | + | |
| 30 | +1. Default (default classifier with all dependencies) | |
| 31 | +2. Netty-Shaded (shaded classifier with all depedencies w/o Netty) | |
| 32 | +5. Guava 17 | |
| 33 | +6. Guava 18 | |
| 34 | +7. Guava 19 |
added driver-tests/osgi/pom.xml +283 −0
| @@ -0,0 +1,283 @@ | ||
| 1 | +<!-- | |
| 2 | + | |
| 3 | + Copyright (C) 2012-2015 DataStax Inc. | |
| 4 | + | |
| 5 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | + you may not use this file except in compliance with the License. | |
| 7 | + You may obtain a copy of the License at | |
| 8 | + | |
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | + | |
| 11 | + Unless required by applicable law or agreed to in writing, software | |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | + See the License for the specific language governing permissions and | |
| 15 | + limitations under the License. | |
| 16 | + | |
| 17 | +--> | |
| 18 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| 20 | + <modelVersion>4.0.0</modelVersion> | |
| 21 | + <parent> | |
| 22 | + <groupId>com.datastax.cassandra</groupId> | |
| 23 | + <artifactId>cassandra-driver-tests-parent</artifactId> | |
| 24 | + <version>3.0.1-SNAPSHOT</version> | |
| 25 | + </parent> | |
| 26 | + | |
| 27 | + <artifactId>cassandra-driver-tests-osgi</artifactId> | |
| 28 | + <packaging>bundle</packaging> | |
| 29 | + <name>DataStax Java Driver for Apache Cassandra Tests - OSGi</name> | |
| 30 | + <description>A test for the DataStax Java Driver in an OSGi container.</description> | |
| 31 | + <url>https://github.com/datastax/java-driver</url> | |
| 32 | + | |
| 33 | + <properties> | |
| 34 | + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | |
| 35 | + <felix.version>4.6.0</felix.version> | |
| 36 | + <!-- more recent version require JDK7+ --> | |
| 37 | + <pax-exam.version>3.6.0</pax-exam.version> | |
| 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> | |
| 46 | + <main.basedir>${project.parent.parent.basedir}</main.basedir> | |
| 47 | + </properties> | |
| 48 | + | |
| 49 | + <dependencies> | |
| 50 | + | |
| 51 | + <dependency> | |
| 52 | + <groupId>com.datastax.cassandra</groupId> | |
| 53 | + <artifactId>cassandra-driver-core</artifactId> | |
| 54 | + <version>${project.parent.version}</version> | |
| 55 | + </dependency> | |
| 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 | + | |
| 69 | + <dependency> | |
| 70 | + <groupId>org.apache.felix</groupId> | |
| 71 | + <artifactId>org.apache.felix.framework</artifactId> | |
| 72 | + <version>${felix.version}</version> | |
| 73 | + </dependency> | |
| 74 | + | |
| 75 | + <dependency> | |
| 76 | + <groupId>com.datastax.cassandra</groupId> | |
| 77 | + <artifactId>cassandra-driver-core</artifactId> | |
| 78 | + <version>${project.parent.version}</version> | |
| 79 | + <type>test-jar</type> | |
| 80 | + <scope>test</scope> | |
| 81 | + </dependency> | |
| 82 | + | |
| 83 | + <dependency> | |
| 84 | + <groupId>org.ops4j.pax.exam</groupId> | |
| 85 | + <artifactId>pax-exam</artifactId> | |
| 86 | + <version>${pax-exam.version}</version> | |
| 87 | + <scope>test</scope> | |
| 88 | + </dependency> | |
| 89 | + | |
| 90 | + <dependency> | |
| 91 | + <groupId>org.ops4j.pax.exam</groupId> | |
| 92 | + <artifactId>pax-exam-testng</artifactId> | |
| 93 | + <version>${pax-exam.version}</version> | |
| 94 | + <scope>test</scope> | |
| 95 | + </dependency> | |
| 96 | + | |
| 97 | + <dependency> | |
| 98 | + <groupId>org.ops4j.pax.exam</groupId> | |
| 99 | + <artifactId>pax-exam-container-native</artifactId> | |
| 100 | + <version>${pax-exam.version}</version> | |
| 101 | + <scope>test</scope> | |
| 102 | + </dependency> | |
| 103 | + | |
| 104 | + <dependency> | |
| 105 | + <groupId>org.ops4j.pax.exam</groupId> | |
| 106 | + <artifactId>pax-exam-link-mvn</artifactId> | |
| 107 | + <version>${pax-exam.version}</version> | |
| 108 | + <scope>test</scope> | |
| 109 | + </dependency> | |
| 110 | + | |
| 111 | + <dependency> | |
| 112 | + <groupId>javax.transaction</groupId> | |
| 113 | + <artifactId>jta</artifactId> | |
| 114 | + <version>1.1</version> | |
| 115 | + <scope>test</scope> | |
| 116 | + </dependency> | |
| 117 | + | |
| 118 | + <dependency> | |
| 119 | + <groupId>com.jcabi</groupId> | |
| 120 | + <artifactId>jcabi-manifests</artifactId> | |
| 121 | + <version>1.1</version> | |
| 122 | + <scope>test</scope> | |
| 123 | + </dependency> | |
| 124 | + | |
| 125 | + <dependency> | |
| 126 | + <groupId>javax.servlet</groupId> | |
| 127 | + <artifactId>javax.servlet-api</artifactId> | |
| 128 | + <version>3.1.0</version> | |
| 129 | + <scope>test</scope> | |
| 130 | + </dependency> | |
| 131 | + | |
| 132 | + <dependency> | |
| 133 | + <groupId>javax.inject</groupId> | |
| 134 | + <artifactId>javax.inject</artifactId> | |
| 135 | + <version>1</version> | |
| 136 | + <scope>test</scope> | |
| 137 | + </dependency> | |
| 138 | + | |
| 139 | + <dependency> | |
| 140 | + <groupId>org.apache.commons</groupId> | |
| 141 | + <artifactId>commons-exec</artifactId> | |
| 142 | + <version>1.3</version> | |
| 143 | + <scope>test</scope> | |
| 144 | + </dependency> | |
| 145 | + | |
| 146 | + <dependency> | |
| 147 | + <groupId>ch.qos.logback</groupId> | |
| 148 | + <artifactId>logback-classic</artifactId> | |
| 149 | + <version>${logback.version}</version> | |
| 150 | + </dependency> | |
| 151 | + | |
| 152 | + <dependency> | |
| 153 | + <groupId>ch.qos.logback</groupId> | |
| 154 | + <artifactId>logback-core</artifactId> | |
| 155 | + <version>${logback.version}</version> | |
| 156 | + </dependency> | |
| 157 | + | |
| 158 | + </dependencies> | |
| 159 | + | |
| 160 | + <build> | |
| 161 | + | |
| 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 | + | |
| 182 | + <plugin> | |
| 183 | + <groupId>org.apache.maven.plugins</groupId> | |
| 184 | + <artifactId>maven-failsafe-plugin</artifactId> | |
| 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> | |
| 194 | + <executions> | |
| 195 | + <execution> | |
| 196 | + <id>default</id> | |
| 197 | + <goals> | |
| 198 | + <goal>integration-test</goal> | |
| 199 | + <goal>verify</goal> | |
| 200 | + </goals> | |
| 201 | + </execution> | |
| 202 | + </executions> | |
| 203 | + </plugin> | |
| 204 | + | |
| 205 | + <plugin> | |
| 206 | + <groupId>org.apache.felix</groupId> | |
| 207 | + <artifactId>maven-bundle-plugin</artifactId> | |
| 208 | + <extensions>true</extensions> | |
| 209 | + <version>2.4.0</version> | |
| 210 | + <configuration> | |
| 211 | + <instructions> | |
| 212 | + <Bundle-SymbolicName>com.datastax.driver.osgi</Bundle-SymbolicName> | |
| 213 | + <Bundle-Version>${project.version}</Bundle-Version> | |
| 214 | + <Export-Package>com.datastax.driver.osgi.api,!com.datastax.driver.osgi.impl</Export-Package> | |
| 215 | + <Bundle-Activator>com.datastax.driver.osgi.impl.Activator</Bundle-Activator> | |
| 216 | + <_include>-osgi.bnd</_include> | |
| 217 | + <Import-Package><![CDATA[com.google.common*;version="[16.0.1,20)",*]]></Import-Package> | |
| 218 | + </instructions> | |
| 219 | + <supportedProjectTypes> | |
| 220 | + <supportedProjectType>jar</supportedProjectType> | |
| 221 | + <supportedProjectType>bundle</supportedProjectType> | |
| 222 | + <supportedProjectType>pom</supportedProjectType> | |
| 223 | + </supportedProjectTypes> | |
| 224 | + </configuration> | |
| 225 | + <executions> | |
| 226 | + <execution> | |
| 227 | + <id>bundle-manifest</id> | |
| 228 | + <phase>compile</phase> | |
| 229 | + <goals> | |
| 230 | + <goal>manifest</goal> | |
| 231 | + </goals> | |
| 232 | + </execution> | |
| 233 | + </executions> | |
| 234 | + </plugin> | |
| 235 | + | |
| 236 | + </plugins> | |
| 237 | + | |
| 238 | + </build> | |
| 239 | + | |
| 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 | + | |
| 250 | + <profile> | |
| 251 | + <id>long</id> | |
| 252 | + <properties> | |
| 253 | + <test.groups>unit,short,long</test.groups> | |
| 254 | + <test.skip>false</test.skip> | |
| 255 | + </properties> | |
| 256 | + </profile> | |
| 257 | + | |
| 258 | + </profiles> | |
| 259 | + | |
| 260 | + <licenses> | |
| 261 | + <license> | |
| 262 | + <name>Apache 2</name> | |
| 263 | + <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | |
| 264 | + <distribution>repo</distribution> | |
| 265 | + <comments>Apache License Version 2.0</comments> | |
| 266 | + </license> | |
| 267 | + </licenses> | |
| 268 | + | |
| 269 | + <scm> | |
| 270 | + <connection>scm:git:git@github.com:datastax/java-driver.git</connection> | |
| 271 | + <developerConnection>scm:git:git@github.com:datastax/java-driver.git</developerConnection> | |
| 272 | + <url>https://github.com/datastax/java-driver</url> | |
| 273 | + <tag>HEAD</tag> | |
| 274 | + </scm> | |
| 275 | + | |
| 276 | + <developers> | |
| 277 | + <developer> | |
| 278 | + <name>Various</name> | |
| 279 | + <organization>DataStax</organization> | |
| 280 | + </developer> | |
| 281 | + </developers> | |
| 282 | +</project> | |
| 283 | + |
added driver-tests/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxException.java +23 −0
| @@ -0,0 +1,23 @@ | ||
| 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.api; | |
| 17 | + | |
| 18 | +public class MailboxException extends Exception { | |
| 19 | + | |
| 20 | + public MailboxException(Throwable cause) { | |
| 21 | + super("Failure interacting with Mailbox", cause); | |
| 22 | + } | |
| 23 | +} |
added driver-tests/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxMessage.java +106 −0
| @@ -0,0 +1,106 @@ | ||
| 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.api; | |
| 17 | + | |
| 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; | |
| 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) | |
| 32 | +public class MailboxMessage { | |
| 33 | + | |
| 34 | + public static final String TABLE = "mailbox"; | |
| 35 | + | |
| 36 | + @PartitionKey | |
| 37 | + private String recipient; | |
| 38 | + | |
| 39 | + @ClusteringColumn | |
| 40 | + @Column(name = "time", codec = SimpleTimestampCodec.class) | |
| 41 | + private long date; | |
| 42 | + | |
| 43 | + @Column | |
| 44 | + private String sender; | |
| 45 | + | |
| 46 | + @Column | |
| 47 | + private String body; | |
| 48 | + | |
| 49 | + public MailboxMessage() { | |
| 50 | + } | |
| 51 | + | |
| 52 | + public MailboxMessage(String recipient, long date, String sender, String body) { | |
| 53 | + this.recipient = recipient; | |
| 54 | + this.date = date; | |
| 55 | + this.sender = sender; | |
| 56 | + this.body = body; | |
| 57 | + } | |
| 58 | + | |
| 59 | + public String getRecipient() { | |
| 60 | + return recipient; | |
| 61 | + } | |
| 62 | + | |
| 63 | + public void setRecipient(String recipient) { | |
| 64 | + this.recipient = recipient; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public long getDate() { | |
| 68 | + return date; | |
| 69 | + } | |
| 70 | + | |
| 71 | + public void setDate(long date) { | |
| 72 | + this.date = date; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public String getSender() { | |
| 76 | + return sender; | |
| 77 | + } | |
| 78 | + | |
| 79 | + public void setSender(String sender) { | |
| 80 | + this.sender = sender; | |
| 81 | + } | |
| 82 | + | |
| 83 | + public String getBody() { | |
| 84 | + return body; | |
| 85 | + } | |
| 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 | + | |
| 102 | + @Override | |
| 103 | + public int hashCode() { | |
| 104 | + return Objects.hashCode(recipient, date, sender, body); | |
| 105 | + } | |
| 106 | +} |
added driver-tests/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxService.java +42 −0
| @@ -0,0 +1,42 @@ | ||
| 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.api; | |
| 17 | + | |
| 18 | +public interface MailboxService { | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * Retrieve all messages for a given recipient. | |
| 22 | + * | |
| 23 | + * @param recipient User whose mailbox is being read. | |
| 24 | + * @return All messages in the mailbox. | |
| 25 | + */ | |
| 26 | + public Iterable<MailboxMessage> getMessages(String recipient) throws MailboxException; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Stores the given message in the appropriate mailbox. | |
| 30 | + * | |
| 31 | + * @param message Message to send. | |
| 32 | + * @return The timestamp generated for the message (milliseconds since the Epoch). | |
| 33 | + */ | |
| 34 | + public long sendMessage(MailboxMessage message) throws MailboxException; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * Deletes all mail for the given recipient. | |
| 38 | + * | |
| 39 | + * @param recipient User whose mailbox will be cleared. | |
| 40 | + */ | |
| 41 | + public void clearMailbox(String recipient) throws MailboxException; | |
| 42 | +} |
added driver-tests/osgi/src/main/java/com/datastax/driver/osgi/impl/Activator.java +95 −0
| @@ -0,0 +1,95 @@ | ||
| 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.impl; | |
| 17 | + | |
| 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; | |
| 22 | +import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 23 | +import com.datastax.driver.extras.codecs.date.SimpleTimestampCodec; | |
| 24 | +import com.datastax.driver.osgi.api.MailboxService; | |
| 25 | +import org.osgi.framework.BundleActivator; | |
| 26 | +import org.osgi.framework.BundleContext; | |
| 27 | + | |
| 28 | +import java.util.Hashtable; | |
| 29 | + | |
| 30 | +import static com.datastax.driver.osgi.api.MailboxMessage.TABLE; | |
| 31 | + | |
| 32 | +public class Activator implements BundleActivator { | |
| 33 | + | |
| 34 | + private Cluster cluster; | |
| 35 | + | |
| 36 | + @Override | |
| 37 | + public void start(BundleContext context) throws Exception { | |
| 38 | + String contactPointsStr = context.getProperty("cassandra.contactpoints"); | |
| 39 | + if (contactPointsStr == null) { | |
| 40 | + contactPointsStr = "127.0.0.1"; | |
| 41 | + } | |
| 42 | + String[] contactPoints = contactPointsStr.split(","); | |
| 43 | + | |
| 44 | + String keyspace = context.getProperty("cassandra.keyspace"); | |
| 45 | + if (keyspace == null) { | |
| 46 | + keyspace = "mailbox"; | |
| 47 | + } | |
| 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 | + } | |
| 71 | + | |
| 72 | + MailboxImpl mailbox = new MailboxImpl(session, keyspace); | |
| 73 | + mailbox.init(); | |
| 74 | + | |
| 75 | + context.registerService(MailboxService.class.getName(), mailbox, new Hashtable<String, String>()); | |
| 76 | + } | |
| 77 | + | |
| 78 | + @Override | |
| 79 | + public void stop(BundleContext context) throws Exception { | |
| 80 | + if (cluster != null) { | |
| 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); | |
| 93 | + } | |
| 94 | + } | |
| 95 | +} |
added driver-tests/osgi/src/main/java/com/datastax/driver/osgi/impl/MailboxImpl.java +98 −0
| @@ -0,0 +1,98 @@ | ||
| 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.impl; | |
| 17 | + | |
| 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; | |
| 23 | +import com.datastax.driver.osgi.api.MailboxException; | |
| 24 | +import com.datastax.driver.osgi.api.MailboxMessage; | |
| 25 | +import com.datastax.driver.osgi.api.MailboxService; | |
| 26 | + | |
| 27 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 28 | +import static com.datastax.driver.osgi.api.MailboxMessage.TABLE; | |
| 29 | + | |
| 30 | +public class MailboxImpl implements MailboxService { | |
| 31 | + | |
| 32 | + private final Session session; | |
| 33 | + | |
| 34 | + private final String keyspace; | |
| 35 | + | |
| 36 | + private volatile boolean initialized = false; | |
| 37 | + | |
| 38 | + private PreparedStatement retrieveStatement; | |
| 39 | + | |
| 40 | + private PreparedStatement deleteStatement; | |
| 41 | + | |
| 42 | + private Mapper<MailboxMessage> mapper; | |
| 43 | + | |
| 44 | + public MailboxImpl(Session session, String keyspace) { | |
| 45 | + this.session = session; | |
| 46 | + this.keyspace = keyspace; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public synchronized void init() { | |
| 50 | + if (initialized) | |
| 51 | + return; | |
| 52 | + | |
| 53 | + retrieveStatement = session.prepare(select() | |
| 54 | + .from(keyspace, TABLE) | |
| 55 | + .where(eq("recipient", bindMarker()))); | |
| 56 | + | |
| 57 | + deleteStatement = session.prepare(delete().from(keyspace, TABLE) | |
| 58 | + .where(eq("recipient", bindMarker()))); | |
| 59 | + | |
| 60 | + MappingManager mappingManager = new MappingManager(session); | |
| 61 | + | |
| 62 | + mapper = mappingManager.mapper(MailboxMessage.class); | |
| 63 | + | |
| 64 | + initialized = true; | |
| 65 | + } | |
| 66 | + | |
| 67 | + @Override | |
| 68 | + public Iterable<MailboxMessage> getMessages(String recipient) throws MailboxException { | |
| 69 | + try { | |
| 70 | + BoundStatement statement = new BoundStatement(retrieveStatement); | |
| 71 | + statement.setString(0, recipient); | |
| 72 | + return mapper.map(session.execute(statement)); | |
| 73 | + } catch (Exception e) { | |
| 74 | + throw new MailboxException(e); | |
| 75 | + } | |
| 76 | + } | |
| 77 | + | |
| 78 | + @Override | |
| 79 | + public long sendMessage(MailboxMessage message) throws MailboxException { | |
| 80 | + try { | |
| 81 | + mapper.save(message); | |
| 82 | + return message.getDate(); | |
| 83 | + } catch (Exception e) { | |
| 84 | + throw new MailboxException(e); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + | |
| 88 | + @Override | |
| 89 | + public void clearMailbox(String recipient) throws MailboxException { | |
| 90 | + try { | |
| 91 | + BoundStatement statement = new BoundStatement(deleteStatement); | |
| 92 | + statement.setString(0, recipient); | |
| 93 | + session.execute(statement); | |
| 94 | + } catch (Exception e) { | |
| 95 | + throw new MailboxException(e); | |
| 96 | + } | |
| 97 | + } | |
| 98 | +} |
added driver-tests/osgi/src/test/java/com/datastax/driver/osgi/BundleOptions.java +93 −0
| @@ -0,0 +1,93 @@ | ||
| 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.TestUtils; | |
| 19 | +import org.ops4j.pax.exam.Option; | |
| 20 | +import org.ops4j.pax.exam.options.CompositeOption; | |
| 21 | +import org.ops4j.pax.exam.options.MavenArtifactProvisionOption; | |
| 22 | +import org.ops4j.pax.exam.options.UrlProvisionOption; | |
| 23 | +import org.ops4j.pax.exam.util.PathUtils; | |
| 24 | + | |
| 25 | +import static com.datastax.driver.osgi.VersionProvider.projectVersion; | |
| 26 | +import static org.ops4j.pax.exam.CoreOptions.*; | |
| 27 | + | |
| 28 | +public class BundleOptions { | |
| 29 | + | |
| 30 | + public static UrlProvisionOption driverBundle() { | |
| 31 | + return driverBundle(false); | |
| 32 | + } | |
| 33 | + | |
| 34 | + public static UrlProvisionOption driverBundle(boolean useShaded) { | |
| 35 | + String classifier = useShaded ? "-shaded" : ""; | |
| 36 | + return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-core/target/cassandra-driver-core-" + projectVersion() + classifier + ".jar"); | |
| 37 | + } | |
| 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 | + | |
| 47 | + public static MavenArtifactProvisionOption guavaBundle() { | |
| 48 | + return mavenBundle("com.google.guava", "guava", "16.0.1"); | |
| 49 | + } | |
| 50 | + | |
| 51 | + public static CompositeOption nettyBundles() { | |
| 52 | + final String nettyVersion = "4.0.33.Final"; | |
| 53 | + return new CompositeOption() { | |
| 54 | + | |
| 55 | + @Override | |
| 56 | + public Option[] getOptions() { | |
| 57 | + return options( | |
| 58 | + mavenBundle("io.netty", "netty-buffer", nettyVersion), | |
| 59 | + mavenBundle("io.netty", "netty-codec", nettyVersion), | |
| 60 | + mavenBundle("io.netty", "netty-common", nettyVersion), | |
| 61 | + mavenBundle("io.netty", "netty-handler", nettyVersion), | |
| 62 | + mavenBundle("io.netty", "netty-transport", nettyVersion) | |
| 63 | + ); | |
| 64 | + } | |
| 65 | + }; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public static UrlProvisionOption mailboxBundle() { | |
| 69 | + return bundle("reference:file:" + PathUtils.getBaseDir() + "/target/classes"); | |
| 70 | + } | |
| 71 | + | |
| 72 | + public static CompositeOption defaultOptions() { | |
| 73 | + return new CompositeOption() { | |
| 74 | + | |
| 75 | + @Override | |
| 76 | + public Option[] getOptions() { | |
| 77 | + return options( | |
| 78 | + // Delegate javax.security.cert to the parent classloader. javax.security.cert.X509Certificate is used in | |
| 79 | + // io.netty.util.internal.EmptyArrays, but not directly by the driver. | |
| 80 | + bootDelegationPackage("javax.security.cert"), | |
| 81 | + systemProperty("cassandra.contactpoints").value(TestUtils.IP_PREFIX + 1), | |
| 82 | + systemProperty("logback.configurationFile").value("file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"), | |
| 83 | + mavenBundle("org.slf4j", "slf4j-api", "1.7.5"), | |
| 84 | + mavenBundle("ch.qos.logback", "logback-classic", "1.1.3"), | |
| 85 | + mavenBundle("ch.qos.logback", "logback-core", "1.1.3"), | |
| 86 | + mavenBundle("io.dropwizard.metrics", "metrics-core", "3.1.2"), | |
| 87 | + systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation", | |
| 88 | + "org.junit.runner.notification", "com.jcabi.manifests") | |
| 89 | + ); | |
| 90 | + } | |
| 91 | + }; | |
| 92 | + } | |
| 93 | +} |
added driver-tests/osgi/src/test/java/com/datastax/driver/osgi/CCMBridgeListener.java +65 −0
| @@ -0,0 +1,65 @@ | ||
| 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.CCMBridge; | |
| 19 | +import org.testng.ITestContext; | |
| 20 | +import org.testng.ITestListener; | |
| 21 | +import org.testng.ITestResult; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * A listener that fires up a single node CCM instance on test class start and tears it | |
| 25 | + * down on test class end. | |
| 26 | + * <p/> | |
| 27 | + * This is needed for tests that use Pax-Exam since it runs some methods in the OSGi container | |
| 28 | + * which we do not want. | |
| 29 | + */ | |
| 30 | +public class CCMBridgeListener implements ITestListener { | |
| 31 | + | |
| 32 | + private CCMBridge ccm; | |
| 33 | + | |
| 34 | + @Override | |
| 35 | + public void onStart(ITestContext context) { | |
| 36 | + ccm = CCMBridge.builder().withNodes(1).withBinaryPort(9042).build(); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @Override | |
| 40 | + public void onFinish(ITestContext context) { | |
| 41 | + if (ccm != null) { | |
| 42 | + ccm.remove(); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public void onTestStart(ITestResult result) { | |
| 48 | + } | |
| 49 | + | |
| 50 | + @Override | |
| 51 | + public void onTestSuccess(ITestResult result) { | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + public void onTestFailure(ITestResult result) { | |
| 56 | + } | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + public void onTestSkipped(ITestResult result) { | |
| 60 | + } | |
| 61 | + | |
| 62 | + @Override | |
| 63 | + public void onTestFailedButWithinSuccessPercentage(ITestResult result) { | |
| 64 | + } | |
| 65 | +} |
added driver-tests/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-tests/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-tests/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-tests/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 | +} |
added driver-tests/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-tests/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 | +} |
added driver-tests/osgi/src/test/java/com/datastax/driver/osgi/VersionProvider.java +59 −0
| @@ -0,0 +1,59 @@ | ||
| 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 | +} |
added driver-tests/osgi/src/test/resources/exam.properties +18 −0
| @@ -0,0 +1,18 @@ | ||
| 1 | +# | |
| 2 | +# Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | +# | |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | +# you may not use this file except in compliance with the License. | |
| 6 | +# You may obtain a copy of the License at | |
| 7 | +# | |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | +# | |
| 10 | +# Unless required by applicable law or agreed to in writing, software | |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | +# See the License for the specific language governing permissions and | |
| 14 | +# limitations under the License. | |
| 15 | +# | |
| 16 | + | |
| 17 | +pax.exam.system=test | |
| 18 | +pax.exam.logging=none | |
| No newline at the end of the file |
added driver-tests/osgi/src/test/resources/logback.xml +50 −0
| @@ -0,0 +1,50 @@ | ||
| 1 | +<!-- | |
| 2 | + | |
| 3 | + Copyright (C) 2012-2015 DataStax Inc. | |
| 4 | + | |
| 5 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | + you may not use this file except in compliance with the License. | |
| 7 | + You may obtain a copy of the License at | |
| 8 | + | |
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | + | |
| 11 | + Unless required by applicable law or agreed to in writing, software | |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | + See the License for the specific language governing permissions and | |
| 15 | + limitations under the License. | |
| 16 | + | |
| 17 | +--> | |
| 18 | +<configuration> | |
| 19 | + | |
| 20 | + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | |
| 21 | + <encoder> | |
| 22 | + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | |
| 23 | + </encoder> | |
| 24 | + </appender> | |
| 25 | + | |
| 26 | + <root level="INFO"> | |
| 27 | + <appender-ref ref="STDOUT"/> | |
| 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 | + | |
| 50 | +</configuration> |
added driver-tests/pom.xml +83 −0
| @@ -0,0 +1,83 @@ | ||
| 1 | +<!-- | |
| 2 | + | |
| 3 | + Copyright (C) 2012-2015 DataStax Inc. | |
| 4 | + | |
| 5 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | + you may not use this file except in compliance with the License. | |
| 7 | + You may obtain a copy of the License at | |
| 8 | + | |
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | + | |
| 11 | + Unless required by applicable law or agreed to in writing, software | |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | + See the License for the specific language governing permissions and | |
| 15 | + limitations under the License. | |
| 16 | + | |
| 17 | +--> | |
| 18 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| 19 | + <modelVersion>4.0.0</modelVersion> | |
| 20 | + <parent> | |
| 21 | + <groupId>com.datastax.cassandra</groupId> | |
| 22 | + <artifactId>cassandra-driver-parent</artifactId> | |
| 23 | + <version>3.0.1-SNAPSHOT</version> | |
| 24 | + </parent> | |
| 25 | + <artifactId>cassandra-driver-tests-parent</artifactId> | |
| 26 | + <packaging>pom</packaging> | |
| 27 | + <name>DataStax Java Driver for Apache Cassandra Tests</name> | |
| 28 | + <description>Tests for the DataStax Java Driver for Apache Cassandra.</description> | |
| 29 | + <url>https://github.com/datastax/java-driver</url> | |
| 30 | + | |
| 31 | + <properties> | |
| 32 | + <main.basedir>${project.parent.basedir}</main.basedir> | |
| 33 | + </properties> | |
| 34 | + | |
| 35 | + <modules> | |
| 36 | + <module>stress</module> | |
| 37 | + <module>osgi</module> | |
| 38 | + </modules> | |
| 39 | + | |
| 40 | + <licenses> | |
| 41 | + <license> | |
| 42 | + <name>Apache 2</name> | |
| 43 | + <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | |
| 44 | + <distribution>repo</distribution> | |
| 45 | + <comments>Apache License Version 2.0</comments> | |
| 46 | + </license> | |
| 47 | + </licenses> | |
| 48 | + | |
| 49 | + <scm> | |
| 50 | + <connection>scm:git:git@github.com:datastax/java-driver.git</connection> | |
| 51 | + <developerConnection>scm:git:git@github.com:datastax/java-driver.git</developerConnection> | |
| 52 | + <url>https://github.com/datastax/java-driver</url> | |
| 53 | + <tag>HEAD</tag> | |
| 54 | + </scm> | |
| 55 | + | |
| 56 | + <developers> | |
| 57 | + <developer> | |
| 58 | + <name>Various</name> | |
| 59 | + <organization>DataStax</organization> | |
| 60 | + </developer> | |
| 61 | + </developers> | |
| 62 | + | |
| 63 | + <build> | |
| 64 | + <plugins> | |
| 65 | + <plugin> | |
| 66 | + <groupId>org.apache.maven.plugins</groupId> | |
| 67 | + <artifactId>maven-install-plugin</artifactId> | |
| 68 | + <version>2.5.1</version> | |
| 69 | + <configuration> | |
| 70 | + <skip>true</skip> | |
| 71 | + </configuration> | |
| 72 | + </plugin> | |
| 73 | + <plugin> | |
| 74 | + <groupId>org.apache.maven.plugins</groupId> | |
| 75 | + <artifactId>maven-deploy-plugin</artifactId> | |
| 76 | + <version>2.8.1</version> | |
| 77 | + <configuration> | |
| 78 | + <skip>true</skip> | |
| 79 | + </configuration> | |
| 80 | + </plugin> | |
| 81 | + </plugins> | |
| 82 | + </build> | |
| 83 | +</project> |
added driver-tests/stress/README.md +25 −0
| @@ -0,0 +1,25 @@ | ||
| 1 | +# Stress application | |
| 2 | + | |
| 3 | +A simple example application that uses the Java driver to stress test | |
| 4 | +Cassandra. This also somewhat stress tests the Java driver as a result. | |
| 5 | + | |
| 6 | +Please note that this simple example is far from being a complete stress | |
| 7 | +application. In particular it currently supports a very limited number of | |
| 8 | +stress scenarios. | |
| 9 | + | |
| 10 | +## Usage | |
| 11 | + | |
| 12 | +You will need to build the stress application fist: | |
| 13 | + | |
| 14 | + ./bin/build | |
| 15 | + | |
| 16 | +After which you can run it using for instance: | |
| 17 | + | |
| 18 | + ./bin/stress insert_prepared | |
| 19 | + | |
| 20 | +Of course, you will need to have at least one Cassandra node running (on | |
| 21 | +127.0.0.1 by default) for this to work. Please refer to: | |
| 22 | + | |
| 23 | + ./bin/stress -h | |
| 24 | + | |
| 25 | +for more details on the options available. |
added driver-tests/stress/bin/build +36 −0
| @@ -0,0 +1,36 @@ | ||
| 1 | +#!/bin/sh | |
| 2 | + | |
| 3 | +SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd ) | |
| 4 | +CURRENT_DIR=$( pwd ) | |
| 5 | + | |
| 6 | +LOG_FILE="$CURRENT_DIR/stress_build.log" | |
| 7 | +[ -f $LOG_FILE ] && rm $LOG_FILE | |
| 8 | + | |
| 9 | +echo "Building java driver ..." | |
| 10 | +echo "-- Driver build --\n" > $LOG_FILE | |
| 11 | + | |
| 12 | +cd $SCRIPT_DIR/../../.. | |
| 13 | +mvn clean install -Dmaven.test.skip=true >> $LOG_FILE 2>&1 | |
| 14 | +EXIT_CODE=$? | |
| 15 | +if [ $EXIT_CODE -ne 0 ]; | |
| 16 | +then | |
| 17 | + echo "Error building driver. See $LOG_FILE for details." 1>&2 | |
| 18 | + cd $CURRENT_DIR | |
| 19 | + exit $EXIT_CODE | |
| 20 | +fi | |
| 21 | + | |
| 22 | +echo "Building stress application ..." | |
| 23 | +echo "\n-- Stress build --\n" >> $LOG_FILE | |
| 24 | + | |
| 25 | +cd $SCRIPT_DIR/.. | |
| 26 | +mvn package assembly:single >> $LOG_FILE 2>&1 | |
| 27 | +EXIT_CODE=$? | |
| 28 | +if [ $EXIT_CODE -ne 0 ]; | |
| 29 | +then | |
| 30 | + echo "Error building stress application. See $LOG_FILE for details." 1>&2 | |
| 31 | + cd $CURRENT_DIR | |
| 32 | + exit $EXIT_CODE | |
| 33 | +fi | |
| 34 | + | |
| 35 | +cd $CURRENT_DIR | |
| 36 | +rm $LOG_FILE |
added driver-tests/stress/bin/stress +30 −0
| @@ -0,0 +1,30 @@ | ||
| 1 | +#!/bin/sh | |
| 2 | + | |
| 3 | +SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd ) | |
| 4 | +CURRENT_DIR=$( pwd ) | |
| 5 | + | |
| 6 | +# Use $JAVA_HOME if set | |
| 7 | +if [ -n "$JAVA_HOME" ]; then | |
| 8 | + JAVA="$JAVA_HOME/bin/java" | |
| 9 | +else | |
| 10 | + JAVA=java | |
| 11 | +fi | |
| 12 | + | |
| 13 | +if [ "x$STRESS_JAR" = "x" ]; then | |
| 14 | + | |
| 15 | + STRESS_JAR="$SCRIPT_DIR/../target/cassandra-driver-tests-stress-*-jar-with-dependencies.jar" | |
| 16 | + | |
| 17 | + if [ ! -f $STRESS_JAR ]; then | |
| 18 | + # Trash the version file in case there was some crap in it | |
| 19 | + RELATIVE_SCRIPT_DIR=`dirname $0` | |
| 20 | + echo "Stress application does not seem to be build, try $RELATIVE_SCRIPT_DIR/build first" 1>&2 | |
| 21 | + exit 1 | |
| 22 | + fi | |
| 23 | +else | |
| 24 | + if [ ! -f $STRESS_JAR ]; then | |
| 25 | + echo "Cannot find file $STRESS_JAR" 1>&2 | |
| 26 | + exit 1 | |
| 27 | + fi | |
| 28 | +fi | |
| 29 | + | |
| 30 | +"$JAVA" -Dlog4j.configuration="$SCRIPT_DIR/../conf/log4j.properties" -jar $STRESS_JAR $@ |
added driver-tests/stress/pom.xml +109 −0
| @@ -0,0 +1,109 @@ | ||
| 1 | +<!-- | |
| 2 | + | |
| 3 | + Copyright (C) 2012-2015 DataStax Inc. | |
| 4 | + | |
| 5 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | + you may not use this file except in compliance with the License. | |
| 7 | + You may obtain a copy of the License at | |
| 8 | + | |
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | + | |
| 11 | + Unless required by applicable law or agreed to in writing, software | |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | + See the License for the specific language governing permissions and | |
| 15 | + limitations under the License. | |
| 16 | + | |
| 17 | +--> | |
| 18 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| 19 | + <modelVersion>4.0.0</modelVersion> | |
| 20 | + <parent> | |
| 21 | + <groupId>com.datastax.cassandra</groupId> | |
| 22 | + <artifactId>cassandra-driver-tests-parent</artifactId> | |
| 23 | + <version>3.0.1-SNAPSHOT</version> | |
| 24 | + </parent> | |
| 25 | + <artifactId>cassandra-driver-tests-stress</artifactId> | |
| 26 | + <packaging>jar</packaging> | |
| 27 | + <name>DataStax Java Driver for Apache Cassandra Tests - Stress</name> | |
| 28 | + <description>A stress test example for DataStax Java Driver for Apache Cassandra.</description> | |
| 29 | + <url>https://github.com/datastax/java-driver</url> | |
| 30 | + | |
| 31 | + <properties> | |
| 32 | + <main.basedir>${project.parent.parent.basedir}</main.basedir> | |
| 33 | + </properties> | |
| 34 | + | |
| 35 | + <dependencies> | |
| 36 | + <dependency> | |
| 37 | + <groupId>com.datastax.cassandra</groupId> | |
| 38 | + <artifactId>cassandra-driver-core</artifactId> | |
| 39 | + <version>3.0.1-SNAPSHOT</version> | |
| 40 | + </dependency> | |
| 41 | + | |
| 42 | + <dependency> | |
| 43 | + <groupId>com.yammer.metrics</groupId> | |
| 44 | + <artifactId>metrics-core</artifactId> | |
| 45 | + <version>2.2.0</version> | |
| 46 | + </dependency> | |
| 47 | + | |
| 48 | + <dependency> | |
| 49 | + <groupId>net.sf.jopt-simple</groupId> | |
| 50 | + <artifactId>jopt-simple</artifactId> | |
| 51 | + <version>4.5</version> | |
| 52 | + </dependency> | |
| 53 | + | |
| 54 | + <dependency> | |
| 55 | + <groupId>log4j</groupId> | |
| 56 | + <artifactId>log4j</artifactId> | |
| 57 | + <version>1.2.17</version> | |
| 58 | + </dependency> | |
| 59 | + | |
| 60 | + <dependency> | |
| 61 | + <groupId>org.slf4j</groupId> | |
| 62 | + <artifactId>slf4j-log4j12</artifactId> | |
| 63 | + <version>1.7.5</version> | |
| 64 | + </dependency> | |
| 65 | + </dependencies> | |
| 66 | + | |
| 67 | + <build> | |
| 68 | + <plugins> | |
| 69 | + <plugin> | |
| 70 | + <artifactId>maven-assembly-plugin</artifactId> | |
| 71 | + <version>2.4</version> | |
| 72 | + <configuration> | |
| 73 | + <archive> | |
| 74 | + <manifest> | |
| 75 | + <mainClass>com.datastax.driver.stress.Stress</mainClass> | |
| 76 | + </manifest> | |
| 77 | + </archive> | |
| 78 | + <descriptorRefs> | |
| 79 | + <descriptorRef>jar-with-dependencies</descriptorRef> | |
| 80 | + </descriptorRefs> | |
| 81 | + </configuration> | |
| 82 | + </plugin> | |
| 83 | + </plugins> | |
| 84 | + </build> | |
| 85 | + | |
| 86 | + <licenses> | |
| 87 | + <license> | |
| 88 | + <name>Apache 2</name> | |
| 89 | + <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | |
| 90 | + <distribution>repo</distribution> | |
| 91 | + <comments>Apache License Version 2.0</comments> | |
| 92 | + </license> | |
| 93 | + </licenses> | |
| 94 | + | |
| 95 | + <scm> | |
| 96 | + <connection>scm:git:git@github.com:datastax/java-driver.git</connection> | |
| 97 | + <developerConnection>scm:git:git@github.com:datastax/java-driver.git</developerConnection> | |
| 98 | + <url>https://github.com/datastax/java-driver</url> | |
| 99 | + <tag>HEAD</tag> | |
| 100 | + </scm> | |
| 101 | + | |
| 102 | + <developers> | |
| 103 | + <developer> | |
| 104 | + <name>Various</name> | |
| 105 | + <organization>DataStax</organization> | |
| 106 | + </developer> | |
| 107 | + </developers> | |
| 108 | +</project> | |
| 109 | + |
added driver-tests/stress/src/main/java/com/datastax/driver/stress/AsynchronousConsumer.java +98 −0
| @@ -0,0 +1,98 @@ | ||
| 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.stress; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.ResultSet; | |
| 19 | +import com.datastax.driver.core.ResultSetFuture; | |
| 20 | +import com.datastax.driver.core.Session; | |
| 21 | +import com.google.common.util.concurrent.FutureCallback; | |
| 22 | +import com.google.common.util.concurrent.Futures; | |
| 23 | + | |
| 24 | +import java.util.concurrent.CountDownLatch; | |
| 25 | +import java.util.concurrent.ExecutorService; | |
| 26 | +import java.util.concurrent.Executors; | |
| 27 | + | |
| 28 | +import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; | |
| 29 | + | |
| 30 | +public class AsynchronousConsumer implements Consumer { | |
| 31 | + | |
| 32 | + private static final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); | |
| 33 | + | |
| 34 | + private final CountDownLatch shutdownLatch = new CountDownLatch(1); | |
| 35 | + | |
| 36 | + private final Session session; | |
| 37 | + private final QueryGenerator requests; | |
| 38 | + private final Reporter reporter; | |
| 39 | + | |
| 40 | + public AsynchronousConsumer(Session session, | |
| 41 | + QueryGenerator requests, | |
| 42 | + Reporter reporter) { | |
| 43 | + this.session = session; | |
| 44 | + this.requests = requests; | |
| 45 | + this.reporter = reporter; | |
| 46 | + } | |
| 47 | + | |
| 48 | + @Override | |
| 49 | + public void start() { | |
| 50 | + executorService.execute(new Runnable() { | |
| 51 | + @Override | |
| 52 | + public void run() { | |
| 53 | + request(); | |
| 54 | + } | |
| 55 | + }); | |
| 56 | + } | |
| 57 | + | |
| 58 | + private void request() { | |
| 59 | + | |
| 60 | + if (!requests.hasNext()) { | |
| 61 | + shutdown(); | |
| 62 | + return; | |
| 63 | + } | |
| 64 | + | |
| 65 | + handle(requests.next()); | |
| 66 | + } | |
| 67 | + | |
| 68 | + @Override | |
| 69 | + public void join() { | |
| 70 | + awaitUninterruptibly(shutdownLatch); | |
| 71 | + } | |
| 72 | + | |
| 73 | + protected void handle(QueryGenerator.Request request) { | |
| 74 | + | |
| 75 | + final Reporter.Context ctx = reporter.newRequest(); | |
| 76 | + | |
| 77 | + ResultSetFuture resultSetFuture = request.executeAsync(session); | |
| 78 | + Futures.addCallback(resultSetFuture, new FutureCallback<ResultSet>() { | |
| 79 | + @Override | |
| 80 | + public void onSuccess(final ResultSet result) { | |
| 81 | + ctx.done(); | |
| 82 | + request(); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Override | |
| 86 | + public void onFailure(final Throwable t) { | |
| 87 | + // Could do better I suppose | |
| 88 | + System.err.println("Error during request: " + t); | |
| 89 | + ctx.done(); | |
| 90 | + request(); | |
| 91 | + } | |
| 92 | + }, executorService); | |
| 93 | + } | |
| 94 | + | |
| 95 | + protected void shutdown() { | |
| 96 | + shutdownLatch.countDown(); | |
| 97 | + } | |
| 98 | +} |
added driver-tests/stress/src/main/java/com/datastax/driver/stress/BlockingConsumer.java +74 −0
| @@ -0,0 +1,74 @@ | ||
| 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.stress; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.Session; | |
| 19 | +import com.datastax.driver.core.exceptions.DriverException; | |
| 20 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 21 | + | |
| 22 | +public class BlockingConsumer implements Consumer { | |
| 23 | + | |
| 24 | + private final Runner runner = new Runner(); | |
| 25 | + | |
| 26 | + private final Session session; | |
| 27 | + private final QueryGenerator requests; | |
| 28 | + private final Reporter reporter; | |
| 29 | + | |
| 30 | + public BlockingConsumer(Session session, | |
| 31 | + QueryGenerator requests, | |
| 32 | + Reporter reporter) { | |
| 33 | + this.session = session; | |
| 34 | + this.requests = requests; | |
| 35 | + this.reporter = reporter; | |
| 36 | + this.runner.setDaemon(true); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @Override | |
| 40 | + public void start() { | |
| 41 | + this.runner.start(); | |
| 42 | + } | |
| 43 | + | |
| 44 | + @Override | |
| 45 | + public void join() { | |
| 46 | + Uninterruptibles.joinUninterruptibly(this.runner); | |
| 47 | + } | |
| 48 | + | |
| 49 | + private class Runner extends Thread { | |
| 50 | + | |
| 51 | + public Runner() { | |
| 52 | + super("Consumer Threads"); | |
| 53 | + } | |
| 54 | + | |
| 55 | + @Override | |
| 56 | + public void run() { | |
| 57 | + try { | |
| 58 | + while (requests.hasNext()) | |
| 59 | + handle(requests.next()); | |
| 60 | + } catch (DriverException e) { | |
| 61 | + System.err.println("Error during query: " + e.getMessage()); | |
| 62 | + } | |
| 63 | + } | |
| 64 | + | |
| 65 | + protected void handle(QueryGenerator.Request request) { | |
| 66 | + Reporter.Context ctx = reporter.newRequest(); | |
| 67 | + try { | |
| 68 | + request.execute(session); | |
| 69 | + } finally { | |
| 70 | + ctx.done(); | |
| 71 | + } | |
| 72 | + } | |
| 73 | + } | |
| 74 | +} |
added driver-tests/stress/src/main/java/com/datastax/driver/stress/ConsistencyLevelConverter.java +45 −0
| @@ -0,0 +1,45 @@ | ||
| 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.stress; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.ConsistencyLevel; | |
| 19 | +import joptsimple.ValueConverter; | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * Created by Alram.Lechner on 03.03.2016. | |
| 23 | + */ | |
| 24 | +public class ConsistencyLevelConverter implements ValueConverter<ConsistencyLevel> { | |
| 25 | + | |
| 26 | + @Override | |
| 27 | + public ConsistencyLevel convert(String value) { | |
| 28 | + return ConsistencyLevel.valueOf(value); | |
| 29 | + } | |
| 30 | + | |
| 31 | + @Override | |
| 32 | + public Class<ConsistencyLevel> valueType() { | |
| 33 | + return ConsistencyLevel.class; | |
| 34 | + } | |
| 35 | + | |
| 36 | + @Override | |
| 37 | + public String valuePattern() { | |
| 38 | + StringBuilder pattern = new StringBuilder(); | |
| 39 | + for (ConsistencyLevel level : ConsistencyLevel.values()) { | |
| 40 | + pattern.append("(").append(level.name()).append(")|"); | |
| 41 | + } | |
| 42 | + pattern.setLength(pattern.length() - 1); | |
| 43 | + return pattern.toString(); | |
| 44 | + } | |
| 45 | +} |
added driver-tests/stress/src/main/java/com/datastax/driver/stress/Consumer.java +23 −0
| @@ -0,0 +1,23 @@ | ||
| 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.stress; | |
| 17 | + | |
| 18 | +public interface Consumer { | |
| 19 | + | |
| 20 | + public void start(); | |
| 21 | + | |
| 22 | + public void join(); | |
| 23 | +} |
added driver-tests/stress/src/main/java/com/datastax/driver/stress/Generators.java +227 −0
| @@ -0,0 +1,227 @@ | ||
| 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.stress; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.QueryValidationException; | |
| 20 | +import com.datastax.driver.core.utils.Bytes; | |
| 21 | +import joptsimple.OptionParser; | |
| 22 | +import joptsimple.OptionSet; | |
| 23 | + | |
| 24 | +import java.nio.ByteBuffer; | |
| 25 | +import java.util.Random; | |
| 26 | + | |
| 27 | +public class Generators { | |
| 28 | + private static ThreadLocal<Random> random = new ThreadLocal<Random>() { | |
| 29 | + @Override | |
| 30 | + protected Random initialValue() { | |
| 31 | + return new Random(); | |
| 32 | + } | |
| 33 | + }; | |
| 34 | + | |
| 35 | + private static ByteBuffer makeValue(final int valueSize) { | |
| 36 | + byte[] value = new byte[valueSize]; | |
| 37 | + random.get().nextBytes(value); | |
| 38 | + return ByteBuffer.wrap(value); | |
| 39 | + } | |
| 40 | + | |
| 41 | + private static abstract class AbstractGenerator extends QueryGenerator { | |
| 42 | + protected int iteration; | |
| 43 | + | |
| 44 | + protected AbstractGenerator(int iterations) { | |
| 45 | + super(iterations); | |
| 46 | + } | |
| 47 | + | |
| 48 | + @Override | |
| 49 | + public int currentIteration() { | |
| 50 | + return iteration; | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Override | |
| 54 | + public boolean hasNext() { | |
| 55 | + return iterations == -1 || iteration < iterations; | |
| 56 | + } | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + public void remove() { | |
| 60 | + throw new UnsupportedOperationException(); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + public static final QueryGenerator.Builder INSERTER = new QueryGenerator.Builder() { | |
| 65 | + | |
| 66 | + @Override | |
| 67 | + public String name() { | |
| 68 | + return "insert"; | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public OptionParser addOptions(OptionParser parser) { | |
| 73 | + String msg = "Simple insertion of CQL3 rows (using prepared statements unless the --no-prepare option is used). " | |
| 74 | + + "The inserted rows have a fixed set of columns but no clustering columns."; | |
| 75 | + parser.formatHelpWith(Stress.Help.formatFor(name(), msg)); | |
| 76 | + | |
| 77 | + parser.accepts("no-prepare", "Do no use prepared statement"); | |
| 78 | + parser.accepts("columns-per-row", "Number of columns per CQL3 row").withRequiredArg().ofType(Integer.class).defaultsTo(5); | |
| 79 | + parser.accepts("value-size", "The size in bytes for column values").withRequiredArg().ofType(Integer.class).defaultsTo(34); | |
| 80 | + parser.accepts("with-compact-storage", "Use COMPACT STORAGE on the table used"); | |
| 81 | + return parser; | |
| 82 | + } | |
| 83 | + | |
| 84 | + @Override | |
| 85 | + public void prepare(OptionSet options, Session session) { | |
| 86 | + | |
| 87 | + try { | |
| 88 | + session.execute("DROP KEYSPACE stress;"); | |
| 89 | + } catch (QueryValidationException e) { /* Fine, ignore */ } | |
| 90 | + | |
| 91 | + session.execute("CREATE KEYSPACE stress WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }"); | |
| 92 | + | |
| 93 | + session.execute("USE stress"); | |
| 94 | + | |
| 95 | + StringBuilder sb = new StringBuilder(); | |
| 96 | + sb.append("CREATE TABLE standard1 (key bigint PRIMARY KEY"); | |
| 97 | + for (int i = 0; i < (Integer) options.valueOf("columns-per-row"); ++i) | |
| 98 | + sb.append(", C").append(i).append(" blob"); | |
| 99 | + sb.append(')'); | |
| 100 | + | |
| 101 | + if (options.has("with-compact-storage")) | |
| 102 | + sb.append(" WITH COMPACT STORAGE"); | |
| 103 | + | |
| 104 | + session.execute(sb.toString()); | |
| 105 | + } | |
| 106 | + | |
| 107 | + @Override | |
| 108 | + public QueryGenerator create(int id, int iterations, OptionSet options, Session session) { | |
| 109 | + | |
| 110 | + return options.has("no-prepare") | |
| 111 | + ? createRegular(id, iterations, options, session) | |
| 112 | + : createPrepared(id, iterations, options, session); | |
| 113 | + } | |
| 114 | + | |
| 115 | + public QueryGenerator createRegular(int id, int iterations, OptionSet options, final Session session) { | |
| 116 | + final int valueSize = (Integer) options.valueOf("value-size"); | |
| 117 | + final int columnsPerRow = (Integer) options.valueOf("columns-per-row"); | |
| 118 | + final long prefix = (long) id << 32; | |
| 119 | + | |
| 120 | + return new AbstractGenerator(iterations) { | |
| 121 | + @Override | |
| 122 | + public QueryGenerator.Request next() { | |
| 123 | + StringBuilder sb = new StringBuilder(); | |
| 124 | + sb.append("UPDATE standard1 SET "); | |
| 125 | + for (int i = 0; i < columnsPerRow; ++i) { | |
| 126 | + if (i > 0) sb.append(", "); | |
| 127 | + sb.append('C').append(i).append("='").append(Bytes.toHexString(makeValue(valueSize))).append('\''); | |
| 128 | + } | |
| 129 | + sb.append(" WHERE key = ").append(prefix | iteration); | |
| 130 | + ++iteration; | |
| 131 | + return new QueryGenerator.Request.SimpleQuery(new SimpleStatement(sb.toString())); | |
| 132 | + } | |
| 133 | + }; | |
| 134 | + } | |
| 135 | + | |
| 136 | + public QueryGenerator createPrepared(int id, int iterations, OptionSet options, Session session) { | |
| 137 | + final int valueSize = (Integer) options.valueOf("value-size"); | |
| 138 | + final int columnsPerRow = (Integer) options.valueOf("columns-per-row"); | |
| 139 | + final long prefix = (long) id << 32; | |
| 140 | + | |
| 141 | + StringBuilder sb = new StringBuilder(); | |
| 142 | + sb.append("UPDATE standard1 SET "); | |
| 143 | + for (int i = 0; i < columnsPerRow; ++i) { | |
| 144 | + if (i > 0) sb.append(", "); | |
| 145 | + sb.append('C').append(i).append("=?"); | |
| 146 | + } | |
| 147 | + sb.append(" WHERE key = ?"); | |
| 148 | + | |
| 149 | + final PreparedStatement stmt = session.prepare(sb.toString()); | |
| 150 | + | |
| 151 | + return new AbstractGenerator(iterations) { | |
| 152 | + @Override | |
| 153 | + public QueryGenerator.Request next() { | |
| 154 | + BoundStatement b = stmt.bind(); | |
| 155 | + b.setLong("key", prefix | iteration); | |
| 156 | + for (int i = 0; i < columnsPerRow; ++i) | |
| 157 | + b.setBytes("c" + i, makeValue(valueSize)); | |
| 158 | + ++iteration; | |
| 159 | + return new QueryGenerator.Request.PreparedQuery(b); | |
| 160 | + } | |
| 161 | + }; | |
| 162 | + } | |
| 163 | + }; | |
| 164 | + | |
| 165 | + public static final QueryGenerator.Builder READER = new QueryGenerator.Builder() { | |
| 166 | + | |
| 167 | + @Override | |
| 168 | + public String name() { | |
| 169 | + return "read"; | |
| 170 | + } | |
| 171 | + | |
| 172 | + @Override | |
| 173 | + public OptionParser addOptions(OptionParser parser) { | |
| 174 | + String msg = "Read the rows inserted with the insert generator. Use prepared statements unless the --no-prepare option is used."; | |
| 175 | + parser.formatHelpWith(Stress.Help.formatFor(name(), msg)); | |
| 176 | + | |
| 177 | + parser.accepts("no-prepare", "Do no use prepared statement"); | |
| 178 | + return parser; | |
| 179 | + } | |
| 180 | + | |
| 181 | + @Override | |
| 182 | + public void prepare(OptionSet options, Session session) { | |
| 183 | + KeyspaceMetadata ks = session.getCluster().getMetadata().getKeyspace("stress"); | |
| 184 | + if (ks == null || ks.getTable("standard1") == null) { | |
| 185 | + System.err.println("There is nothing to reads, please run insert/insert_prepared first."); | |
| 186 | + System.exit(1); | |
| 187 | + } | |
| 188 | + | |
| 189 | + session.execute("USE stress"); | |
| 190 | + } | |
| 191 | + | |
| 192 | + @Override | |
| 193 | + public QueryGenerator create(int id, int iterations, OptionSet options, Session session) { | |
| 194 | + return options.has("no-prepare") | |
| 195 | + ? createRegular(id, iterations, session) | |
| 196 | + : createPrepared(id, iterations, session); | |
| 197 | + } | |
| 198 | + | |
| 199 | + public QueryGenerator createRegular(long id, int iterations, final Session session) { | |
| 200 | + final long prefix = (long) id << 32; | |
| 201 | + return new AbstractGenerator(iterations) { | |
| 202 | + @Override | |
| 203 | + public QueryGenerator.Request next() { | |
| 204 | + StringBuilder sb = new StringBuilder(); | |
| 205 | + sb.append("SELECT * FROM standard1 WHERE key = ").append(prefix | iteration); | |
| 206 | + ++iteration; | |
| 207 | + return new QueryGenerator.Request.SimpleQuery(new SimpleStatement(sb.toString())); | |
| 208 | + } | |
| 209 | + }; | |
| 210 | + } | |
| 211 | + | |
| 212 | + public QueryGenerator createPrepared(long id, int iterations, Session session) { | |
| 213 | + final long prefix = (long) id << 32; | |
| 214 | + final PreparedStatement stmt = session.prepare("SELECT * FROM standard1 WHERE key = ?"); | |
| 215 | + | |
| 216 | + return new AbstractGenerator(iterations) { | |
| 217 | + @Override | |
| 218 | + public QueryGenerator.Request next() { | |
| 219 | + BoundStatement bs = stmt.bind(); | |
| 220 | + bs.setLong("key", prefix | iteration); | |
| 221 | + ++iteration; | |
| 222 | + return new QueryGenerator.Request.PreparedQuery(bs); | |
| 223 | + } | |
| 224 | + }; | |
| 225 | + } | |
| 226 | + }; | |
| 227 | +} |
added driver-tests/stress/src/main/java/com/datastax/driver/stress/QueryGenerator.java +92 −0
| @@ -0,0 +1,92 @@ | ||
| 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.stress; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import joptsimple.OptionParser; | |
| 20 | +import joptsimple.OptionSet; | |
| 21 | + | |
| 22 | +import java.util.Iterator; | |
| 23 | + | |
| 24 | +public abstract class QueryGenerator implements Iterator<QueryGenerator.Request> { | |
| 25 | + | |
| 26 | + protected final int iterations; | |
| 27 | + | |
| 28 | + protected QueryGenerator(int iterations) { | |
| 29 | + this.iterations = iterations; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public abstract int currentIteration(); | |
| 33 | + | |
| 34 | + public int totalIterations() { | |
| 35 | + return iterations; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public interface Builder { | |
| 39 | + public String name(); | |
| 40 | + | |
| 41 | + public OptionParser addOptions(OptionParser parser); | |
| 42 | + | |
| 43 | + public void prepare(OptionSet options, Session session); | |
| 44 | + | |
| 45 | + public QueryGenerator create(int id, int iterations, OptionSet options, Session session); | |
| 46 | + } | |
| 47 | + | |
| 48 | + public interface Request { | |
| 49 | + | |
| 50 | + public ResultSet execute(Session session); | |
| 51 | + | |
| 52 | + public ResultSetFuture executeAsync(Session session); | |
| 53 | + | |
| 54 | + public static class SimpleQuery implements Request { | |
| 55 | + | |
| 56 | + private final Statement statement; | |
| 57 | + | |
| 58 | + public SimpleQuery(Statement statement) { | |
| 59 | + this.statement = statement; | |
| 60 | + } | |
| 61 | + | |
| 62 | + @Override | |
| 63 | + public ResultSet execute(Session session) { | |
| 64 | + return session.execute(statement); | |
| 65 | + } | |
| 66 | + | |
| 67 | + @Override | |
| 68 | + public ResultSetFuture executeAsync(Session session) { | |
| 69 | + return session.executeAsync(statement); | |
| 70 | + } | |
| 71 | + } | |
| 72 | + | |
| 73 | + public static class PreparedQuery implements Request { | |
| 74 | + | |
| 75 | + private final BoundStatement query; | |
| 76 | + | |
| 77 | + public PreparedQuery(BoundStatement query) { | |
| 78 | + this.query = query; | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Override | |
| 82 | + public ResultSet execute(Session session) { | |
| 83 | + return session.execute(query); | |
| 84 | + } | |
| 85 | + | |
| 86 | + @Override | |
| 87 | + public ResultSetFuture executeAsync(Session session) { | |
| 88 | + return session.executeAsync(query); | |
| 89 | + } | |
| 90 | + } | |
| 91 | + } | |
| 92 | +} |
added driver-tests/stress/src/main/java/com/datastax/driver/stress/Reporter.java +281 −0
| @@ -0,0 +1,281 @@ | ||
| 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.stress; | |
| 17 | + | |
| 18 | +import com.yammer.metrics.Metrics; | |
| 19 | +import com.yammer.metrics.core.Meter; | |
| 20 | +import com.yammer.metrics.core.Timer; | |
| 21 | +import com.yammer.metrics.core.TimerContext; | |
| 22 | +import com.yammer.metrics.stats.Snapshot; | |
| 23 | + | |
| 24 | +import java.io.File; | |
| 25 | +import java.io.FileOutputStream; | |
| 26 | +import java.io.IOException; | |
| 27 | +import java.io.PrintStream; | |
| 28 | +import java.util.concurrent.Executors; | |
| 29 | +import java.util.concurrent.ScheduledExecutorService; | |
| 30 | +import java.util.concurrent.TimeUnit; | |
| 31 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 32 | + | |
| 33 | +public class Reporter implements Runnable { | |
| 34 | + | |
| 35 | + private Meter requests; | |
| 36 | + private Timer latencies; | |
| 37 | + | |
| 38 | + public Meter requestsMiddle; | |
| 39 | + public Timer latenciesMiddle; | |
| 40 | + | |
| 41 | + private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); | |
| 42 | + | |
| 43 | + private final File csvFile; | |
| 44 | + private final String header; | |
| 45 | + private final long period; | |
| 46 | + private final int consoleReportPeriod; | |
| 47 | + private final int iterations; | |
| 48 | + private final AtomicInteger requestsDone = new AtomicInteger(0); | |
| 49 | + | |
| 50 | + private final int middleLowBound; | |
| 51 | + private final int middleHighBound; | |
| 52 | + | |
| 53 | + private volatile double meanMiddleRate = -1.0; | |
| 54 | + | |
| 55 | + private long startTime; | |
| 56 | + private long lastOpCount; | |
| 57 | + | |
| 58 | + private PrintStream csv; | |
| 59 | + | |
| 60 | + private long lastConsoleOpCount; | |
| 61 | + private long lastConsoleTimestamp; | |
| 62 | + private int tickSinceLastConsoleReport; | |
| 63 | + | |
| 64 | + public Reporter(int consoleReportPeriod, String csvFileName, String[] args, int iterations) { | |
| 65 | + this(1, consoleReportPeriod, new File(csvFileName), formatHeader(args), iterations); | |
| 66 | + } | |
| 67 | + | |
| 68 | + private Reporter(int csvPeriod, int consolePeriod, File csvFile, String header, int iterations) { | |
| 69 | + this.period = csvPeriod; | |
| 70 | + this.consoleReportPeriod = consolePeriod / csvPeriod; | |
| 71 | + this.csvFile = csvFile; | |
| 72 | + this.header = header; | |
| 73 | + this.iterations = iterations; | |
| 74 | + | |
| 75 | + // Middle = exclude first and last 10% (note: if requests is -1, we'll end up with negative bounds, which will always exclude. It's fine if we never stop anyway) | |
| 76 | + this.middleLowBound = (int) (0.1 * iterations); | |
| 77 | + this.middleHighBound = (int) (0.9 * iterations); | |
| 78 | + } | |
| 79 | + | |
| 80 | + private static String formatHeader(String[] args) { | |
| 81 | + StringBuilder sb = new StringBuilder(); | |
| 82 | + sb.append("stress"); | |
| 83 | + for (String arg : args) | |
| 84 | + sb.append(' ').append(arg); | |
| 85 | + return sb.toString(); | |
| 86 | + } | |
| 87 | + | |
| 88 | + public void start() { | |
| 89 | + | |
| 90 | + this.requests = Metrics.newMeter(Reporter.class, "requests", "requests", TimeUnit.SECONDS); | |
| 91 | + this.latencies = Metrics.newTimer(Reporter.class, "latencies", TimeUnit.MILLISECONDS, TimeUnit.SECONDS); | |
| 92 | + this.startTime = System.currentTimeMillis(); | |
| 93 | + initConsole(); | |
| 94 | + initCSV(); | |
| 95 | + | |
| 96 | + this.executor.scheduleAtFixedRate(this, period, period, TimeUnit.SECONDS); | |
| 97 | + } | |
| 98 | + | |
| 99 | + public Context newRequest() { | |
| 100 | + int iteration = requestsDone.getAndIncrement(); | |
| 101 | + if (iteration >= middleLowBound) { | |
| 102 | + if (latenciesMiddle == null) { | |
| 103 | + synchronized (this) { | |
| 104 | + if (latenciesMiddle == null) { | |
| 105 | + latenciesMiddle = Metrics.newTimer(Reporter.class, "latencies_middle", TimeUnit.MILLISECONDS, TimeUnit.SECONDS); | |
| 106 | + requestsMiddle = Metrics.newMeter(Reporter.class, "requests_middle", "requests", TimeUnit.SECONDS); | |
| 107 | + } | |
| 108 | + } | |
| 109 | + } | |
| 110 | + if (iteration > middleHighBound) { | |
| 111 | + if (meanMiddleRate < 0) | |
| 112 | + meanMiddleRate = requestsMiddle.meanRate(); | |
| 113 | + | |
| 114 | + return new Context(this, latencies.time(), null); | |
| 115 | + } else { | |
| 116 | + return new Context(this, latencies.time(), latenciesMiddle.time()); | |
| 117 | + } | |
| 118 | + } else { | |
| 119 | + return new Context(this, latencies.time(), null); | |
| 120 | + } | |
| 121 | + } | |
| 122 | + | |
| 123 | + public void stop() { | |
| 124 | + executor.shutdown(); | |
| 125 | + | |
| 126 | + long tstamp = System.currentTimeMillis(); | |
| 127 | + long elapsed = TimeUnit.MILLISECONDS.toSeconds(tstamp - startTime); | |
| 128 | + Report lastReport = new Report(tstamp, elapsed, requests, latencies, lastOpCount); | |
| 129 | + | |
| 130 | + stopCSV(lastReport); | |
| 131 | + stopConsole(lastReport); | |
| 132 | + } | |
| 133 | + | |
| 134 | + @Override | |
| 135 | + public void run() { | |
| 136 | + report(); | |
| 137 | + } | |
| 138 | + | |
| 139 | + private void report() { | |
| 140 | + long tstamp = System.currentTimeMillis(); | |
| 141 | + long elapsed = TimeUnit.MILLISECONDS.toSeconds(tstamp - startTime); | |
| 142 | + | |
| 143 | + Report report = new Report(tstamp, elapsed, requests, latencies, lastOpCount); | |
| 144 | + lastOpCount = report.totalOps; | |
| 145 | + | |
| 146 | + reportToCSV(report); | |
| 147 | + reportToConsole(report); | |
| 148 | + } | |
| 149 | + | |
| 150 | + private void initCSV() { | |
| 151 | + if (csvFile.exists()) | |
| 152 | + if (!csvFile.delete()) | |
| 153 | + throw new RuntimeException("File " + csvFile + " already exists and cannot delete it"); | |
| 154 | + | |
| 155 | + try { | |
| 156 | + if (!csvFile.createNewFile()) | |
| 157 | + throw new RuntimeException("Unable to create report file " + csvFile); | |
| 158 | + | |
| 159 | + csv = new PrintStream(new FileOutputStream(csvFile)); | |
| 160 | + | |
| 161 | + csv.println("# " + header); | |
| 162 | + csv.println("# elapsed,total_ops,interval_rate,mean_rate,mean_latency,95th_latency,99th_latency,std_dev"); | |
| 163 | + | |
| 164 | + } catch (IOException e) { | |
| 165 | + throw new RuntimeException("Error creating report file " + csvFile, e); | |
| 166 | + } | |
| 167 | + } | |
| 168 | + | |
| 169 | + private void reportToCSV(Report report) { | |
| 170 | + csv.println(new StringBuilder() | |
| 171 | + .append(report.elapsed).append(',') | |
| 172 | + .append(report.totalOps).append(',') | |
| 173 | + .append(report.intervalRate).append(',') | |
| 174 | + .append(report.meanRate).append(',') | |
| 175 | + .append(report.meanLatency).append(',') | |
| 176 | + .append(report.latency95th).append(',') | |
| 177 | + .append(report.latency99th).append(',') | |
| 178 | + .append(report.stdDev)); | |
| 179 | + } | |
| 180 | + | |
| 181 | + private void stopCSV(Report lastReport) { | |
| 182 | + reportToCSV(lastReport); | |
| 183 | + } | |
| 184 | + | |
| 185 | + private void initConsole() { | |
| 186 | + this.lastConsoleTimestamp = startTime; | |
| 187 | + | |
| 188 | + System.out.println(" Time (s) | total ops | interval rate | mean rate | mean latency (ms) | 95th latency (ms) | 99th latency (ms) | std dev"); | |
| 189 | + System.out.println("--------------------------------------------------------------------------------------------------------------------------------"); | |
| 190 | + } | |
| 191 | + | |
| 192 | + private void reportToConsole(Report report) { | |
| 193 | + | |
| 194 | + if (++tickSinceLastConsoleReport < consoleReportPeriod) | |
| 195 | + return; | |
| 196 | + | |
| 197 | + printReportToConsole(report); | |
| 198 | + | |
| 199 | + tickSinceLastConsoleReport = 0; | |
| 200 | + lastConsoleTimestamp = report.timestamp; | |
| 201 | + lastConsoleOpCount = report.totalOps; | |
| 202 | + } | |
| 203 | + | |
| 204 | + private void printReportToConsole(Report report) { | |
| 205 | + long delay = report.timestamp - lastConsoleTimestamp; | |
| 206 | + double intervalRate = (((double) (report.totalOps - lastConsoleOpCount)) / delay) * 1000; | |
| 207 | + | |
| 208 | + String msg = String.format(" %8d | %12d | %13.2f | %12.2f | %17.3f | %17.3f | %17.3f | %9.3f", | |
| 209 | + report.elapsed, report.totalOps, intervalRate, report.meanRate, report.meanLatency, report.latency95th, report.latency99th, report.stdDev); | |
| 210 | + System.out.println(msg); | |
| 211 | + } | |
| 212 | + | |
| 213 | + private void stopConsole(Report lastReport) { | |
| 214 | + printReportToConsole(lastReport); | |
| 215 | + | |
| 216 | + if (latenciesMiddle == null) | |
| 217 | + return; | |
| 218 | + | |
| 219 | + Snapshot snapshot = latenciesMiddle.getSnapshot(); | |
| 220 | + | |
| 221 | + System.out.println(); | |
| 222 | + System.out.println("For the middle 80% of values:"); | |
| 223 | + System.out.println(String.format(" Mean rate (ops/sec): %10.1f", meanMiddleRate)); | |
| 224 | + System.out.println(String.format(" Mean latency (ms): %10.3f", latenciesMiddle.mean())); | |
| 225 | + System.out.println(String.format(" Median latency (ms): %10.3f", snapshot.getMedian())); | |
| 226 | + System.out.println(String.format(" 75th percentile latency (ms): %10.3f", snapshot.get75thPercentile())); | |
| 227 | + System.out.println(String.format(" 95th percentile latency (ms): %10.3f", snapshot.get95thPercentile())); | |
| 228 | + System.out.println(String.format(" 99th percentile latency (ms): %10.3f", snapshot.get99thPercentile())); | |
| 229 | + System.out.println(String.format(" Standard latency deviation: %10.3f", latenciesMiddle.stdDev())); | |
| 230 | + } | |
| 231 | + | |
| 232 | + private static class Report { | |
| 233 | + public final long timestamp; | |
| 234 | + public final long elapsed; | |
| 235 | + | |
| 236 | + public final long totalOps; | |
| 237 | + public final long intervalRate; | |
| 238 | + public final double meanRate; | |
| 239 | + | |
| 240 | + public final double meanLatency; | |
| 241 | + public final double latency95th; | |
| 242 | + public final double latency99th; | |
| 243 | + public final double stdDev; | |
| 244 | + | |
| 245 | + public Report(long timestamp, long elapsed, Meter meter, Timer timer, long lastOpCount) { | |
| 246 | + this.timestamp = timestamp; | |
| 247 | + this.elapsed = elapsed; | |
| 248 | + | |
| 249 | + this.totalOps = meter.count(); | |
| 250 | + this.intervalRate = totalOps - lastOpCount; | |
| 251 | + this.meanRate = meter.meanRate(); | |
| 252 | + | |
| 253 | + Snapshot snapshot = timer.getSnapshot(); | |
| 254 | + this.meanLatency = timer.mean(); | |
| 255 | + this.latency95th = snapshot.get95thPercentile(); | |
| 256 | + this.latency99th = snapshot.get99thPercentile(); | |
| 257 | + this.stdDev = timer.stdDev(); | |
| 258 | + } | |
| 259 | + } | |
| 260 | + | |
| 261 | + public static class Context { | |
| 262 | + private final Reporter reporter; | |
| 263 | + private final TimerContext context; | |
| 264 | + private final TimerContext contextMiddle; | |
| 265 | + | |
| 266 | + private Context(Reporter reporter, TimerContext context, TimerContext contextMiddle) { | |
| 267 | + this.reporter = reporter; | |
| 268 | + this.context = context; | |
| 269 | + this.contextMiddle = contextMiddle; | |
| 270 | + } | |
| 271 | + | |
| 272 | + public void done() { | |
| 273 | + context.stop(); | |
| 274 | + reporter.requests.mark(); | |
| 275 | + if (contextMiddle != null) { | |
| 276 | + contextMiddle.stop(); | |
| 277 | + reporter.requestsMiddle.mark(); | |
| 278 | + } | |
| 279 | + } | |
| 280 | + } | |
| 281 | +} |
added driver-tests/stress/src/main/java/com/datastax/driver/stress/Stress.java +285 −0
| @@ -0,0 +1,285 @@ | ||
| 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.stress; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 20 | +import joptsimple.*; | |
| 21 | +import org.apache.log4j.PropertyConfigurator; | |
| 22 | + | |
| 23 | +import java.io.IOException; | |
| 24 | +import java.util.HashMap; | |
| 25 | +import java.util.List; | |
| 26 | +import java.util.Map; | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * A simple stress tool to demonstrate the use of the driver. | |
| 30 | + * <p/> | |
| 31 | + * Sample usage: | |
| 32 | + * stress insert -n 100000 | |
| 33 | + * stress read -n 10000 | |
| 34 | + */ | |
| 35 | +public class Stress { | |
| 36 | + | |
| 37 | + private static final Map<String, QueryGenerator.Builder> generators = new HashMap<String, QueryGenerator.Builder>(); | |
| 38 | + | |
| 39 | + static { | |
| 40 | + PropertyConfigurator.configure(System.getProperty("log4j.configuration", "./conf/log4j.properties")); | |
| 41 | + | |
| 42 | + QueryGenerator.Builder[] gs = new QueryGenerator.Builder[]{ | |
| 43 | + Generators.INSERTER, | |
| 44 | + Generators.READER | |
| 45 | + }; | |
| 46 | + | |
| 47 | + for (QueryGenerator.Builder b : gs) | |
| 48 | + register(b.name(), b); | |
| 49 | + } | |
| 50 | + | |
| 51 | + private static OptionParser defaultParser() { | |
| 52 | + OptionParser parser = new OptionParser() {{ | |
| 53 | + accepts("h", "Show this help message"); | |
| 54 | + accepts("n", "Number of requests to perform (default: unlimited)").withRequiredArg().ofType(Integer.class); | |
| 55 | + accepts("t", "Level of concurrency to use").withRequiredArg().ofType(Integer.class).defaultsTo(50); | |
| 56 | + accepts("async", "Make asynchronous requests instead of blocking ones"); | |
| 57 | + accepts("ip", "The hosts ip to connect to").withRequiredArg().ofType(String.class).defaultsTo("127.0.0.1"); | |
| 58 | + accepts("report-file", "The name of csv file to use for reporting results").withRequiredArg().ofType(String.class).defaultsTo("last.csv"); | |
| 59 | + accepts("print-delay", "The delay in seconds at which to report on the console").withRequiredArg().ofType(Integer.class).defaultsTo(5); | |
| 60 | + accepts("compression", "Use compression (SNAPPY)"); | |
| 61 | + accepts("connections-per-host", "The number of connections per hosts (default: based on the number of threads)").withRequiredArg().ofType(Integer.class); | |
| 62 | + accepts("consistency-level", "Consistency level").withRequiredArg().withValuesConvertedBy(new ConsistencyLevelConverter()) | |
| 63 | + .ofType(ConsistencyLevel.class).defaultsTo(ConsistencyLevel.LOCAL_ONE); | |
| 64 | + }}; | |
| 65 | + String msg = "Where <generator> can be one of " + generators.keySet() + '\n' | |
| 66 | + + "You can get more help on a particular generator with: stress <generator> -h"; | |
| 67 | + parser.formatHelpWith(Help.formatFor("<generator>", msg)); | |
| 68 | + return parser; | |
| 69 | + } | |
| 70 | + | |
| 71 | + public static void register(String name, QueryGenerator.Builder generator) { | |
| 72 | + if (generators.containsKey(name)) | |
| 73 | + throw new IllegalStateException("There is already a generator registered with the name " + name); | |
| 74 | + | |
| 75 | + generators.put(name, generator); | |
| 76 | + } | |
| 77 | + | |
| 78 | + private static class Stresser { | |
| 79 | + private final QueryGenerator.Builder genBuilder; | |
| 80 | + private final OptionParser parser; | |
| 81 | + private final OptionSet options; | |
| 82 | + | |
| 83 | + private Stresser(QueryGenerator.Builder genBuilder, OptionParser parser, OptionSet options) { | |
| 84 | + this.genBuilder = genBuilder; | |
| 85 | + this.parser = parser; | |
| 86 | + this.options = options; | |
| 87 | + } | |
| 88 | + | |
| 89 | + public static Stresser forCommandLineArguments(String[] args) { | |
| 90 | + OptionParser parser = defaultParser(); | |
| 91 | + | |
| 92 | + String generatorName = findPotentialGenerator(args); | |
| 93 | + if (generatorName == null) { | |
| 94 | + // Still parse the options to handle -h | |
| 95 | + OptionSet options = parseOptions(parser, args); | |
| 96 | + System.err.println("Missing generator, you need to provide a generator."); | |
| 97 | + printHelp(parser); | |
| 98 | + System.exit(1); | |
| 99 | + } | |
| 100 | + | |
| 101 | + if (!generators.containsKey(generatorName)) { | |
| 102 | + System.err.println(String.format("Unknown generator '%s'", generatorName)); | |
| 103 | + printHelp(parser); | |
| 104 | + System.exit(1); | |
| 105 | + } | |
| 106 | + | |
| 107 | + QueryGenerator.Builder genBuilder = generators.get(generatorName); | |
| 108 | + parser = genBuilder.addOptions(parser); | |
| 109 | + OptionSet options = parseOptions(parser, args); | |
| 110 | + | |
| 111 | + List<?> nonOpts = options.nonOptionArguments(); | |
| 112 | + if (nonOpts.size() > 1) { | |
| 113 | + System.err.println("Too many generators provided. Got " + nonOpts + " but only one generator supported."); | |
| 114 | + printHelp(parser); | |
| 115 | + System.exit(1); | |
| 116 | + } | |
| 117 | + | |
| 118 | + return new Stresser(genBuilder, parser, options); | |
| 119 | + } | |
| 120 | + | |
| 121 | + private static String findPotentialGenerator(String[] args) { | |
| 122 | + for (String arg : args) | |
| 123 | + if (!arg.startsWith("-")) | |
| 124 | + return arg; | |
| 125 | + | |
| 126 | + return null; | |
| 127 | + } | |
| 128 | + | |
| 129 | + private static OptionSet parseOptions(OptionParser parser, String[] args) { | |
| 130 | + try { | |
| 131 | + OptionSet options = parser.parse(args); | |
| 132 | + if (options.has("h")) { | |
| 133 | + printHelp(parser); | |
| 134 | + System.exit(0); | |
| 135 | + } | |
| 136 | + return options; | |
| 137 | + } catch (Exception e) { | |
| 138 | + System.err.println("Error parsing options: " + e.getMessage()); | |
| 139 | + printHelp(parser); | |
| 140 | + System.exit(1); | |
| 141 | + throw new AssertionError(); | |
| 142 | + } | |
| 143 | + } | |
| 144 | + | |
| 145 | + private static void printHelp(OptionParser parser) { | |
| 146 | + try { | |
| 147 | + parser.printHelpOn(System.out); | |
| 148 | + } catch (IOException e) { | |
| 149 | + throw new AssertionError(e); | |
| 150 | + } | |
| 151 | + } | |
| 152 | + | |
| 153 | + public OptionSet getOptions() { | |
| 154 | + return options; | |
| 155 | + } | |
| 156 | + | |
| 157 | + public void prepare(Session session) { | |
| 158 | + genBuilder.prepare(options, session); | |
| 159 | + } | |
| 160 | + | |
| 161 | + public QueryGenerator newGenerator(int id, Session session, int iterations) { | |
| 162 | + return genBuilder.create(id, iterations, options, session); | |
| 163 | + } | |
| 164 | + } | |
| 165 | + | |
| 166 | + public static class Help implements HelpFormatter { | |
| 167 | + | |
| 168 | + private final HelpFormatter defaultFormatter; | |
| 169 | + private final String generator; | |
| 170 | + private final String header; | |
| 171 | + | |
| 172 | + private Help(HelpFormatter defaultFormatter, String generator, String header) { | |
| 173 | + this.defaultFormatter = defaultFormatter; | |
| 174 | + this.generator = generator; | |
| 175 | + this.header = header; | |
| 176 | + } | |
| 177 | + | |
| 178 | + public static Help formatFor(String generator, String header) { | |
| 179 | + // It's a pain in the ass to get the real console width in JAVA so hardcode it. But it's the 21th | |
| 180 | + // century, we're not stuck at 80 characters anymore. | |
| 181 | + int width = 120; | |
| 182 | + return new Help(new BuiltinHelpFormatter(width, 4), generator, header); | |
| 183 | + } | |
| 184 | + | |
| 185 | + @Override | |
| 186 | + public String format(Map<String, ? extends OptionDescriptor> options) { | |
| 187 | + StringBuilder sb = new StringBuilder(); | |
| 188 | + | |
| 189 | + sb.append("Usage: stress ").append(generator).append(" [<option>]*").append("\n\n"); | |
| 190 | + sb.append(header).append("\n\n"); | |
| 191 | + sb.append(defaultFormatter.format(options)); | |
| 192 | + return sb.toString(); | |
| 193 | + } | |
| 194 | + } | |
| 195 | + | |
| 196 | + public static void main(String[] args) throws Exception { | |
| 197 | + | |
| 198 | + Stresser stresser = Stresser.forCommandLineArguments(args); | |
| 199 | + OptionSet options = stresser.getOptions(); | |
| 200 | + | |
| 201 | + int requests = options.has("n") ? (Integer) options.valueOf("n") : -1; | |
| 202 | + int concurrency = (Integer) options.valueOf("t"); | |
| 203 | + ConsistencyLevel consistencyLevel = (ConsistencyLevel) options.valueOf("consistency-level"); | |
| 204 | + | |
| 205 | + String reportFileName = (String) options.valueOf("report-file"); | |
| 206 | + | |
| 207 | + boolean async = options.has("async"); | |
| 208 | + | |
| 209 | + int iterations = (requests == -1 ? -1 : requests / concurrency); | |
| 210 | + | |
| 211 | + final int maxRequestsPerConnection = 128; | |
| 212 | + int maxConnections = options.has("connections-per-host") | |
| 213 | + ? (Integer) options.valueOf("connections-per-host") | |
| 214 | + : concurrency / maxRequestsPerConnection + 1; | |
| 215 | + | |
| 216 | + PoolingOptions pools = new PoolingOptions(); | |
| 217 | + pools.setNewConnectionThreshold(HostDistance.LOCAL, concurrency); | |
| 218 | + pools.setCoreConnectionsPerHost(HostDistance.LOCAL, maxConnections); | |
| 219 | + pools.setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnections); | |
| 220 | + pools.setCoreConnectionsPerHost(HostDistance.REMOTE, maxConnections); | |
| 221 | + pools.setMaxConnectionsPerHost(HostDistance.REMOTE, maxConnections); | |
| 222 | + | |
| 223 | + System.out.println("Initializing stress test:"); | |
| 224 | + System.out.println(" request count: " + (requests == -1 ? "unlimited" : requests)); | |
| 225 | + System.out.println(" concurrency: " + concurrency + " (" + iterations + " requests/thread)"); | |
| 226 | + System.out.println(" mode: " + (async ? "asynchronous" : "blocking")); | |
| 227 | + System.out.println(" per-host connections: " + maxConnections); | |
| 228 | + System.out.println(" compression: " + options.has("compression")); | |
| 229 | + System.out.println(" consistency-level: " + consistencyLevel.name()); | |
| 230 | + | |
| 231 | + try { | |
| 232 | + // Create session to hosts | |
| 233 | + Cluster cluster = new Cluster.Builder() | |
| 234 | + .addContactPoints(String.valueOf(options.valueOf("ip"))) | |
| 235 | + .withPoolingOptions(pools) | |
| 236 | + .withSocketOptions(new SocketOptions().setTcpNoDelay(true)) | |
| 237 | + .withQueryOptions(new QueryOptions().setConsistencyLevel(consistencyLevel)) | |
| 238 | + .build(); | |
| 239 | + | |
| 240 | + if (options.has("compression")) | |
| 241 | + cluster.getConfiguration().getProtocolOptions().setCompression(ProtocolOptions.Compression.SNAPPY); | |
| 242 | + | |
| 243 | + Session session = cluster.connect(); | |
| 244 | + | |
| 245 | + Metadata metadata = cluster.getMetadata(); | |
| 246 | + System.out.println(String.format("Connected to cluster '%s' on %s.", metadata.getClusterName(), metadata.getAllHosts())); | |
| 247 | + | |
| 248 | + System.out.println("Preparing test..."); | |
| 249 | + stresser.prepare(session); | |
| 250 | + | |
| 251 | + Reporter reporter = new Reporter((Integer) options.valueOf("print-delay"), reportFileName, args, requests); | |
| 252 | + | |
| 253 | + Consumer[] consumers = new Consumer[concurrency]; | |
| 254 | + for (int i = 0; i < concurrency; i++) { | |
| 255 | + QueryGenerator generator = stresser.newGenerator(i, session, iterations); | |
| 256 | + consumers[i] = async ? new AsynchronousConsumer(session, generator, reporter) : | |
| 257 | + new BlockingConsumer(session, generator, reporter); | |
| 258 | + } | |
| 259 | + | |
| 260 | + System.out.println("Starting to stress test..."); | |
| 261 | + System.out.println(); | |
| 262 | + | |
| 263 | + reporter.start(); | |
| 264 | + | |
| 265 | + for (Consumer consumer : consumers) | |
| 266 | + consumer.start(); | |
| 267 | + | |
| 268 | + for (Consumer consumer : consumers) | |
| 269 | + consumer.join(); | |
| 270 | + | |
| 271 | + reporter.stop(); | |
| 272 | + | |
| 273 | + System.out.println("Stress test successful."); | |
| 274 | + System.exit(0); | |
| 275 | + | |
| 276 | + } catch (NoHostAvailableException e) { | |
| 277 | + System.err.println("No alive hosts to use: " + e.getMessage()); | |
| 278 | + System.exit(1); | |
| 279 | + } catch (Exception e) { | |
| 280 | + System.err.println("Unexpected error: " + e.getMessage()); | |
| 281 | + e.printStackTrace(); | |
| 282 | + System.exit(1); | |
| 283 | + } | |
| 284 | + } | |
| 285 | +} |
modified faq/README.md +19 −0
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | CQL with `LIMIT` and the `token()` function. See |
| 12 | 12 | [this conversation](https://groups.google.com/a/lists.datastax.com/d/msg/java-driver-user/U2KzAHruWO4/6vDmUVDDkOwJ) on the mailing list. |
| 13 | 13 | |
| 14 | + | |
| 14 | 15 | ### Can I check if a conditional statement (lightweight transaction) was successful? |
| 15 | 16 | |
| 16 | 17 | When executing a conditional statement, the `ResultSet` will contain a single `Row` with a |
| @@ -36,6 +37,7 @@ | ||
| 36 | 37 | |
| 37 | 38 | [wasApplied]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/ResultSet.html#wasApplied-- |
| 38 | 39 | |
| 40 | + | |
| 39 | 41 | ### What is a parameterized statement and how can I use it? |
| 40 | 42 | |
| 41 | 43 | Starting with Cassandra 2.0, normal statements (that is non-prepared statements) do |
| @@ -49,12 +51,14 @@ | ||
| 49 | 51 | |
| 50 | 52 | See [Simple statements](../manual/statements/simple/) for more information. |
| 51 | 53 | |
| 54 | + | |
| 52 | 55 | ### Does a parameterized statement escape parameters? |
| 53 | 56 | |
| 54 | 57 | A parameterized statement sends the values of parameters separate from the query |
| 55 | 58 | (similar to the way a prepared statement does) as bytes so there is no need to escape |
| 56 | 59 | parameters. |
| 57 | 60 | |
| 61 | + | |
| 58 | 62 | ### What's the difference between a parameterized statement and a Prepared statement? |
| 59 | 63 | |
| 60 | 64 | The only similarity between a parameterized statement and a prepared statement is in |
| @@ -67,6 +71,7 @@ | ||
| 67 | 71 | |
| 68 | 72 | See [Prepared statements](../manual/statements/prepared/) for more information. |
| 69 | 73 | |
| 74 | + | |
| 70 | 75 | ### Can I combine `PreparedStatements` and normal statements in a batch? |
| 71 | 76 | |
| 72 | 77 | Yes. A batch can include both bound statements and simple statements: |
| @@ -82,6 +87,7 @@ | ||
| 82 | 87 | session.execute(batch); |
| 83 | 88 | ``` |
| 84 | 89 | |
| 90 | + | |
| 85 | 91 | ### Can I get the raw bytes of a text column? |
| 86 | 92 | |
| 87 | 93 | If you need to access the raw bytes of a text column, call the |
| @@ -90,6 +96,7 @@ | ||
| 90 | 96 | Trying to use `Row.getBytes("columnName")` for the same purpose results in an |
| 91 | 97 | exception, as the `getBytes` method can only be used if the column has the CQL type `BLOB`. |
| 92 | 98 | |
| 99 | + | |
| 93 | 100 | ### How do I increment counters with `QueryBuilder`? |
| 94 | 101 | |
| 95 | 102 | Considering the following query: |
| @@ -106,6 +113,7 @@ | ||
| 106 | 113 | .where(eq("userid", id)); |
| 107 | 114 | ``` |
| 108 | 115 | |
| 116 | + | |
| 109 | 117 | ### Is there a way to control the batch size of the results returned from a query? |
| 110 | 118 | |
| 111 | 119 | Use the `setFetchSize()` method on your `Statement` object. The fetch size controls |
| @@ -118,6 +126,7 @@ | ||
| 118 | 126 | |
| 119 | 127 | See [Paging](../manual/paging/) for more information. |
| 120 | 128 | |
| 129 | + | |
| 121 | 130 | ### What's the difference between using `setFetchSize()` and `LIMIT`? |
| 122 | 131 | |
| 123 | 132 | Basically, `LIMIT` controls the maximum number of results returned by the query, |
| @@ -128,3 +137,13 @@ | ||
| 128 | 137 | rows each. |
| 129 | 138 | |
| 130 | 139 | See [Paging](../manual/paging/) for more information. |
| 140 | + | |
| 141 | + | |
| 142 | +### I'm reading a BLOB column and the driver returns incorrect data. | |
| 143 | + | |
| 144 | +Check your code to ensure that you read the returned `ByteBuffer` correctly. `ByteBuffer` is a very error-prone API, | |
| 145 | +and we've had many reports where the problem turned out to be in user code. | |
| 146 | + | |
| 147 | +See [Blobs.java] in the `driver-examples` module for some examples and explanations. | |
| 148 | + | |
| 149 | +[Blobs.java]: https://github.com/datastax/java-driver/tree/3.0.x/driver-examples/src/main/java/com/datastax/driver/examples/datatypes/Blobs.java | |
| No newline at the end of the file |
modified pom.xml +1 −0
| @@ -41,6 +41,7 @@ | ||
| 41 | 41 | <module>driver-mapping</module> |
| 42 | 42 | <module>driver-extras</module> |
| 43 | 43 | <module>driver-examples</module> |
| 44 | + <module>driver-tests</module> | |
| 44 | 45 | <module>driver-dist</module> |
| 45 | 46 | </modules> |
| 46 | 47 |