Elffuss BraidHub

kikocis/java-driver public

2.1 specific test fixes for recent changes.  Add travis status.

Adds fixes for recent changes involving PerClassSingleNodeCluster.
Changeset2f8dc102409ee3b90aef84dd2d4c7be27d41699b09e6e708a5cccc83ea9fded1
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-03-30 17:07 -05:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-03-30 17:07 -05:00
Parents66f63295d45c

Browse the files at this changeset

16 files changed

modified driver-core/README.rst +4 −0
@@ -1,6 +1,10 @@
11 Driver Core
22 ===========
33
4+.. image:: https://travis-ci.org/datastax/java-driver.svg?branch=2.1
5+ :target: https://travis-ci.org/datastax/java-driver
6+ :alt: Travis Build
7+
48 This is the core module of the DataStax Java Driver for Apache Cassandra (C*),
59 which offers a simple (as in, not abstracted) but complete API to work with
610 CQL3. The main goal of the module is to handle all the functionality related
modified driver-core/src/test/java/com/datastax/driver/core/ClusterStressTest.java +2 −1
@@ -2,6 +2,7 @@
22
33 import java.util.ArrayList;
44 import java.util.Collection;
5+import java.util.Collections;
56 import java.util.List;
67 import java.util.concurrent.*;
78
@@ -135,7 +136,7 @@
135136 public Cluster call() throws Exception {
136137 startSignal.await();
137138
138- Cluster cluster = Cluster.builder().addContactPoints(CCMBridge.IP_PREFIX + '1')
139+ Cluster cluster = Cluster.builder().addContactPointsWithPorts(Collections.singletonList(hostAddress))
139140 .withPoolingOptions(new PoolingOptions().setCoreConnectionsPerHost(HostDistance.LOCAL, 1)).build();
140141
141142 try {
modified driver-core/src/test/java/com/datastax/driver/core/SchemaTest.java +1 −3
@@ -148,9 +148,7 @@
148148 TableMetadata metadata = cluster.getMetadata().getKeyspace(keyspace).getTable("with_options");
149149
150150 String withOpts = withOptions;
151- VersionNumber version = cluster.getMetadata()
152- .getHost(new InetSocketAddress(CCMBridge.IP_PREFIX + "1", 9042))
153- .getCassandraVersion();
151+ VersionNumber version = TestUtils.findHost(cluster, 1).getCassandraVersion();
154152
155153 if (version.getMajor() == 2) {
156154 // Strip the last ';'
modified driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +4 −3
@@ -17,15 +17,16 @@
1717 // create a new cluster object and ensure 0 sessions and connections
1818 cluster = Cluster.builder().addContactPoints(CCMBridge.IP_PREFIX + '1').build();
1919
20- int corePoolSize = cluster.getConfiguration()
21- .getPoolingOptions()
22- .getCoreConnectionsPerHost(HostDistance.LOCAL);
2320
2421 assertEquals(cluster.manager.sessions.size(), 0);
2522 assertEquals((int)cluster.getMetrics().getOpenConnections().getValue(), 0);
2623
2724 // ensure sessions.size() returns with 1 control connection + core pool size.
2825 Session session = cluster.connect();
26+
27+ // Special check for protocol version 3, number of connections should be 1.
28+ int corePoolSize = TestUtils.numberOfLocalCoreConnections(cluster);
29+
2930 assertEquals(cluster.manager.sessions.size(), 1);
3031 assertEquals((int)cluster.getMetrics().getOpenConnections().getValue(), 1 + corePoolSize);
3132
modified driver-core/src/test/java/com/datastax/driver/core/SessionStressTest.java +1 −1
@@ -54,7 +54,7 @@
5454 @Test(groups = "long")
5555 public void sessions_should_not_leak_connections() {
5656 // override inherited field with a new cluster object and ensure 0 sessions and connections
57- cluster = Cluster.builder().addContactPoints(CCMBridge.IP_PREFIX + '1')
57+ cluster = Cluster.builder().addContactPointsWithPorts(Collections.singletonList(hostAddress))
5858 .withPoolingOptions(new PoolingOptions().setCoreConnectionsPerHost(HostDistance.LOCAL, 1)).build();
5959
6060 // The cluster has not been initialized yet, therefore the control connection is not opened
modified driver-core/src/test/java/com/datastax/driver/core/SessionTest.java +1 −1
@@ -149,7 +149,7 @@
149149 assertEquals(host.getAddress().toString(), hostAddress);
150150 assertEquals(host.getDatacenter(), "datacenter1");
151151 assertEquals(host.getRack(), "rack1");
152- assertEquals(host.getSocketAddress().toString(), hostAddress + ":9042");
152+ assertEquals(host.getSocketAddress().toString(), hostAddress + ":" + ports[2]);
153153
154154 assertEquals(state.getOpenConnections(host), TestUtils.numberOfLocalCoreConnections(cluster));
155155 assertEquals(state.getInFlightQueries(host), 0);
modified driver-core/src/test/java/com/datastax/driver/core/TupleTest.java +1 −3
@@ -27,8 +27,6 @@
2727
2828 import com.datastax.driver.core.utils.CassandraVersion;
2929
30-import static com.datastax.driver.core.TestUtils.SIMPLE_KEYSPACE;
31-
3230 @CassandraVersion(major=2.1)
3331 public class TupleTest extends CCMBridge.PerClassSingleNodeCluster {
3432
@@ -60,7 +58,7 @@
6058 @Test(groups = "short")
6159 public void simpleWriteReadTest() throws Exception {
6260 try {
63- session.execute("USE " + SIMPLE_KEYSPACE);
61+ session.execute("USE " + keyspace);
6462 PreparedStatement ins = session.prepare("INSERT INTO t(k, v) VALUES (?, ?)");
6563 PreparedStatement sel = session.prepare("SELECT * FROM t WHERE k=?");
6664
modified driver-core/src/test/java/com/datastax/driver/core/UserTypesTest.java +19 −18
@@ -63,12 +63,12 @@
6363 int userId = 0;
6464
6565 try {
66- session.execute("USE ks");
66+ session.execute("USE " + keyspace);
6767 PreparedStatement ins = session.prepare("INSERT INTO user(id, addr) VALUES (?, ?)");
6868 PreparedStatement sel = session.prepare("SELECT * FROM user WHERE id=?");
6969
70- UserType addrDef = cluster.getMetadata().getKeyspace("ks").getUserType("address");
71- UserType phoneDef = cluster.getMetadata().getKeyspace("ks").getUserType("phone");
70+ UserType addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("address");
71+ UserType phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone");
7272
7373 UDTValue phone1 = phoneDef.newValue().setString("alias", "home").setString("number", "0123548790");
7474 UDTValue phone2 = phoneDef.newValue().setString("alias", "work").setString("number", "0698265251");
@@ -96,9 +96,9 @@
9696 int userId = 1;
9797
9898 try {
99- session.execute("USE ks");
100- UserType addrDef = cluster.getMetadata().getKeyspace("ks").getUserType("address");
101- UserType phoneDef = cluster.getMetadata().getKeyspace("ks").getUserType("phone");
99+ session.execute("USE " + keyspace);
100+ UserType addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("address");
101+ UserType phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone");
102102
103103 UDTValue phone1 = phoneDef.newValue().setString("alias", "home").setString("number", "0123548790");
104104 UDTValue phone2 = phoneDef.newValue().setString("alias", "work").setString("number", "0698265251");
@@ -124,32 +124,33 @@
124124 @Test(groups = "short")
125125 public void nonExistingTypesTest() throws Exception {
126126 try {
127- session.execute("USE ks");
127+ session.execute("USE " + keyspace);
128128
129- UserType addrDef = cluster.getMetadata().getKeyspace("ks").getUserType("address1");
130- UserType phoneDef = cluster.getMetadata().getKeyspace("ks").getUserType("phone1");
129+ UserType addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("address1");
130+ UserType phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone1");
131131 assertEquals(addrDef, null);
132132 assertEquals(phoneDef, null);
133133
134- addrDef = cluster.getMetadata().getKeyspace("ks").getUserType("address");
135- phoneDef = cluster.getMetadata().getKeyspace("ks").getUserType("phone");
134+ addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("address");
135+ phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone");
136136 assertNotEquals(addrDef, null);
137137 assertNotEquals(phoneDef, null);
138138
139139 // create keyspace
140- session.execute("CREATE KEYSPACE nonExistingTypesTest " +
140+ String nonExistingKeyspace = keyspace + "_nonEx";
141+ session.execute("CREATE KEYSPACE " + nonExistingKeyspace + " " +
141142 "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}");
142- session.execute("USE nonExistingTypesTest");
143+ session.execute("USE " + nonExistingKeyspace);
143144
144- addrDef = cluster.getMetadata().getKeyspace("nonExistingTypesTest").getUserType("address");
145- phoneDef = cluster.getMetadata().getKeyspace("nonExistingTypesTest").getUserType("phone");
145+ addrDef = cluster.getMetadata().getKeyspace(nonExistingKeyspace).getUserType("address");
146+ phoneDef = cluster.getMetadata().getKeyspace(nonExistingKeyspace).getUserType("phone");
146147 assertEquals(addrDef, null);
147148 assertEquals(phoneDef, null);
148149
149- session.execute("USE ks");
150+ session.execute("USE " + keyspace);
150151
151- addrDef = cluster.getMetadata().getKeyspace("ks").getUserType("address");
152- phoneDef = cluster.getMetadata().getKeyspace("ks").getUserType("phone");
152+ addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("address");
153+ phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone");
153154 assertNotEquals(addrDef, null);
154155 assertNotEquals(phoneDef, null);
155156
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderUDTExecutionTest.java +2 −2
@@ -33,7 +33,7 @@
3333
3434 @Test(groups = "short")
3535 public void insertUdtTest() throws Exception {
36- UserType udtType = cluster.getMetadata().getKeyspace("ks").getUserType("udt");
36+ UserType udtType = cluster.getMetadata().getKeyspace(keyspace).getUserType("udt");
3737 UDTValue udtValue = udtType.newValue().setInt("i", 2).setInet("a", InetAddress.getByName("localhost"));
3838
3939 Statement insert = insertInto("udtTest").value("k", 1).value("t", udtValue);
@@ -51,7 +51,7 @@
5151
5252 @Test(groups = "short")
5353 public void should_handle_collections_of_UDT() throws Exception {
54- UserType udtType = cluster.getMetadata().getKeyspace("ks").getUserType("udt");
54+ UserType udtType = cluster.getMetadata().getKeyspace(keyspace).getUserType("udt");
5555 UDTValue udtValue = udtType.newValue().setInt("i", 2).setInet("a", InetAddress.getByName("localhost"));
5656 UDTValue udtValue2 = udtType.newValue().setInt("i", 3).setInet("a", InetAddress.getByName("localhost"));
5757
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperDefaultKeyspaceTest.java +13 −6
@@ -23,6 +23,7 @@
2323 import com.google.common.base.Objects;
2424 import org.testng.annotations.Test;
2525
26+import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT;
2627 import static org.testng.Assert.assertEquals;
2728 import static org.testng.Assert.assertNull;
2829
@@ -34,10 +35,12 @@
3435 */
3536 @CassandraVersion(major=2.1)
3637 public class MapperDefaultKeyspaceTest extends CCMBridge.PerClassSingleNodeCluster {
38+
39+ private static final String KEYSPACE = "mapper_default_keyspace_test_ks";
40+
3741 protected Collection<String> getTableDefinitions() {
3842 return Arrays.asList("CREATE TABLE groups (group_id uuid PRIMARY KEY, name text)",
39- "CREATE TYPE group_name (name text)",
40- "CREATE TABLE groups2 (group_id uuid PRIMARY KEY, name frozen<group_name>)");
43+ "CREATE TYPE IF NOT EXISTS group_name (name text)");
4144 }
4245
4346 /*
@@ -95,7 +98,7 @@
9598 @Test(groups = "short")
9699 public void testTableWithDefaultKeyspace() throws Exception {
97100 // Ensure that the test session is logged into the "ks" keyspace.
98- session.execute("USE ks");
101+ session.execute("USE " + keyspace);
99102
100103 MappingManager manager = new MappingManager(session);
101104 Mapper<Group> m = manager.mapper(Group.class);
@@ -114,7 +117,7 @@
114117 assertNull(m.get(groupId));
115118 }
116119
117- @Table(keyspace = "ks", name = "groups2")
120+ @Table(keyspace = KEYSPACE, name = "groups2")
118121 public static class Group2 {
119122
120123 @PartitionKey
@@ -203,8 +206,12 @@
203206
204207 @Test(groups = "short")
205208 public void testUDTWithDefaultKeyspace() throws Exception {
206- // Ensure that the test session is logged into the "ks" keyspace.
207- session.execute("USE ks");
209+ // Create test specific keyspace and table.
210+ session.execute(String.format("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }", KEYSPACE));
211+ session.execute(String.format("CREATE TYPE IF NOT EXISTS %s.group_name (name text)", KEYSPACE));
212+ session.execute(String.format("CREATE TABLE IF NOT EXISTS %s.groups2 (group_id uuid PRIMARY KEY, name frozen<group_name>)", KEYSPACE));
213+ // Ensure that the test session is logged into the keyspace.
214+ session.execute("USE " + keyspace);
208215
209216 MappingManager manager = new MappingManager(session);
210217 Mapper<Group2> m = manager.mapper(Group2.class);
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperNestedCollectionsTest.java +2 −2
@@ -70,7 +70,7 @@
7070 assertThat(testTable2.getM2()).isEqualTo(m2);
7171 }
7272
73- @UDT(keyspace = "ks", name = "testType")
73+ @UDT(name = "testType")
7474 public static class TestType {
7575 private int i;
7676
@@ -132,7 +132,7 @@
132132 }
133133 }
134134
135- @Table(keyspace = "ks", name = "testTable")
135+ @Table(name = "testTable")
136136 public static class TestTable {
137137 @PartitionKey
138138 private int k;
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperPrimitiveTypesTest.java +1 −1
@@ -119,7 +119,7 @@
119119 }
120120
121121
122- @Table(keyspace = "ks", name = "primitiveTypes")
122+ @Table(name = "primitiveTypes")
123123 public static class PrimitiveTypes {
124124 @PartitionKey
125125 private ByteBuffer byteBufferCol;
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperTest.java +7 −7
@@ -52,7 +52,7 @@
5252 *
5353 * And the next step will be to support UDT (which should be relatively simple).
5454 */
55- @Table(keyspace="ks", name = "users",
55+ @Table(name = "users",
5656 readConsistency="QUORUM",
5757 writeConsistency="QUORUM")
5858 public static class User {
@@ -147,7 +147,7 @@
147147 * the order must be specified (@ClusteringColumn(0), @ClusteringColumn(1), ...).
148148 * The same stands for the @PartitionKey.
149149 */
150- @Table(keyspace = "ks", name = "posts")
150+ @Table(name = "posts")
151151 public static class Post {
152152
153153 @PartitionKey
@@ -263,31 +263,31 @@
263263 // don't have @Param annotation like in the 2 other method, we default to some
264264 // harcoded arg0, arg1, .... A big annoying, and apparently Java 8 will fix that
265265 // somehow, but well, not a huge deal.
266- @Query("SELECT * FROM ks.posts WHERE user_id=:userId AND post_id=:postId")
266+ @Query("SELECT * FROM posts WHERE user_id=:userId AND post_id=:postId")
267267 public Post getOne(@Param("userId") UUID userId,
268268 @Param("postId") UUID postId);
269269
270270 // Note that the following method will be asynchronous (it will use executeAsync
271271 // underneath) because it's return type is a ListenableFuture. Similarly, we know
272272 // that we need to map the result to the Post entity thanks to the return type.
273- @Query("SELECT * FROM ks.posts WHERE user_id=?")
273+ @Query("SELECT * FROM posts WHERE user_id=?")
274274 @QueryParameters(consistency="QUORUM")
275275 public ListenableFuture<Result<Post>> getAllAsync(UUID userId);
276276
277277 // The method above actually query stuff, but if a method is declared to return
278278 // a Statement, it will not execute anything, but just return you the BoundStatement
279279 // ready for execution. That way, you can batch stuff for instance (see usage below).
280- @Query("UPDATE ks.posts SET content=? WHERE user_id=? AND post_id=?")
280+ @Query("UPDATE posts SET content=? WHERE user_id=? AND post_id=?")
281281 public Statement updateContentQuery(String newContent, UUID userId, UUID postId);
282282
283- @Query("SELECT * FROM ks.posts")
283+ @Query("SELECT * FROM posts")
284284 public Result<Post> getAll();
285285 }
286286
287287 @Accessor
288288 public interface UserAccessor {
289289 // Demonstrates use of an enum as an accessor parameter
290- @Query("UPDATE ks.users SET name=?, gender=? WHERE user_id=?")
290+ @Query("UPDATE users SET name=?, gender=? WHERE user_id=?")
291291 ResultSet updateNameAndGender(String name, Gender gender, UUID userId);
292292 }
293293
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperUDTCollectionsTest.java +2 −2
@@ -38,7 +38,7 @@
3838 "CREATE TABLE collection_examples (id int PRIMARY KEY, l list<frozen<sub>>, s set<frozen<sub>>, m1 map<int,frozen<sub>>, m2 map<frozen<sub>,int>, m3 map<frozen<sub>,frozen<sub>>)");
3939 }
4040
41- @UDT(keyspace = "ks", name = "sub")
41+ @UDT(name = "sub")
4242 public static class Sub {
4343 private int i;
4444
@@ -72,7 +72,7 @@
7272 }
7373 }
7474
75- @Table(keyspace = "ks", name = "collection_examples")
75+ @Table(name = "collection_examples")
7676 public static class CollectionExamples {
7777 @PartitionKey
7878 private int id;
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperUDTTest.java +6 −6
@@ -47,7 +47,7 @@
4747 session.execute("TRUNCATE users");
4848 }
4949
50- @Table(keyspace = "ks", name = "users",
50+ @Table(name = "users",
5151 readConsistency = "QUORUM",
5252 writeConsistency = "QUORUM")
5353 public static class User {
@@ -123,7 +123,7 @@
123123 }
124124 }
125125
126- @UDT(keyspace = "ks", name = "address")
126+ @UDT(name = "address")
127127 public static class Address {
128128
129129 // Dummy constant to test that static fields are properly ignored
@@ -199,16 +199,16 @@
199199
200200 @Accessor
201201 public interface UserAccessor {
202- @Query("SELECT * FROM ks.users WHERE user_id=:userId")
202+ @Query("SELECT * FROM users WHERE user_id=:userId")
203203 User getOne(@Param("userId") UUID userId);
204204
205- @Query("UPDATE ks.users SET other_addresses[:name]=:address WHERE user_id=:id")
205+ @Query("UPDATE users SET other_addresses[:name]=:address WHERE user_id=:id")
206206 ResultSet addAddress(@Param("id") UUID id, @Param("name") String addressName, @Param("address") Address address);
207207
208- @Query("UPDATE ks.users SET other_addresses=:addresses where user_id=:id")
208+ @Query("UPDATE users SET other_addresses=:addresses where user_id=:id")
209209 ResultSet setOtherAddresses(@Param("id") UUID id, @Param("addresses") Map<String, Address> addresses);
210210
211- @Query("SELECT * FROM ks.users")
211+ @Query("SELECT * FROM users")
212212 public Result<User> getAll();
213213 }
214214
modified driver-mapping/src/test/java/com/datastax/driver/mapping/SyntheticFieldsMapperTest.java +1 −1
@@ -88,7 +88,7 @@
8888 }
8989 }
9090
91- @Table(keyspace = "ks", name = "synthetic_fields")
91+ @Table(name = "synthetic_fields")
9292 public static class ClassWithSyntheticField {
9393 @PartitionKey
9494 private int id;