kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | a6b44c4c2439e462b5992b43feaedbff5687552cc11a313f3ea990aa144ab628 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-01-28 11:17 +01:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-01-28 11:17 +01:00 |
| Parents | 95e17baa7f4f, b1d245a67292 |
126 files changed
modified driver-core/src/test/java/com/datastax/driver/core/AbstractPoliciesTest.java +53 −86
| @@ -15,6 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 19 | +import org.slf4j.Logger; | |
| 20 | +import org.slf4j.LoggerFactory; | |
| 21 | +import org.testng.annotations.AfterMethod; | |
| 18 | 22 | import org.testng.annotations.BeforeMethod; |
| 19 | 23 | |
| 20 | 24 | import java.net.InetAddress; |
| @@ -23,45 +27,53 @@ | ||
| 23 | 27 | import java.util.Map; |
| 24 | 28 | import java.util.concurrent.Callable; |
| 25 | 29 | |
| 26 | -import static com.datastax.driver.core.TestUtils.*; | |
| 30 | +import static com.datastax.driver.core.ConditionChecker.check; | |
| 31 | +import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_GENERIC_FORMAT; | |
| 32 | +import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT; | |
| 27 | 33 | import static com.datastax.driver.core.querybuilder.QueryBuilder.batch; |
| 28 | 34 | import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; |
| 29 | -import static org.testng.Assert.*; | |
| 35 | +import static java.util.concurrent.TimeUnit.MINUTES; | |
| 36 | +import static org.testng.Assert.assertEquals; | |
| 30 | 37 | |
| 31 | 38 | public abstract class AbstractPoliciesTest extends CCMTestsSupport { |
| 32 | 39 | |
| 33 | - private static final boolean DEBUG = false; | |
| 40 | + private static final Logger logger = LoggerFactory.getLogger(AbstractPoliciesTest.class); | |
| 41 | + private String tableName; | |
| 42 | + | |
| 43 | + private static class SchemaInAgreement implements Callable<Boolean> { | |
| 44 | + | |
| 45 | + private final Cluster cluster; | |
| 46 | + | |
| 47 | + private SchemaInAgreement(Cluster cluster) { | |
| 48 | + this.cluster = cluster; | |
| 49 | + } | |
| 50 | + | |
| 51 | + @Override | |
| 52 | + public Boolean call() throws Exception { | |
| 53 | + return cluster.getMetadata().checkSchemaAgreement(); | |
| 54 | + } | |
| 55 | + } | |
| 34 | 56 | |
| 35 | 57 | protected Map<InetAddress, Integer> coordinators = new HashMap<InetAddress, Integer>(); |
| 36 | 58 | |
| 37 | 59 | protected PreparedStatement prepared; |
| 38 | 60 | |
| 39 | 61 | protected void createSchema(int replicationFactor) { |
| 40 | - final String ks = TestUtils.getAvailableKeyspaceName(); | |
| 41 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, ks, replicationFactor)); | |
| 42 | - // tests fail randomly here with InvalidQueryException: Keyspace 'xxx' does not exist | |
| 43 | - ConditionChecker.awaitUntil(new Callable<Boolean>() { | |
| 44 | - @Override | |
| 45 | - public Boolean call() { | |
| 46 | - return cluster.getMetadata().getKeyspace(ks) != null; | |
| 47 | - } | |
| 48 | - }, 60000); | |
| 49 | - session.execute("USE " + ks); | |
| 50 | - session.execute(String.format("CREATE TABLE %s (k int PRIMARY KEY, i int)", SIMPLE_TABLE)); | |
| 62 | + final String ks = TestUtils.generateIdentifier("ks_"); | |
| 63 | + tableName = TestUtils.generateIdentifier("table_"); | |
| 64 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, ks, replicationFactor)); | |
| 65 | + useKeyspace(ks); | |
| 66 | + session().execute(String.format("CREATE TABLE %s (k int PRIMARY KEY, i int)", tableName)); | |
| 67 | + check().before(5, MINUTES).that(new SchemaInAgreement(cluster())).becomesTrue(); | |
| 51 | 68 | } |
| 52 | 69 | |
| 53 | 70 | protected void createMultiDCSchema(int dc1RF, int dc2RF) { |
| 54 | - final String ks = TestUtils.getAvailableKeyspaceName(); | |
| 55 | - session.execute(String.format(CREATE_KEYSPACE_GENERIC_FORMAT, ks, "NetworkTopologyStrategy", String.format("'dc1' : %d, 'dc2' : %d", dc1RF, dc2RF))); | |
| 56 | - // tests fail randomly here with InvalidQueryException: Keyspace 'xxx' does not exist | |
| 57 | - ConditionChecker.awaitUntil(new Callable<Boolean>() { | |
| 58 | - @Override | |
| 59 | - public Boolean call() { | |
| 60 | - return cluster.getMetadata().getKeyspace(ks) != null; | |
| 61 | - } | |
| 62 | - }, 60000); | |
| 63 | - session.execute("USE " + ks); | |
| 64 | - session.execute(String.format("CREATE TABLE %s (k int PRIMARY KEY, i int)", SIMPLE_TABLE)); | |
| 71 | + final String ks = TestUtils.generateIdentifier("ks_"); | |
| 72 | + tableName = TestUtils.generateIdentifier("table_"); | |
| 73 | + session().execute(String.format(CREATE_KEYSPACE_GENERIC_FORMAT, ks, "NetworkTopologyStrategy", String.format("'dc1' : %d, 'dc2' : %d", dc1RF, dc2RF))); | |
| 74 | + useKeyspace(ks); | |
| 75 | + session().execute(String.format("CREATE TABLE %s (k int PRIMARY KEY, i int)", tableName)); | |
| 76 | + check().before(5, MINUTES).that(new SchemaInAgreement(cluster())).becomesTrue(); | |
| 65 | 77 | } |
| 66 | 78 | |
| 67 | 79 | /** |
| @@ -78,6 +90,12 @@ | ||
| 78 | 90 | coordinators = new HashMap<InetAddress, Integer>(); |
| 79 | 91 | } |
| 80 | 92 | |
| 93 | + @AfterMethod(groups = "long") | |
| 94 | + protected void pause() { | |
| 95 | + // pause before engaging in another expensive CCM cluster creation | |
| 96 | + Uninterruptibles.sleepUninterruptibly(1, MINUTES); | |
| 97 | + } | |
| 98 | + | |
| 81 | 99 | private String queriedMapString() { |
| 82 | 100 | StringBuilder sb = new StringBuilder(); |
| 83 | 101 | sb.append("{"); |
| @@ -92,67 +110,15 @@ | ||
| 92 | 110 | protected void assertQueried(String host, int n) { |
| 93 | 111 | try { |
| 94 | 112 | Integer queried = coordinators.get(InetAddress.getByName(host)); |
| 95 | - if (DEBUG) | |
| 96 | - System.out.println(String.format("Expected: %s\tReceived: %s", n, queried)); | |
| 97 | - else { | |
| 98 | - assertEquals(queried == null ? 0 : queried, n, queriedMapString()); | |
| 99 | - } | |
| 100 | - } catch (Exception e) { | |
| 101 | - throw new RuntimeException(e); | |
| 102 | - } | |
| 103 | - } | |
| 104 | - | |
| 105 | - protected void assertQueriedAtLeast(String host, int n) { | |
| 106 | - try { | |
| 107 | - Integer queried = coordinators.get(InetAddress.getByName(host)); | |
| 108 | - queried = queried == null ? 0 : queried; | |
| 109 | - if (DEBUG) | |
| 110 | - System.out.println(String.format("Expected > %s\tReceived: %s", n, queried)); | |
| 113 | + if (logger.isDebugEnabled()) | |
| 114 | + logger.debug(String.format("Expected: %s\tReceived: %s", n, queried)); | |
| 111 | 115 | else |
| 112 | - assertTrue(queried >= n, "For " + host); | |
| 113 | - } catch (Exception e) { | |
| 114 | - throw new RuntimeException(e); | |
| 115 | - } | |
| 116 | - } | |
| 117 | - | |
| 118 | - /** | |
| 119 | - * Assert that one of the nodes in the list was queried with n, no matter which one | |
| 120 | - */ | |
| 121 | - protected void assertOneNodeQueried(int n, String... hosts) { | |
| 122 | - try { | |
| 123 | - boolean found = false; | |
| 124 | - for (String host : hosts) { | |
| 125 | - InetAddress addr = InetAddress.getByName(host); | |
| 126 | - int queried = coordinators.containsKey(addr) ? coordinators.get(addr) : 0; | |
| 127 | - if (DEBUG) | |
| 128 | - System.out.println(String.format("Expected: %s\tReceived: %s", n, queried)); | |
| 129 | - else { | |
| 130 | - | |
| 131 | - if (n == queried) { | |
| 132 | - if (found) | |
| 133 | - throw new AssertionError(String.format("Found 2 nodes with %s queries in %s", n, queriedMapString())); | |
| 134 | - found = true; | |
| 135 | - } else { | |
| 136 | - if (queried != 0) | |
| 137 | - throw new AssertionError(String.format("Host %s should have be queried: %s", addr, queriedMapString())); | |
| 138 | - } | |
| 139 | - } | |
| 140 | - } | |
| 141 | - if (!found) | |
| 142 | - throw new AssertionError("Found no host queried exactly " + n + " times in " + queriedMapString()); | |
| 116 | + assertEquals(queried == null ? 0 : queried, n, queriedMapString()); | |
| 143 | 117 | } catch (Exception e) { |
| 144 | 118 | throw new RuntimeException(e); |
| 145 | 119 | } |
| 146 | 120 | } |
| 147 | 121 | |
| 148 | - protected void failDebug(String message) { | |
| 149 | - if (DEBUG) | |
| 150 | - System.out.println(message); | |
| 151 | - else | |
| 152 | - fail(message); | |
| 153 | - } | |
| 154 | - | |
| 155 | - | |
| 156 | 122 | /** |
| 157 | 123 | * Init methods that handle writes using batch and consistency options. |
| 158 | 124 | */ |
| @@ -170,7 +136,7 @@ | ||
| 170 | 136 | |
| 171 | 137 | protected void init(int n, boolean batch, ConsistencyLevel cl) { |
| 172 | 138 | write(n, batch, cl); |
| 173 | - prepared = session.prepare("SELECT * FROM " + SIMPLE_TABLE + " WHERE k = ?").setConsistencyLevel(cl); | |
| 139 | + prepared = session().prepare("SELECT * FROM " + tableName + " WHERE k = ?").setConsistencyLevel(cl); | |
| 174 | 140 | } |
| 175 | 141 | |
| 176 | 142 | protected void write(int n) { |
| @@ -191,11 +157,11 @@ | ||
| 191 | 157 | for (int i = 0; i < n; ++i) |
| 192 | 158 | if (batch) |
| 193 | 159 | // BUG: WriteType == SIMPLE |
| 194 | - session.execute(batch() | |
| 195 | - .add(insertInto(SIMPLE_TABLE).values(new String[]{"k", "i"}, new Object[]{0, 0})) | |
| 160 | + session().execute(batch() | |
| 161 | + .add(insertInto(tableName).values(new String[]{"k", "i"}, new Object[]{0, 0})) | |
| 196 | 162 | .setConsistencyLevel(cl)); |
| 197 | 163 | else |
| 198 | - session.execute(new SimpleStatement(String.format("INSERT INTO %s(k, i) VALUES (0, 0)", SIMPLE_TABLE)).setConsistencyLevel(cl)); | |
| 164 | + session().execute(new SimpleStatement(String.format("INSERT INTO %s(k, i) VALUES (0, 0)", tableName)).setConsistencyLevel(cl)); | |
| 199 | 165 | } |
| 200 | 166 | |
| 201 | 167 | |
| @@ -218,12 +184,13 @@ | ||
| 218 | 184 | if (usePrepared) { |
| 219 | 185 | BoundStatement bs = prepared.bind(0); |
| 220 | 186 | for (int i = 0; i < n; ++i) |
| 221 | - addCoordinator(session.execute(bs)); | |
| 187 | + addCoordinator(session().execute(bs)); | |
| 222 | 188 | } else { |
| 223 | 189 | ByteBuffer routingKey = ByteBuffer.allocate(4); |
| 224 | 190 | routingKey.putInt(0, 0); |
| 225 | 191 | for (int i = 0; i < n; ++i) |
| 226 | - addCoordinator(session.execute(new SimpleStatement(String.format("SELECT * FROM %s WHERE k = 0", SIMPLE_TABLE)).setRoutingKey(routingKey).setConsistencyLevel(cl))); | |
| 192 | + addCoordinator(session().execute(new SimpleStatement(String.format("SELECT * FROM %s WHERE k = 0", tableName)).setRoutingKey(routingKey).setConsistencyLevel(cl))); | |
| 227 | 193 | } |
| 228 | 194 | } |
| 195 | + | |
| 229 | 196 | } |
modified driver-core/src/test/java/com/datastax/driver/core/AbstractReconnectionHandlerTest.java +13 −11
| @@ -33,6 +33,7 @@ | ||
| 33 | 33 | import java.util.concurrent.*; |
| 34 | 34 | import java.util.concurrent.atomic.AtomicReference; |
| 35 | 35 | |
| 36 | +import static com.datastax.driver.core.ConditionChecker.check; | |
| 36 | 37 | import static org.assertj.core.api.Assertions.assertThat; |
| 37 | 38 | import static org.mockito.Mockito.*; |
| 38 | 39 | import static org.testng.Assert.fail; |
| @@ -43,8 +44,14 @@ | ||
| 43 | 44 | ScheduledExecutorService executor; |
| 44 | 45 | MockReconnectionSchedule schedule; |
| 45 | 46 | MockReconnectionWork work; |
| 46 | - final AtomicReference<ListenableFuture<?>> future = new AtomicReference<ListenableFuture<?>>(); | |
| 47 | + AtomicReference<ListenableFuture<?>> future = new AtomicReference<ListenableFuture<?>>(); | |
| 47 | 48 | AbstractReconnectionHandler handler; |
| 49 | + Callable<Boolean> nextTryAssigned = new Callable<Boolean>() { | |
| 50 | + @Override | |
| 51 | + public Boolean call() throws Exception { | |
| 52 | + return handler.handlerFuture.nextTry != null; | |
| 53 | + } | |
| 54 | + }; | |
| 48 | 55 | |
| 49 | 56 | @BeforeMethod(groups = {"unit", "short"}) |
| 50 | 57 | public void setup() { |
| @@ -60,7 +67,7 @@ | ||
| 60 | 67 | |
| 61 | 68 | @Override |
| 62 | 69 | protected void onReconnection(Connection connection) { |
| 63 | - work.onReconnection(connection); | |
| 70 | + work.onReconnection(); | |
| 64 | 71 | } |
| 65 | 72 | }; |
| 66 | 73 | } |
| @@ -151,12 +158,7 @@ | ||
| 151 | 158 | verify(executor, timeout(10000)).schedule(handler, schedule.delay, TimeUnit.MILLISECONDS); |
| 152 | 159 | |
| 153 | 160 | // Wait until nextTry is assigned after schedule completes. |
| 154 | - ConditionChecker.awaitUntil(new Callable<Boolean>() { | |
| 155 | - @Override | |
| 156 | - public Boolean call() throws Exception { | |
| 157 | - return handler.handlerFuture.nextTry != null; | |
| 158 | - } | |
| 159 | - }, 10000); | |
| 161 | + check().before(10000).that(nextTryAssigned).becomesTrue(); | |
| 160 | 162 | |
| 161 | 163 | future.get().cancel(false); |
| 162 | 164 | |
| @@ -343,7 +345,7 @@ | ||
| 343 | 345 | tries += 1; |
| 344 | 346 | logger.debug("in reconnection work, wait for tick from main thread"); |
| 345 | 347 | try { |
| 346 | - barrier.await(10, TimeUnit.SECONDS); | |
| 348 | + barrier.await(60, TimeUnit.SECONDS); | |
| 347 | 349 | logger.debug("in reconnection work, got tick from main thread, proceeding"); |
| 348 | 350 | } catch (Exception e) { |
| 349 | 351 | fail("Error while waiting for tick", e); |
| @@ -364,14 +366,14 @@ | ||
| 364 | 366 | public void tick() { |
| 365 | 367 | logger.debug("send tick to reconnection work"); |
| 366 | 368 | try { |
| 367 | - barrier.await(10, TimeUnit.SECONDS); | |
| 369 | + barrier.await(60, TimeUnit.SECONDS); | |
| 368 | 370 | } catch (Exception e) { |
| 369 | 371 | fail("Error while sending tick, no thread was waiting", e); |
| 370 | 372 | } |
| 371 | 373 | barrier.reset(); |
| 372 | 374 | } |
| 373 | 375 | |
| 374 | - protected void onReconnection(Connection connection) { | |
| 376 | + protected void onReconnection() { | |
| 375 | 377 | success = true; |
| 376 | 378 | } |
| 377 | 379 | } |
modified driver-core/src/test/java/com/datastax/driver/core/AggregateMetadataTest.java +18 −21
| @@ -18,12 +18,9 @@ | ||
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | 19 | import org.testng.annotations.Test; |
| 20 | 20 | |
| 21 | -import java.util.Collection; | |
| 22 | - | |
| 23 | 21 | import static com.datastax.driver.core.Assertions.assertThat; |
| 24 | 22 | import static com.datastax.driver.core.DataType.cint; |
| 25 | 23 | import static com.datastax.driver.core.DataType.text; |
| 26 | -import static com.google.common.collect.Lists.newArrayList; | |
| 27 | 24 | |
| 28 | 25 | @CassandraVersion(major = 2.2) |
| 29 | 26 | @CCMConfig(config = "enable_user_defined_functions:true") |
| @@ -35,10 +32,10 @@ | ||
| 35 | 32 | String cqlFunction = String.format("CREATE FUNCTION %s.cat(s text,v int) RETURNS NULL ON NULL INPUT RETURNS text LANGUAGE java AS 'return s+v;';", keyspace); |
| 36 | 33 | String cqlAggregate = String.format("CREATE AGGREGATE %s.cat_tos(int) SFUNC cat STYPE text INITCOND '0';", keyspace); |
| 37 | 34 | // when |
| 38 | - session.execute(cqlFunction); | |
| 39 | - session.execute(cqlAggregate); | |
| 35 | + session().execute(cqlFunction); | |
| 36 | + session().execute(cqlAggregate); | |
| 40 | 37 | // then |
| 41 | - KeyspaceMetadata keyspace = cluster.getMetadata().getKeyspace(this.keyspace); | |
| 38 | + KeyspaceMetadata keyspace = cluster().getMetadata().getKeyspace(this.keyspace); | |
| 42 | 39 | FunctionMetadata stateFunc = keyspace.getFunction("cat", text(), cint()); |
| 43 | 40 | AggregateMetadata aggregate = keyspace.getAggregate("cat_tos", cint()); |
| 44 | 41 | assertThat(aggregate).isNotNull(); |
| @@ -62,10 +59,10 @@ | ||
| 62 | 59 | String cqlFunction = String.format("CREATE FUNCTION %s.inc(i int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return i+1;';", keyspace); |
| 63 | 60 | String cqlAggregate = String.format("CREATE AGGREGATE %s.mycount() SFUNC inc STYPE int INITCOND 0;", keyspace); |
| 64 | 61 | // when |
| 65 | - session.execute(cqlFunction); | |
| 66 | - session.execute(cqlAggregate); | |
| 62 | + session().execute(cqlFunction); | |
| 63 | + session().execute(cqlAggregate); | |
| 67 | 64 | // then |
| 68 | - KeyspaceMetadata keyspace = cluster.getMetadata().getKeyspace(this.keyspace); | |
| 65 | + KeyspaceMetadata keyspace = cluster().getMetadata().getKeyspace(this.keyspace); | |
| 69 | 66 | FunctionMetadata stateFunc = keyspace.getFunction("inc", cint()); |
| 70 | 67 | AggregateMetadata aggregate = keyspace.getAggregate("mycount"); |
| 71 | 68 | assertThat(aggregate).isNotNull(); |
| @@ -90,11 +87,11 @@ | ||
| 90 | 87 | String cqlFunction2 = String.format("CREATE FUNCTION %s.announce(i int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return i;';", keyspace); |
| 91 | 88 | String cqlAggregate = String.format("CREATE AGGREGATE %s.prettysum(int) SFUNC plus STYPE int FINALFUNC announce INITCOND 0;", keyspace); |
| 92 | 89 | // when |
| 93 | - session.execute(cqlFunction1); | |
| 94 | - session.execute(cqlFunction2); | |
| 95 | - session.execute(cqlAggregate); | |
| 90 | + session().execute(cqlFunction1); | |
| 91 | + session().execute(cqlFunction2); | |
| 92 | + session().execute(cqlAggregate); | |
| 96 | 93 | // then |
| 97 | - KeyspaceMetadata keyspace = cluster.getMetadata().getKeyspace(this.keyspace); | |
| 94 | + KeyspaceMetadata keyspace = cluster().getMetadata().getKeyspace(this.keyspace); | |
| 98 | 95 | FunctionMetadata stateFunc = keyspace.getFunction("plus", cint(), cint()); |
| 99 | 96 | FunctionMetadata finalFunc = keyspace.getFunction("announce", cint()); |
| 100 | 97 | AggregateMetadata aggregate = keyspace.getAggregate("prettysum", cint()); |
| @@ -120,10 +117,10 @@ | ||
| 120 | 117 | String cqlFunction = String.format("CREATE FUNCTION %s.plus2(i int, j int) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return i+j;';", keyspace); |
| 121 | 118 | String cqlAggregate = String.format("CREATE AGGREGATE %s.sum(int) SFUNC plus2 STYPE int;", keyspace); |
| 122 | 119 | // when |
| 123 | - session.execute(cqlFunction); | |
| 124 | - session.execute(cqlAggregate); | |
| 120 | + session().execute(cqlFunction); | |
| 121 | + session().execute(cqlAggregate); | |
| 125 | 122 | // then |
| 126 | - KeyspaceMetadata keyspace = cluster.getMetadata().getKeyspace(this.keyspace); | |
| 123 | + KeyspaceMetadata keyspace = cluster().getMetadata().getKeyspace(this.keyspace); | |
| 127 | 124 | FunctionMetadata stateFunc = keyspace.getFunction("plus2", cint(), cint()); |
| 128 | 125 | AggregateMetadata aggregate = keyspace.getAggregate("sum", cint()); |
| 129 | 126 | assertThat(aggregate).isNotNull(); |
| @@ -155,10 +152,10 @@ | ||
| 155 | 152 | + "STYPE \"Address\";", |
| 156 | 153 | keyspace); |
| 157 | 154 | // when |
| 158 | - session.execute(cqlFunction); | |
| 159 | - session.execute(cqlAggregate); | |
| 155 | + session().execute(cqlFunction); | |
| 156 | + session().execute(cqlAggregate); | |
| 160 | 157 | // then |
| 161 | - KeyspaceMetadata keyspace = cluster.getMetadata().getKeyspace(this.keyspace); | |
| 158 | + KeyspaceMetadata keyspace = cluster().getMetadata().getKeyspace(this.keyspace); | |
| 162 | 159 | UserType addressType = keyspace.getUserType("\"Address\""); |
| 163 | 160 | FunctionMetadata stateFunc = keyspace.getFunction("\"MY_FUNC\"", addressType, addressType); |
| 164 | 161 | AggregateMetadata aggregate = keyspace.getAggregate("\"MY_AGGREGATE\"", addressType); |
| @@ -175,8 +172,8 @@ | ||
| 175 | 172 | } |
| 176 | 173 | |
| 177 | 174 | @Override |
| 178 | - public Collection<String> createTestFixtures() { | |
| 179 | - return newArrayList( | |
| 175 | + public void onTestContextInitialized() { | |
| 176 | + execute( | |
| 180 | 177 | String.format("CREATE TYPE IF NOT EXISTS %s.phone (number text)", keyspace), |
| 181 | 178 | String.format("CREATE TYPE IF NOT EXISTS %s.\"Address\" (" |
| 182 | 179 | + " street text," |
modified driver-core/src/test/java/com/datastax/driver/core/AsyncQueryTest.java +22 −32
| @@ -23,7 +23,6 @@ | ||
| 23 | 23 | import org.testng.annotations.Test; |
| 24 | 24 | |
| 25 | 25 | import java.util.Collection; |
| 26 | -import java.util.List; | |
| 27 | 26 | import java.util.concurrent.*; |
| 28 | 27 | |
| 29 | 28 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -38,18 +37,15 @@ | ||
| 38 | 37 | } |
| 39 | 38 | |
| 40 | 39 | @Override |
| 41 | - public Collection<String> createTestFixtures() { | |
| 42 | - List<String> definitions = Lists.newArrayList(); | |
| 43 | - | |
| 40 | + public void onTestContextInitialized() { | |
| 44 | 41 | for (Object[] objects : keyspace()) { |
| 45 | 42 | String keyspace = (String) objects[0]; |
| 46 | - | |
| 47 | - definitions.add(String.format("create keyspace %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", keyspace)); | |
| 48 | - definitions.add(String.format("create table %s.foo(k int primary key, v int)", keyspace)); | |
| 49 | - definitions.add(String.format("insert into %s.foo (k, v) values (1, 1)", keyspace)); | |
| 43 | + execute( | |
| 44 | + String.format("create keyspace %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", keyspace), | |
| 45 | + String.format("create table %s.foo(k int primary key, v int)", keyspace), | |
| 46 | + String.format("insert into %s.foo (k, v) values (1, 1)", keyspace) | |
| 47 | + ); | |
| 50 | 48 | } |
| 51 | - | |
| 52 | - return definitions; | |
| 53 | 49 | } |
| 54 | 50 | |
| 55 | 51 | /** |
| @@ -57,13 +53,13 @@ | ||
| 57 | 53 | */ |
| 58 | 54 | @Test(groups = "short") |
| 59 | 55 | public void cancelled_query_should_release_the_connection() throws InterruptedException { |
| 60 | - ResultSetFuture future = session.executeAsync("select release_version from system.local"); | |
| 56 | + ResultSetFuture future = session().executeAsync("select release_version from system.local"); | |
| 61 | 57 | future.cancel(true); |
| 62 | 58 | assertTrue(future.isCancelled()); |
| 63 | 59 | |
| 64 | 60 | TimeUnit.MILLISECONDS.sleep(100); |
| 65 | 61 | |
| 66 | - HostConnectionPool pool = getPool(session); | |
| 62 | + HostConnectionPool pool = getPool(session()); | |
| 67 | 63 | for (Connection connection : pool.connections) { |
| 68 | 64 | assertEquals(connection.inFlight.get(), 0); |
| 69 | 65 | } |
| @@ -73,26 +69,20 @@ | ||
| 73 | 69 | public void should_init_cluster_and_session_if_needed() throws Exception { |
| 74 | 70 | // For this test we need an uninitialized cluster, so we can't reuse the one provided by the |
| 75 | 71 | // parent class. Rebuild a new one with the same (unique) host. |
| 76 | - Host host = cluster.getMetadata().allHosts().iterator().next(); | |
| 72 | + Host host = cluster().getMetadata().allHosts().iterator().next(); | |
| 77 | 73 | |
| 78 | - Cluster cluster2 = null; | |
| 79 | - try { | |
| 80 | - cluster2 = Cluster.builder() | |
| 81 | - .addContactPointsWithPorts(Lists.newArrayList(host.getSocketAddress())) | |
| 82 | - .build(); | |
| 83 | - Session session2 = cluster2.newSession(); | |
| 84 | - | |
| 85 | - // Neither cluster2 nor session2 are initialized at this point | |
| 86 | - assertThat(cluster2.manager.metadata).isNull(); | |
| 87 | - | |
| 88 | - ResultSetFuture future = session2.executeAsync("select release_version from system.local"); | |
| 89 | - Row row = Uninterruptibles.getUninterruptibly(future).one(); | |
| 90 | - | |
| 91 | - assertThat(row.getString(0)).isNotEmpty(); | |
| 92 | - } finally { | |
| 93 | - if (cluster2 != null) | |
| 94 | - cluster2.close(); | |
| 95 | - } | |
| 74 | + Cluster cluster2 = register(Cluster.builder() | |
| 75 | + .addContactPointsWithPorts(Lists.newArrayList(host.getSocketAddress())) | |
| 76 | + .build()); | |
| 77 | + Session session2 = cluster2.newSession(); | |
| 78 | + | |
| 79 | + // Neither cluster2 nor session2 are initialized at this point | |
| 80 | + assertThat(cluster2.manager.metadata).isNull(); | |
| 81 | + | |
| 82 | + ResultSetFuture future = session2.executeAsync("select release_version from system.local"); | |
| 83 | + Row row = Uninterruptibles.getUninterruptibly(future).one(); | |
| 84 | + | |
| 85 | + assertThat(row.getString(0)).isNotEmpty(); | |
| 96 | 86 | } |
| 97 | 87 | |
| 98 | 88 | @Test(groups = "short", dataProvider = "keyspace", enabled = false, |
| @@ -130,7 +120,7 @@ | ||
| 130 | 120 | } |
| 131 | 121 | |
| 132 | 122 | private ListenableFuture<Integer> connectAndQuery(String keyspace, Executor executor) { |
| 133 | - ListenableFuture<Session> sessionFuture = cluster.connectAsync(keyspace); | |
| 123 | + ListenableFuture<Session> sessionFuture = cluster().connectAsync(keyspace); | |
| 134 | 124 | ListenableFuture<ResultSet> queryFuture = Futures.transform(sessionFuture, new AsyncFunction<Session, ResultSet>() { |
| 135 | 125 | @Override |
| 136 | 126 | public ListenableFuture<ResultSet> apply(Session session) throws Exception { |
modified driver-core/src/test/java/com/datastax/driver/core/AsyncResultSetTest.java +7 −8
| @@ -16,14 +16,12 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | -import com.google.common.collect.Lists; | |
| 20 | 19 | import com.google.common.util.concurrent.AsyncFunction; |
| 21 | 20 | import com.google.common.util.concurrent.Futures; |
| 22 | 21 | import com.google.common.util.concurrent.ListenableFuture; |
| 23 | 22 | import org.testng.annotations.BeforeMethod; |
| 24 | 23 | import org.testng.annotations.Test; |
| 25 | 24 | |
| 26 | -import java.util.Collection; | |
| 27 | 25 | import java.util.Set; |
| 28 | 26 | import java.util.concurrent.ConcurrentSkipListSet; |
| 29 | 27 | |
| @@ -31,15 +29,16 @@ | ||
| 31 | 29 | |
| 32 | 30 | @CassandraVersion(major = 2.0, description = "uses paging") |
| 33 | 31 | public class AsyncResultSetTest extends CCMTestsSupport { |
| 32 | + | |
| 34 | 33 | @Override |
| 35 | - public Collection<String> createTestFixtures() { | |
| 36 | - return Lists.newArrayList( | |
| 34 | + public void onTestContextInitialized() { | |
| 35 | + execute( | |
| 37 | 36 | "create table ints (i int primary key)"); |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | 39 | @BeforeMethod(groups = "short") |
| 41 | 40 | public void cleanup() { |
| 42 | - session.execute("truncate ints"); | |
| 41 | + session().execute("truncate ints"); | |
| 43 | 42 | } |
| 44 | 43 | |
| 45 | 44 | @Test(groups = "short") |
| @@ -54,13 +53,13 @@ | ||
| 54 | 53 | |
| 55 | 54 | private void should_iterate_result_set_asynchronously(int totalCount, int fetchSize) { |
| 56 | 55 | for (int i = 0; i < totalCount; i++) |
| 57 | - session.execute(String.format("insert into ints (i) values (%d)", i)); | |
| 56 | + session().execute(String.format("insert into ints (i) values (%d)", i)); | |
| 58 | 57 | |
| 59 | 58 | Statement statement = new SimpleStatement("select * from ints").setFetchSize(fetchSize); |
| 60 | 59 | ResultsAccumulator results = new ResultsAccumulator(); |
| 61 | 60 | |
| 62 | 61 | ListenableFuture<ResultSet> future = Futures.transform( |
| 63 | - session.executeAsync(statement), | |
| 62 | + session().executeAsync(statement), | |
| 64 | 63 | results); |
| 65 | 64 | |
| 66 | 65 | Futures.getUnchecked(future); |
| @@ -69,7 +68,7 @@ | ||
| 69 | 68 | } |
| 70 | 69 | |
| 71 | 70 | /** |
| 72 | - * Dummy tranformation that accumulates all traversed results | |
| 71 | + * Dummy transformation that accumulates all traversed results | |
| 73 | 72 | */ |
| 74 | 73 | static class ResultsAccumulator implements AsyncFunction<ResultSet, ResultSet> { |
| 75 | 74 | final Set<Integer> all = new ConcurrentSkipListSet<Integer>(); |
modified driver-core/src/test/java/com/datastax/driver/core/AuthenticationTest.java +7 −7
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | public void sleepIf12() { |
| 41 | 41 | // For C* 1.2, sleep before attempting to connect as there is a small delay between |
| 42 | 42 | // user being created. |
| 43 | - if (ccm.getVersion().getMajor() < 2) { | |
| 43 | + if (ccm().getVersion().getMajor() < 2) { | |
| 44 | 44 | Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); |
| 45 | 45 | } |
| 46 | 46 | } |
| @@ -49,8 +49,8 @@ | ||
| 49 | 49 | public void should_connect_with_credentials() throws InterruptedException { |
| 50 | 50 | PlainTextAuthProvider authProvider = spy(new PlainTextAuthProvider("cassandra", "cassandra")); |
| 51 | 51 | Cluster cluster = Cluster.builder() |
| 52 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 53 | - .withPort(ccm.getBinaryPort()) | |
| 52 | + .addContactPoints(getContactPoints()) | |
| 53 | + .withPort(ccm().getBinaryPort()) | |
| 54 | 54 | .withAuthProvider(authProvider) |
| 55 | 55 | .build(); |
| 56 | 56 | cluster.connect(); |
| @@ -60,8 +60,8 @@ | ||
| 60 | 60 | @Test(groups = "short", expectedExceptions = AuthenticationException.class) |
| 61 | 61 | public void should_fail_to_connect_with_wrong_credentials() throws InterruptedException { |
| 62 | 62 | Cluster cluster = register(Cluster.builder() |
| 63 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 64 | - .withPort(ccm.getBinaryPort()) | |
| 63 | + .addContactPoints(getContactPoints()) | |
| 64 | + .withPort(ccm().getBinaryPort()) | |
| 65 | 65 | .withCredentials("bogus", "bogus") |
| 66 | 66 | .build()); |
| 67 | 67 | cluster.connect(); |
| @@ -70,8 +70,8 @@ | ||
| 70 | 70 | @Test(groups = "short", expectedExceptions = AuthenticationException.class) |
| 71 | 71 | public void should_fail_to_connect_without_credentials() throws InterruptedException { |
| 72 | 72 | Cluster cluster = register(Cluster.builder() |
| 73 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 74 | - .withPort(ccm.getBinaryPort()) | |
| 73 | + .addContactPoints(getContactPoints()) | |
| 74 | + .withPort(ccm().getBinaryPort()) | |
| 75 | 75 | .build()); |
| 76 | 76 | cluster.connect(); |
| 77 | 77 | } |
modified driver-core/src/test/java/com/datastax/driver/core/BatchStatementTest.java +9 −12
| @@ -19,9 +19,6 @@ | ||
| 19 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 20 | 20 | import org.testng.annotations.Test; |
| 21 | 21 | |
| 22 | -import java.util.Collection; | |
| 23 | -import java.util.Collections; | |
| 24 | - | |
| 25 | 22 | import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD; |
| 26 | 23 | import static org.testng.Assert.assertEquals; |
| 27 | 24 | import static org.testng.Assert.assertTrue; |
| @@ -30,14 +27,14 @@ | ||
| 30 | 27 | public class BatchStatementTest extends CCMTestsSupport { |
| 31 | 28 | |
| 32 | 29 | @Override |
| 33 | - public Collection<String> createTestFixtures() { | |
| 34 | - return Collections.singletonList("CREATE TABLE test (k text, v int, PRIMARY KEY (k, v))"); | |
| 30 | + public void onTestContextInitialized() { | |
| 31 | + execute("CREATE TABLE test (k text, v int, PRIMARY KEY (k, v))"); | |
| 35 | 32 | } |
| 36 | 33 | |
| 37 | 34 | @Test(groups = "short") |
| 38 | 35 | public void simpleBatchTest() { |
| 39 | 36 | try { |
| 40 | - PreparedStatement st = session.prepare("INSERT INTO test (k, v) VALUES (?, ?)"); | |
| 37 | + PreparedStatement st = session().prepare("INSERT INTO test (k, v) VALUES (?, ?)"); | |
| 41 | 38 | |
| 42 | 39 | BatchStatement batch = new BatchStatement(); |
| 43 | 40 | |
| @@ -47,9 +44,9 @@ | ||
| 47 | 44 | |
| 48 | 45 | assertEquals(3, batch.size()); |
| 49 | 46 | |
| 50 | - session.execute(batch); | |
| 47 | + session().execute(batch); | |
| 51 | 48 | |
| 52 | - ResultSet rs = session.execute("SELECT * FROM test"); | |
| 49 | + ResultSet rs = session().execute("SELECT * FROM test"); | |
| 53 | 50 | |
| 54 | 51 | Row r; |
| 55 | 52 | |
| @@ -69,14 +66,14 @@ | ||
| 69 | 66 | |
| 70 | 67 | } catch (UnsupportedFeatureException e) { |
| 71 | 68 | // This is expected when testing the protocol v1 |
| 72 | - assertEquals(cluster.getConfiguration().getProtocolOptions().getProtocolVersion(), ProtocolVersion.V1); | |
| 69 | + assertEquals(cluster().getConfiguration().getProtocolOptions().getProtocolVersion(), ProtocolVersion.V1); | |
| 73 | 70 | } |
| 74 | 71 | } |
| 75 | 72 | |
| 76 | 73 | @Test(groups = "short") |
| 77 | 74 | @CassandraVersion(major = 2.0, minor = 9, description = "This will only work with C* 2.0.9 (CASSANDRA-7337)") |
| 78 | 75 | public void casBatchTest() { |
| 79 | - PreparedStatement st = session.prepare("INSERT INTO test (k, v) VALUES (?, ?) IF NOT EXISTS"); | |
| 76 | + PreparedStatement st = session().prepare("INSERT INTO test (k, v) VALUES (?, ?) IF NOT EXISTS"); | |
| 80 | 77 | |
| 81 | 78 | BatchStatement batch = new BatchStatement(); |
| 82 | 79 | |
| @@ -86,12 +83,12 @@ | ||
| 86 | 83 | |
| 87 | 84 | assertEquals(3, batch.size()); |
| 88 | 85 | |
| 89 | - ResultSet rs = session.execute(batch); | |
| 86 | + ResultSet rs = session().execute(batch); | |
| 90 | 87 | Row r = rs.one(); |
| 91 | 88 | assertTrue(!r.isNull("[applied]")); |
| 92 | 89 | assertEquals(r.getBool("[applied]"), true); |
| 93 | 90 | |
| 94 | - rs = session.execute(batch); | |
| 91 | + rs = session().execute(batch); | |
| 95 | 92 | r = rs.one(); |
| 96 | 93 | assertTrue(!r.isNull("[applied]")); |
| 97 | 94 | assertEquals(r.getBool("[applied]"), false); |
modified driver-core/src/test/java/com/datastax/driver/core/BoundStatementTest.java +3 −5
| @@ -20,8 +20,6 @@ | ||
| 20 | 20 | import org.testng.annotations.BeforeClass; |
| 21 | 21 | import org.testng.annotations.Test; |
| 22 | 22 | |
| 23 | -import java.util.Collection; | |
| 24 | - | |
| 25 | 23 | import static org.assertj.core.api.Assertions.assertThat; |
| 26 | 24 | import static org.assertj.core.api.Assertions.fail; |
| 27 | 25 | |
| @@ -30,13 +28,13 @@ | ||
| 30 | 28 | PreparedStatement prepared; |
| 31 | 29 | |
| 32 | 30 | @Override |
| 33 | - public Collection<String> createTestFixtures() { | |
| 34 | - return Lists.newArrayList("CREATE TABLE foo (k int primary key, v1 text, v2 list<int>)"); | |
| 31 | + public void onTestContextInitialized() { | |
| 32 | + execute("CREATE TABLE foo (k int primary key, v1 text, v2 list<int>)"); | |
| 35 | 33 | } |
| 36 | 34 | |
| 37 | 35 | @BeforeClass(groups = "short") |
| 38 | 36 | public void setup() { |
| 39 | - prepared = session.prepare("INSERT INTO foo (k, v1, v2) VALUES (?, ?, ?)"); | |
| 37 | + prepared = session().prepare("INSERT INTO foo (k, v1, v2) VALUES (?, ?, ?)"); | |
| 40 | 38 | } |
| 41 | 39 | |
| 42 | 40 | @Test(groups = "short") |
modified driver-core/src/test/java/com/datastax/driver/core/CCMAccess.java +7 −1
| @@ -22,6 +22,8 @@ | ||
| 22 | 22 | |
| 23 | 23 | public interface CCMAccess extends Closeable { |
| 24 | 24 | |
| 25 | + enum Workload {cassandra, solr, hadoop, spark, cfs, graph} | |
| 26 | + | |
| 25 | 27 | // Inspection methods |
| 26 | 28 | |
| 27 | 29 | /** |
| @@ -130,6 +132,10 @@ | ||
| 130 | 132 | */ |
| 131 | 133 | void updateDSEConfig(Map<String, Object> configs); |
| 132 | 134 | |
| 135 | + /** | |
| 136 | + * Checks for errors in the logs of all nodes in the cluster. | |
| 137 | + */ | |
| 138 | + String checkForErrors(); | |
| 133 | 139 | |
| 134 | 140 | // Methods altering nodes |
| 135 | 141 | |
| @@ -201,7 +207,7 @@ | ||
| 201 | 207 | * |
| 202 | 208 | * @param n the node number (starting from 1). |
| 203 | 209 | */ |
| 204 | - void setWorkload(int n, String workload); | |
| 210 | + void setWorkload(int n, Workload workload); | |
| 205 | 211 | |
| 206 | 212 | |
| 207 | 213 | // Methods blocking until nodes are up or down |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +78 −25
| @@ -31,7 +31,6 @@ | ||
| 31 | 31 | import java.net.InetSocketAddress; |
| 32 | 32 | import java.util.*; |
| 33 | 33 | import java.util.concurrent.TimeUnit; |
| 34 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 35 | 34 | |
| 36 | 35 | import static com.datastax.driver.core.TestUtils.executeNoFail; |
| 37 | 36 | import static com.datastax.driver.core.TestUtils.findAvailablePort; |
| @@ -384,7 +383,17 @@ | ||
| 384 | 383 | return; |
| 385 | 384 | if (logger.isDebugEnabled()) |
| 386 | 385 | logger.debug("Starting: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB()); |
| 387 | - execute(CCM_COMMAND + " start --wait-other-notice --wait-for-binary-proto" + jvmArgs); | |
| 386 | + try { | |
| 387 | + execute(CCM_COMMAND + " start --wait-other-notice --wait-for-binary-proto" + jvmArgs); | |
| 388 | + } catch (CCMException e) { | |
| 389 | + logger.error("Could not start " + this, e); | |
| 390 | + logger.error("CCM output:\n{}", e.getOut()); | |
| 391 | + setKeepLogs(true); | |
| 392 | + String errors = checkForErrors(); | |
| 393 | + if (errors != null) | |
| 394 | + logger.error("CCM check errors:\n{}", errors); | |
| 395 | + throw e; | |
| 396 | + } | |
| 388 | 397 | if (logger.isDebugEnabled()) |
| 389 | 398 | logger.debug("Started: {} - Free memory: {} MB", this, TestUtils.getFreeMemoryMB()); |
| 390 | 399 | started = true; |
| @@ -396,7 +405,6 @@ | ||
| 396 | 405 | return; |
| 397 | 406 | if (logger.isDebugEnabled()) |
| 398 | 407 | logger.debug("Stopping: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB()); |
| 399 | - execute(CCM_COMMAND + " stop"); | |
| 400 | 408 | if (logger.isDebugEnabled()) |
| 401 | 409 | logger.debug("Stopped: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB()); |
| 402 | 410 | closed = true; |
| @@ -411,10 +419,38 @@ | ||
| 411 | 419 | closed = true; |
| 412 | 420 | } |
| 413 | 421 | |
| 422 | + @Override | |
| 423 | + public synchronized void remove() { | |
| 424 | + stop(); | |
| 425 | + logger.debug("Removing: {}", this); | |
| 426 | + execute(CCM_COMMAND + " remove"); | |
| 427 | + } | |
| 428 | + | |
| 429 | + @Override | |
| 430 | + public String checkForErrors() { | |
| 431 | + logger.debug("Checking for errors in: {}", this); | |
| 432 | + try { | |
| 433 | + return execute(CCM_COMMAND + " checklogerror"); | |
| 434 | + } catch (CCMException e) { | |
| 435 | + logger.warn("Check for errors failed"); | |
| 436 | + return null; | |
| 437 | + } | |
| 438 | + } | |
| 439 | + | |
| 414 | 440 | @Override |
| 415 | 441 | public void start(int n) { |
| 416 | 442 | logger.debug(String.format("Starting: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 417 | - execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto" + jvmArgs, n); | |
| 443 | + try { | |
| 444 | + execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto" + jvmArgs, n); | |
| 445 | + } catch (CCMException e) { | |
| 446 | + logger.error(String.format("Could not start node %s in %s", n, this), e); | |
| 447 | + logger.error("CCM output:\n{}", e.getOut()); | |
| 448 | + setKeepLogs(true); | |
| 449 | + String errors = checkForErrors(); | |
| 450 | + if (errors != null) | |
| 451 | + logger.error("CCM check errors:\n{}", errors); | |
| 452 | + throw e; | |
| 453 | + } | |
| 418 | 454 | } |
| 419 | 455 | |
| 420 | 456 | @Override |
| @@ -429,13 +465,6 @@ | ||
| 429 | 465 | execute(CCM_COMMAND + " node%d stop --not-gently", n); |
| 430 | 466 | } |
| 431 | 467 | |
| 432 | - @Override | |
| 433 | - public synchronized void remove() { | |
| 434 | - stop(); | |
| 435 | - logger.debug("Removing: {}", this); | |
| 436 | - execute(CCM_COMMAND + " remove"); | |
| 437 | - } | |
| 438 | - | |
| 439 | 468 | @Override |
| 440 | 469 | public void remove(int n) { |
| 441 | 470 | logger.debug(String.format("Removing: node %s (%s%s:%s) from %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| @@ -509,31 +538,36 @@ | ||
| 509 | 538 | } |
| 510 | 539 | |
| 511 | 540 | @Override |
| 512 | - public void setWorkload(int node, String workload) { | |
| 541 | + public void setWorkload(int node, Workload workload) { | |
| 513 | 542 | execute(CCM_COMMAND + " node%d setworkload %s", node, workload); |
| 514 | 543 | } |
| 515 | 544 | |
| 516 | - private void execute(String command, Object... args) { | |
| 517 | - | |
| 545 | + private String execute(String command, Object... args) { | |
| 518 | 546 | String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir; |
| 519 | 547 | Closer closer = Closer.create(); |
| 520 | 548 | // 10 minutes timeout |
| 521 | 549 | ExecuteWatchdog watchDog = new ExecuteWatchdog(TimeUnit.MINUTES.toMillis(10)); |
| 550 | + StringWriter sw = new StringWriter(); | |
| 551 | + final PrintWriter pw = new PrintWriter(sw); | |
| 552 | + closer.register(pw); | |
| 522 | 553 | try { |
| 523 | 554 | logger.trace("Executing: " + fullCommand); |
| 524 | 555 | CommandLine cli = CommandLine.parse(fullCommand); |
| 525 | 556 | Executor executor = new DefaultExecutor(); |
| 526 | - | |
| 527 | 557 | LogOutputStream outStream = new LogOutputStream() { |
| 528 | 558 | @Override |
| 529 | 559 | protected void processLine(String line, int logLevel) { |
| 530 | - logger.debug("ccmout> " + line); | |
| 560 | + String out = "ccmout> " + line; | |
| 561 | + logger.debug(out); | |
| 562 | + pw.println(out); | |
| 531 | 563 | } |
| 532 | 564 | }; |
| 533 | 565 | LogOutputStream errStream = new LogOutputStream() { |
| 534 | 566 | @Override |
| 535 | 567 | protected void processLine(String line, int logLevel) { |
| 536 | - logger.error("ccmerr> " + line); | |
| 568 | + String err = "ccmerr> " + line; | |
| 569 | + logger.error(err); | |
| 570 | + pw.println(err); | |
| 537 | 571 | } |
| 538 | 572 | }; |
| 539 | 573 | closer.register(outStream); |
| @@ -541,16 +575,17 @@ | ||
| 541 | 575 | ExecuteStreamHandler streamHandler = new PumpStreamHandler(outStream, errStream); |
| 542 | 576 | executor.setStreamHandler(streamHandler); |
| 543 | 577 | executor.setWatchdog(watchDog); |
| 544 | - | |
| 545 | 578 | int retValue = executor.execute(cli, ENVIRONMENT_MAP); |
| 546 | 579 | if (retValue != 0) { |
| 547 | 580 | logger.error("Non-zero exit code ({}) returned from executing ccm command: {}", retValue, fullCommand); |
| 548 | - throw new RuntimeException(); | |
| 581 | + pw.flush(); | |
| 582 | + throw new CCMException(String.format("Non-zero exit code (%s) returned from executing ccm command: %s", retValue, fullCommand), sw.toString()); | |
| 549 | 583 | } |
| 550 | 584 | } catch (IOException e) { |
| 551 | 585 | if (watchDog.killedProcess()) |
| 552 | - logger.error("The command {} was killed after 5 minutes", fullCommand); | |
| 553 | - throw new RuntimeException(String.format("The command %s failed to execute", fullCommand), e); | |
| 586 | + logger.error("The command {} was killed after 10 minutes", fullCommand); | |
| 587 | + pw.flush(); | |
| 588 | + throw new CCMException(String.format("The command %s failed to execute", fullCommand), sw.toString(), e); | |
| 554 | 589 | } finally { |
| 555 | 590 | try { |
| 556 | 591 | closer.close(); |
| @@ -558,6 +593,7 @@ | ||
| 558 | 593 | Throwables.propagate(e); |
| 559 | 594 | } |
| 560 | 595 | } |
| 596 | + return sw.toString(); | |
| 561 | 597 | } |
| 562 | 598 | |
| 563 | 599 | /** |
| @@ -626,8 +662,7 @@ | ||
| 626 | 662 | * use {@link #builder()} to get an instance |
| 627 | 663 | */ |
| 628 | 664 | public static class Builder { |
| 629 | - private static final AtomicInteger COUNTER = new AtomicInteger(0); | |
| 630 | - private final String clusterName = "test_" + COUNTER.incrementAndGet(); | |
| 665 | + private final String clusterName = TestUtils.generateIdentifier("cluster_"); | |
| 631 | 666 | int[] nodes = {1}; |
| 632 | 667 | private boolean start = true; |
| 633 | 668 | private boolean isDSE = isDSE(); |
| @@ -640,6 +675,7 @@ | ||
| 640 | 675 | private int thriftPort = -1; |
| 641 | 676 | private int binaryPort = -1; |
| 642 | 677 | private int storagePort = -1; |
| 678 | + private Map<Integer, Workload> workloads = new HashMap<Integer, Workload>(); | |
| 643 | 679 | |
| 644 | 680 | private Builder() { |
| 645 | 681 | } |
| @@ -714,7 +750,7 @@ | ||
| 714 | 750 | |
| 715 | 751 | /** |
| 716 | 752 | * Free-form options that will be added at the end of the {@code ccm create} command |
| 717 | - * (defaults to {@link #getInstallArguments()} if this is never called). | |
| 753 | + * (defaults to {@link #getInstallArguments()} if this is never called). | |
| 718 | 754 | */ |
| 719 | 755 | public Builder withCreateOptions(String... createOptions) { |
| 720 | 756 | Collections.addAll(this.createOptions, createOptions); |
| @@ -762,6 +798,18 @@ | ||
| 762 | 798 | return this; |
| 763 | 799 | } |
| 764 | 800 | |
| 801 | + /** | |
| 802 | + * Sets the DSE workload for a given node. | |
| 803 | + * | |
| 804 | + * @param node The node to set the workload for (starting with 1). | |
| 805 | + * @param workload The workload (e.g. solr, spark, hadoop) | |
| 806 | + * @return This builder | |
| 807 | + */ | |
| 808 | + public Builder withWorkload(int node, Workload workload) { | |
| 809 | + this.workloads.put(node, workload); | |
| 810 | + return this; | |
| 811 | + } | |
| 812 | + | |
| 765 | 813 | public CCMBridge build() { |
| 766 | 814 | // be careful NOT to alter internal state (hashCode/equals) during build! |
| 767 | 815 | int storagePort = this.storagePort == -1 ? findAvailablePort() : this.storagePort; |
| @@ -785,6 +833,9 @@ | ||
| 785 | 833 | ccm.updateConfig(config); |
| 786 | 834 | if (!dseConfiguration.isEmpty()) |
| 787 | 835 | ccm.updateDSEConfig(dseConfiguration); |
| 836 | + for (Map.Entry<Integer, Workload> entry : workloads.entrySet()) { | |
| 837 | + ccm.setWorkload(entry.getKey(), entry.getValue()); | |
| 838 | + } | |
| 788 | 839 | if (start) |
| 789 | 840 | ccm.start(); |
| 790 | 841 | return ccm; |
| @@ -890,8 +941,9 @@ | ||
| 890 | 941 | if (!Arrays.equals(nodes, builder.nodes)) return false; |
| 891 | 942 | if (!createOptions.equals(builder.createOptions)) return false; |
| 892 | 943 | if (!jvmArgs.equals(builder.jvmArgs)) return false; |
| 893 | - if (!dseConfiguration.equals(builder.dseConfiguration)) return false; | |
| 894 | 944 | if (!cassandraConfiguration.equals(builder.cassandraConfiguration)) return false; |
| 945 | + if (!dseConfiguration.equals(builder.dseConfiguration)) return false; | |
| 946 | + if (!workloads.equals(builder.workloads)) return false; | |
| 895 | 947 | return version.equals(builder.version); |
| 896 | 948 | } |
| 897 | 949 | |
| @@ -905,6 +957,7 @@ | ||
| 905 | 957 | result = 31 * result + jvmArgs.hashCode(); |
| 906 | 958 | result = 31 * result + cassandraConfiguration.hashCode(); |
| 907 | 959 | result = 31 * result + dseConfiguration.hashCode(); |
| 960 | + result = 31 * result + workloads.hashCode(); | |
| 908 | 961 | result = 31 * result + thriftPort; |
| 909 | 962 | result = 31 * result + binaryPort; |
| 910 | 963 | result = 31 * result + storagePort; |
modified driver-core/src/test/java/com/datastax/driver/core/CCMCache.java +6 −1
| @@ -139,6 +139,11 @@ | ||
| 139 | 139 | ccm.updateDSEConfig(configs); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | + @Override | |
| 143 | + public String checkForErrors() { | |
| 144 | + return ccm.checkForErrors(); | |
| 145 | + } | |
| 146 | + | |
| 142 | 147 | @Override |
| 143 | 148 | public void start(int n) { |
| 144 | 149 | ccm.start(n); |
| @@ -185,7 +190,7 @@ | ||
| 185 | 190 | } |
| 186 | 191 | |
| 187 | 192 | @Override |
| 188 | - public void setWorkload(int n, String workload) { | |
| 193 | + public void setWorkload(int n, Workload workload) { | |
| 189 | 194 | ccm.setWorkload(n, workload); |
| 190 | 195 | } |
| 191 | 196 |
modified driver-core/src/test/java/com/datastax/driver/core/CCMConfig.java +84 −22
| @@ -34,7 +34,9 @@ | ||
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * The number of nodes to create, per data center. |
| 37 | - * If not set, this defaults to {1}, i.e., one data center with one node. | |
| 37 | + * If not set, this defaults to {@code {1}}, i.e., one data center with one node. | |
| 38 | + * <p/> | |
| 39 | + * This attribute is ignored if {@link #ccmProvider()} is defined. | |
| 38 | 40 | * |
| 39 | 41 | * @return The number of nodes to create, per data center. |
| 40 | 42 | */ |
| @@ -44,9 +46,11 @@ | ||
| 44 | 46 | * The C* or DSE version to use; defaults to the version defined by |
| 45 | 47 | * the System property {@code cassandra.version}. |
| 46 | 48 | * <p/> |
| 47 | - * Note that setting this property completely | |
| 49 | + * Note that setting this attribute completely | |
| 48 | 50 | * overrides the System properties {@code cassandra.version} |
| 49 | 51 | * and {@code cassandra.directory}. |
| 52 | + * <p/> | |
| 53 | + * This attribute is ignored if {@link #ccmProvider()} is defined. | |
| 50 | 54 | * |
| 51 | 55 | * @return The C* or DSE version to use |
| 52 | 56 | * @see CCMBridge#getCassandraVersion() |
| @@ -56,8 +60,10 @@ | ||
| 56 | 60 | /** |
| 57 | 61 | * Whether to launch a DSE instance rather than an OSS C*. |
| 58 | 62 | * <p/> |
| 59 | - * Note that setting this property completely | |
| 63 | + * Note that setting this attribute completely | |
| 60 | 64 | * overrides the System property {@code dse}. |
| 65 | + * <p/> | |
| 66 | + * This attribute is ignored if {@link #ccmProvider()} is defined. | |
| 61 | 67 | * |
| 62 | 68 | * @return {@code true} to launch a DSE instance, {@code false} to launch an OSS C* instance (default). |
| 63 | 69 | */ |
| @@ -66,6 +72,8 @@ | ||
| 66 | 72 | /** |
| 67 | 73 | * Configuration items to add to cassandra.yaml configuration file. |
| 68 | 74 | * Each configuration item must be in the form {@code key:value}. |
| 75 | + * <p/> | |
| 76 | + * This attribute is ignored if {@link #ccmProvider()} is defined. | |
| 69 | 77 | * |
| 70 | 78 | * @return Configuration items to add to cassandra.yaml configuration file. |
| 71 | 79 | */ |
| @@ -74,6 +82,8 @@ | ||
| 74 | 82 | /** |
| 75 | 83 | * Configuration items to add to dse.yaml configuration file. |
| 76 | 84 | * Each configuration item must be in the form {@code key:value}. |
| 85 | + * <p/> | |
| 86 | + * This attribute is ignored if {@link #ccmProvider()} is defined. | |
| 77 | 87 | * |
| 78 | 88 | * @return Configuration items to add to dse.yaml configuration file. |
| 79 | 89 | */ |
| @@ -83,6 +93,8 @@ | ||
| 83 | 93 | * JVM args to use when starting hosts. |
| 84 | 94 | * System properties should be provided one by one, in the form |
| 85 | 95 | * {@code -Dname=value}. |
| 96 | + * <p/> | |
| 97 | + * This attribute is ignored if {@link #ccmProvider()} is defined. | |
| 86 | 98 | * |
| 87 | 99 | * @return JVM args to use when starting hosts. |
| 88 | 100 | */ |
| @@ -90,6 +102,8 @@ | ||
| 90 | 102 | |
| 91 | 103 | /** |
| 92 | 104 | * Free-form options that will be added at the end of the {@code ccm create} command. |
| 105 | + * <p/> | |
| 106 | + * This attribute is ignored if {@link #ccmProvider()} is defined. | |
| 93 | 107 | * |
| 94 | 108 | * @return Free-form options that will be added at the end of the {@code ccm create} command. |
| 95 | 109 | */ |
| @@ -97,6 +111,8 @@ | ||
| 97 | 111 | |
| 98 | 112 | /** |
| 99 | 113 | * Whether to use SSL encryption. |
| 114 | + * <p/> | |
| 115 | + * This attribute is ignored if {@link #ccmProvider()} is defined. | |
| 100 | 116 | * |
| 101 | 117 | * @return {@code true} to use encryption, {@code false} to use unencrypted communication (default). |
| 102 | 118 | */ |
| @@ -104,11 +120,23 @@ | ||
| 104 | 120 | |
| 105 | 121 | /** |
| 106 | 122 | * Whether to use authentication. Implies the use of SSL encryption. |
| 123 | + * <p/> | |
| 124 | + * This attribute is ignored if {@link #ccmProvider()} is defined. | |
| 107 | 125 | * |
| 108 | 126 | * @return {@code true} to use authentication, {@code false} to use unauthenticated communication (default). |
| 109 | 127 | */ |
| 110 | 128 | boolean[] auth() default {}; |
| 111 | 129 | |
| 130 | + /** | |
| 131 | + * The workloads to assign to each node. If this attribute is defined, | |
| 132 | + * the number of its elements must be lesser than or equal to the number of nodes in the cluster. | |
| 133 | + * <p/> | |
| 134 | + * This attribute is ignored if {@link #ccmProvider()} is defined. | |
| 135 | + * | |
| 136 | + * @return The workloads to assign to each node. | |
| 137 | + */ | |
| 138 | + CCMAccess.Workload[] workloads() default {}; | |
| 139 | + | |
| 112 | 140 | /** |
| 113 | 141 | * Returns {@code true} if a {@link CCMBridge} instance should be automatically created, {@code false} otherwise. |
| 114 | 142 | * <p/> |
| @@ -160,10 +188,10 @@ | ||
| 160 | 188 | * and this session will be used to create the test keyspace. |
| 161 | 189 | * <p/> |
| 162 | 190 | * The keyspace will be created once for the whole class if CCM test mode is {@link CreateCCM.TestMode#PER_CLASS}, |
| 163 | - * or once per test method, if the CCM test mode is {@link CreateCCM.TestMode#PER_METHOD}, | |
| 191 | + * or once per test method, if the CCM test mode is {@link CreateCCM.TestMode#PER_METHOD}. | |
| 164 | 192 | * <p/> |
| 165 | 193 | * The test keyspace will be automatically populated upon creation with fixtures provided by |
| 166 | - * {@link #fixturesProvider()} and {@link #fixturesProviderClass()}. | |
| 194 | + * {@link #testInitializer()} and {@link #testInitializerClass()}. | |
| 167 | 195 | * |
| 168 | 196 | * @return {@code true} if a test keyspace should be automatically created, {@code false} otherwise. |
| 169 | 197 | */ |
| @@ -183,12 +211,44 @@ | ||
| 183 | 211 | */ |
| 184 | 212 | boolean[] dirtiesContext() default {}; |
| 185 | 213 | |
| 214 | + /** | |
| 215 | + * Returns the name of the method that should be invoked to obtain | |
| 216 | + * a {@link com.datastax.driver.core.CCMBridge.Builder} instance. | |
| 217 | + * <p/> | |
| 218 | + * This method should be declared in {@link #ccmProviderClass()}, | |
| 219 | + * or if that attribute is not set, | |
| 220 | + * it will be looked up on the test class itself. | |
| 221 | + * <p/> | |
| 222 | + * The method should not have parameters. It can be static or not, | |
| 223 | + * and have any visibility. | |
| 224 | + * <p/> | |
| 225 | + * By default, a {@link com.datastax.driver.core.CCMBridge.Builder} instance | |
| 226 | + * is obtained by parsing other attributes of this annotation. | |
| 227 | + * | |
| 228 | + * @return The name of the method that should be invoked to obtain a | |
| 229 | + * {@link com.datastax.driver.core.CCMBridge.Builder} instance. | |
| 230 | + */ | |
| 231 | + String ccmProvider() default ""; | |
| 232 | + | |
| 233 | + /** | |
| 234 | + * Returns the name of the class that should be invoked to obtain | |
| 235 | + * a {@link com.datastax.driver.core.CCMBridge.Builder} instance. | |
| 236 | + * <p/> | |
| 237 | + * This class should contain a method named after {@link #ccmProvider()}; | |
| 238 | + * if this attribute is not set, | |
| 239 | + * it will default to the test class itself. | |
| 240 | + * | |
| 241 | + * @return The name of the class that should be invoked to obtain a | |
| 242 | + * {@link com.datastax.driver.core.CCMBridge.Builder} instance. | |
| 243 | + */ | |
| 244 | + Class<?> ccmProviderClass() default Undefined.class; | |
| 245 | + | |
| 186 | 246 | /** |
| 187 | 247 | * Returns the name of the method that should be invoked to obtain |
| 188 | 248 | * a {@link com.datastax.driver.core.Cluster.Builder} instance. |
| 189 | 249 | * <p/> |
| 190 | 250 | * This method should be declared in {@link #clusterProviderClass()}, |
| 191 | - * or if that property is not set, | |
| 251 | + * or if that attribute is not set, | |
| 192 | 252 | * it will be looked up on the test class itself. |
| 193 | 253 | * <p/> |
| 194 | 254 | * The method should not have parameters. It can be static or not, |
| @@ -206,7 +266,7 @@ | ||
| 206 | 266 | * a {@link com.datastax.driver.core.Cluster.Builder} instance. |
| 207 | 267 | * <p/> |
| 208 | 268 | * This class should contain a method named after {@link #clusterProvider()}; |
| 209 | - * if this property is not set, | |
| 269 | + * if this attribute is not set, | |
| 210 | 270 | * it will default to the test class itself. |
| 211 | 271 | * |
| 212 | 272 | * @return The name of the class that should be invoked to obtain a |
| @@ -215,33 +275,35 @@ | ||
| 215 | 275 | Class<?> clusterProviderClass() default Undefined.class; |
| 216 | 276 | |
| 217 | 277 | /** |
| 218 | - * Returns the name of the method that should be invoked to obtain | |
| 219 | - * the test fixtures to use. | |
| 278 | + * Returns the name of the method that should be invoked once the test context | |
| 279 | + * is initialized. | |
| 220 | 280 | * <p/> |
| 221 | - * This method should return {@code Collection<String>}. | |
| 222 | - * <p/> | |
| 223 | - * This method should be declared in {@link #fixturesProviderClass()}, | |
| 224 | - * or if that property is not set, | |
| 281 | + * This method should be declared in {@link #testInitializerClass()}, | |
| 282 | + * or if that attribute is not set, | |
| 225 | 283 | * it will be looked up on the test class itself. |
| 226 | 284 | * <p/> |
| 227 | 285 | * The method should not have parameters. It can be static or not, |
| 228 | 286 | * and have any visibility. |
| 287 | + * <p/> | |
| 288 | + * By default, the framework will look for a method named | |
| 289 | + * {@code onTestContextInitialized}. | |
| 229 | 290 | * |
| 230 | - * @return The name of the method that should be invoked to obtain the test fixtures to use. | |
| 291 | + * @return The name of the method that should be invoked once the test context | |
| 292 | + * is initialized. | |
| 231 | 293 | */ |
| 232 | - String fixturesProvider() default ""; | |
| 294 | + String testInitializer() default ""; | |
| 233 | 295 | |
| 234 | 296 | /** |
| 235 | - * Returns the name of the class that should be invoked to obtain | |
| 236 | - * the test fixtures to use. | |
| 297 | + * Returns the name of the class that should be invoked once the test context | |
| 298 | + * is initialized. | |
| 237 | 299 | * <p/> |
| 238 | - * This class should contain a method named after {@link #fixturesProvider()}; | |
| 239 | - * if this property is not set, | |
| 300 | + * This class should contain a method named after {@link #testInitializer()}; | |
| 301 | + * if this attribute is not set, | |
| 240 | 302 | * it will default to the test class itself. |
| 241 | 303 | * |
| 242 | - * @return The name of the class that should be invoked to obtain a | |
| 243 | - * {@link com.datastax.driver.core.Cluster.Builder} instance. | |
| 304 | + * @return The name of the class that should be invoked once the test context | |
| 305 | + * is initialized. | |
| 244 | 306 | */ |
| 245 | - Class<?> fixturesProviderClass() default Undefined.class; | |
| 307 | + Class<?> testInitializerClass() default Undefined.class; | |
| 246 | 308 | |
| 247 | 309 | } |
added driver-core/src/test/java/com/datastax/driver/core/CCMException.java +36 −0
| @@ -0,0 +1,36 @@ | ||
| 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.core; | |
| 17 | + | |
| 18 | +public class CCMException extends RuntimeException { | |
| 19 | + | |
| 20 | + private final String out; | |
| 21 | + | |
| 22 | + public CCMException(String message, String out) { | |
| 23 | + super(message); | |
| 24 | + this.out = out; | |
| 25 | + } | |
| 26 | + | |
| 27 | + public CCMException(String message, String out, Throwable cause) { | |
| 28 | + super(message, cause); | |
| 29 | + this.out = out; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public String getOut() { | |
| 33 | + return out; | |
| 34 | + } | |
| 35 | + | |
| 36 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +275 −95
| @@ -15,11 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.CCMAccess.Workload; | |
| 18 | 19 | import com.datastax.driver.core.CreateCCM.TestMode; |
| 20 | +import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 19 | 21 | import com.google.common.base.Throwables; |
| 20 | 22 | import com.google.common.collect.ImmutableMap; |
| 21 | 23 | import com.google.common.collect.Lists; |
| 22 | 24 | import com.google.common.io.Closer; |
| 25 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 23 | 26 | import org.slf4j.Logger; |
| 24 | 27 | import org.slf4j.LoggerFactory; |
| 25 | 28 | import org.testng.ITestResult; |
| @@ -32,10 +35,12 @@ | ||
| 32 | 35 | import java.lang.reflect.Constructor; |
| 33 | 36 | import java.lang.reflect.Method; |
| 34 | 37 | import java.lang.reflect.Modifier; |
| 35 | -import java.lang.reflect.ParameterizedType; | |
| 38 | +import java.net.InetAddress; | |
| 36 | 39 | import java.net.InetSocketAddress; |
| 40 | +import java.net.UnknownHostException; | |
| 37 | 41 | import java.util.*; |
| 38 | 42 | import java.util.concurrent.Callable; |
| 43 | +import java.util.concurrent.TimeUnit; | |
| 39 | 44 | import java.util.concurrent.atomic.AtomicInteger; |
| 40 | 45 | |
| 41 | 46 | import static com.datastax.driver.core.CreateCCM.TestMode.PER_CLASS; |
| @@ -59,12 +64,11 @@ | ||
| 59 | 64 | .put("enable_user_defined_functions", VersionNumber.parse("2.2.0")) |
| 60 | 65 | .build(); |
| 61 | 66 | |
| 62 | - | |
| 63 | - private static class ReadOnlyCCMBridge implements CCMAccess { | |
| 67 | + private static class ReadOnlyCCMAccess implements CCMAccess { | |
| 64 | 68 | |
| 65 | 69 | private final CCMAccess delegate; |
| 66 | 70 | |
| 67 | - private ReadOnlyCCMBridge(CCMAccess delegate) { | |
| 71 | + private ReadOnlyCCMAccess(CCMAccess delegate) { | |
| 68 | 72 | this.delegate = delegate; |
| 69 | 73 | } |
| 70 | 74 | |
| @@ -123,6 +127,11 @@ | ||
| 123 | 127 | delegate.setKeepLogs(keepLogs); |
| 124 | 128 | } |
| 125 | 129 | |
| 130 | + @Override | |
| 131 | + public String checkForErrors() { | |
| 132 | + return delegate.checkForErrors(); | |
| 133 | + } | |
| 134 | + | |
| 126 | 135 | @Override |
| 127 | 136 | public void close() { |
| 128 | 137 | throw new UnsupportedOperationException("This CCM cluster is read-only"); |
| @@ -204,7 +213,7 @@ | ||
| 204 | 213 | } |
| 205 | 214 | |
| 206 | 215 | @Override |
| 207 | - public void setWorkload(int node, String workload) { | |
| 216 | + public void setWorkload(int node, Workload workload) { | |
| 208 | 217 | throw new UnsupportedOperationException("This CCM cluster is read-only"); |
| 209 | 218 | } |
| 210 | 219 | |
| @@ -281,7 +290,7 @@ | ||
| 281 | 290 | @SuppressWarnings("SimplifiableIfStatement") |
| 282 | 291 | private Map<String, Object> config() { |
| 283 | 292 | Map<String, Object> config = new HashMap<String, Object>(); |
| 284 | - for (int i = annotations.size() - 1; i == 0; i--) { | |
| 293 | + for (int i = annotations.size() - 1; i >= 0; i--) { | |
| 285 | 294 | CCMConfig ann = annotations.get(i); |
| 286 | 295 | addConfigOptions(ann.config(), config); |
| 287 | 296 | } |
| @@ -342,6 +351,22 @@ | ||
| 342 | 351 | return args; |
| 343 | 352 | } |
| 344 | 353 | |
| 354 | + private List<Workload> workloads() { | |
| 355 | + int total = 0; | |
| 356 | + for (int perDc : numberOfNodes()) | |
| 357 | + total += perDc; | |
| 358 | + List<Workload> workloads = new ArrayList<Workload>(Collections.<Workload>nCopies(total, null)); | |
| 359 | + for (int i = annotations.size() - 1; i >= 0; i--) { | |
| 360 | + CCMConfig ann = annotations.get(i); | |
| 361 | + Workload[] annWorkloads = ann.workloads(); | |
| 362 | + for (int j = 0; j < annWorkloads.length; j++) { | |
| 363 | + Workload workload = annWorkloads[j]; | |
| 364 | + workloads.set(j, workload); | |
| 365 | + } | |
| 366 | + } | |
| 367 | + return workloads; | |
| 368 | + } | |
| 369 | + | |
| 345 | 370 | @SuppressWarnings("SimplifiableIfStatement") |
| 346 | 371 | private boolean createCcm() { |
| 347 | 372 | for (CCMConfig ann : annotations) { |
| @@ -387,34 +412,69 @@ | ||
| 387 | 412 | return false; |
| 388 | 413 | } |
| 389 | 414 | |
| 390 | - private CCMBridge.Builder ccmBuilder() { | |
| 415 | + private CCMBridge.Builder ccmBuilder(Object testInstance) throws Exception { | |
| 391 | 416 | if (ccmBuilder == null) { |
| 392 | - ccmBuilder = CCMBridge.builder().withNodes(numberOfNodes()).notStarted(); | |
| 393 | - if (version() != null) | |
| 394 | - ccmBuilder.withVersion(version()); | |
| 395 | - if (dse()) | |
| 396 | - ccmBuilder.withDSE(); | |
| 397 | - if (ssl()) | |
| 398 | - ccmBuilder.withSSL(); | |
| 399 | - if (auth()) | |
| 400 | - ccmBuilder.withAuth(); | |
| 401 | - for (Map.Entry<String, Object> entry : config().entrySet()) { | |
| 402 | - ccmBuilder.withCassandraConfiguration(entry.getKey(), entry.getValue()); | |
| 403 | - } | |
| 404 | - for (Map.Entry<String, Object> entry : dseConfig().entrySet()) { | |
| 405 | - ccmBuilder.withDSEConfiguration(entry.getKey(), entry.getValue()); | |
| 417 | + ccmBuilder = ccmProvider(testInstance); | |
| 418 | + if (ccmBuilder == null) { | |
| 419 | + ccmBuilder = CCMBridge.builder().withNodes(numberOfNodes()).notStarted(); | |
| 420 | + if (version() != null) | |
| 421 | + ccmBuilder.withVersion(version()); | |
| 422 | + if (dse()) | |
| 423 | + ccmBuilder.withDSE(); | |
| 424 | + if (ssl()) | |
| 425 | + ccmBuilder.withSSL(); | |
| 426 | + if (auth()) | |
| 427 | + ccmBuilder.withAuth(); | |
| 428 | + for (Map.Entry<String, Object> entry : config().entrySet()) { | |
| 429 | + ccmBuilder.withCassandraConfiguration(entry.getKey(), entry.getValue()); | |
| 430 | + } | |
| 431 | + for (Map.Entry<String, Object> entry : dseConfig().entrySet()) { | |
| 432 | + ccmBuilder.withDSEConfiguration(entry.getKey(), entry.getValue()); | |
| 433 | + } | |
| 434 | + for (String option : startOptions()) { | |
| 435 | + ccmBuilder.withCreateOptions(option); | |
| 436 | + } | |
| 437 | + for (String arg : jvmArgs()) { | |
| 438 | + ccmBuilder.withJvmArgs(arg); | |
| 439 | + } | |
| 440 | + List<Workload> workloads = workloads(); | |
| 441 | + for (int i = 0; i < workloads.size(); i++) { | |
| 442 | + Workload workload = workloads.get(i); | |
| 443 | + if (workload != null) | |
| 444 | + ccmBuilder.withWorkload(i + 1, workload); | |
| 445 | + } | |
| 406 | 446 | } |
| 407 | - for (String option : startOptions()) { | |
| 408 | - ccmBuilder.withCreateOptions(option); | |
| 447 | + } | |
| 448 | + return ccmBuilder; | |
| 449 | + } | |
| 450 | + | |
| 451 | + private CCMBridge.Builder ccmProvider(Object testInstance) throws Exception { | |
| 452 | + String methodName = null; | |
| 453 | + Class<?> clazz = null; | |
| 454 | + for (int i = annotations.size() - 1; i >= 0; i--) { | |
| 455 | + CCMConfig ann = annotations.get(i); | |
| 456 | + if (!ann.ccmProvider().isEmpty()) { | |
| 457 | + methodName = ann.ccmProvider(); | |
| 409 | 458 | } |
| 410 | - for (String arg : jvmArgs()) { | |
| 411 | - ccmBuilder.withJvmArgs(arg); | |
| 459 | + if (!ann.ccmProviderClass().equals(CCMConfig.Undefined.class)) { | |
| 460 | + clazz = ann.ccmProviderClass(); | |
| 412 | 461 | } |
| 413 | 462 | } |
| 414 | - return ccmBuilder; | |
| 463 | + if (methodName == null) | |
| 464 | + return null; | |
| 465 | + if (clazz == null) | |
| 466 | + clazz = testInstance.getClass(); | |
| 467 | + Method method = locateMethod(methodName, clazz); | |
| 468 | + assert CCMBridge.Builder.class.isAssignableFrom(method.getReturnType()); | |
| 469 | + if (Modifier.isStatic(method.getModifiers())) { | |
| 470 | + return (CCMBridge.Builder) method.invoke(null); | |
| 471 | + } else { | |
| 472 | + Object receiver = testInstance.getClass().equals(clazz) ? testInstance : instantiate(clazz); | |
| 473 | + return (CCMBridge.Builder) method.invoke(receiver); | |
| 474 | + } | |
| 415 | 475 | } |
| 416 | 476 | |
| 417 | - private Cluster.Builder clusterBuilder(Object testInstance) throws Exception { | |
| 477 | + private Cluster.Builder clusterProvider(Object testInstance) throws Exception { | |
| 418 | 478 | String methodName = null; |
| 419 | 479 | Class<?> clazz = null; |
| 420 | 480 | for (int i = annotations.size() - 1; i >= 0; i--) { |
| @@ -441,31 +501,28 @@ | ||
| 441 | 501 | } |
| 442 | 502 | |
| 443 | 503 | @SuppressWarnings("unchecked") |
| 444 | - private Collection<String> fixtures(Object testInstance) throws Exception { | |
| 504 | + private void invokeInitTest(Object testInstance) throws Exception { | |
| 445 | 505 | String methodName = null; |
| 446 | 506 | Class<?> clazz = null; |
| 447 | 507 | for (int i = annotations.size() - 1; i >= 0; i--) { |
| 448 | 508 | CCMConfig ann = annotations.get(i); |
| 449 | - if (!ann.fixturesProvider().isEmpty()) { | |
| 450 | - methodName = ann.fixturesProvider(); | |
| 509 | + if (!ann.testInitializer().isEmpty()) { | |
| 510 | + methodName = ann.testInitializer(); | |
| 451 | 511 | } |
| 452 | - if (!ann.fixturesProviderClass().equals(CCMConfig.Undefined.class)) { | |
| 453 | - clazz = ann.fixturesProviderClass(); | |
| 512 | + if (!ann.testInitializerClass().equals(CCMConfig.Undefined.class)) { | |
| 513 | + clazz = ann.testInitializerClass(); | |
| 454 | 514 | } |
| 455 | 515 | } |
| 456 | 516 | if (methodName == null) |
| 457 | - methodName = "createTestFixtures"; | |
| 517 | + methodName = "onTestContextInitialized"; | |
| 458 | 518 | if (clazz == null) |
| 459 | 519 | clazz = testInstance.getClass(); |
| 460 | 520 | Method method = locateMethod(methodName, clazz); |
| 461 | - assert Collection.class.isAssignableFrom(method.getReturnType()); | |
| 462 | - assert method.getGenericReturnType() instanceof ParameterizedType; | |
| 463 | - assert String.class.equals(((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments()[0]); | |
| 464 | 521 | if (Modifier.isStatic(method.getModifiers())) { |
| 465 | - return (Collection<String>) method.invoke(null); | |
| 522 | + method.invoke(null); | |
| 466 | 523 | } else { |
| 467 | 524 | Object receiver = testInstance.getClass().equals(clazz) ? testInstance : instantiate(clazz); |
| 468 | - return (Collection<String>) method.invoke(receiver); | |
| 525 | + method.invoke(receiver); | |
| 469 | 526 | } |
| 470 | 527 | } |
| 471 | 528 | |
| @@ -473,13 +530,15 @@ | ||
| 473 | 530 | |
| 474 | 531 | private TestMode testMode; |
| 475 | 532 | |
| 476 | - private CCMTestConfig ccmTestConfig; | |
| 533 | + protected CCMTestConfig ccmTestConfig; | |
| 534 | + | |
| 535 | + private CCMAccess ccm; | |
| 477 | 536 | |
| 478 | - protected CCMAccess ccm; | |
| 537 | + private CCMBridge.Builder ccmBuilder; | |
| 479 | 538 | |
| 480 | - protected Cluster cluster; | |
| 539 | + private Cluster cluster; | |
| 481 | 540 | |
| 482 | - protected Session session; | |
| 541 | + private Session session; | |
| 483 | 542 | |
| 484 | 543 | protected String keyspace; |
| 485 | 544 | |
| @@ -508,11 +567,18 @@ | ||
| 508 | 567 | testMode = determineTestMode(testInstance.getClass()); |
| 509 | 568 | if (testMode == PER_CLASS) { |
| 510 | 569 | closer = Closer.create(); |
| 511 | - initTestContext(testInstance, null); | |
| 512 | - initTestCluster(testInstance); | |
| 513 | - initTestSession(); | |
| 514 | - initTestKeyspace(); | |
| 515 | - initTestFixtures(testInstance); | |
| 570 | + try { | |
| 571 | + initTestContext(testInstance, null); | |
| 572 | + initTestCluster(testInstance); | |
| 573 | + initTestSession(); | |
| 574 | + initTestKeyspace(); | |
| 575 | + initTest(testInstance); | |
| 576 | + } catch (Exception e) { | |
| 577 | + LOGGER.error(e.getMessage(), e); | |
| 578 | + errorOut(); | |
| 579 | + fail(e.getMessage()); | |
| 580 | + | |
| 581 | + } | |
| 516 | 582 | } |
| 517 | 583 | } |
| 518 | 584 | |
| @@ -538,11 +604,17 @@ | ||
| 538 | 604 | if (closer == null) |
| 539 | 605 | closer = Closer.create(); |
| 540 | 606 | if (testMode == PER_METHOD || erroredOut) { |
| 541 | - initTestContext(testInstance, testMethod); | |
| 542 | - initTestCluster(testInstance); | |
| 543 | - initTestSession(); | |
| 544 | - initTestKeyspace(); | |
| 545 | - initTestFixtures(testInstance); | |
| 607 | + try { | |
| 608 | + initTestContext(testInstance, testMethod); | |
| 609 | + initTestCluster(testInstance); | |
| 610 | + initTestSession(); | |
| 611 | + initTestKeyspace(); | |
| 612 | + initTest(testInstance); | |
| 613 | + } catch (Exception e) { | |
| 614 | + LOGGER.error(e.getMessage(), e); | |
| 615 | + errorOut(); | |
| 616 | + fail(e.getMessage()); | |
| 617 | + } | |
| 546 | 618 | } |
| 547 | 619 | assert ccmTestConfig != null; |
| 548 | 620 | assert !ccmTestConfig.createCcm() || ccm != null; |
| @@ -553,7 +625,7 @@ | ||
| 553 | 625 | * Hook executed after each test method. |
| 554 | 626 | */ |
| 555 | 627 | @AfterMethod(groups = {"isolated", "short", "long", "stress", "duration"}, alwaysRun = true) |
| 556 | - public void afterTestMethod(ITestResult tr) { | |
| 628 | + public void afterTestMethod(ITestResult tr) throws Exception { | |
| 557 | 629 | if (isCcmEnabled(tr.getMethod().getConstructorOrMethod().getMethod())) { |
| 558 | 630 | if (tr.getStatus() == ITestResult.FAILURE) { |
| 559 | 631 | errorOut(); |
| @@ -571,7 +643,7 @@ | ||
| 571 | 643 | * Hook executed after each test class. |
| 572 | 644 | */ |
| 573 | 645 | @AfterClass(groups = {"isolated", "short", "long", "stress", "duration"}, alwaysRun = true) |
| 574 | - public void afterTestClass() { | |
| 646 | + public void afterTestClass() throws Exception { | |
| 575 | 647 | if (testMode == PER_CLASS) { |
| 576 | 648 | closeCloseables(); |
| 577 | 649 | closeTestCluster(); |
| @@ -609,20 +681,85 @@ | ||
| 609 | 681 | } |
| 610 | 682 | |
| 611 | 683 | /** |
| 612 | - * The CQL statements to execute before the tests in this class. | |
| 613 | - * Useful to create tables or other objects inside the test keyspace, | |
| 614 | - * or to insert test data. | |
| 684 | + * Hook invoked when the test context is ready, but before the test itself. | |
| 685 | + * Useful to create fixtures or to insert test data. | |
| 686 | + * <p/> | |
| 687 | + * This method is invoked once per class is the {@link TestMode} is {@link TestMode#PER_CLASS} | |
| 688 | + * or before each test method, if the {@link TestMode} is {@link TestMode#PER_METHOD}. | |
| 689 | + * <p/> | |
| 690 | + * When this method is called, the cluster and the session are ready | |
| 691 | + * to be used (unless the configuration specifies that such objects | |
| 692 | + * should not be created). | |
| 693 | + * <p/> | |
| 694 | + * Statements executed inside this method do not need to be qualified with a keyspace name, | |
| 695 | + * in which case they are executed with the default keyspace for the test | |
| 696 | + * (unless the configuration specifies that no keyspace should be creaed for the test). | |
| 697 | + * <p/> | |
| 698 | + * The default implementation does nothing (no fixtures required). | |
| 699 | + */ | |
| 700 | + public void onTestContextInitialized() { | |
| 701 | + // nothing to do by default | |
| 702 | + } | |
| 703 | + | |
| 704 | + /** | |
| 705 | + * @return The {@link CCMAccess} instance to use with this test. | |
| 706 | + */ | |
| 707 | + public CCMAccess ccm() { | |
| 708 | + return ccm; | |
| 709 | + } | |
| 710 | + | |
| 711 | + /** | |
| 712 | + * @return The {@link Cluster} instance to use with this test. | |
| 713 | + * Can be null if CCM configuration specifies {@code createCluster = false}. | |
| 714 | + */ | |
| 715 | + public Cluster cluster() { | |
| 716 | + return cluster; | |
| 717 | + } | |
| 718 | + | |
| 719 | + /** | |
| 720 | + * @return The {@link Session} instance to use with this test. | |
| 721 | + * Can be null if CCM configuration specifies {@code createSession = false}. | |
| 722 | + */ | |
| 723 | + public Session session() { | |
| 724 | + return session; | |
| 725 | + } | |
| 726 | + | |
| 727 | + /** | |
| 728 | + * Executes the given statements with the test's session object. | |
| 615 | 729 | * <p/> |
| 616 | - * Statements do not need to be qualified with keyspace name. | |
| 730 | + * Useful to create test fixtures and/or load data before tests. | |
| 617 | 731 | * <p/> |
| 618 | - * The default implementation returns an empty list (no fixtures required). | |
| 732 | + * This method should not be called if a session object hasn't been created | |
| 733 | + * (if CCM configuration specifies {@code createSession = false}) | |
| 619 | 734 | * |
| 620 | - * @return The DDL statements to execute before the tests. | |
| 735 | + * @param statements The statements to execute. | |
| 621 | 736 | */ |
| 622 | - public Collection<String> createTestFixtures() { | |
| 623 | - return Collections.emptyList(); | |
| 737 | + public void execute(String... statements) { | |
| 738 | + execute(Arrays.asList(statements)); | |
| 624 | 739 | } |
| 625 | 740 | |
| 741 | + /** | |
| 742 | + * Executes the given statements with the test's session object. | |
| 743 | + * <p/> | |
| 744 | + * Useful to create test fixtures and/or load data before tests. | |
| 745 | + * <p/> | |
| 746 | + * This method should not be called if a session object hasn't been created | |
| 747 | + * (if CCM configuration specifies {@code createSession = false}) | |
| 748 | + * | |
| 749 | + * @param statements The statements to execute. | |
| 750 | + */ | |
| 751 | + public void execute(Collection<String> statements) { | |
| 752 | + assert session != null; | |
| 753 | + for (String stmt : statements) { | |
| 754 | + try { | |
| 755 | + session.execute(stmt); | |
| 756 | + } catch (Exception e) { | |
| 757 | + errorOut(); | |
| 758 | + LOGGER.error("Could not execute statement: " + stmt, e); | |
| 759 | + Throwables.propagate(e); | |
| 760 | + } | |
| 761 | + } | |
| 762 | + } | |
| 626 | 763 | /** |
| 627 | 764 | * Signals that the test has encountered an unexpected error. |
| 628 | 765 | * <p/> |
| @@ -637,8 +774,40 @@ | ||
| 637 | 774 | */ |
| 638 | 775 | public void errorOut() { |
| 639 | 776 | erroredOut = true; |
| 640 | - if (ccm != null) | |
| 777 | + if (ccm != null) { | |
| 641 | 778 | ccm.setKeepLogs(true); |
| 779 | + } | |
| 780 | + } | |
| 781 | + | |
| 782 | + /** | |
| 783 | + * Returns the contact points to use to contact the CCM cluster. | |
| 784 | + * <p/> | |
| 785 | + * This method returns as many contact points as the number of nodes initially present in the CCM cluster, | |
| 786 | + * according to {@link CCMConfig} annotations. | |
| 787 | + * <p/> | |
| 788 | + * On a multi-DC setup, this will include nodes in all data centers. | |
| 789 | + * <p/> | |
| 790 | + * This method should not be called before the test has started, nor after the test is finished. | |
| 791 | + * | |
| 792 | + * @return the contact points to use to contact the CCM cluster. | |
| 793 | + */ | |
| 794 | + public List<InetAddress> getContactPoints() { | |
| 795 | + assert ccmTestConfig != null; | |
| 796 | + List<InetAddress> contactPoints = new ArrayList<InetAddress>(); | |
| 797 | + int n = 1; | |
| 798 | + int[] numberOfNodes = ccmTestConfig.numberOfNodes(); | |
| 799 | + for (int dc = 1; dc <= numberOfNodes.length; dc++) { | |
| 800 | + int nodesInDc = numberOfNodes[dc - 1]; | |
| 801 | + for (int i = 0; i < nodesInDc; i++) { | |
| 802 | + try { | |
| 803 | + contactPoints.add(InetAddress.getByName(ipOfNode(n))); | |
| 804 | + } catch (UnknownHostException e) { | |
| 805 | + Throwables.propagate(e); | |
| 806 | + } | |
| 807 | + n++; | |
| 808 | + } | |
| 809 | + } | |
| 810 | + return contactPoints; | |
| 642 | 811 | } |
| 643 | 812 | |
| 644 | 813 | /** |
| @@ -653,7 +822,7 @@ | ||
| 653 | 822 | * |
| 654 | 823 | * @return the contact points to use to contact the CCM cluster. |
| 655 | 824 | */ |
| 656 | - public List<InetSocketAddress> getInitialContactPoints() { | |
| 825 | + public List<InetSocketAddress> getContactPointsWithPorts() { | |
| 657 | 826 | assert ccmTestConfig != null; |
| 658 | 827 | List<InetSocketAddress> contactPoints = new ArrayList<InetSocketAddress>(); |
| 659 | 828 | int n = 1; |
| @@ -681,52 +850,73 @@ | ||
| 681 | 850 | return closeable; |
| 682 | 851 | } |
| 683 | 852 | |
| 684 | - private void initTestContext(Object testInstance, Method testMethod) throws Exception { | |
| 853 | + /** | |
| 854 | + * Tests fail randomly with InvalidQueryException: Keyspace 'xxx' does not exist; | |
| 855 | + * this method tries at most 3 times to issue a successful USE statement. | |
| 856 | + * | |
| 857 | + * @param ks The keyspace to use | |
| 858 | + */ | |
| 859 | + public void useKeyspace(String ks) { | |
| 860 | + final int maxTries = 3; | |
| 861 | + for (int i = 1; i <= maxTries; i++) { | |
| 862 | + try { | |
| 863 | + session.execute("USE " + ks); | |
| 864 | + } catch (InvalidQueryException e) { | |
| 865 | + if (i == maxTries) | |
| 866 | + throw e; | |
| 867 | + LOGGER.error("Could not USE keyspace, retrying"); | |
| 868 | + Uninterruptibles.sleepUninterruptibly(1, TimeUnit.MINUTES); | |
| 869 | + } | |
| 870 | + } | |
| 871 | + } | |
| 872 | + | |
| 873 | + protected void initTestContext(Object testInstance, Method testMethod) throws Exception { | |
| 685 | 874 | erroredOut = false; |
| 686 | 875 | ccmTestConfig = createCCMTestConfig(testInstance, testMethod); |
| 687 | 876 | assert ccmTestConfig != null; |
| 688 | 877 | if (ccmTestConfig.createCcm()) { |
| 689 | - CCMAccess ccm = CCMCache.get(ccmTestConfig.ccmBuilder()); | |
| 878 | + ccmBuilder = ccmTestConfig.ccmBuilder(testInstance); | |
| 879 | + CCMAccess ccm = CCMCache.get(ccmBuilder); | |
| 690 | 880 | assert ccm != null; |
| 691 | 881 | if (ccmTestConfig.dirtiesContext()) { |
| 692 | 882 | this.ccm = ccm; |
| 693 | 883 | } else { |
| 694 | - this.ccm = new ReadOnlyCCMBridge(ccm); | |
| 884 | + this.ccm = new ReadOnlyCCMAccess(ccm); | |
| 695 | 885 | } |
| 696 | 886 | try { |
| 697 | 887 | ccm.start(); |
| 698 | - } catch (RuntimeException e) { | |
| 699 | - LOGGER.error("Could not start " + ccm, e); | |
| 888 | + } catch (CCMException e) { | |
| 889 | + errorOut(); | |
| 700 | 890 | fail(e.getMessage()); |
| 701 | 891 | } |
| 702 | 892 | LOGGER.debug("Using {}", ccm); |
| 703 | 893 | } |
| 704 | 894 | } |
| 705 | 895 | |
| 706 | - private void initTestCluster(Object testInstance) throws Exception { | |
| 896 | + protected void initTestCluster(Object testInstance) throws Exception { | |
| 707 | 897 | if (ccmTestConfig.createCcm() && ccmTestConfig.createCluster()) { |
| 708 | - Cluster.Builder builder = ccmTestConfig.clusterBuilder(testInstance); | |
| 898 | + Cluster.Builder builder = ccmTestConfig.clusterProvider(testInstance); | |
| 709 | 899 | // add contact points only if the provided builder didn't do so |
| 710 | 900 | if (builder.getContactPoints().isEmpty()) |
| 711 | - builder.addContactPointsWithPorts(getInitialContactPoints()); | |
| 901 | + builder.addContactPoints(getContactPoints()); | |
| 712 | 902 | builder.withPort(ccm.getBinaryPort()); |
| 713 | 903 | cluster = register(builder.build()); |
| 714 | 904 | cluster.init(); |
| 715 | 905 | } |
| 716 | 906 | } |
| 717 | 907 | |
| 718 | - private void initTestSession() throws Exception { | |
| 908 | + protected void initTestSession() throws Exception { | |
| 719 | 909 | if (ccmTestConfig.createCcm() && ccmTestConfig.createCluster() && ccmTestConfig.createSession()) |
| 720 | 910 | session = register(cluster.connect()); |
| 721 | 911 | } |
| 722 | 912 | |
| 723 | - private void initTestKeyspace() { | |
| 913 | + protected void initTestKeyspace() { | |
| 724 | 914 | if (ccmTestConfig.createCcm() && ccmTestConfig.createCluster() && ccmTestConfig.createSession() && ccmTestConfig.createKeyspace()) { |
| 725 | 915 | try { |
| 726 | - keyspace = TestUtils.getAvailableKeyspaceName(); | |
| 916 | + keyspace = TestUtils.generateIdentifier("ks_"); | |
| 727 | 917 | LOGGER.debug("Using keyspace " + keyspace); |
| 728 | 918 | session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); |
| 729 | - session.execute("USE " + keyspace); | |
| 919 | + useKeyspace(keyspace); | |
| 730 | 920 | } catch (Exception e) { |
| 731 | 921 | errorOut(); |
| 732 | 922 | LOGGER.error("Could not create test keyspace", e); |
| @@ -735,35 +925,25 @@ | ||
| 735 | 925 | } |
| 736 | 926 | } |
| 737 | 927 | |
| 738 | - private void initTestFixtures(Object testInstance) throws Exception { | |
| 739 | - if (ccmTestConfig.createCcm() && ccmTestConfig.createCluster() && ccmTestConfig.createSession()) { | |
| 740 | - for (String stmt : ccmTestConfig.fixtures(testInstance)) { | |
| 741 | - try { | |
| 742 | - session.execute(stmt); | |
| 743 | - } catch (Exception e) { | |
| 744 | - errorOut(); | |
| 745 | - LOGGER.error("Could not execute statement: " + stmt, e); | |
| 746 | - Throwables.propagate(e); | |
| 747 | - } | |
| 748 | - } | |
| 749 | - } | |
| 928 | + protected void initTest(Object testInstance) throws Exception { | |
| 929 | + ccmTestConfig.invokeInitTest(testInstance); | |
| 750 | 930 | } |
| 751 | 931 | |
| 752 | - private void closeTestContext() { | |
| 753 | - if (ccmTestConfig != null && ccm != null) { | |
| 754 | - CCMBridge.Builder key = ccmTestConfig.ccmBuilder(); | |
| 932 | + protected void closeTestContext() throws Exception { | |
| 933 | + if (ccmTestConfig != null && ccmBuilder != null && ccm != null) { | |
| 755 | 934 | if (ccmTestConfig.dirtiesContext()) { |
| 756 | - CCMCache.remove(key); | |
| 935 | + CCMCache.remove(ccmBuilder); | |
| 757 | 936 | ccm.close(); |
| 758 | 937 | } else { |
| 759 | - ((ReadOnlyCCMBridge) ccm).delegate.close(); | |
| 938 | + ((ReadOnlyCCMAccess) ccm).delegate.close(); | |
| 760 | 939 | } |
| 761 | 940 | } |
| 762 | 941 | ccmTestConfig = null; |
| 942 | + ccmBuilder = null; | |
| 763 | 943 | ccm = null; |
| 764 | 944 | } |
| 765 | 945 | |
| 766 | - private void closeTestCluster() { | |
| 946 | + protected void closeTestCluster() { | |
| 767 | 947 | if (cluster != null && !cluster.isClosed()) |
| 768 | 948 | executeNoFail(new Runnable() { |
| 769 | 949 | @Override |
| @@ -776,7 +956,7 @@ | ||
| 776 | 956 | keyspace = null; |
| 777 | 957 | } |
| 778 | 958 | |
| 779 | - private void closeCloseables() { | |
| 959 | + protected void closeCloseables() { | |
| 780 | 960 | if (closer != null) |
| 781 | 961 | executeNoFail(new Callable<Void>() { |
| 782 | 962 | @Override |
modified driver-core/src/test/java/com/datastax/driver/core/CaseSensitivityTest.java +4 −4
| @@ -26,7 +26,7 @@ | ||
| 26 | 26 | @Test(groups = "short") |
| 27 | 27 | public void testCaseInsensitiveKeyspace() throws Throwable { |
| 28 | 28 | String ksName = "MyKeyspace1"; |
| 29 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, ksName, 1)); | |
| 29 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, ksName, 1)); | |
| 30 | 30 | assertExists(ksName, "mykeyspace1"); |
| 31 | 31 | assertExists("mykeyspace1", "mykeyspace1"); |
| 32 | 32 | assertExists("MYKEYSPACE1", "mykeyspace1"); |
| @@ -35,7 +35,7 @@ | ||
| 35 | 35 | @Test(groups = "short") |
| 36 | 36 | public void testCaseSensitiveKeyspace() throws Throwable { |
| 37 | 37 | String ksName = "\"MyKeyspace2\""; |
| 38 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, ksName, 1)); | |
| 38 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, ksName, 1)); | |
| 39 | 39 | assertExists(ksName, "MyKeyspace2"); |
| 40 | 40 | assertExists(Metadata.quote("MyKeyspace2"), "MyKeyspace2"); |
| 41 | 41 | assertNotExists("mykeyspace2"); |
| @@ -44,13 +44,13 @@ | ||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | private void assertExists(String fetchName, String realName) { |
| 47 | - KeyspaceMetadata km = cluster.getMetadata().getKeyspace(fetchName); | |
| 47 | + KeyspaceMetadata km = cluster().getMetadata().getKeyspace(fetchName); | |
| 48 | 48 | assertNotNull(km); |
| 49 | 49 | assertEquals(realName, km.getName()); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | private void assertNotExists(String name) { |
| 53 | - assertNull(cluster.getMetadata().getKeyspace(name)); | |
| 53 | + assertNull(cluster().getMetadata().getKeyspace(name)); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterDelegateTest.java +1 −1
| @@ -23,7 +23,7 @@ | ||
| 23 | 23 | |
| 24 | 24 | @Test(groups = "short") |
| 25 | 25 | public void should_allow_subclass_to_delegate_to_other_instance() { |
| 26 | - SimpleDelegatingCluster delegatingCluster = new SimpleDelegatingCluster(cluster); | |
| 26 | + SimpleDelegatingCluster delegatingCluster = new SimpleDelegatingCluster(cluster()); | |
| 27 | 27 | |
| 28 | 28 | ResultSet rs = delegatingCluster.connect().execute("select * from system.local"); |
| 29 | 29 |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +4 −3
| @@ -32,7 +32,6 @@ | ||
| 32 | 32 | import java.net.InetAddress; |
| 33 | 33 | import java.net.InetSocketAddress; |
| 34 | 34 | import java.net.UnknownHostException; |
| 35 | -import java.util.Collections; | |
| 36 | 35 | import java.util.List; |
| 37 | 36 | import java.util.Map; |
| 38 | 37 | import java.util.concurrent.TimeUnit; |
| @@ -134,7 +133,7 @@ | ||
| 134 | 133 | // There is a possible race here in that the host is marked down in a separate Executor in onDown |
| 135 | 134 | // and then starts a periodic reconnection attempt shortly after. Since setDown is called before |
| 136 | 135 | // startPeriodicReconnectionAttempt, we add a slight delay here if the future isn't set yet. |
| 137 | - if (host.getReconnectionAttemptFuture() == null || host.getReconnectionAttemptFuture().isDone()) { | |
| 136 | + if (host != null && (host.getReconnectionAttemptFuture() == null || host.getReconnectionAttemptFuture().isDone())) { | |
| 138 | 137 | logger.warn("Periodic Reconnection Attempt hasn't started yet for {}, waiting 1 second and then checking.", host); |
| 139 | 138 | Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); |
| 140 | 139 | } |
| @@ -198,7 +197,7 @@ | ||
| 198 | 197 | @Test(groups = "short") |
| 199 | 198 | public void should_be_able_to_close_cluster_that_never_successfully_connected() throws Exception { |
| 200 | 199 | Cluster cluster = Cluster.builder() |
| 201 | - .addContactPointsWithPorts(Collections.singleton(new InetSocketAddress("127.0.0.1", 65534))) | |
| 200 | + .addContactPointsWithPorts(new InetSocketAddress("127.0.0.1", 65534)) | |
| 202 | 201 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 203 | 202 | .build(); |
| 204 | 203 | try { |
| @@ -212,6 +211,8 @@ | ||
| 212 | 211 | } catch (TimeoutException e1) { |
| 213 | 212 | fail("Close Future did not complete quickly."); |
| 214 | 213 | } |
| 214 | + } finally { | |
| 215 | + cluster.close(); | |
| 215 | 216 | } |
| 216 | 217 | } |
| 217 | 218 |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterStressTest.java +7 −5
| @@ -172,7 +172,9 @@ | ||
| 172 | 172 | |
| 173 | 173 | CreateClusterAndCheckConnections(CountDownLatch startSignal) { |
| 174 | 174 | this.startSignal = startSignal; |
| 175 | - this.cluster = Cluster.builder().addContactPointsWithPorts(getInitialContactPoints()) | |
| 175 | + this.cluster = Cluster.builder() | |
| 176 | + .addContactPoints(getContactPoints()) | |
| 177 | + .withPort(ccm().getBinaryPort()) | |
| 176 | 178 | .withPoolingOptions(new PoolingOptions().setCoreConnectionsPerHost(HostDistance.LOCAL, 1)) |
| 177 | 179 | .withNettyOptions(channelMonitor.nettyOptions()).build(); |
| 178 | 180 | } |
| @@ -186,19 +188,19 @@ | ||
| 186 | 188 | cluster.init(); |
| 187 | 189 | assertEquals(cluster.manager.sessions.size(), 0); |
| 188 | 190 | assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); |
| 189 | - assertEquals(channelMonitor.openChannels(getInitialContactPoints()).size(), 1); | |
| 191 | + assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), 1); | |
| 190 | 192 | |
| 191 | 193 | // The first session initializes the cluster and its control connection |
| 192 | 194 | Session session = cluster.connect(); |
| 193 | 195 | assertEquals(cluster.manager.sessions.size(), 1); |
| 194 | 196 | assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + TestUtils.numberOfLocalCoreConnections(cluster)); |
| 195 | - assertEquals(channelMonitor.openChannels(getInitialContactPoints()).size(), 1 + TestUtils.numberOfLocalCoreConnections(cluster)); | |
| 197 | + assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), 1 + TestUtils.numberOfLocalCoreConnections(cluster)); | |
| 196 | 198 | |
| 197 | 199 | // Closing the session keeps the control connection opened |
| 198 | 200 | session.close(); |
| 199 | 201 | assertEquals(cluster.manager.sessions.size(), 0); |
| 200 | 202 | assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); |
| 201 | - assertEquals(channelMonitor.openChannels(getInitialContactPoints()).size(), 1); | |
| 203 | + assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), 1); | |
| 202 | 204 | |
| 203 | 205 | return this; |
| 204 | 206 | } catch (AssertionError e) { |
| @@ -230,7 +232,7 @@ | ||
| 230 | 232 | try { |
| 231 | 233 | cluster.close(); |
| 232 | 234 | assertEquals(cluster.manager.sessions.size(), 0); |
| 233 | - assertEquals(channelMonitor.openChannels(getInitialContactPoints()).size(), 0); | |
| 235 | + assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), 0); | |
| 234 | 236 | } finally { |
| 235 | 237 | channelMonitor.stop(); |
| 236 | 238 | cluster = null; |
modified driver-core/src/test/java/com/datastax/driver/core/ConditionChecker.java +78 −57
| @@ -23,83 +23,106 @@ | ||
| 23 | 23 | import java.util.Timer; |
| 24 | 24 | import java.util.TimerTask; |
| 25 | 25 | import java.util.concurrent.Callable; |
| 26 | +import java.util.concurrent.TimeUnit; | |
| 26 | 27 | import java.util.concurrent.locks.Condition; |
| 27 | 28 | import java.util.concurrent.locks.Lock; |
| 28 | 29 | import java.util.concurrent.locks.ReentrantLock; |
| 29 | 30 | |
| 30 | -import static com.google.common.base.Preconditions.checkState; | |
| 31 | -import static java.util.concurrent.TimeUnit.MILLISECONDS; | |
| 32 | 31 | import static org.assertj.core.api.Fail.fail; |
| 33 | 32 | |
| 34 | 33 | public class ConditionChecker { |
| 35 | 34 | |
| 36 | - private static final Logger logger = LoggerFactory.getLogger(ConditionChecker.class); | |
| 37 | - | |
| 38 | 35 | private static final int DEFAULT_PERIOD_MILLIS = 500; |
| 39 | 36 | |
| 40 | - public static <T> void awaitUntil(T input, Predicate<? super T> predicate, long timeoutMillis) { | |
| 41 | - new ConditionChecker(input, predicate).await(timeoutMillis); | |
| 42 | - } | |
| 37 | + private static final int DEFAULT_TIMEOUT_MILLIS = 60000; | |
| 43 | 38 | |
| 44 | - public static void awaitUntil(final Callable<Boolean> condition, long timeoutMillis) { | |
| 45 | - new ConditionChecker(condition).await(timeoutMillis); | |
| 46 | - } | |
| 39 | + public static class ConditionCheckerBuilder { | |
| 47 | 40 | |
| 48 | - public static <T> void awaitWhile(T input, Predicate<? super T> predicate, long timeoutMillis) { | |
| 49 | - new ConditionChecker(input, Predicates.not(predicate)).await(timeoutMillis); | |
| 50 | - } | |
| 41 | + private long timeout = DEFAULT_TIMEOUT_MILLIS; | |
| 51 | 42 | |
| 52 | - public static void awaitWhile(final Callable<Boolean> condition, long timeoutMillis) { | |
| 53 | - new ConditionChecker(new Callable<Boolean>() { | |
| 54 | - @Override | |
| 55 | - public Boolean call() throws Exception { | |
| 56 | - return !condition.call(); | |
| 57 | - } | |
| 58 | - }).await(timeoutMillis); | |
| 59 | - } | |
| 43 | + private TimeUnit timeoutUnit = TimeUnit.MILLISECONDS; | |
| 60 | 44 | |
| 61 | - private final Object input; | |
| 45 | + private long period = DEFAULT_PERIOD_MILLIS; | |
| 62 | 46 | |
| 63 | - private final Predicate<Object> predicate; | |
| 47 | + private TimeUnit periodUnit = TimeUnit.MILLISECONDS; | |
| 64 | 48 | |
| 65 | - private final Lock lock; | |
| 49 | + private Object input; | |
| 66 | 50 | |
| 67 | - private final Condition condition; | |
| 51 | + private Predicate<?> predicate; | |
| 68 | 52 | |
| 69 | - private final Timer timer; | |
| 53 | + public ConditionCheckerBuilder every(long period, TimeUnit unit) { | |
| 54 | + this.period = period; | |
| 55 | + periodUnit = unit; | |
| 56 | + return this; | |
| 57 | + } | |
| 70 | 58 | |
| 71 | - /** | |
| 72 | - * When using this constructor, one must override {@link #evalCondition()}. | |
| 73 | - */ | |
| 74 | - public ConditionChecker() { | |
| 75 | - this(null, null); | |
| 76 | - checkState(!this.getClass().equals(ConditionChecker.class), "This constructor requires subclassing ConditionChecker"); | |
| 77 | - } | |
| 59 | + public ConditionCheckerBuilder every(long periodMillis) { | |
| 60 | + period = periodMillis; | |
| 61 | + periodUnit = TimeUnit.MILLISECONDS; | |
| 62 | + return this; | |
| 63 | + } | |
| 78 | 64 | |
| 79 | - public ConditionChecker(Callable<Boolean> condition) { | |
| 80 | - this(condition, DEFAULT_PERIOD_MILLIS); | |
| 81 | - } | |
| 65 | + public ConditionCheckerBuilder before(long timeout, TimeUnit unit) { | |
| 66 | + this.timeout = timeout; | |
| 67 | + timeoutUnit = unit; | |
| 68 | + return this; | |
| 69 | + } | |
| 82 | 70 | |
| 83 | - public ConditionChecker(final Callable<Boolean> condition, int periodMillis) { | |
| 84 | - this(null, new Predicate<Void>() { | |
| 85 | - @Override | |
| 86 | - public boolean apply(Void input) { | |
| 87 | - try { | |
| 88 | - return condition.call(); | |
| 89 | - } catch (Exception e) { | |
| 90 | - logger.error("Evaluation of condition threw exception", e); | |
| 91 | - return false; | |
| 71 | + public ConditionCheckerBuilder before(long timeoutMillis) { | |
| 72 | + timeout = timeoutMillis; | |
| 73 | + timeoutUnit = TimeUnit.MILLISECONDS; | |
| 74 | + return this; | |
| 75 | + } | |
| 76 | + | |
| 77 | + public <T> ConditionCheckerBuilder that(T input, Predicate<? super T> predicate) { | |
| 78 | + this.input = input; | |
| 79 | + this.predicate = predicate; | |
| 80 | + return this; | |
| 81 | + } | |
| 82 | + | |
| 83 | + public ConditionCheckerBuilder that(final Callable<Boolean> condition) { | |
| 84 | + this.input = null; | |
| 85 | + this.predicate = new Predicate<Void>() { | |
| 86 | + @Override | |
| 87 | + public boolean apply(Void input) { | |
| 88 | + try { | |
| 89 | + return condition.call(); | |
| 90 | + } catch (Exception e) { | |
| 91 | + logger.error("Evaluation of condition threw exception", e); | |
| 92 | + return false; | |
| 93 | + } | |
| 92 | 94 | } |
| 93 | - } | |
| 94 | - }, periodMillis); | |
| 95 | + }; | |
| 96 | + return this; | |
| 97 | + } | |
| 98 | + | |
| 99 | + @SuppressWarnings("unchecked") | |
| 100 | + public void becomesTrue() { | |
| 101 | + new ConditionChecker(input, (Predicate<Object>) predicate, period, periodUnit).await(timeout, timeoutUnit); | |
| 102 | + } | |
| 103 | + | |
| 104 | + @SuppressWarnings("unchecked") | |
| 105 | + public void becomesFalse() { | |
| 106 | + this.predicate = Predicates.not(predicate); | |
| 107 | + new ConditionChecker(input, (Predicate<Object>) predicate, period, periodUnit).await(timeout, timeoutUnit); | |
| 108 | + } | |
| 109 | + | |
| 95 | 110 | } |
| 96 | 111 | |
| 97 | - public <T> ConditionChecker(T input, Predicate<? super T> predicate) { | |
| 98 | - this(input, predicate, DEFAULT_PERIOD_MILLIS); | |
| 112 | + private static final Logger logger = LoggerFactory.getLogger(ConditionChecker.class); | |
| 113 | + | |
| 114 | + public static ConditionCheckerBuilder check() { | |
| 115 | + return new ConditionCheckerBuilder(); | |
| 99 | 116 | } |
| 100 | 117 | |
| 118 | + private final Object input; | |
| 119 | + private final Predicate<Object> predicate; | |
| 120 | + private final Lock lock; | |
| 121 | + private final Condition condition; | |
| 122 | + private final Timer timer; | |
| 123 | + | |
| 101 | 124 | @SuppressWarnings("unchecked") |
| 102 | - public <T> ConditionChecker(T input, Predicate<? super T> predicate, int periodMillis) { | |
| 125 | + public <T> ConditionChecker(T input, Predicate<? super T> predicate, long period, TimeUnit periodUnit) { | |
| 103 | 126 | this.input = input; |
| 104 | 127 | this.predicate = (Predicate<Object>) predicate; |
| 105 | 128 | lock = new ReentrantLock(); |
| @@ -110,23 +133,21 @@ | ||
| 110 | 133 | public void run() { |
| 111 | 134 | checkCondition(); |
| 112 | 135 | } |
| 113 | - }, 0, periodMillis); | |
| 136 | + }, 0, periodUnit.toMillis(period)); | |
| 114 | 137 | } |
| 115 | 138 | |
| 116 | 139 | /** |
| 117 | 140 | * Waits until the predicate becomes true, |
| 118 | 141 | * or a timeout occurs, whichever happens first. |
| 119 | - * | |
| 120 | - * @param timeoutMillis timeout in milliseconds | |
| 121 | 142 | */ |
| 122 | - public void await(long timeoutMillis) { | |
| 143 | + public void await(long timeout, TimeUnit unit) { | |
| 123 | 144 | boolean interrupted = false; |
| 124 | - long nanos = MILLISECONDS.toNanos(timeoutMillis); | |
| 145 | + long nanos = unit.toNanos(timeout); | |
| 125 | 146 | lock.lock(); |
| 126 | 147 | try { |
| 127 | 148 | while (!evalCondition()) { |
| 128 | 149 | if (nanos <= 0L) |
| 129 | - fail(String.format("Timeout after %s milliseconds while waiting for condition", timeoutMillis)); | |
| 150 | + fail(String.format("Timeout after %s %s while waiting for condition", timeout, unit.toString().toLowerCase())); | |
| 130 | 151 | try { |
| 131 | 152 | nanos = condition.awaitNanos(nanos); |
| 132 | 153 | } catch (InterruptedException e) { |
| @@ -151,7 +172,7 @@ | ||
| 151 | 172 | } |
| 152 | 173 | } |
| 153 | 174 | |
| 154 | - protected boolean evalCondition() { | |
| 175 | + private boolean evalCondition() { | |
| 155 | 176 | return predicate.apply(input); |
| 156 | 177 | } |
| 157 | 178 |
modified driver-core/src/test/java/com/datastax/driver/core/ConditionalUpdateTest.java +24 −27
| @@ -18,9 +18,6 @@ | ||
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | 19 | import org.testng.annotations.Test; |
| 20 | 20 | |
| 21 | -import java.util.Collection; | |
| 22 | -import java.util.Collections; | |
| 23 | - | |
| 24 | 21 | import static org.testng.Assert.assertFalse; |
| 25 | 22 | import static org.testng.Assert.assertTrue; |
| 26 | 23 | |
| @@ -31,55 +28,55 @@ | ||
| 31 | 28 | public class ConditionalUpdateTest extends CCMTestsSupport { |
| 32 | 29 | |
| 33 | 30 | @Override |
| 34 | - public Collection<String> createTestFixtures() { | |
| 35 | - return Collections.singletonList("CREATE TABLE test(k1 int, k2 int, v int, PRIMARY KEY (k1, k2))"); | |
| 31 | + public void onTestContextInitialized() { | |
| 32 | + execute("CREATE TABLE test(k1 int, k2 int, v int, PRIMARY KEY (k1, k2))"); | |
| 36 | 33 | } |
| 37 | 34 | |
| 38 | 35 | @Test(groups = "short") |
| 39 | 36 | public void singleUpdateTest() { |
| 40 | - session.execute("TRUNCATE test"); | |
| 41 | - session.execute("INSERT INTO test (k1, k2, v) VALUES (1, 1, 1)"); | |
| 37 | + session().execute("TRUNCATE test"); | |
| 38 | + session().execute("INSERT INTO test (k1, k2, v) VALUES (1, 1, 1)"); | |
| 42 | 39 | |
| 43 | - ResultSet rs = session.execute("UPDATE test SET v = 3 WHERE k1 = 1 AND k2 = 1 IF v = 2"); | |
| 40 | + ResultSet rs = session().execute("UPDATE test SET v = 3 WHERE k1 = 1 AND k2 = 1 IF v = 2"); | |
| 44 | 41 | assertFalse(rs.wasApplied()); |
| 45 | 42 | // Ensure that reading the status does not consume a row: |
| 46 | 43 | assertFalse(rs.isExhausted()); |
| 47 | 44 | |
| 48 | - rs = session.execute("UPDATE test SET v = 3 WHERE k1 = 1 AND k2 = 1 IF v = 1"); | |
| 45 | + rs = session().execute("UPDATE test SET v = 3 WHERE k1 = 1 AND k2 = 1 IF v = 1"); | |
| 49 | 46 | assertTrue(rs.wasApplied()); |
| 50 | 47 | assertFalse(rs.isExhausted()); |
| 51 | 48 | |
| 52 | 49 | // Non-conditional statement |
| 53 | - rs = session.execute("UPDATE test SET v = 4 WHERE k1 = 1 AND k2 = 1"); | |
| 50 | + rs = session().execute("UPDATE test SET v = 4 WHERE k1 = 1 AND k2 = 1"); | |
| 54 | 51 | assertTrue(rs.wasApplied()); |
| 55 | 52 | } |
| 56 | 53 | |
| 57 | 54 | @Test(groups = "short") |
| 58 | 55 | public void batchUpdateTest() { |
| 59 | - session.execute("TRUNCATE test"); | |
| 60 | - session.execute("INSERT INTO test (k1, k2, v) VALUES (1, 1, 1)"); | |
| 61 | - session.execute("INSERT INTO test (k1, k2, v) VALUES (1, 2, 1)"); | |
| 62 | - | |
| 63 | - PreparedStatement ps = session.prepare("UPDATE test SET v = :new WHERE k1 = :k1 AND k2 = :k2 IF v = :old"); | |
| 56 | + session().execute("TRUNCATE test"); | |
| 57 | + session().execute("INSERT INTO test (k1, k2, v) VALUES (1, 1, 1)"); | |
| 58 | + session().execute("INSERT INTO test (k1, k2, v) VALUES (1, 2, 1)"); | |
| 59 | + | |
| 60 | + PreparedStatement ps = session().prepare("UPDATE test SET v = :new WHERE k1 = :k1 AND k2 = :k2 IF v = :old"); | |
| 64 | 61 | BatchStatement batch = new BatchStatement(); |
| 65 | 62 | batch.add(ps.bind().setInt("k1", 1).setInt("k2", 1).setInt("old", 2).setInt("new", 3)); // will fail |
| 66 | 63 | batch.add(ps.bind().setInt("k1", 1).setInt("k2", 2).setInt("old", 1).setInt("new", 3)); |
| 67 | 64 | |
| 68 | 65 | |
| 69 | - ResultSet rs = session.execute(batch); | |
| 66 | + ResultSet rs = session().execute(batch); | |
| 70 | 67 | assertFalse(rs.wasApplied()); |
| 71 | 68 | } |
| 72 | 69 | |
| 73 | 70 | |
| 74 | 71 | @Test(groups = "short") |
| 75 | 72 | public void multipageResultSetTest() { |
| 76 | - session.execute("TRUNCATE test"); | |
| 77 | - session.execute("INSERT INTO test (k1, k2, v) VALUES (1, 1, 1)"); | |
| 78 | - session.execute("INSERT INTO test (k1, k2, v) VALUES (1, 2, 1)"); | |
| 73 | + session().execute("TRUNCATE test"); | |
| 74 | + session().execute("INSERT INTO test (k1, k2, v) VALUES (1, 1, 1)"); | |
| 75 | + session().execute("INSERT INTO test (k1, k2, v) VALUES (1, 2, 1)"); | |
| 79 | 76 | |
| 80 | 77 | // This is really contrived, we just want to cover the code path in ArrayBackedResultSet#MultiPage. |
| 81 | 78 | // Currently CAS update results are never multipage, so it's hard to come up with a meaningful example. |
| 82 | - ResultSet rs = session.execute(new SimpleStatement("SELECT * FROM test WHERE k1 = 1").setFetchSize(1)); | |
| 79 | + ResultSet rs = session().execute(new SimpleStatement("SELECT * FROM test WHERE k1 = 1").setFetchSize(1)); | |
| 83 | 80 | |
| 84 | 81 | assertTrue(rs.wasApplied()); |
| 85 | 82 | } |
| @@ -95,13 +92,13 @@ | ||
| 95 | 92 | @Test(groups = "short") |
| 96 | 93 | public void insert_if_not_exist_should_support_wasApplied_boolean() { |
| 97 | 94 | // First, make sure the test table and the row exist |
| 98 | - session.execute("CREATE TABLE IF NOT EXISTS Java358 (key int primary key, value int)"); | |
| 95 | + session().execute("CREATE TABLE IF NOT EXISTS Java358 (key int primary key, value int)"); | |
| 99 | 96 | ResultSet rs; |
| 100 | - rs = session.execute("INSERT INTO Java358(key, value) VALUES (42, 42) IF NOT EXISTS"); | |
| 97 | + rs = session().execute("INSERT INTO Java358(key, value) VALUES (42, 42) IF NOT EXISTS"); | |
| 101 | 98 | assertTrue(rs.wasApplied()); |
| 102 | 99 | |
| 103 | 100 | // Then, make sure the flag reports correctly that we did not create a new row |
| 104 | - rs = session.execute("INSERT INTO Java358(key, value) VALUES (42, 42) IF NOT EXISTS"); | |
| 101 | + rs = session().execute("INSERT INTO Java358(key, value) VALUES (42, 42) IF NOT EXISTS"); | |
| 105 | 102 | assertFalse(rs.wasApplied()); |
| 106 | 103 | } |
| 107 | 104 | |
| @@ -116,16 +113,16 @@ | ||
| 116 | 113 | @Test(groups = "short") |
| 117 | 114 | public void delete_if_not_exist_should_support_wasApplied_boolean() { |
| 118 | 115 | // First, make sure the test table and the row exist |
| 119 | - session.execute("CREATE TABLE IF NOT EXISTS Java358 (key int primary key, value int)"); | |
| 120 | - session.execute("INSERT INTO Java358(key, value) VALUES (42, 42)"); | |
| 116 | + session().execute("CREATE TABLE IF NOT EXISTS Java358 (key int primary key, value int)"); | |
| 117 | + session().execute("INSERT INTO Java358(key, value) VALUES (42, 42)"); | |
| 121 | 118 | |
| 122 | 119 | // Then, make sure the flag reports correctly that we did delete the row |
| 123 | 120 | ResultSet rs; |
| 124 | - rs = session.execute("DELETE FROM Java358 WHERE KEY=42 IF EXISTS"); | |
| 121 | + rs = session().execute("DELETE FROM Java358 WHERE KEY=42 IF EXISTS"); | |
| 125 | 122 | assertTrue(rs.wasApplied()); |
| 126 | 123 | |
| 127 | 124 | // Finally, make sure the flag reports correctly that we did did not delete an non-existing row |
| 128 | - rs = session.execute("DELETE FROM Java358 WHERE KEY=42 IF EXISTS"); | |
| 125 | + rs = session().execute("DELETE FROM Java358 WHERE KEY=42 IF EXISTS"); | |
| 129 | 126 | assertFalse(rs.wasApplied()); |
| 130 | 127 | } |
| 131 | 128 | } |
modified driver-core/src/test/java/com/datastax/driver/core/ConnectionReleaseTest.java +3 −2
| @@ -24,7 +24,6 @@ | ||
| 24 | 24 | import org.testng.annotations.Test; |
| 25 | 25 | |
| 26 | 26 | import java.util.Collection; |
| 27 | -import java.util.Collections; | |
| 28 | 27 | import java.util.concurrent.TimeUnit; |
| 29 | 28 | import java.util.concurrent.TimeoutException; |
| 30 | 29 | |
| @@ -84,7 +83,9 @@ | ||
| 84 | 83 | .build() |
| 85 | 84 | ); |
| 86 | 85 | |
| 87 | - cluster = Cluster.builder().addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 86 | + cluster = Cluster.builder() | |
| 87 | + .addContactPoints(hostAddress.getAddress()) | |
| 88 | + .withPort(scassandra.getBinaryPort()) | |
| 88 | 89 | .withProtocolVersion(ProtocolVersion.V2) |
| 89 | 90 | .withPoolingOptions(new PoolingOptions() |
| 90 | 91 | .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) |
modified driver-core/src/test/java/com/datastax/driver/core/ConsistencyTest.java +7 −5
| @@ -48,10 +48,12 @@ | ||
| 48 | 48 | dirtiesContext = true, |
| 49 | 49 | createKeyspace = false, |
| 50 | 50 | config = { |
| 51 | + // tests fail often with write or read timeouts | |
| 51 | 52 | "hinted_handoff_enabled:true", |
| 52 | - "phi_convict_threshold:1", | |
| 53 | + "phi_convict_threshold:5", | |
| 53 | 54 | "read_request_timeout_in_ms:100000", |
| 54 | - "write_request_timeout_in_ms:100000"} | |
| 55 | + "write_request_timeout_in_ms:100000" | |
| 56 | + } | |
| 55 | 57 | ) |
| 56 | 58 | public class ConsistencyTest extends AbstractPoliciesTest { |
| 57 | 59 | |
| @@ -719,9 +721,9 @@ | ||
| 719 | 721 | |
| 720 | 722 | private void stopAndWait(int node) { |
| 721 | 723 | logger.debug("Stopping node " + node); |
| 722 | - ccm.stop(node); | |
| 723 | - ccm.waitForDown(node);// this uses port ping | |
| 724 | - TestUtils.waitForDown(ipOfNode(node), cluster, 10); // this uses UP/DOWN events | |
| 724 | + ccm().stop(node); | |
| 725 | + ccm().waitForDown(node);// this uses port ping | |
| 726 | + TestUtils.waitForDown(ipOfNode(node), cluster()); // this uses UP/DOWN events | |
| 725 | 727 | logger.debug("Node " + node + " stopped, sleeping one extra minute to allow nodes to gossip"); |
| 726 | 728 | Uninterruptibles.sleepUninterruptibly(1, TimeUnit.MINUTES); |
| 727 | 729 | } |
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +17 −17
| @@ -47,7 +47,6 @@ | ||
| 47 | 47 | @Test(groups = "short") |
| 48 | 48 | @CCMConfig(numberOfNodes = 2) |
| 49 | 49 | public void should_prevent_simultaneous_reconnection_attempts() throws InterruptedException { |
| 50 | - Cluster cluster; | |
| 51 | 50 | |
| 52 | 51 | // Custom load balancing policy that counts the number of calls to newQueryPlan(). |
| 53 | 52 | // Since we don't open any session from our Cluster, only the control connection reattempts are calling this |
| @@ -60,20 +59,20 @@ | ||
| 60 | 59 | ReconnectionPolicy reconnectionPolicy = new ConstantReconnectionPolicy(60 * 1000); |
| 61 | 60 | |
| 62 | 61 | // We pass only the first host as contact point, so we know the control connection will be on this host |
| 63 | - cluster = register(Cluster.builder() | |
| 64 | - .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 65 | - .withPort(ccm.getBinaryPort()) | |
| 62 | + Cluster cluster = register(Cluster.builder() | |
| 63 | + .addContactPoints(getContactPoints().get(0)) | |
| 64 | + .withPort(ccm().getBinaryPort()) | |
| 66 | 65 | .withReconnectionPolicy(reconnectionPolicy) |
| 67 | 66 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 68 | 67 | .build()); |
| 69 | 68 | cluster.init(); |
| 70 | 69 | |
| 71 | 70 | // Kill the control connection host, there should be exactly one reconnection attempt |
| 72 | - ccm.stop(1); | |
| 71 | + ccm().stop(1); | |
| 73 | 72 | TimeUnit.SECONDS.sleep(1); // Sleep for a while to make sure our final count is not the result of lucky timing |
| 74 | 73 | assertThat(reconnectionAttempts.get()).isEqualTo(1); |
| 75 | 74 | |
| 76 | - ccm.stop(2); | |
| 75 | + ccm().stop(2); | |
| 77 | 76 | TimeUnit.SECONDS.sleep(1); |
| 78 | 77 | assertThat(reconnectionAttempts.get()).isEqualTo(2); |
| 79 | 78 | } |
| @@ -87,12 +86,10 @@ | ||
| 87 | 86 | @Test(groups = "short") |
| 88 | 87 | @CassandraVersion(major = 2.1) |
| 89 | 88 | public void should_parse_UDT_definitions_when_using_default_protocol_version() { |
| 90 | - Cluster cluster; | |
| 91 | - InetSocketAddress firstHost = ccm.addressOfNode(1); | |
| 92 | 89 | // First driver instance: create UDT |
| 93 | - cluster = register(Cluster.builder() | |
| 94 | - .addContactPointsWithPorts(firstHost) | |
| 95 | - .withPort(ccm.getBinaryPort()) | |
| 90 | + Cluster cluster = register(Cluster.builder() | |
| 91 | + .addContactPoints(getContactPoints().get(0)) | |
| 92 | + .withPort(ccm().getBinaryPort()) | |
| 96 | 93 | .build()); |
| 97 | 94 | Session session = cluster.connect(); |
| 98 | 95 | session.execute("create keyspace ks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); |
| @@ -100,8 +97,11 @@ | ||
| 100 | 97 | cluster.close(); |
| 101 | 98 | |
| 102 | 99 | // Second driver instance: read UDT definition |
| 103 | - cluster = register(Cluster.builder().addContactPointsWithPorts(firstHost).build()); | |
| 104 | - UserType fooType = cluster.getMetadata().getKeyspace("ks").getUserType("foo"); | |
| 100 | + Cluster cluster2 = register(Cluster.builder() | |
| 101 | + .addContactPoints(getContactPoints().get(0)) | |
| 102 | + .withPort(ccm().getBinaryPort()) | |
| 103 | + .build()); | |
| 104 | + UserType fooType = cluster2.getMetadata().getKeyspace("ks").getUserType("foo"); | |
| 105 | 105 | |
| 106 | 106 | assertThat(fooType.getFieldNames()).containsExactly("i"); |
| 107 | 107 | } |
| @@ -118,10 +118,10 @@ | ||
| 118 | 118 | @Test(groups = "long") |
| 119 | 119 | @CCMConfig(numberOfNodes = 3) |
| 120 | 120 | public void should_reestablish_if_control_node_decommissioned() throws InterruptedException { |
| 121 | - InetSocketAddress firstHost = ccm.addressOfNode(1); | |
| 121 | + InetSocketAddress firstHost = ccm().addressOfNode(1); | |
| 122 | 122 | Cluster cluster = register(Cluster.builder() |
| 123 | - .addContactPointsWithPorts(firstHost) | |
| 124 | - .withPort(ccm.getBinaryPort()) | |
| 123 | + .addContactPoints(firstHost.getAddress()) | |
| 124 | + .withPort(ccm().getBinaryPort()) | |
| 125 | 125 | .withQueryOptions(nonDebouncingQueryOptions()) |
| 126 | 126 | .build()); |
| 127 | 127 | cluster.init(); |
| @@ -131,7 +131,7 @@ | ||
| 131 | 131 | assertThat(controlHost).isEqualTo(firstHost.getAddress()); |
| 132 | 132 | |
| 133 | 133 | // Decommission the node. |
| 134 | - ccm.decommission(1); | |
| 134 | + ccm().decommission(1); | |
| 135 | 135 | |
| 136 | 136 | // Ensure that the new control connection is not null and it's host is not equal to the decommissioned node. |
| 137 | 137 | Host newHost = cluster.manager.controlConnection.connectedHost(); |
modified driver-core/src/test/java/com/datastax/driver/core/CustomPayloadTest.java +26 −35
| @@ -26,8 +26,6 @@ | ||
| 26 | 26 | import org.testng.annotations.Test; |
| 27 | 27 | |
| 28 | 28 | import java.nio.ByteBuffer; |
| 29 | -import java.util.Collection; | |
| 30 | -import java.util.Collections; | |
| 31 | 29 | import java.util.HashMap; |
| 32 | 30 | import java.util.Map; |
| 33 | 31 | |
| @@ -64,7 +62,7 @@ | ||
| 64 | 62 | public void should_echo_custom_payload_when_executing_statement() throws Exception { |
| 65 | 63 | Statement statement = new SimpleStatement("SELECT c2 FROM t1 where c1 = ?", 1); |
| 66 | 64 | statement.setOutgoingPayload(payload1); |
| 67 | - ResultSet rows = session.execute(statement); | |
| 65 | + ResultSet rows = session().execute(statement); | |
| 68 | 66 | Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); |
| 69 | 67 | assertThat(actual).isEqualTo(payload1); |
| 70 | 68 | } |
| @@ -73,7 +71,7 @@ | ||
| 73 | 71 | public void should_echo_custom_payload_when_executing_batch_statement() throws Exception { |
| 74 | 72 | Statement statement = new BatchStatement().add(new SimpleStatement("INSERT INTO t1 (c1, c2) values (1, 'foo')")); |
| 75 | 73 | statement.setOutgoingPayload(payload1); |
| 76 | - ResultSet rows = session.execute(statement); | |
| 74 | + ResultSet rows = session().execute(statement); | |
| 77 | 75 | Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); |
| 78 | 76 | assertThat(actual).isEqualTo(payload1); |
| 79 | 77 | } |
| @@ -81,7 +79,7 @@ | ||
| 81 | 79 | @Test(groups = "short") |
| 82 | 80 | public void should_echo_custom_payload_when_building_statement() throws Exception { |
| 83 | 81 | Statement statement = select("c2").from("t1").where(eq("c1", 1)).setOutgoingPayload(payload1); |
| 84 | - ResultSet rows = session.execute(statement); | |
| 82 | + ResultSet rows = session().execute(statement); | |
| 85 | 83 | Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); |
| 86 | 84 | assertThat(actual).isEqualTo(payload1); |
| 87 | 85 | } |
| @@ -97,7 +95,7 @@ | ||
| 97 | 95 | public void should_propagate_incoming_payload_to_bound_statement() throws Exception { |
| 98 | 96 | RegularStatement statement = new SimpleStatement("SELECT c2 as col1 FROM t1 where c1 = ?"); |
| 99 | 97 | statement.setOutgoingPayload(payload1); |
| 100 | - PreparedStatement ps = session.prepare(statement); | |
| 98 | + PreparedStatement ps = session().prepare(statement); | |
| 101 | 99 | // Prepared statement should inherit outgoing payload |
| 102 | 100 | assertThat(ps.getOutgoingPayload()).isEqualTo(payload1); |
| 103 | 101 | // Prepared statement should receive incoming payload |
| @@ -105,12 +103,12 @@ | ||
| 105 | 103 | ps.setOutgoingPayload(null); // unset outgoing payload |
| 106 | 104 | // bound statement should inherit from prepared statement's incoming payload |
| 107 | 105 | BoundStatement bs = ps.bind(1); |
| 108 | - ResultSet rows = session.execute(bs); | |
| 106 | + ResultSet rows = session().execute(bs); | |
| 109 | 107 | Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); |
| 110 | 108 | assertThat(actual).isEqualTo(payload1); |
| 111 | 109 | bs = ps.bind(); |
| 112 | 110 | bs.setInt(0, 1); |
| 113 | - rows = session.execute(bs); | |
| 111 | + rows = session().execute(bs); | |
| 114 | 112 | actual = rows.getExecutionInfo().getIncomingPayload(); |
| 115 | 113 | assertThat(actual).isEqualTo(payload1); |
| 116 | 114 | } |
| @@ -125,7 +123,7 @@ | ||
| 125 | 123 | public void should_override_incoming_payload_when_outgoing_payload_explicitly_set_on_preparing_statement() throws Exception { |
| 126 | 124 | RegularStatement statement = new SimpleStatement("SELECT c2 as col2 FROM t1 where c1 = ?"); |
| 127 | 125 | statement.setOutgoingPayload(payload1); |
| 128 | - PreparedStatement ps = session.prepare(statement); | |
| 126 | + PreparedStatement ps = session().prepare(statement); | |
| 129 | 127 | // Prepared statement should inherit outgoing payload |
| 130 | 128 | assertThat(ps.getOutgoingPayload()).isEqualTo(payload1); |
| 131 | 129 | // Prepared statement should receive incoming payload |
| @@ -133,12 +131,12 @@ | ||
| 133 | 131 | ps.setOutgoingPayload(payload2); // override outgoing payload |
| 134 | 132 | // bound statement should inherit from prepared statement's outgoing payload |
| 135 | 133 | BoundStatement bs = ps.bind(1); |
| 136 | - ResultSet rows = session.execute(bs); | |
| 134 | + ResultSet rows = session().execute(bs); | |
| 137 | 135 | Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); |
| 138 | 136 | assertThat(actual).isEqualTo(payload2); |
| 139 | 137 | bs = ps.bind(); |
| 140 | 138 | bs.setInt(0, 1); |
| 141 | - rows = session.execute(bs); | |
| 139 | + rows = session().execute(bs); | |
| 142 | 140 | actual = rows.getExecutionInfo().getIncomingPayload(); |
| 143 | 141 | assertThat(actual).isEqualTo(payload2); |
| 144 | 142 | } |
| @@ -152,7 +150,7 @@ | ||
| 152 | 150 | @Test(groups = "short") |
| 153 | 151 | public void should_not_set_any_payload_on_bound_statement() throws Exception { |
| 154 | 152 | RegularStatement statement = new SimpleStatement("SELECT c2 as col3 FROM t1 where c1 = ?"); |
| 155 | - PreparedStatement ps = session.prepare(statement); | |
| 153 | + PreparedStatement ps = session().prepare(statement); | |
| 156 | 154 | assertThat(ps.getOutgoingPayload()).isNull(); |
| 157 | 155 | assertThat(ps.getIncomingPayload()).isNull(); |
| 158 | 156 | // bound statement should not have outgoing payload |
| @@ -160,14 +158,14 @@ | ||
| 160 | 158 | assertThat(bs.getOutgoingPayload()).isNull(); |
| 161 | 159 | // explicitly set a payload for this boudn statement only |
| 162 | 160 | bs.setOutgoingPayload(payload1); |
| 163 | - ResultSet rows = session.execute(bs); | |
| 161 | + ResultSet rows = session().execute(bs); | |
| 164 | 162 | Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); |
| 165 | 163 | assertThat(actual).isEqualTo(payload1); |
| 166 | 164 | // a second bound statement should not have any payload |
| 167 | 165 | bs = ps.bind(); |
| 168 | 166 | assertThat(bs.getOutgoingPayload()).isNull(); |
| 169 | 167 | bs.setInt(0, 1); |
| 170 | - rows = session.execute(bs); | |
| 168 | + rows = session().execute(bs); | |
| 171 | 169 | actual = rows.getExecutionInfo().getIncomingPayload(); |
| 172 | 170 | assertThat(actual).isNull(); |
| 173 | 171 | } |
| @@ -181,12 +179,12 @@ | ||
| 181 | 179 | */ |
| 182 | 180 | @Test(groups = "short") |
| 183 | 181 | public void should_echo_custom_payload_when_paginating() throws Exception { |
| 184 | - session.execute("INSERT INTO t1 (c1, c2) VALUES (1, 'a')"); | |
| 185 | - session.execute("INSERT INTO t1 (c1, c2) VALUES (1, 'b')"); | |
| 182 | + session().execute("INSERT INTO t1 (c1, c2) VALUES (1, 'a')"); | |
| 183 | + session().execute("INSERT INTO t1 (c1, c2) VALUES (1, 'b')"); | |
| 186 | 184 | Statement statement = new SimpleStatement("SELECT c2 FROM t1 where c1 = 1"); |
| 187 | 185 | statement.setFetchSize(1); |
| 188 | 186 | statement.setOutgoingPayload(payload1); |
| 189 | - ResultSet rows = session.execute(statement); | |
| 187 | + ResultSet rows = session().execute(statement); | |
| 190 | 188 | rows.all(); |
| 191 | 189 | assertThat(rows.getAllExecutionInfo()).extracting("incomingPayload").containsOnly(payload1); |
| 192 | 190 | } |
| @@ -201,7 +199,7 @@ | ||
| 201 | 199 | payload.put("k1", Statement.NULL_PAYLOAD_VALUE); |
| 202 | 200 | Statement statement = new SimpleStatement("SELECT c2 FROM t1 where c1 = ?", 1); |
| 203 | 201 | statement.setOutgoingPayload(payload); |
| 204 | - ResultSet rows = session.execute(statement); | |
| 202 | + ResultSet rows = session().execute(statement); | |
| 205 | 203 | Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); |
| 206 | 204 | assertThat(actual).isEqualTo(payload); |
| 207 | 205 | } |
| @@ -224,28 +222,26 @@ | ||
| 224 | 222 | public void should_throw_npe_when_null_key_on_prepared_statement() throws Exception { |
| 225 | 223 | Map<String, ByteBuffer> payload = new HashMap<String, ByteBuffer>(); |
| 226 | 224 | payload.put(null, ByteBuffer.wrap(new byte[]{1})); |
| 227 | - session.prepare(new SimpleStatement("SELECT c2 FROM t1 where c1 = 1")).setOutgoingPayload(payload); | |
| 225 | + session().prepare(new SimpleStatement("SELECT c2 FROM t1 where c1 = 1")).setOutgoingPayload(payload); | |
| 228 | 226 | } |
| 229 | 227 | |
| 230 | 228 | @Test(groups = "short", expectedExceptions = NullPointerException.class) |
| 231 | 229 | public void should_throw_npe_when_null_value_on_prepared_statement() throws Exception { |
| 232 | 230 | Map<String, ByteBuffer> payload = new HashMap<String, ByteBuffer>(); |
| 233 | 231 | payload.put("k1", null); |
| 234 | - session.prepare(new SimpleStatement("SELECT c2 FROM t1 where c1 = 2")).setOutgoingPayload(payload); | |
| 232 | + session().prepare(new SimpleStatement("SELECT c2 FROM t1 where c1 = 2")).setOutgoingPayload(payload); | |
| 235 | 233 | } |
| 236 | 234 | |
| 237 | 235 | @Test(groups = "short") |
| 238 | 236 | public void should_throw_ufe_when_protocol_version_lesser_than_4() throws Exception { |
| 239 | - Cluster v3cluster = null; | |
| 240 | - Session v3session = null; | |
| 241 | 237 | try { |
| 242 | - v3cluster = Cluster.builder() | |
| 243 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 244 | - .withPort(ccm.getBinaryPort()) | |
| 238 | + Cluster v3cluster = register(Cluster.builder() | |
| 239 | + .addContactPoints(getContactPoints()) | |
| 240 | + .withPort(ccm().getBinaryPort()) | |
| 245 | 241 | .withProtocolVersion(V3) |
| 246 | - .build() | |
| 242 | + .build()) | |
| 247 | 243 | .init(); |
| 248 | - v3session = v3cluster.connect(); | |
| 244 | + Session v3session = v3cluster.connect(); | |
| 249 | 245 | Statement statement = new SimpleStatement("SELECT c2 FROM t1 where c1 = ?", 1); |
| 250 | 246 | statement.setOutgoingPayload(payload1); |
| 251 | 247 | v3session.execute(statement); |
| @@ -261,11 +257,6 @@ | ||
| 261 | 257 | .hasOnlyElementsOfType(UnsupportedFeatureException.class) |
| 262 | 258 | .extracting("message") |
| 263 | 259 | .containsOnly("Unsupported feature with the native protocol V3 (which is currently in use): Custom payloads are only supported since native protocol V4"); |
| 264 | - } finally { | |
| 265 | - if (v3session != null) | |
| 266 | - v3session.close(); | |
| 267 | - if (v3cluster != null) | |
| 268 | - v3cluster.close(); | |
| 269 | 260 | } |
| 270 | 261 | } |
| 271 | 262 | |
| @@ -285,7 +276,7 @@ | ||
| 285 | 276 | logger.addAppender(appender); |
| 286 | 277 | Statement statement = new SimpleStatement("SELECT c2 FROM t1 where c1 = ?", 1); |
| 287 | 278 | statement.setOutgoingPayload(payload1); |
| 288 | - session.execute(statement); | |
| 279 | + session().execute(statement); | |
| 289 | 280 | String logs = appender.waitAndGet(10000); |
| 290 | 281 | assertThat(logs) |
| 291 | 282 | .contains("Sending payload: {k1:0x010203, k2:0x040506} (20 bytes total)") |
| @@ -297,8 +288,8 @@ | ||
| 297 | 288 | } |
| 298 | 289 | |
| 299 | 290 | @Override |
| 300 | - public Collection<String> createTestFixtures() { | |
| 301 | - return Collections.singletonList("CREATE TABLE t1 (c1 int, c2 text, PRIMARY KEY (c1, c2))"); | |
| 291 | + public void onTestContextInitialized() { | |
| 292 | + execute("CREATE TABLE t1 (c1 int, c2 text, PRIMARY KEY (c1, c2))"); | |
| 302 | 293 | } |
| 303 | 294 | |
| 304 | 295 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CustomTypeTest.java +16 −18
| @@ -16,12 +16,10 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | -import com.google.common.collect.Lists; | |
| 20 | 19 | import org.testng.annotations.Test; |
| 21 | 20 | |
| 22 | 21 | import java.nio.ByteBuffer; |
| 23 | 22 | import java.util.ArrayList; |
| 24 | -import java.util.Collection; | |
| 25 | 23 | import java.util.List; |
| 26 | 24 | import java.util.Map; |
| 27 | 25 | |
| @@ -45,8 +43,8 @@ | ||
| 45 | 43 | + "org.apache.cassandra.db.marshal.Int32Type)"); |
| 46 | 44 | |
| 47 | 45 | @Override |
| 48 | - public Collection<String> createTestFixtures() { | |
| 49 | - return Lists.newArrayList( | |
| 46 | + public void onTestContextInitialized() { | |
| 47 | + execute( | |
| 50 | 48 | "CREATE TABLE test (" |
| 51 | 49 | + " k int," |
| 52 | 50 | + " c1 'DynamicCompositeType(s => UTF8Type, i => Int32Type)'," |
| @@ -77,17 +75,17 @@ | ||
| 77 | 75 | @Test(groups = "short") |
| 78 | 76 | public void should_serialize_and_deserialize_custom_types() { |
| 79 | 77 | |
| 80 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("test"); | |
| 78 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("test"); | |
| 81 | 79 | |
| 82 | 80 | assertThat(table.getColumn("c1")).isClusteringColumn().hasType(CUSTOM_DYNAMIC_COMPOSITE); |
| 83 | 81 | assertThat(table.getColumn("c2")).isClusteringColumn().hasType(CUSTOM_COMPOSITE).hasClusteringOrder(ClusteringOrder.DESC); |
| 84 | 82 | assertThat(table.getColumn("c3")).hasType(cint()); |
| 85 | 83 | |
| 86 | - session.execute("INSERT INTO test(k, c1, c2, c3) VALUES (0, 's@foo:i@32', 'foo:32', 1)"); | |
| 87 | - session.execute("INSERT INTO test(k, c1, c2, c3) VALUES (0, 'i@42', ':42', 2)"); | |
| 88 | - session.execute("INSERT INTO test(k, c1, c2, c3) VALUES (0, 'i@12:i@3', 'foo', 3)"); | |
| 84 | + session().execute("INSERT INTO test(k, c1, c2, c3) VALUES (0, 's@foo:i@32', 'foo:32', 1)"); | |
| 85 | + session().execute("INSERT INTO test(k, c1, c2, c3) VALUES (0, 'i@42', ':42', 2)"); | |
| 86 | + session().execute("INSERT INTO test(k, c1, c2, c3) VALUES (0, 'i@12:i@3', 'foo', 3)"); | |
| 89 | 87 | |
| 90 | - ResultSet rs = session.execute("SELECT * FROM test"); | |
| 88 | + ResultSet rs = session().execute("SELECT * FROM test"); | |
| 91 | 89 | |
| 92 | 90 | Row r = rs.one(); |
| 93 | 91 | |
| @@ -121,13 +119,13 @@ | ||
| 121 | 119 | */ |
| 122 | 120 | @Test(groups = "short") |
| 123 | 121 | public void should_serialize_and_deserialize_collections_of_custom_types() { |
| 124 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("test_collection"); | |
| 122 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("test_collection"); | |
| 125 | 123 | assertThat(table.getColumn("c1")).hasType(DataType.list(CUSTOM_DYNAMIC_COMPOSITE)); |
| 126 | 124 | assertThat(table.getColumn("c2")).hasType(DataType.map(CUSTOM_DYNAMIC_COMPOSITE, CUSTOM_DYNAMIC_COMPOSITE)); |
| 127 | 125 | |
| 128 | - session.execute("INSERT INTO test_collection(k, c1, c2) VALUES (0, [ 's@foo:i@32' ], { 's@foo:i@32': 's@bar:i@42' })"); | |
| 126 | + session().execute("INSERT INTO test_collection(k, c1, c2) VALUES (0, [ 's@foo:i@32' ], { 's@foo:i@32': 's@bar:i@42' })"); | |
| 129 | 127 | |
| 130 | - Row r = session.execute("SELECT * FROM test_collection").one(); | |
| 128 | + Row r = session().execute("SELECT * FROM test_collection").one(); | |
| 131 | 129 | |
| 132 | 130 | assertThat(r.getColumnDefinitions().getType("c1")).isEqualTo(DataType.list(CUSTOM_DYNAMIC_COMPOSITE)); |
| 133 | 131 | List<ByteBuffer> c1 = r.getList("c1", ByteBuffer.class); |
| @@ -156,26 +154,26 @@ | ||
| 156 | 154 | @CassandraVersion(major = 2.1) |
| 157 | 155 | public void should_handle_udt_with_custom_type() { |
| 158 | 156 | // Given: a UDT with custom types, and a table using it. |
| 159 | - session.execute("CREATE TYPE custom_udt (regular int, c1 'DynamicCompositeType(s => UTF8Type, i => Int32Type)', c2 'LongType')"); | |
| 160 | - session.execute("CREATE TABLE custom_udt_tbl (k int primary key, v frozen<custom_udt>)"); | |
| 157 | + session().execute("CREATE TYPE custom_udt (regular int, c1 'DynamicCompositeType(s => UTF8Type, i => Int32Type)', c2 'LongType')"); | |
| 158 | + session().execute("CREATE TABLE custom_udt_tbl (k int primary key, v frozen<custom_udt>)"); | |
| 161 | 159 | |
| 162 | 160 | // When: Retrieving User Type via schema metadata. |
| 163 | - UserType custom_udt = cluster.getMetadata().getKeyspace(keyspace).getUserType("custom_udt"); | |
| 161 | + UserType custom_udt = cluster().getMetadata().getKeyspace(keyspace).getUserType("custom_udt"); | |
| 164 | 162 | assertThat(custom_udt.getFieldType("regular")).isEqualTo(cint()); |
| 165 | 163 | // Then: The fields with custom types should be appropriately represented with their defined types. |
| 166 | 164 | assertThat(custom_udt.getFieldType("c1")).isEqualTo(CUSTOM_DYNAMIC_COMPOSITE); |
| 167 | 165 | assertThat(custom_udt.getFieldType("c2")).isEqualTo(DataType.bigint()); |
| 168 | 166 | |
| 169 | 167 | // When: Retrieving Table via schema metadata. |
| 170 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("custom_udt_tbl"); | |
| 168 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("custom_udt_tbl"); | |
| 171 | 169 | // Then: The column with the user type should be represented and match the type previously retrieved. |
| 172 | 170 | assertThat(table.getColumn("v")).hasType(custom_udt); |
| 173 | 171 | |
| 174 | 172 | // Given: Existing data in table with a UDT with custom types. |
| 175 | - session.execute("INSERT INTO custom_udt_tbl (k, v) VALUES (0, {regular: 5, c1: 's@hello:i@93', c2: 400})"); | |
| 173 | + session().execute("INSERT INTO custom_udt_tbl (k, v) VALUES (0, {regular: 5, c1: 's@hello:i@93', c2: 400})"); | |
| 176 | 174 | |
| 177 | 175 | // When: Data is retrieved. |
| 178 | - Row row = session.execute("select * from custom_udt_tbl").one(); | |
| 176 | + Row row = session().execute("select * from custom_udt_tbl").one(); | |
| 179 | 177 | |
| 180 | 178 | // Then: The resulting row's column definitions should match the table definition. |
| 181 | 179 | assertThat(row.getColumnDefinitions().getType("k")).isEqualTo(cint()); |
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeCqlNameParserTest.java +44 −47
| @@ -16,11 +16,8 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | -import com.google.common.collect.Lists; | |
| 20 | 19 | import org.testng.annotations.Test; |
| 21 | 20 | |
| 22 | -import java.util.Collection; | |
| 23 | - | |
| 24 | 21 | import static com.datastax.driver.core.Assertions.assertThat; |
| 25 | 22 | import static com.datastax.driver.core.DataType.*; |
| 26 | 23 | import static com.datastax.driver.core.DataTypeCqlNameParser.parse; |
| @@ -31,96 +28,96 @@ | ||
| 31 | 28 | |
| 32 | 29 | @Test(groups = "short") |
| 33 | 30 | public void should_parse_native_types() { |
| 34 | - assertThat(parse("ascii", cluster, null, null, null, false, false)).isEqualTo(ascii()); | |
| 35 | - assertThat(parse("bigint", cluster, null, null, null, false, false)).isEqualTo(bigint()); | |
| 36 | - assertThat(parse("blob", cluster, null, null, null, false, false)).isEqualTo(blob()); | |
| 37 | - assertThat(parse("boolean", cluster, null, null, null, false, false)).isEqualTo(cboolean()); | |
| 38 | - assertThat(parse("counter", cluster, null, null, null, false, false)).isEqualTo(counter()); | |
| 39 | - assertThat(parse("decimal", cluster, null, null, null, false, false)).isEqualTo(decimal()); | |
| 40 | - assertThat(parse("double", cluster, null, null, null, false, false)).isEqualTo(cdouble()); | |
| 41 | - assertThat(parse("float", cluster, null, null, null, false, false)).isEqualTo(cfloat()); | |
| 42 | - assertThat(parse("inet", cluster, null, null, null, false, false)).isEqualTo(inet()); | |
| 43 | - assertThat(parse("int", cluster, null, null, null, false, false)).isEqualTo(cint()); | |
| 44 | - assertThat(parse("text", cluster, null, null, null, false, false)).isEqualTo(text()); | |
| 45 | - assertThat(parse("varchar", cluster, null, null, null, false, false)).isEqualTo(varchar()); | |
| 46 | - assertThat(parse("timestamp", cluster, null, null, null, false, false)).isEqualTo(timestamp()); | |
| 47 | - assertThat(parse("date", cluster, null, null, null, false, false)).isEqualTo(date()); | |
| 48 | - assertThat(parse("time", cluster, null, null, null, false, false)).isEqualTo(time()); | |
| 49 | - assertThat(parse("uuid", cluster, null, null, null, false, false)).isEqualTo(uuid()); | |
| 50 | - assertThat(parse("varint", cluster, null, null, null, false, false)).isEqualTo(varint()); | |
| 51 | - assertThat(parse("timeuuid", cluster, null, null, null, false, false)).isEqualTo(timeuuid()); | |
| 52 | - assertThat(parse("tinyint", cluster, null, null, null, false, false)).isEqualTo(tinyint()); | |
| 53 | - assertThat(parse("smallint", cluster, null, null, null, false, false)).isEqualTo(smallint()); | |
| 31 | + assertThat(parse("ascii", cluster(), null, null, null, false, false)).isEqualTo(ascii()); | |
| 32 | + assertThat(parse("bigint", cluster(), null, null, null, false, false)).isEqualTo(bigint()); | |
| 33 | + assertThat(parse("blob", cluster(), null, null, null, false, false)).isEqualTo(blob()); | |
| 34 | + assertThat(parse("boolean", cluster(), null, null, null, false, false)).isEqualTo(cboolean()); | |
| 35 | + assertThat(parse("counter", cluster(), null, null, null, false, false)).isEqualTo(counter()); | |
| 36 | + assertThat(parse("decimal", cluster(), null, null, null, false, false)).isEqualTo(decimal()); | |
| 37 | + assertThat(parse("double", cluster(), null, null, null, false, false)).isEqualTo(cdouble()); | |
| 38 | + assertThat(parse("float", cluster(), null, null, null, false, false)).isEqualTo(cfloat()); | |
| 39 | + assertThat(parse("inet", cluster(), null, null, null, false, false)).isEqualTo(inet()); | |
| 40 | + assertThat(parse("int", cluster(), null, null, null, false, false)).isEqualTo(cint()); | |
| 41 | + assertThat(parse("text", cluster(), null, null, null, false, false)).isEqualTo(text()); | |
| 42 | + assertThat(parse("varchar", cluster(), null, null, null, false, false)).isEqualTo(varchar()); | |
| 43 | + assertThat(parse("timestamp", cluster(), null, null, null, false, false)).isEqualTo(timestamp()); | |
| 44 | + assertThat(parse("date", cluster(), null, null, null, false, false)).isEqualTo(date()); | |
| 45 | + assertThat(parse("time", cluster(), null, null, null, false, false)).isEqualTo(time()); | |
| 46 | + assertThat(parse("uuid", cluster(), null, null, null, false, false)).isEqualTo(uuid()); | |
| 47 | + assertThat(parse("varint", cluster(), null, null, null, false, false)).isEqualTo(varint()); | |
| 48 | + assertThat(parse("timeuuid", cluster(), null, null, null, false, false)).isEqualTo(timeuuid()); | |
| 49 | + assertThat(parse("tinyint", cluster(), null, null, null, false, false)).isEqualTo(tinyint()); | |
| 50 | + assertThat(parse("smallint", cluster(), null, null, null, false, false)).isEqualTo(smallint()); | |
| 54 | 51 | } |
| 55 | 52 | |
| 56 | 53 | @Test(groups = "short") |
| 57 | 54 | public void should_ignore_whitespace() { |
| 58 | - assertThat(parse(" int ", cluster, null, null, null, false, false)).isEqualTo(cint()); | |
| 59 | - assertThat(parse(" set < bigint > ", cluster, null, null, null, false, false)).isEqualTo(set(bigint())); | |
| 60 | - assertThat(parse(" map < date , timeuuid > ", cluster, null, null, null, false, false)).isEqualTo(map(date(), timeuuid())); | |
| 55 | + assertThat(parse(" int ", cluster(), null, null, null, false, false)).isEqualTo(cint()); | |
| 56 | + assertThat(parse(" set < bigint > ", cluster(), null, null, null, false, false)).isEqualTo(set(bigint())); | |
| 57 | + assertThat(parse(" map < date , timeuuid > ", cluster(), null, null, null, false, false)).isEqualTo(map(date(), timeuuid())); | |
| 61 | 58 | } |
| 62 | 59 | |
| 63 | 60 | @Test(groups = "short") |
| 64 | 61 | public void should_ignore_case() { |
| 65 | - assertThat(parse("INT", cluster, null, null, null, false, false)).isEqualTo(cint()); | |
| 66 | - assertThat(parse("SET<BIGint>", cluster, null, null, null, false, false)).isEqualTo(set(bigint())); | |
| 67 | - assertThat(parse("FROZEN<mAp<Date,Tuple<timeUUID>>>", cluster, null, null, null, false, false)).isEqualTo(map(date(), cluster.getMetadata().newTupleType(timeuuid()), true)); | |
| 62 | + assertThat(parse("INT", cluster(), null, null, null, false, false)).isEqualTo(cint()); | |
| 63 | + assertThat(parse("SET<BIGint>", cluster(), null, null, null, false, false)).isEqualTo(set(bigint())); | |
| 64 | + assertThat(parse("FROZEN<mAp<Date,Tuple<timeUUID>>>", cluster(), null, null, null, false, false)).isEqualTo(map(date(), cluster().getMetadata().newTupleType(timeuuid()), true)); | |
| 68 | 65 | } |
| 69 | 66 | |
| 70 | 67 | @Test(groups = "short") |
| 71 | 68 | public void should_parse_collection_types() { |
| 72 | - assertThat(parse("list<int>", cluster, null, null, null, false, false)).isEqualTo(list(cint())); | |
| 73 | - assertThat(parse("set<bigint>", cluster, null, null, null, false, false)).isEqualTo(set(bigint())); | |
| 74 | - assertThat(parse("map<date,timeuuid>", cluster, null, null, null, false, false)).isEqualTo(map(date(), timeuuid())); | |
| 69 | + assertThat(parse("list<int>", cluster(), null, null, null, false, false)).isEqualTo(list(cint())); | |
| 70 | + assertThat(parse("set<bigint>", cluster(), null, null, null, false, false)).isEqualTo(set(bigint())); | |
| 71 | + assertThat(parse("map<date,timeuuid>", cluster(), null, null, null, false, false)).isEqualTo(map(date(), timeuuid())); | |
| 75 | 72 | } |
| 76 | 73 | |
| 77 | 74 | @Test(groups = "short") |
| 78 | 75 | public void should_parse_frozen_collection_types() { |
| 79 | - assertThat(parse("frozen<list<int>>", cluster, null, null, null, false, false)).isEqualTo(list(cint(), true)); | |
| 80 | - assertThat(parse("frozen<set<bigint>>", cluster, null, null, null, false, false)).isEqualTo(set(bigint(), true)); | |
| 81 | - assertThat(parse("frozen<map<date,timeuuid>>", cluster, null, null, null, false, false)).isEqualTo(map(date(), timeuuid(), true)); | |
| 76 | + assertThat(parse("frozen<list<int>>", cluster(), null, null, null, false, false)).isEqualTo(list(cint(), true)); | |
| 77 | + assertThat(parse("frozen<set<bigint>>", cluster(), null, null, null, false, false)).isEqualTo(set(bigint(), true)); | |
| 78 | + assertThat(parse("frozen<map<date,timeuuid>>", cluster(), null, null, null, false, false)).isEqualTo(map(date(), timeuuid(), true)); | |
| 82 | 79 | } |
| 83 | 80 | |
| 84 | 81 | @Test(groups = "short") |
| 85 | 82 | public void should_parse_nested_collection_types() { |
| 86 | - Metadata metadata = cluster.getMetadata(); | |
| 83 | + Metadata metadata = cluster().getMetadata(); | |
| 87 | 84 | KeyspaceMetadata keyspaceMetadata = metadata.getKeyspace(this.keyspace); |
| 88 | - assertThat(parse("list<list<int>>", cluster, null, null, null, false, false)).isEqualTo(list(list(cint()))); | |
| 89 | - assertThat(parse("set<list<frozen<map<bigint,varchar>>>>", cluster, null, null, null, false, false)).isEqualTo(set(list(map(bigint(), varchar(), true)))); | |
| 85 | + assertThat(parse("list<list<int>>", cluster(), null, null, null, false, false)).isEqualTo(list(list(cint()))); | |
| 86 | + assertThat(parse("set<list<frozen<map<bigint,varchar>>>>", cluster(), null, null, null, false, false)).isEqualTo(set(list(map(bigint(), varchar(), true)))); | |
| 90 | 87 | |
| 91 | 88 | UserType keyType = keyspaceMetadata.getUserType(quote("Incr,edibly\" EvilTy<>><<><p\"e")); |
| 92 | 89 | UserType valueType = keyspaceMetadata.getUserType(quote("A")); |
| 93 | - assertThat(parse("map<frozen<\"Incr,edibly\"\" EvilTy<>><<><p\"\"e\">,frozen<\"A\">>", cluster, keyspace, keyspaceMetadata.userTypes, null, false, false)) | |
| 90 | + assertThat(parse("map<frozen<\"Incr,edibly\"\" EvilTy<>><<><p\"\"e\">,frozen<\"A\">>", cluster(), keyspace, keyspaceMetadata.userTypes, null, false, false)) | |
| 94 | 91 | .isEqualTo(map(keyType, valueType, false)); |
| 95 | 92 | } |
| 96 | 93 | |
| 97 | 94 | @Test(groups = "short") |
| 98 | 95 | public void should_parse_tuple_types() { |
| 99 | - assertThat(parse("tuple<int,list<text>>", cluster, null, null, null, false, false)).isEqualTo(cluster.getMetadata().newTupleType(cint(), list(text()))); | |
| 96 | + assertThat(parse("tuple<int,list<text>>", cluster(), null, null, null, false, false)).isEqualTo(cluster().getMetadata().newTupleType(cint(), list(text()))); | |
| 100 | 97 | } |
| 101 | 98 | |
| 102 | 99 | @Test(groups = "short") |
| 103 | 100 | public void should_parse_user_defined_type_when_definition_in_current_user_types() { |
| 104 | - Metadata metadata = cluster.getMetadata(); | |
| 101 | + Metadata metadata = cluster().getMetadata(); | |
| 105 | 102 | KeyspaceMetadata keyspaceMetadata = metadata.getKeyspace(this.keyspace); |
| 106 | - assertThat(parse("frozen<\"A\">", cluster, keyspace, keyspaceMetadata.userTypes, null, false, false)).isUserType(keyspace, "A"); | |
| 103 | + assertThat(parse("frozen<\"A\">", cluster(), keyspace, keyspaceMetadata.userTypes, null, false, false)).isUserType(keyspace, "A"); | |
| 107 | 104 | } |
| 108 | 105 | |
| 109 | 106 | @Test(groups = "short") |
| 110 | 107 | public void should_parse_user_defined_type_when_definition_in_old_user_types() { |
| 111 | - Metadata metadata = cluster.getMetadata(); | |
| 108 | + Metadata metadata = cluster().getMetadata(); | |
| 112 | 109 | KeyspaceMetadata keyspaceMetadata = metadata.getKeyspace(this.keyspace); |
| 113 | - assertThat(parse("\"A\"", cluster, keyspace, null, keyspaceMetadata.userTypes, false, false)).isUserType(keyspace, "A"); | |
| 110 | + assertThat(parse("\"A\"", cluster(), keyspace, null, keyspaceMetadata.userTypes, false, false)).isUserType(keyspace, "A"); | |
| 114 | 111 | } |
| 115 | 112 | |
| 116 | 113 | @Test(groups = "short") |
| 117 | 114 | public void should_parse_user_defined_type_to_shallow_type_if_requested() { |
| 118 | - assertThat(parse("\"A\"", cluster, keyspace, null, null, false, true)).isShallowUserType(keyspace, "A"); | |
| 115 | + assertThat(parse("\"A\"", cluster(), keyspace, null, null, false, true)).isShallowUserType(keyspace, "A"); | |
| 119 | 116 | } |
| 120 | 117 | |
| 121 | 118 | @Override |
| 122 | - public Collection<String> createTestFixtures() { | |
| 123 | - return Lists.newArrayList( | |
| 119 | + public void onTestContextInitialized() { | |
| 120 | + execute( | |
| 124 | 121 | String.format("CREATE TYPE %s.\"A\" (f1 int)", keyspace), |
| 125 | 122 | String.format("CREATE TYPE %s.\"Incr,edibly\"\" EvilTy<>><<><p\"\"e\" (a frozen<\"A\">)", keyspace) |
| 126 | 123 | ); |
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeIntegrationTest.java +13 −15
| @@ -46,10 +46,9 @@ | ||
| 46 | 46 | enum StatementType {RAW_STRING, SIMPLE_WITH_PARAM, PREPARED} |
| 47 | 47 | |
| 48 | 48 | @Override |
| 49 | - public Collection<String> createTestFixtures() { | |
| 50 | - Host host = cluster.getMetadata().getAllHosts().iterator().next(); | |
| 49 | + public void onTestContextInitialized() { | |
| 50 | + Host host = cluster().getMetadata().getAllHosts().iterator().next(); | |
| 51 | 51 | cassandraVersion = host.getCassandraVersion().nextStable(); |
| 52 | - | |
| 53 | 52 | List<String> statements = Lists.newArrayList(); |
| 54 | 53 | for (TestTable table : tables) { |
| 55 | 54 | if (cassandraVersion.compareTo(table.minCassandraVersion) < 0) |
| @@ -58,8 +57,7 @@ | ||
| 58 | 57 | else |
| 59 | 58 | statements.add(table.createStatement); |
| 60 | 59 | } |
| 61 | - | |
| 62 | - return statements; | |
| 60 | + execute(statements); | |
| 63 | 61 | } |
| 64 | 62 | |
| 65 | 63 | @Test(groups = "long") |
| @@ -79,8 +77,8 @@ | ||
| 79 | 77 | } |
| 80 | 78 | |
| 81 | 79 | protected void should_insert_and_retrieve_data(StatementType statementType) { |
| 82 | - ProtocolVersion protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 83 | - CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); | |
| 80 | + ProtocolVersion protocolVersion = cluster().getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 81 | + CodecRegistry codecRegistry = cluster().getConfiguration().getCodecRegistry(); | |
| 84 | 82 | |
| 85 | 83 | for (TestTable table : tables) { |
| 86 | 84 | if (cassandraVersion.compareTo(table.minCassandraVersion) < 0) |
| @@ -92,22 +90,22 @@ | ||
| 92 | 90 | String formatValue = codec.format(table.sampleValue); |
| 93 | 91 | assertThat(formatValue).isNotNull(); |
| 94 | 92 | String query = table.insertStatement.replace("?", formatValue); |
| 95 | - session.execute(query); | |
| 93 | + session().execute(query); | |
| 96 | 94 | break; |
| 97 | 95 | case SIMPLE_WITH_PARAM: |
| 98 | 96 | SimpleStatement statement = new SimpleStatement(table.insertStatement, table.sampleValue); |
| 99 | 97 | checkGetValuesReturnsSerializedValue(protocolVersion, statement, table); |
| 100 | - session.execute(statement); | |
| 98 | + session().execute(statement); | |
| 101 | 99 | break; |
| 102 | 100 | case PREPARED: |
| 103 | - PreparedStatement ps = session.prepare(table.insertStatement); | |
| 101 | + PreparedStatement ps = session().prepare(table.insertStatement); | |
| 104 | 102 | BoundStatement bs = ps.bind(table.sampleValue); |
| 105 | 103 | checkGetterReturnsValue(bs, table); |
| 106 | - session.execute(bs); | |
| 104 | + session().execute(bs); | |
| 107 | 105 | break; |
| 108 | 106 | } |
| 109 | 107 | |
| 110 | - Row row = session.execute(table.selectStatement).one(); | |
| 108 | + Row row = session().execute(table.selectStatement).one(); | |
| 111 | 109 | Object queriedValue = codec.deserialize(row.getBytesUnsafe("v"), protocolVersion); |
| 112 | 110 | |
| 113 | 111 | // Since codec.deserialize will get the unboxed version for primitive check against expected unboxed value. |
| @@ -130,7 +128,7 @@ | ||
| 130 | 128 | .isEqualTo(table.expectedPrimitiveValue); |
| 131 | 129 | |
| 132 | 130 | |
| 133 | - session.execute(table.truncateStatement); | |
| 131 | + session().execute(table.truncateStatement); | |
| 134 | 132 | } |
| 135 | 133 | } |
| 136 | 134 | |
| @@ -145,7 +143,7 @@ | ||
| 145 | 143 | } |
| 146 | 144 | |
| 147 | 145 | public void checkGetValuesReturnsSerializedValue(ProtocolVersion protocolVersion, SimpleStatement statement, TestTable table) { |
| 148 | - CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); | |
| 146 | + CodecRegistry codecRegistry = cluster().getConfiguration().getCodecRegistry(); | |
| 149 | 147 | ByteBuffer[] values = statement.getValues(protocolVersion, codecRegistry); |
| 150 | 148 | assertThat(values.length).isEqualTo(1); |
| 151 | 149 | assertThat(values[0]) |
| @@ -415,7 +413,7 @@ | ||
| 415 | 413 | |
| 416 | 414 | private Object getValue(GettableByIndexData data, DataType dataType) { |
| 417 | 415 | // This is kind of lame, but better than testing all getters manually |
| 418 | - CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); | |
| 416 | + CodecRegistry codecRegistry = cluster().getConfiguration().getCodecRegistry(); | |
| 419 | 417 | switch (dataType.getName()) { |
| 420 | 418 | case ASCII: |
| 421 | 419 | return data.getString(0); |
modified driver-core/src/test/java/com/datastax/driver/core/DseCCMClusterTest.java +7 −0
| @@ -59,6 +59,13 @@ | ||
| 59 | 59 | * dse_username = myusername |
| 60 | 60 | * dse_password = mypassword |
| 61 | 61 | * </pre> |
| 62 | + * <p/> | |
| 63 | + * <h3>Other requirements</h3> | |
| 64 | + * <p/> | |
| 65 | + * DSE requires your {@code PATH} variable to provide access | |
| 66 | + * to super-user executables in {@code /usr/sbin}. | |
| 67 | + * <p/> | |
| 68 | + * A correct example is as follows: {@code /usr/bin:/usr/local/bin:/bin:/usr/sbin:$JAVA_HOME/bin:$PATH}. | |
| 62 | 69 | */ |
| 63 | 70 | @Test(enabled = false) |
| 64 | 71 | @CCMConfig(dse = true, version = "4.8.3") |
modified driver-core/src/test/java/com/datastax/driver/core/EventDebouncerIntegrationTest.java +4 −4
| @@ -44,8 +44,8 @@ | ||
| 44 | 44 | public void should_wait_until_load_balancing_policy_is_fully_initialized() throws InterruptedException { |
| 45 | 45 | TestLoadBalancingPolicy policy = new TestLoadBalancingPolicy(); |
| 46 | 46 | final Cluster cluster = register(createClusterBuilderNoDebouncing() |
| 47 | - .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 48 | - .withPort(ccm.getBinaryPort()) | |
| 47 | + .addContactPoints(getContactPoints().get(0)) | |
| 48 | + .withPort(ccm().getBinaryPort()) | |
| 49 | 49 | .withLoadBalancingPolicy(policy).build()); |
| 50 | 50 | new Thread() { |
| 51 | 51 | @Override |
| @@ -59,8 +59,8 @@ | ||
| 59 | 59 | // because the debouncers are not started |
| 60 | 60 | // note: a graceful stop notify other nodes which send a topology change event to the driver right away |
| 61 | 61 | // while forceStop kills the node so other nodes take much more time to detect node failure |
| 62 | - ccm.stop(3); | |
| 63 | - ccm.waitForDown(3); | |
| 62 | + ccm().stop(3); | |
| 63 | + ccm().waitForDown(3); | |
| 64 | 64 | // finish cluster initialization and deliver the DOWN event |
| 65 | 65 | policy.proceed(); |
| 66 | 66 | assertThat(policy.onDownCalledBeforeInit).isFalse(); |
modified driver-core/src/test/java/com/datastax/driver/core/FetchingTest.java +5 −8
| @@ -18,9 +18,6 @@ | ||
| 18 | 18 | import com.datastax.driver.core.exceptions.UnsupportedFeatureException; |
| 19 | 19 | import org.testng.annotations.Test; |
| 20 | 20 | |
| 21 | -import java.util.Collection; | |
| 22 | -import java.util.Collections; | |
| 23 | - | |
| 24 | 21 | import static org.testng.Assert.*; |
| 25 | 22 | |
| 26 | 23 | /** |
| @@ -29,8 +26,8 @@ | ||
| 29 | 26 | public class FetchingTest extends CCMTestsSupport { |
| 30 | 27 | |
| 31 | 28 | @Override |
| 32 | - public Collection<String> createTestFixtures() { | |
| 33 | - return Collections.singletonList("CREATE TABLE test (k text, v int, PRIMARY KEY (k, v))"); | |
| 29 | + public void onTestContextInitialized() { | |
| 30 | + execute("CREATE TABLE test (k text, v int, PRIMARY KEY (k, v))"); | |
| 34 | 31 | } |
| 35 | 32 | |
| 36 | 33 | @Test(groups = "short") |
| @@ -39,11 +36,11 @@ | ||
| 39 | 36 | // Insert data |
| 40 | 37 | String key = "paging_test"; |
| 41 | 38 | for (int i = 0; i < 100; i++) |
| 42 | - session.execute(String.format("INSERT INTO test (k, v) VALUES ('%s', %d)", key, i)); | |
| 39 | + session().execute(String.format("INSERT INTO test (k, v) VALUES ('%s', %d)", key, i)); | |
| 43 | 40 | |
| 44 | 41 | SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", key)); |
| 45 | 42 | st.setFetchSize(5); // Ridiculously small fetch size for testing purpose. Don't do at home. |
| 46 | - ResultSet rs = session.execute(st); | |
| 43 | + ResultSet rs = session().execute(st); | |
| 47 | 44 | |
| 48 | 45 | assertFalse(rs.isFullyFetched()); |
| 49 | 46 | |
| @@ -59,7 +56,7 @@ | ||
| 59 | 56 | |
| 60 | 57 | } catch (UnsupportedFeatureException e) { |
| 61 | 58 | // This is expected when testing the protocol v1 |
| 62 | - assertEquals(cluster.getConfiguration().getProtocolOptions().getProtocolVersion(), ProtocolVersion.V1); | |
| 59 | + assertEquals(cluster().getConfiguration().getProtocolOptions().getProtocolVersion(), ProtocolVersion.V1); | |
| 63 | 60 | } |
| 64 | 61 | } |
| 65 | 62 | } |
modified driver-core/src/test/java/com/datastax/driver/core/FunctionMetadataTest.java +8 −11
| @@ -18,11 +18,8 @@ | ||
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | 19 | import org.testng.annotations.Test; |
| 20 | 20 | |
| 21 | -import java.util.Collection; | |
| 22 | - | |
| 23 | 21 | import static com.datastax.driver.core.Assertions.assertThat; |
| 24 | 22 | import static com.datastax.driver.core.DataType.cint; |
| 25 | -import static com.google.common.collect.Lists.newArrayList; | |
| 26 | 23 | import static org.assertj.core.api.Assertions.entry; |
| 27 | 24 | |
| 28 | 25 | @CassandraVersion(major = 2.2) |
| @@ -34,9 +31,9 @@ | ||
| 34 | 31 | // given |
| 35 | 32 | String cql = String.format("CREATE FUNCTION %s.plus(s int,v int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return s+v;';", keyspace); |
| 36 | 33 | // when |
| 37 | - session.execute(cql); | |
| 34 | + session().execute(cql); | |
| 38 | 35 | // then |
| 39 | - KeyspaceMetadata keyspace = cluster.getMetadata().getKeyspace(this.keyspace); | |
| 36 | + KeyspaceMetadata keyspace = cluster().getMetadata().getKeyspace(this.keyspace); | |
| 40 | 37 | FunctionMetadata function = keyspace.getFunction("plus", cint(), cint()); |
| 41 | 38 | assertThat(function).isNotNull(); |
| 42 | 39 | assertThat(function.getKeyspace()).isEqualTo(keyspace); |
| @@ -66,9 +63,9 @@ | ||
| 66 | 63 | // given |
| 67 | 64 | String cql = String.format("CREATE FUNCTION %s.pi() CALLED ON NULL INPUT RETURNS double LANGUAGE java AS 'return Math.PI;';", keyspace); |
| 68 | 65 | // when |
| 69 | - session.execute(cql); | |
| 66 | + session().execute(cql); | |
| 70 | 67 | // then |
| 71 | - KeyspaceMetadata keyspace = cluster.getMetadata().getKeyspace(this.keyspace); | |
| 68 | + KeyspaceMetadata keyspace = cluster().getMetadata().getKeyspace(this.keyspace); | |
| 72 | 69 | FunctionMetadata function = keyspace.getFunction("pi"); |
| 73 | 70 | assertThat(function).isNotNull(); |
| 74 | 71 | assertThat(function.getKeyspace()).isEqualTo(keyspace); |
| @@ -108,9 +105,9 @@ | ||
| 108 | 105 | + body |
| 109 | 106 | + "';", keyspace); |
| 110 | 107 | // when |
| 111 | - session.execute(cqlFunction); | |
| 108 | + session().execute(cqlFunction); | |
| 112 | 109 | // then |
| 113 | - KeyspaceMetadata keyspace = cluster.getMetadata().getKeyspace(this.keyspace); | |
| 110 | + KeyspaceMetadata keyspace = cluster().getMetadata().getKeyspace(this.keyspace); | |
| 114 | 111 | UserType addressType = keyspace.getUserType("\"Address\""); |
| 115 | 112 | FunctionMetadata function = keyspace.getFunction("\"NUM_PHONES_ACCU\"", cint(), addressType); |
| 116 | 113 | assertThat(function).isNotNull(); |
| @@ -127,8 +124,8 @@ | ||
| 127 | 124 | } |
| 128 | 125 | |
| 129 | 126 | @Override |
| 130 | - public Collection<String> createTestFixtures() { | |
| 131 | - return newArrayList( | |
| 127 | + public void onTestContextInitialized() { | |
| 128 | + execute( | |
| 132 | 129 | String.format("CREATE TYPE IF NOT EXISTS %s.\"Phone\" (number text)", keyspace), |
| 133 | 130 | String.format("CREATE TYPE IF NOT EXISTS %s.\"Address\" (" |
| 134 | 131 | + " street text," |
modified driver-core/src/test/java/com/datastax/driver/core/GettableDataIntegrationTest.java +10 −10
| @@ -44,10 +44,10 @@ | ||
| 44 | 44 | AtomicInteger keyCounter = new AtomicInteger(0); |
| 45 | 45 | |
| 46 | 46 | @Override |
| 47 | - public Collection<String> createTestFixtures() { | |
| 48 | - is21 = ccm.getVersion().compareTo(VersionNumber.parse("2.1.3")) > 0; | |
| 47 | + public void onTestContextInitialized() { | |
| 48 | + is21 = ccm().getVersion().compareTo(VersionNumber.parse("2.1.3")) > 0; | |
| 49 | 49 | // only add tuples / nested collections at > 2.1.3. |
| 50 | - return newArrayList("CREATE TABLE codec_mapping (k int PRIMARY KEY, " | |
| 50 | + execute("CREATE TABLE codec_mapping (k int PRIMARY KEY, " | |
| 51 | 51 | + "v int, l list<int>, m map<int,int>" + |
| 52 | 52 | (is21 ? ", t tuple<int,int>, s set<frozen<list<int>>>)" : ")")); |
| 53 | 53 | } |
| @@ -140,11 +140,11 @@ | ||
| 140 | 140 | @Test(groups = "short") |
| 141 | 141 | public void should_allow_getting_and_setting_by_type_if_codec_registered() { |
| 142 | 142 | String insertStmt = "INSERT INTO codec_mapping (k,v,l,m" + (is21 ? ",t,s" : "") + ") values (?,?,?,?" + (is21 ? ",?,?)" : ")"); |
| 143 | - PreparedStatement insert = session.prepare(insertStmt); | |
| 144 | - PreparedStatement select = session.prepare("SELECT v,l,m" + (is21 ? ",t,s" : "") + " from codec_mapping where k=?"); | |
| 143 | + PreparedStatement insert = session().prepare(insertStmt); | |
| 144 | + PreparedStatement select = session().prepare("SELECT v,l,m" + (is21 ? ",t,s" : "") + " from codec_mapping where k=?"); | |
| 145 | 145 | |
| 146 | 146 | TupleType tupleType = new TupleType(newArrayList(DataType.cint(), DataType.cint()), |
| 147 | - cluster.getConfiguration().getProtocolOptions().getProtocolVersion(), registry); | |
| 147 | + cluster().getConfiguration().getProtocolOptions().getProtocolVersion(), registry); | |
| 148 | 148 | |
| 149 | 149 | for (TypeMapping<?> mapping : mappings) { |
| 150 | 150 | // Keys used to insert data in this iteration. |
| @@ -170,7 +170,7 @@ | ||
| 170 | 170 | byName.setTupleValue("t", tupleValue); |
| 171 | 171 | byName.setSet("s", set, TypeTokens.listOf(mapping.javaType)); |
| 172 | 172 | } |
| 173 | - session.execute(byName); | |
| 173 | + session().execute(byName); | |
| 174 | 174 | |
| 175 | 175 | // Insert by index. |
| 176 | 176 | BoundStatement byIndex = insert.bind(); |
| @@ -184,7 +184,7 @@ | ||
| 184 | 184 | byIndex.setTupleValue(4, tupleValue); |
| 185 | 185 | byIndex.setSet(5, set, TypeTokens.listOf(mapping.javaType)); |
| 186 | 186 | } |
| 187 | - session.execute(byIndex); | |
| 187 | + session().execute(byIndex); | |
| 188 | 188 | |
| 189 | 189 | // Insert by binding all at once. |
| 190 | 190 | BoundStatement fullBind; |
| @@ -195,11 +195,11 @@ | ||
| 195 | 195 | } else { |
| 196 | 196 | fullBind = insert.bind(fullBindKey, mapping.value, list, map); |
| 197 | 197 | } |
| 198 | - session.execute(fullBind); | |
| 198 | + session().execute(fullBind); | |
| 199 | 199 | |
| 200 | 200 | for (int key : keys) { |
| 201 | 201 | // Retrieve by name. |
| 202 | - Row row = session.execute(select.bind(key)).one(); | |
| 202 | + Row row = session().execute(select.bind(key)).one(); | |
| 203 | 203 | assertThat(getValue(row, "v", mapping.outerType, registry)).isEqualTo(mapping.value); |
| 204 | 204 | assertThat(row.getList("l", mapping.codec.getJavaType())).isEqualTo(list); |
| 205 | 205 | assertThat(row.getMap("m", mapping.codec.getJavaType(), mapping.codec.getJavaType())).isEqualTo(map); |
modified driver-core/src/test/java/com/datastax/driver/core/HeartbeatTest.java +4 −4
| @@ -57,8 +57,8 @@ | ||
| 57 | 57 | @Test(groups = "long") |
| 58 | 58 | public void should_send_heartbeat_when_connection_is_inactive() throws InterruptedException { |
| 59 | 59 | Cluster cluster = register(Cluster.builder() |
| 60 | - .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 61 | - .withPort(ccm.getBinaryPort()) | |
| 60 | + .addContactPoints(getContactPoints().get(0)) | |
| 61 | + .withPort(ccm().getBinaryPort()) | |
| 62 | 62 | .withPoolingOptions(new PoolingOptions() |
| 63 | 63 | .setHeartbeatIntervalSeconds(3)) |
| 64 | 64 | .build()); |
| @@ -113,8 +113,8 @@ | ||
| 113 | 113 | @Test(groups = "long") |
| 114 | 114 | public void should_not_send_heartbeat_when_disabled() throws InterruptedException { |
| 115 | 115 | Cluster cluster = register(Cluster.builder() |
| 116 | - .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 117 | - .withPort(ccm.getBinaryPort()) | |
| 116 | + .addContactPoints(getContactPoints().get(0)) | |
| 117 | + .withPort(ccm().getBinaryPort()) | |
| 118 | 118 | .withPoolingOptions(new PoolingOptions() |
| 119 | 119 | .setHeartbeatIntervalSeconds(0)) |
| 120 | 120 | .build()); |
modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolTest.java +0 −8
| @@ -79,13 +79,6 @@ | ||
| 79 | 79 | return requests; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - @Override | |
| 83 | - protected Cluster.Builder configure(Cluster.Builder builder) { | |
| 84 | - // Use version 2 at highest. | |
| 85 | - ProtocolVersion versionToUse = TestUtils.getDesiredProtocolVersion(ProtocolVersion.V2); | |
| 86 | - return builder.withProtocolVersion(versionToUse); | |
| 87 | - } | |
| 88 | - | |
| 89 | 82 | /** |
| 90 | 83 | * Completes count requests by simulating a successful response. |
| 91 | 84 | */ |
| @@ -433,7 +426,6 @@ | ||
| 433 | 426 | // On returning of the connection, should detect that there are no available streams and trash it. |
| 434 | 427 | assertThat(pool.trash).hasSize(0); |
| 435 | 428 | pool.returnConnection(extra1); |
| 436 | - assertThat(pool.connections).hasSize(1); | |
| 437 | 429 | assertThat(pool.trash).hasSize(1); |
| 438 | 430 | } finally { |
| 439 | 431 | completeRequests(requests); |
modified driver-core/src/test/java/com/datastax/driver/core/IndexMetadataTest.java +24 −28
| @@ -24,7 +24,6 @@ | ||
| 24 | 24 | import org.testng.annotations.Test; |
| 25 | 25 | |
| 26 | 26 | import java.nio.ByteBuffer; |
| 27 | -import java.util.Collection; | |
| 28 | 27 | import java.util.List; |
| 29 | 28 | import java.util.Map; |
| 30 | 29 | |
| @@ -63,10 +62,9 @@ | ||
| 63 | 62 | private ProtocolVersion protocolVersion; |
| 64 | 63 | |
| 65 | 64 | @Override |
| 66 | - public Collection<String> createTestFixtures() { | |
| 67 | - protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 68 | - ImmutableList.Builder<String> builder = ImmutableList.builder(); | |
| 69 | - builder.add("CREATE TABLE indexing (" | |
| 65 | + public void onTestContextInitialized() { | |
| 66 | + protocolVersion = cluster().getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 67 | + String createTable = "CREATE TABLE indexing (" | |
| 70 | 68 | + "id int," |
| 71 | 69 | + "id2 int," |
| 72 | 70 | + "map_values map<text, int>," |
| @@ -77,23 +75,21 @@ | ||
| 77 | 75 | + "\"MixedCaseColumn\" list<text>," |
| 78 | 76 | + |
| 79 | 77 | // Frozen collections was introduced only in C* 2.1.3 |
| 80 | - (ccm.getVersion().compareTo(VersionNumber.parse("2.1.3")) >= 0 | |
| 78 | + (ccm().getVersion().compareTo(VersionNumber.parse("2.1.3")) >= 0 | |
| 81 | 79 | ? |
| 82 | 80 | ", map_full frozen<map<text, int>>," |
| 83 | 81 | + "set_full frozen<set<text>>," |
| 84 | 82 | + "list_full frozen<list<text>>," |
| 85 | 83 | : |
| 86 | 84 | "") |
| 87 | - + "PRIMARY KEY (id, id2));" | |
| 88 | - ); | |
| 89 | - | |
| 90 | - return builder.build(); | |
| 85 | + + "PRIMARY KEY (id, id2));"; | |
| 86 | + execute(createTable); | |
| 91 | 87 | } |
| 92 | 88 | |
| 93 | 89 | @Test(groups = "short") |
| 94 | 90 | public void should_create_metadata_for_simple_index() { |
| 95 | 91 | String createValuesIndex = String.format("CREATE INDEX text_column_index ON %s.indexing (text_column);", keyspace); |
| 96 | - session.execute(createValuesIndex); | |
| 92 | + session().execute(createValuesIndex); | |
| 97 | 93 | ColumnMetadata column = getColumn("text_column"); |
| 98 | 94 | IndexMetadata index = getIndex("text_column_index"); |
| 99 | 95 | assertThat(index) |
| @@ -110,17 +106,17 @@ | ||
| 110 | 106 | @CassandraVersion(major = 2.1, description = "index names with quoted identifiers and collection indexes not supported until 2.1") |
| 111 | 107 | public void should_create_metadata_for_values_index_on_mixed_case_column() { |
| 112 | 108 | // 3.0 assumes the 'values' keyword if index on a collection |
| 113 | - String createValuesIndex = ccm.getVersion().getMajor() > 2 ? | |
| 109 | + String createValuesIndex = ccm().getVersion().getMajor() > 2 ? | |
| 114 | 110 | String.format("CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (values(\"MixedCaseColumn\"));", keyspace) : |
| 115 | 111 | String.format("CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (\"MixedCaseColumn\");", keyspace); |
| 116 | - session.execute(createValuesIndex); | |
| 112 | + session().execute(createValuesIndex); | |
| 117 | 113 | ColumnMetadata column = getColumn("\"MixedCaseColumn\""); |
| 118 | 114 | IndexMetadata index = getIndex("\"MixedCaseIndex\""); |
| 119 | 115 | assertThat(index) |
| 120 | 116 | .hasName("MixedCaseIndex") |
| 121 | 117 | .hasParent((TableMetadata) column.getParent()) |
| 122 | 118 | .isNotCustomIndex() |
| 123 | - .hasTarget(ccm.getVersion().getMajor() > 2 ? "values(\"MixedCaseColumn\")" : "\"MixedCaseColumn\"") | |
| 119 | + .hasTarget(ccm().getVersion().getMajor() > 2 ? "values(\"MixedCaseColumn\")" : "\"MixedCaseColumn\"") | |
| 124 | 120 | .hasKind(COMPOSITES) |
| 125 | 121 | .asCqlQuery(createValuesIndex); |
| 126 | 122 | assertThat((TableMetadata) column.getParent()).hasIndex(index); |
| @@ -130,17 +126,17 @@ | ||
| 130 | 126 | @CassandraVersion(major = 2.1) |
| 131 | 127 | public void should_create_metadata_for_index_on_map_values() { |
| 132 | 128 | // 3.0 assumes the 'values' keyword if index on a collection |
| 133 | - String createValuesIndex = ccm.getVersion().getMajor() > 2 ? | |
| 129 | + String createValuesIndex = ccm().getVersion().getMajor() > 2 ? | |
| 134 | 130 | String.format("CREATE INDEX map_values_index ON %s.indexing (values(map_values));", keyspace) : |
| 135 | 131 | String.format("CREATE INDEX map_values_index ON %s.indexing (map_values);", keyspace); |
| 136 | - session.execute(createValuesIndex); | |
| 132 | + session().execute(createValuesIndex); | |
| 137 | 133 | ColumnMetadata column = getColumn("map_values"); |
| 138 | 134 | IndexMetadata index = getIndex("map_values_index"); |
| 139 | 135 | assertThat(index) |
| 140 | 136 | .hasName("map_values_index") |
| 141 | 137 | .hasParent((TableMetadata) column.getParent()) |
| 142 | 138 | .isNotCustomIndex() |
| 143 | - .hasTarget(ccm.getVersion().getMajor() > 2 ? "values(map_values)" : "map_values") | |
| 139 | + .hasTarget(ccm().getVersion().getMajor() > 2 ? "values(map_values)" : "map_values") | |
| 144 | 140 | .hasKind(COMPOSITES) |
| 145 | 141 | .asCqlQuery(createValuesIndex); |
| 146 | 142 | assertThat((TableMetadata) column.getParent()).hasIndex(index); |
| @@ -150,7 +146,7 @@ | ||
| 150 | 146 | @CassandraVersion(major = 2.1) |
| 151 | 147 | public void should_create_metadata_for_index_on_map_keys() { |
| 152 | 148 | String createKeysIndex = String.format("CREATE INDEX map_keys_index ON %s.indexing (keys(map_keys));", keyspace); |
| 153 | - session.execute(createKeysIndex); | |
| 149 | + session().execute(createKeysIndex); | |
| 154 | 150 | ColumnMetadata column = getColumn("map_keys"); |
| 155 | 151 | IndexMetadata index = getIndex("map_keys_index"); |
| 156 | 152 | assertThat(index) |
| @@ -167,7 +163,7 @@ | ||
| 167 | 163 | @CassandraVersion(major = 2.1, minor = 3) |
| 168 | 164 | public void should_create_metadata_for_full_index_on_map() { |
| 169 | 165 | String createFullIndex = String.format("CREATE INDEX map_full_index ON %s.indexing (full(map_full));", keyspace); |
| 170 | - session.execute(createFullIndex); | |
| 166 | + session().execute(createFullIndex); | |
| 171 | 167 | ColumnMetadata column = getColumn("map_full"); |
| 172 | 168 | IndexMetadata index = getIndex("map_full_index"); |
| 173 | 169 | assertThat(index) |
| @@ -184,7 +180,7 @@ | ||
| 184 | 180 | @CassandraVersion(major = 2.1, minor = 3) |
| 185 | 181 | public void should_create_metadata_for_full_index_on_set() { |
| 186 | 182 | String createFullIndex = String.format("CREATE INDEX set_full_index ON %s.indexing (full(set_full));", keyspace); |
| 187 | - session.execute(createFullIndex); | |
| 183 | + session().execute(createFullIndex); | |
| 188 | 184 | ColumnMetadata column = getColumn("set_full"); |
| 189 | 185 | IndexMetadata index = getIndex("set_full_index"); |
| 190 | 186 | assertThat(index) |
| @@ -201,7 +197,7 @@ | ||
| 201 | 197 | @CassandraVersion(major = 2.1, minor = 3) |
| 202 | 198 | public void should_create_metadata_for_full_index_on_list() { |
| 203 | 199 | String createFullIndex = String.format("CREATE INDEX list_full_index ON %s.indexing (full(list_full));", keyspace); |
| 204 | - session.execute(createFullIndex); | |
| 200 | + session().execute(createFullIndex); | |
| 205 | 201 | ColumnMetadata column = getColumn("list_full"); |
| 206 | 202 | IndexMetadata index = getIndex("list_full_index"); |
| 207 | 203 | assertThat(index) |
| @@ -218,7 +214,7 @@ | ||
| 218 | 214 | @CassandraVersion(major = 2.2) |
| 219 | 215 | public void should_create_metadata_for_index_on_map_entries() { |
| 220 | 216 | String createEntriesIndex = String.format("CREATE INDEX map_entries_index ON %s.indexing (entries(map_entries));", keyspace); |
| 221 | - session.execute(createEntriesIndex); | |
| 217 | + session().execute(createEntriesIndex); | |
| 222 | 218 | ColumnMetadata column = getColumn("map_entries"); |
| 223 | 219 | IndexMetadata index = getIndex("map_entries_index"); |
| 224 | 220 | assertThat(index) |
| @@ -235,11 +231,11 @@ | ||
| 235 | 231 | @CassandraVersion(major = 3.0) |
| 236 | 232 | public void should_allow_multiple_indexes_on_map_column() { |
| 237 | 233 | String createEntriesIndex = String.format("CREATE INDEX map_all_entries_index ON %s.indexing (entries(map_all));", keyspace); |
| 238 | - session.execute(createEntriesIndex); | |
| 234 | + session().execute(createEntriesIndex); | |
| 239 | 235 | String createKeysIndex = String.format("CREATE INDEX map_all_keys_index ON %s.indexing (keys(map_all));", keyspace); |
| 240 | - session.execute(createKeysIndex); | |
| 236 | + session().execute(createKeysIndex); | |
| 241 | 237 | String createValuesIndex = String.format("CREATE INDEX map_all_values_index ON %s.indexing (values(map_all));", keyspace); |
| 242 | - session.execute(createValuesIndex); | |
| 238 | + session().execute(createValuesIndex); | |
| 243 | 239 | |
| 244 | 240 | ColumnMetadata column = getColumn("map_all"); |
| 245 | 241 | TableMetadata table = (TableMetadata) column.getParent(); |
| @@ -335,7 +331,7 @@ | ||
| 335 | 331 | wrap("org.apache.cassandra.db.marshal.BytesType"), // validator |
| 336 | 332 | wrap("null") // index options |
| 337 | 333 | ); |
| 338 | - Row row = ArrayBackedRow.fromData(legacyColumnDefs, M3PToken.FACTORY, cluster.getConfiguration().getProtocolOptions().getProtocolVersion(), data); | |
| 334 | + Row row = ArrayBackedRow.fromData(legacyColumnDefs, M3PToken.FACTORY, cluster().getConfiguration().getProtocolOptions().getProtocolVersion(), data); | |
| 339 | 335 | Raw raw = Raw.fromRow(row, VersionNumber.parse("2.1")); |
| 340 | 336 | ColumnMetadata column = ColumnMetadata.fromRaw(table, raw, DataType.blob()); |
| 341 | 337 | IndexMetadata index = IndexMetadata.fromLegacy(column, raw); |
| @@ -375,10 +371,10 @@ | ||
| 375 | 371 | } |
| 376 | 372 | |
| 377 | 373 | private TableMetadata getTable(String name) { |
| 378 | - return cluster.getMetadata().getKeyspace(keyspace).getTable(name); | |
| 374 | + return cluster().getMetadata().getKeyspace(keyspace).getTable(name); | |
| 379 | 375 | } |
| 380 | 376 | |
| 381 | 377 | private MaterializedViewMetadata getMaterializedView(String name) { |
| 382 | - return cluster.getMetadata().getKeyspace(keyspace).getMaterializedView(name); | |
| 378 | + return cluster().getMetadata().getKeyspace(keyspace).getMaterializedView(name); | |
| 383 | 379 | } |
| 384 | 380 | } |
modified driver-core/src/test/java/com/datastax/driver/core/LargeDataTest.java +32 −32
| @@ -43,11 +43,11 @@ | ||
| 43 | 43 | private void testWideRows(int key) throws Throwable { |
| 44 | 44 | // Write data |
| 45 | 45 | for (int i = 0; i < 1000000; ++i) { |
| 46 | - session.execute(insertInto("wide_rows").value("k", key).value("i", i).setConsistencyLevel(ConsistencyLevel.QUORUM)); | |
| 46 | + session().execute(insertInto("wide_rows").value("k", key).value("i", i).setConsistencyLevel(ConsistencyLevel.QUORUM)); | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | // Read data |
| 50 | - ResultSet rs = session.execute(select("i").from("wide_rows").where(eq("k", key))); | |
| 50 | + ResultSet rs = session().execute(select("i").from("wide_rows").where(eq("k", key))); | |
| 51 | 51 | |
| 52 | 52 | // Verify data |
| 53 | 53 | int i = 0; |
| @@ -68,10 +68,10 @@ | ||
| 68 | 68 | for (int i = 0; i < 4000; ++i) { |
| 69 | 69 | q = q.add(insertInto("wide_batch_rows").value("k", key).value("i", i)); |
| 70 | 70 | } |
| 71 | - session.execute(q.setConsistencyLevel(ConsistencyLevel.QUORUM)); | |
| 71 | + session().execute(q.setConsistencyLevel(ConsistencyLevel.QUORUM)); | |
| 72 | 72 | |
| 73 | 73 | // Read data |
| 74 | - ResultSet rs = session.execute(select("i").from("wide_batch_rows").where(eq("k", key))); | |
| 74 | + ResultSet rs = session().execute(select("i").from("wide_batch_rows").where(eq("k", key))); | |
| 75 | 75 | |
| 76 | 76 | // Verify data |
| 77 | 77 | int i = 0; |
| @@ -94,11 +94,11 @@ | ||
| 94 | 94 | |
| 95 | 95 | // Write data |
| 96 | 96 | for (int i = 0; i < 1000000; ++i) { |
| 97 | - session.execute(insertInto("wide_byte_rows").value("k", key).value("i", bb).setConsistencyLevel(ConsistencyLevel.QUORUM)); | |
| 97 | + session().execute(insertInto("wide_byte_rows").value("k", key).value("i", bb).setConsistencyLevel(ConsistencyLevel.QUORUM)); | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Read data |
| 101 | - ResultSet rs = session.execute(select("i").from("wide_byte_rows").where(eq("k", key))); | |
| 101 | + ResultSet rs = session().execute(select("i").from("wide_byte_rows").where(eq("k", key))); | |
| 102 | 102 | |
| 103 | 103 | // Verify data |
| 104 | 104 | for (Row row : rs) { |
| @@ -119,10 +119,10 @@ | ||
| 119 | 119 | // Create ultra-long text |
| 120 | 120 | b.append(i); |
| 121 | 121 | } |
| 122 | - session.execute(insertInto("large_text").value("k", key).value("txt", b.toString()).setConsistencyLevel(ConsistencyLevel.QUORUM)); | |
| 122 | + session().execute(insertInto("large_text").value("k", key).value("txt", b.toString()).setConsistencyLevel(ConsistencyLevel.QUORUM)); | |
| 123 | 123 | |
| 124 | 124 | // Read data |
| 125 | - Row row = session.execute(select().all().from("large_text").where(eq("k", key))).one(); | |
| 125 | + Row row = session().execute(select().all().from("large_text").where(eq("k", key))).one(); | |
| 126 | 126 | |
| 127 | 127 | // Verify data |
| 128 | 128 | assertTrue(b.toString().equals(row.getString("txt"))); |
| @@ -166,10 +166,10 @@ | ||
| 166 | 166 | for (int i = 0; i < 330; ++i) { |
| 167 | 167 | insertStatement = insertStatement.value(createColumnName(i), i); |
| 168 | 168 | } |
| 169 | - session.execute(insertStatement.setConsistencyLevel(ConsistencyLevel.QUORUM)); | |
| 169 | + session().execute(insertStatement.setConsistencyLevel(ConsistencyLevel.QUORUM)); | |
| 170 | 170 | |
| 171 | 171 | // Read data |
| 172 | - Row row = session.execute(select().all().from("wide_table").where(eq("k", key))).one(); | |
| 172 | + Row row = session().execute(select().all().from("wide_table").where(eq("k", key))).one(); | |
| 173 | 173 | |
| 174 | 174 | // Verify data |
| 175 | 175 | for (int i = 0; i < 330; ++i) { |
| @@ -186,9 +186,9 @@ | ||
| 186 | 186 | @Test(groups = "stress") |
| 187 | 187 | @CassandraVersion(major = 2.0, minor = 0, description = "< 2.0 is skipped as 1.2 does not handle reading wide rows well.") |
| 188 | 188 | public void wideRows() throws Throwable { |
| 189 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, "large_data", 1)); | |
| 190 | - session.execute("USE large_data"); | |
| 191 | - session.execute(String.format("CREATE TABLE %s (k INT, i INT, PRIMARY KEY(k, i))", "wide_rows")); | |
| 189 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, "large_data", 1)); | |
| 190 | + session().execute("USE large_data"); | |
| 191 | + session().execute(String.format("CREATE TABLE %s (k INT, i INT, PRIMARY KEY(k, i))", "wide_rows")); | |
| 192 | 192 | testWideRows(0); |
| 193 | 193 | } |
| 194 | 194 | |
| @@ -200,9 +200,9 @@ | ||
| 200 | 200 | @Test(groups = "stress") |
| 201 | 201 | @CassandraVersion(major = 2.0, minor = 0, description = "< 2.0 is skipped as 1.2 does not handle large batches well.") |
| 202 | 202 | public void wideBatchRows() throws Throwable { |
| 203 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, "large_data", 1)); | |
| 204 | - session.execute("USE large_data"); | |
| 205 | - session.execute(String.format("CREATE TABLE %s (k INT, i INT, PRIMARY KEY(k, i))", "wide_batch_rows")); | |
| 203 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, "large_data", 1)); | |
| 204 | + session().execute("USE large_data"); | |
| 205 | + session().execute(String.format("CREATE TABLE %s (k INT, i INT, PRIMARY KEY(k, i))", "wide_batch_rows")); | |
| 206 | 206 | testWideBatchRows(0); |
| 207 | 207 | } |
| 208 | 208 | |
| @@ -213,9 +213,9 @@ | ||
| 213 | 213 | */ |
| 214 | 214 | @Test(groups = "stress") |
| 215 | 215 | public void wideByteRows() throws Throwable { |
| 216 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, "large_data", 1)); | |
| 217 | - session.execute("USE large_data"); | |
| 218 | - session.execute(String.format("CREATE TABLE %s (k INT, i BLOB, PRIMARY KEY(k, i))", "wide_byte_rows")); | |
| 216 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, "large_data", 1)); | |
| 217 | + session().execute("USE large_data"); | |
| 218 | + session().execute(String.format("CREATE TABLE %s (k INT, i BLOB, PRIMARY KEY(k, i))", "wide_byte_rows")); | |
| 219 | 219 | testByteRows(0); |
| 220 | 220 | } |
| 221 | 221 | |
| @@ -226,9 +226,9 @@ | ||
| 226 | 226 | */ |
| 227 | 227 | @Test(groups = "stress") |
| 228 | 228 | public void largeText() throws Throwable { |
| 229 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, "large_data", 1)); | |
| 230 | - session.execute("USE large_data"); | |
| 231 | - session.execute(String.format("CREATE TABLE %s (k int PRIMARY KEY, txt text)", "large_text")); | |
| 229 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, "large_data", 1)); | |
| 230 | + session().execute("USE large_data"); | |
| 231 | + session().execute(String.format("CREATE TABLE %s (k int PRIMARY KEY, txt text)", "large_text")); | |
| 232 | 232 | testLargeText(0); |
| 233 | 233 | } |
| 234 | 234 | |
| @@ -239,8 +239,8 @@ | ||
| 239 | 239 | */ |
| 240 | 240 | @Test(groups = "stress") |
| 241 | 241 | public void wideTable() throws Throwable { |
| 242 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, "large_data", 1)); | |
| 243 | - session.execute("USE large_data"); | |
| 242 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, "large_data", 1)); | |
| 243 | + session().execute("USE large_data"); | |
| 244 | 244 | // Create the extra wide table definition |
| 245 | 245 | StringBuilder tableDeclaration = new StringBuilder(); |
| 246 | 246 | tableDeclaration.append("CREATE TABLE wide_table ("); |
| @@ -249,7 +249,7 @@ | ||
| 249 | 249 | tableDeclaration.append(String.format(", %s INT", createColumnName(i))); |
| 250 | 250 | } |
| 251 | 251 | tableDeclaration.append(')'); |
| 252 | - session.execute(tableDeclaration.toString()); | |
| 252 | + session().execute(tableDeclaration.toString()); | |
| 253 | 253 | testWideTable(0); |
| 254 | 254 | } |
| 255 | 255 | |
| @@ -261,12 +261,12 @@ | ||
| 261 | 261 | @Test(groups = "duration") |
| 262 | 262 | @CCMConfig(numberOfNodes = 3) |
| 263 | 263 | public void mixedDurationTest() throws Throwable { |
| 264 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, "large_data", 3)); | |
| 265 | - session.execute("USE large_data"); | |
| 266 | - session.execute(String.format("CREATE TABLE %s (k INT, i INT, PRIMARY KEY(k, i))", "wide_rows")); | |
| 267 | - session.execute(String.format("CREATE TABLE %s (k INT, i INT, PRIMARY KEY(k, i))", "wide_batch_rows")); | |
| 268 | - session.execute(String.format("CREATE TABLE %s (k INT, i BLOB, PRIMARY KEY(k, i))", "wide_byte_rows")); | |
| 269 | - session.execute(String.format("CREATE TABLE %s (k int PRIMARY KEY, txt text)", "large_text")); | |
| 264 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, "large_data", 3)); | |
| 265 | + session().execute("USE large_data"); | |
| 266 | + session().execute(String.format("CREATE TABLE %s (k INT, i INT, PRIMARY KEY(k, i))", "wide_rows")); | |
| 267 | + session().execute(String.format("CREATE TABLE %s (k INT, i INT, PRIMARY KEY(k, i))", "wide_batch_rows")); | |
| 268 | + session().execute(String.format("CREATE TABLE %s (k INT, i BLOB, PRIMARY KEY(k, i))", "wide_byte_rows")); | |
| 269 | + session().execute(String.format("CREATE TABLE %s (k int PRIMARY KEY, txt text)", "large_text")); | |
| 270 | 270 | // Create the extra wide table definition |
| 271 | 271 | StringBuilder tableDeclaration = new StringBuilder(); |
| 272 | 272 | tableDeclaration.append("CREATE TABLE wide_table ("); |
| @@ -275,7 +275,7 @@ | ||
| 275 | 275 | tableDeclaration.append(String.format(", %s INT", createColumnName(i))); |
| 276 | 276 | } |
| 277 | 277 | tableDeclaration.append(')'); |
| 278 | - session.execute(tableDeclaration.toString()); | |
| 278 | + session().execute(tableDeclaration.toString()); | |
| 279 | 279 | for (int i = 0; i < 10; ++i) { |
| 280 | 280 | switch ((int) (Math.random() * 5)) { |
| 281 | 281 | case 0: |
modified driver-core/src/test/java/com/datastax/driver/core/LoadBalancingPolicyBootstrapTest.java +8 −8
| @@ -48,8 +48,8 @@ | ||
| 48 | 48 | HistoryPolicy policy = new HistoryPolicy(new RoundRobinPolicy()); |
| 49 | 49 | |
| 50 | 50 | Cluster cluster = register(Cluster.builder() |
| 51 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 52 | - .withPort(ccm.getBinaryPort()) | |
| 51 | + .addContactPoints(getContactPoints()) | |
| 52 | + .withPort(ccm().getBinaryPort()) | |
| 53 | 53 | .withLoadBalancingPolicy(policy) |
| 54 | 54 | .build()); |
| 55 | 55 | |
| @@ -85,13 +85,13 @@ | ||
| 85 | 85 | nodeToStop = (nodeToStop == 1) ? 2 : 1; // switch nodes at each try |
| 86 | 86 | int activeNode = nodeToStop == 2 ? 1 : 2; |
| 87 | 87 | |
| 88 | - ccm.stop(nodeToStop); | |
| 89 | - ccm.waitForDown(nodeToStop); | |
| 88 | + ccm().stop(nodeToStop); | |
| 89 | + ccm().waitForDown(nodeToStop); | |
| 90 | 90 | |
| 91 | 91 | HistoryPolicy policy = new HistoryPolicy(new RoundRobinPolicy()); |
| 92 | 92 | Cluster cluster = register(Cluster.builder() |
| 93 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 94 | - .withPort(ccm.getBinaryPort()) | |
| 93 | + .addContactPoints(getContactPoints()) | |
| 94 | + .withPort(ccm().getBinaryPort()) | |
| 95 | 95 | .withLoadBalancingPolicy(policy) |
| 96 | 96 | .build()); |
| 97 | 97 | |
| @@ -114,8 +114,8 @@ | ||
| 114 | 114 | |
| 115 | 115 | cluster.close(); |
| 116 | 116 | |
| 117 | - ccm.start(nodeToStop); | |
| 118 | - ccm.waitForUp(nodeToStop); | |
| 117 | + ccm().start(nodeToStop); | |
| 118 | + ccm().waitForUp(nodeToStop); | |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 |
modified driver-core/src/test/java/com/datastax/driver/core/LoadBalancingPolicyRefreshTest.java +6 −6
| @@ -82,20 +82,20 @@ | ||
| 82 | 82 | public void refreshTest() throws Throwable { |
| 83 | 83 | // Ugly |
| 84 | 84 | Host[] hosts = new Host[2]; |
| 85 | - for (Host h : cluster.getMetadata().getAllHosts()) { | |
| 86 | - if (h.getAddress().equals(ccm.addressOfNode(1).getAddress())) | |
| 85 | + for (Host h : cluster().getMetadata().getAllHosts()) { | |
| 86 | + if (h.getAddress().equals(ccm().addressOfNode(1).getAddress())) | |
| 87 | 87 | hosts[0] = h; |
| 88 | 88 | else |
| 89 | 89 | hosts[1] = h; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - assertTrue(session.getState().getConnectedHosts().contains(hosts[0]), "Connected hosts: " + session.getState().getConnectedHosts()); | |
| 93 | - assertTrue(!session.getState().getConnectedHosts().contains(hosts[1]), "Connected hosts: " + session.getState().getConnectedHosts()); | |
| 92 | + assertTrue(session().getState().getConnectedHosts().contains(hosts[0]), "Connected hosts: " + session().getState().getConnectedHosts()); | |
| 93 | + assertTrue(!session().getState().getConnectedHosts().contains(hosts[1]), "Connected hosts: " + session().getState().getConnectedHosts()); | |
| 94 | 94 | |
| 95 | 95 | policy.changeTheHost(hosts[1]); |
| 96 | 96 | |
| 97 | - assertTrue(!session.getState().getConnectedHosts().contains(hosts[0]), "Connected hosts: " + session.getState().getConnectedHosts()); | |
| 98 | - assertTrue(session.getState().getConnectedHosts().contains(hosts[1]), "Connected hosts: " + session.getState().getConnectedHosts()); | |
| 97 | + assertTrue(!session().getState().getConnectedHosts().contains(hosts[0]), "Connected hosts: " + session().getState().getConnectedHosts()); | |
| 98 | + assertTrue(session().getState().getConnectedHosts().contains(hosts[1]), "Connected hosts: " + session().getState().getConnectedHosts()); | |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | @SuppressWarnings("unused") |
modified driver-core/src/test/java/com/datastax/driver/core/MaterializedViewMetadataTest.java +8 −15
| @@ -18,9 +18,6 @@ | ||
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | 19 | import org.testng.annotations.Test; |
| 20 | 20 | |
| 21 | -import java.util.Collection; | |
| 22 | -import java.util.Collections; | |
| 23 | - | |
| 24 | 21 | import static com.datastax.driver.core.Assertions.assertThat; |
| 25 | 22 | import static com.datastax.driver.core.ClusteringOrder.DESC; |
| 26 | 23 | import static com.datastax.driver.core.DataType.cint; |
| @@ -58,12 +55,12 @@ | ||
| 58 | 55 | keyspace, keyspace); |
| 59 | 56 | |
| 60 | 57 | // when |
| 61 | - session.execute(createTable); | |
| 62 | - session.execute(createMV); | |
| 58 | + session().execute(createTable); | |
| 59 | + session().execute(createMV); | |
| 63 | 60 | |
| 64 | 61 | // then |
| 65 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("scores"); | |
| 66 | - MaterializedViewMetadata mv = cluster.getMetadata().getKeyspace(keyspace).getMaterializedView("monthlyhigh"); | |
| 62 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("scores"); | |
| 63 | + MaterializedViewMetadata mv = cluster().getMetadata().getKeyspace(keyspace).getMaterializedView("monthlyhigh"); | |
| 67 | 64 | |
| 68 | 65 | assertThat(table).isNotNull().hasName("scores").hasMaterializedView(mv).hasNumberOfColumns(6); |
| 69 | 66 | assertThat(table.getColumns().get(0)).isNotNull().hasName("user").isPartitionKey(); |
| @@ -107,11 +104,11 @@ | ||
| 107 | 104 | + "PRIMARY KEY (\"theKey\", \"the;Clustering\")", |
| 108 | 105 | keyspace, keyspace); |
| 109 | 106 | // when |
| 110 | - session.execute(createTable); | |
| 111 | - session.execute(createMV); | |
| 107 | + session().execute(createTable); | |
| 108 | + session().execute(createMV); | |
| 112 | 109 | // then |
| 113 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("\"T1\""); | |
| 114 | - MaterializedViewMetadata mv = cluster.getMetadata().getKeyspace(keyspace).getMaterializedView("\"Mv1\""); | |
| 110 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("\"T1\""); | |
| 111 | + MaterializedViewMetadata mv = cluster().getMetadata().getKeyspace(keyspace).getMaterializedView("\"Mv1\""); | |
| 115 | 112 | assertThat(table).isNotNull().hasName("T1").hasMaterializedView(mv).hasNumberOfColumns(3); |
| 116 | 113 | assertThat(table.getViews()).hasSize(1).containsOnly(mv); |
| 117 | 114 | assertThat(table.getColumns().get(0)).isNotNull().hasName("theKey").isPartitionKey().hasType(cint()); |
| @@ -124,8 +121,4 @@ | ||
| 124 | 121 | assertThat(mv.asCQLQuery(false)).contains(createMV); |
| 125 | 122 | } |
| 126 | 123 | |
| 127 | - @Override | |
| 128 | - public Collection<String> createTestFixtures() { | |
| 129 | - return Collections.emptyList(); | |
| 130 | - } | |
| 131 | 124 | } |
modified driver-core/src/test/java/com/datastax/driver/core/MetadataTest.java +8 −8
| @@ -23,7 +23,7 @@ | ||
| 23 | 23 | import static com.datastax.driver.core.Assertions.assertThat; |
| 24 | 24 | import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD; |
| 25 | 25 | import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; |
| 26 | -import static com.datastax.driver.core.TestUtils.waitFor; | |
| 26 | +import static com.datastax.driver.core.TestUtils.waitForUp; | |
| 27 | 27 | |
| 28 | 28 | @CreateCCM(PER_METHOD) |
| 29 | 29 | public class MetadataTest extends CCMTestsSupport { |
| @@ -55,8 +55,8 @@ | ||
| 55 | 55 | @CCMConfig(numberOfNodes = 3, dirtiesContext = true, createCluster = false) |
| 56 | 56 | public void should_update_metadata_on_topology_change() { |
| 57 | 57 | Cluster cluster = register(Cluster.builder() |
| 58 | - .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 59 | - .withPort(ccm.getBinaryPort()) | |
| 58 | + .addContactPoints(getContactPoints().get(0)) | |
| 59 | + .withPort(ccm().getBinaryPort()) | |
| 60 | 60 | .withQueryOptions(nonDebouncingQueryOptions()) |
| 61 | 61 | .build()); |
| 62 | 62 | Session session = cluster.connect(); |
| @@ -73,8 +73,8 @@ | ||
| 73 | 73 | Host host3 = TestUtils.findHost(cluster, 3); |
| 74 | 74 | Token host3Token = tokensForHost.get(host3); |
| 75 | 75 | |
| 76 | - ccm.decommission(3); | |
| 77 | - ccm.remove(3); | |
| 76 | + ccm().decommission(3); | |
| 77 | + ccm().remove(3); | |
| 78 | 78 | |
| 79 | 79 | // Ensure that the token ranges were updated, there should only be 2 ranges now. |
| 80 | 80 | assertThat(metadata.getTokenRanges()).hasSize(2); |
| @@ -87,9 +87,9 @@ | ||
| 87 | 87 | assertThat(cluster).hasValidTokenRanges(); |
| 88 | 88 | |
| 89 | 89 | // Add an additional node. |
| 90 | - ccm.add(4); | |
| 91 | - ccm.start(4); | |
| 92 | - waitFor(TestUtils.IP_PREFIX + '4', cluster); | |
| 90 | + ccm().add(4); | |
| 91 | + ccm().start(4); | |
| 92 | + waitForUp(TestUtils.IP_PREFIX + '4', cluster); | |
| 93 | 93 | |
| 94 | 94 | // Ensure that the token ranges were updated, there should only be 3 ranges now. |
| 95 | 95 | assertThat(metadata.getTokenRanges()).hasSize(3); |
modified driver-core/src/test/java/com/datastax/driver/core/MetricsTest.java +13 −15
| @@ -19,7 +19,6 @@ | ||
| 19 | 19 | import com.datastax.driver.core.exceptions.DriverException; |
| 20 | 20 | import com.datastax.driver.core.policies.RetryPolicy; |
| 21 | 21 | import com.datastax.driver.core.policies.RetryPolicy.RetryDecision; |
| 22 | -import com.google.common.collect.Lists; | |
| 23 | 22 | import org.testng.annotations.Test; |
| 24 | 23 | |
| 25 | 24 | import javax.management.InstanceNotFoundException; |
| @@ -27,7 +26,6 @@ | ||
| 27 | 26 | import javax.management.MBeanServer; |
| 28 | 27 | import javax.management.ObjectName; |
| 29 | 28 | import java.lang.management.ManagementFactory; |
| 30 | -import java.util.Collection; | |
| 31 | 29 | |
| 32 | 30 | import static com.datastax.driver.core.Assertions.assertThat; |
| 33 | 31 | import static org.testng.Assert.assertEquals; |
| @@ -71,8 +69,8 @@ | ||
| 71 | 69 | } |
| 72 | 70 | |
| 73 | 71 | @Override |
| 74 | - public Collection<String> createTestFixtures() { | |
| 75 | - return Lists.newArrayList("CREATE TABLE test (k int primary key, v int)", | |
| 72 | + public void onTestContextInitialized() { | |
| 73 | + execute("CREATE TABLE test (k int primary key, v int)", | |
| 76 | 74 | "INSERT INTO test (k, v) VALUES (1, 1)"); |
| 77 | 75 | } |
| 78 | 76 | |
| @@ -82,15 +80,15 @@ | ||
| 82 | 80 | |
| 83 | 81 | // We only have one node, this will throw an unavailable exception |
| 84 | 82 | Statement statement = new SimpleStatement("SELECT v FROM test WHERE k = 1").setConsistencyLevel(ConsistencyLevel.TWO); |
| 85 | - session.execute(statement); | |
| 83 | + session().execute(statement); | |
| 86 | 84 | |
| 87 | - Errors errors = cluster.getMetrics().getErrorMetrics(); | |
| 85 | + Errors errors = cluster().getMetrics().getErrorMetrics(); | |
| 88 | 86 | assertEquals(errors.getUnavailables().getCount(), 1); |
| 89 | 87 | assertEquals(errors.getRetries().getCount(), 1); |
| 90 | 88 | assertEquals(errors.getRetriesOnUnavailable().getCount(), 1); |
| 91 | 89 | |
| 92 | 90 | retryDecision = RetryDecision.ignore(); |
| 93 | - session.execute(statement); | |
| 91 | + session().execute(statement); | |
| 94 | 92 | |
| 95 | 93 | assertEquals(errors.getUnavailables().getCount(), 2); |
| 96 | 94 | assertEquals(errors.getIgnores().getCount(), 1); |
| @@ -106,13 +104,13 @@ | ||
| 106 | 104 | */ |
| 107 | 105 | @Test(groups = "short") |
| 108 | 106 | public void should_enable_metrics_and_jmx_by_default() throws Exception { |
| 109 | - assertThat(cluster.getMetrics()).isNotNull(); | |
| 110 | - ObjectName clusterMetricsON = ObjectName.getInstance(cluster.getClusterName() + "-metrics:name=connected-to"); | |
| 107 | + assertThat(cluster().getMetrics()).isNotNull(); | |
| 108 | + ObjectName clusterMetricsON = ObjectName.getInstance(cluster().getClusterName() + "-metrics:name=connected-to"); | |
| 111 | 109 | MBeanInfo mBean = server.getMBeanInfo(clusterMetricsON); |
| 112 | 110 | assertThat(mBean).isNotNull(); |
| 113 | 111 | |
| 114 | - assertThat(cluster.getConfiguration().getMetricsOptions().isEnabled()).isTrue(); | |
| 115 | - assertThat(cluster.getConfiguration().getMetricsOptions().isJMXReportingEnabled()).isTrue(); | |
| 112 | + assertThat(cluster().getConfiguration().getMetricsOptions().isEnabled()).isTrue(); | |
| 113 | + assertThat(cluster().getConfiguration().getMetricsOptions().isJMXReportingEnabled()).isTrue(); | |
| 116 | 114 | } |
| 117 | 115 | |
| 118 | 116 | /** |
| @@ -125,8 +123,8 @@ | ||
| 125 | 123 | @Test(groups = "short", expectedExceptions = InstanceNotFoundException.class) |
| 126 | 124 | public void metrics_should_be_null_when_metrics_disabled() throws Exception { |
| 127 | 125 | Cluster cluster = register(Cluster.builder() |
| 128 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 129 | - .withPort(ccm.getBinaryPort()) | |
| 126 | + .addContactPoints(getContactPoints()) | |
| 127 | + .withPort(ccm().getBinaryPort()) | |
| 130 | 128 | .withoutMetrics() |
| 131 | 129 | .build()); |
| 132 | 130 | try { |
| @@ -150,8 +148,8 @@ | ||
| 150 | 148 | @Test(groups = "short", expectedExceptions = InstanceNotFoundException.class) |
| 151 | 149 | public void should_be_no_jmx_mbean_when_jmx_is_disabled() throws Exception { |
| 152 | 150 | Cluster cluster = register(Cluster.builder() |
| 153 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 154 | - .withPort(ccm.getBinaryPort()) | |
| 151 | + .addContactPoints(getContactPoints()) | |
| 152 | + .withPort(ccm().getBinaryPort()) | |
| 155 | 153 | .withoutJMXReporting() |
| 156 | 154 | .build()); |
| 157 | 155 | try { |
modified driver-core/src/test/java/com/datastax/driver/core/MissingRpcAddressTest.java +6 −7
| @@ -24,7 +24,6 @@ | ||
| 24 | 24 | import java.net.InetSocketAddress; |
| 25 | 25 | |
| 26 | 26 | import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD; |
| 27 | -import static java.util.Collections.singleton; | |
| 28 | 27 | import static org.testng.Assert.assertEquals; |
| 29 | 28 | import static org.testng.Assert.assertNull; |
| 30 | 29 | |
| @@ -42,22 +41,22 @@ | ||
| 42 | 41 | deleteNode2RpcAddressFromNode1(); |
| 43 | 42 | // Use only one contact point to make sure that the control connection is on node1 |
| 44 | 43 | Cluster cluster = register(Cluster.builder() |
| 45 | - .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 46 | - .withPort(ccm.getBinaryPort()) | |
| 44 | + .addContactPoints(getContactPoints().get(0)) | |
| 45 | + .withPort(ccm().getBinaryPort()) | |
| 47 | 46 | .build()); |
| 48 | 47 | cluster.connect(); |
| 49 | 48 | |
| 50 | 49 | // Since node2's RPC address is unknown on our control host, it should have been ignored |
| 51 | 50 | assertEquals(cluster.getMetrics().getConnectedToHosts().getValue().intValue(), 1); |
| 52 | - assertNull(cluster.getMetadata().getHost(getInitialContactPoints().get(1))); | |
| 51 | + assertNull(cluster.getMetadata().getHost(getContactPointsWithPorts().get(1))); | |
| 53 | 52 | } |
| 54 | 53 | |
| 55 | 54 | // Artificially modify the system tables to simulate the missing rpc_address. |
| 56 | 55 | private void deleteNode2RpcAddressFromNode1() throws Exception { |
| 57 | - InetSocketAddress firstHost = ccm.addressOfNode(1); | |
| 56 | + InetSocketAddress firstHost = ccm().addressOfNode(1); | |
| 58 | 57 | Cluster cluster = register(Cluster.builder() |
| 59 | - .addContactPointsWithPorts(singleton(firstHost)) | |
| 60 | - .withPort(ccm.getBinaryPort()) | |
| 58 | + .addContactPoints(firstHost.getAddress()) | |
| 59 | + .withPort(ccm().getBinaryPort()) | |
| 61 | 60 | // ensure we will only connect to node1 |
| 62 | 61 | .withLoadBalancingPolicy(new WhiteListPolicy(Policies.defaultLoadBalancingPolicy(), |
| 63 | 62 | Lists.newArrayList(firstHost))) |
modified driver-core/src/test/java/com/datastax/driver/core/NettyOptionsTest.java +2 −2
| @@ -65,8 +65,8 @@ | ||
| 65 | 65 | } |
| 66 | 66 | }).when(nettyOptions).afterChannelInitialized(any(SocketChannel.class)); |
| 67 | 67 | Cluster cluster = register(Cluster.builder() |
| 68 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 69 | - .withPort(ccm.getBinaryPort()) | |
| 68 | + .addContactPoints(getContactPoints().get(0)) | |
| 69 | + .withPort(ccm().getBinaryPort()) | |
| 70 | 70 | .withPoolingOptions(new PoolingOptions() |
| 71 | 71 | .setConnectionsPerHost(HostDistance.LOCAL, coreConnections, coreConnections) |
| 72 | 72 | ) |
modified driver-core/src/test/java/com/datastax/driver/core/NodeListRefreshDebouncerTest.java +6 −11
| @@ -15,7 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import org.testng.annotations.AfterMethod; | |
| 19 | 18 | import org.testng.annotations.BeforeMethod; |
| 20 | 19 | import org.testng.annotations.Test; |
| 21 | 20 | |
| @@ -51,10 +50,11 @@ | ||
| 51 | 50 | queryOptions.setMaxPendingRefreshNodeListRequests(5); |
| 52 | 51 | queryOptions.setRefreshSchemaIntervalMillis(0); |
| 53 | 52 | // Create a separate cluster that will receive the schema events on its control connection. |
| 54 | - cluster2 = Cluster.builder() | |
| 55 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 53 | + cluster2 = register(Cluster.builder() | |
| 54 | + .addContactPoints(getContactPoints()) | |
| 55 | + .withPort(ccm().getBinaryPort()) | |
| 56 | 56 | .withQueryOptions(queryOptions) |
| 57 | - .build(); | |
| 57 | + .build()); | |
| 58 | 58 | session2 = cluster2.connect(); |
| 59 | 59 | |
| 60 | 60 | // Create a spy of the Cluster's control connection and replace it with the spy. |
| @@ -63,11 +63,6 @@ | ||
| 63 | 63 | reset(controlConnection); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - @AfterMethod(groups = "short") | |
| 67 | - public void teardown() { | |
| 68 | - cluster2.close(); | |
| 69 | - } | |
| 70 | - | |
| 71 | 66 | /** |
| 72 | 67 | * Ensures that when a keyspace is created that refresh node list request |
| 73 | 68 | * is debounced and processed within {@link QueryOptions#getRefreshSchemaIntervalMillis()} |
| @@ -79,7 +74,7 @@ | ||
| 79 | 74 | @Test(groups = "short") |
| 80 | 75 | public void should_debounce_refresh_when_keyspace_created() { |
| 81 | 76 | String keyspace = "sdrwkc"; |
| 82 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); | |
| 77 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); | |
| 83 | 78 | keyspaces.add(keyspace); |
| 84 | 79 | |
| 85 | 80 | verify(controlConnection, timeout(DEBOUNCE_TIME + queryOptions.getRefreshSchemaIntervalMillis())).refreshNodeListAndTokenMap(); |
| @@ -100,7 +95,7 @@ | ||
| 100 | 95 | String prefix = "srwmprr"; |
| 101 | 96 | for (int i = 0; i < 5; i++) { |
| 102 | 97 | String keyspace = prefix + i; |
| 103 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); | |
| 98 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); | |
| 104 | 99 | keyspaces.add(keyspace); |
| 105 | 100 | } |
| 106 | 101 |
modified driver-core/src/test/java/com/datastax/driver/core/NodeRefreshDebouncerTest.java +6 −6
| @@ -43,17 +43,17 @@ | ||
| 43 | 43 | int refreshNodeInterval = 30000; |
| 44 | 44 | QueryOptions queryOptions = new QueryOptions().setRefreshNodeIntervalMillis(refreshNodeInterval); |
| 45 | 45 | Cluster cluster = register(Cluster.builder() |
| 46 | - .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 47 | - .withPort(ccm.getBinaryPort()) | |
| 46 | + .addContactPoints(getContactPoints().get(0)) | |
| 47 | + .withPort(ccm().getBinaryPort()) | |
| 48 | 48 | .withQueryOptions(queryOptions) |
| 49 | 49 | .build()); |
| 50 | 50 | cluster.connect(); |
| 51 | 51 | Host.StateListener listener = mock(Host.StateListener.class); |
| 52 | 52 | cluster.register(listener); |
| 53 | - ccm.add(2); | |
| 54 | - ccm.start(2); | |
| 55 | - ccm.stop(2); | |
| 56 | - ccm.start(2); | |
| 53 | + ccm().add(2); | |
| 54 | + ccm().start(2); | |
| 55 | + ccm().stop(2); | |
| 56 | + ccm().start(2); | |
| 57 | 57 | |
| 58 | 58 | ArgumentCaptor<Host> captor = forClass(Host.class); |
| 59 | 59 |
modified driver-core/src/test/java/com/datastax/driver/core/PagingStateTest.java +16 −23
| @@ -19,11 +19,8 @@ | ||
| 19 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 20 | 20 | import org.slf4j.Logger; |
| 21 | 21 | import org.slf4j.LoggerFactory; |
| 22 | -import org.testng.annotations.BeforeClass; | |
| 23 | 22 | import org.testng.annotations.Test; |
| 24 | 23 | |
| 25 | -import java.util.Collection; | |
| 26 | -import java.util.Collections; | |
| 27 | 24 | import java.util.Iterator; |
| 28 | 25 | |
| 29 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -36,14 +33,10 @@ | ||
| 36 | 33 | public static final String KEY = "paging_test"; |
| 37 | 34 | |
| 38 | 35 | @Override |
| 39 | - public Collection<String> createTestFixtures() { | |
| 40 | - return Collections.singletonList("CREATE TABLE test (k text, v int, PRIMARY KEY (k, v))"); | |
| 41 | - } | |
| 42 | - | |
| 43 | - @BeforeClass(groups = "short") | |
| 44 | - public void initData() { | |
| 36 | + public void onTestContextInitialized() { | |
| 37 | + execute("CREATE TABLE test (k text, v int, PRIMARY KEY (k, v))"); | |
| 45 | 38 | for (int i = 0; i < 100; i++) { |
| 46 | - session.execute(String.format("INSERT INTO test (k, v) VALUES ('%s', %d)", KEY, i)); | |
| 39 | + execute(String.format("INSERT INTO test (k, v) VALUES ('%s', %d)", KEY, i)); | |
| 47 | 40 | } |
| 48 | 41 | } |
| 49 | 42 | |
| @@ -57,12 +50,12 @@ | ||
| 57 | 50 | @Test(groups = "short") |
| 58 | 51 | public void should_complete_when_using_paging_state() { |
| 59 | 52 | SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); |
| 60 | - ResultSet result = session.execute(st.setFetchSize(20)); | |
| 53 | + ResultSet result = session().execute(st.setFetchSize(20)); | |
| 61 | 54 | int pageSize = result.getAvailableWithoutFetching(); |
| 62 | 55 | String savedPagingStateString = result.getExecutionInfo().getPagingState().toString(); |
| 63 | 56 | |
| 64 | 57 | st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); |
| 65 | - result = session.execute(st.setFetchSize(20).setPagingState(PagingState.fromString(savedPagingStateString))); | |
| 58 | + result = session().execute(st.setFetchSize(20).setPagingState(PagingState.fromString(savedPagingStateString))); | |
| 66 | 59 | |
| 67 | 60 | //We have the result starting from the next page we stopped |
| 68 | 61 | assertThat(result.one().getInt("v")).isEqualTo(pageSize); |
| @@ -87,7 +80,7 @@ | ||
| 87 | 80 | boolean setWithWrongStatement = false; |
| 88 | 81 | |
| 89 | 82 | SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); |
| 90 | - ResultSet result = session.execute(st.setFetchSize(20)); | |
| 83 | + ResultSet result = session().execute(st.setFetchSize(20)); | |
| 91 | 84 | |
| 92 | 85 | PagingState savedPagingState = result.getExecutionInfo().getPagingState(); |
| 93 | 86 | byte[] savedPagingStateBuffer = savedPagingState.toBytes(); |
| @@ -129,14 +122,14 @@ | ||
| 129 | 122 | @Test(groups = "short") |
| 130 | 123 | @CassandraVersion(major = 2.0) |
| 131 | 124 | public void should_be_able_to_use_state_with_bound_statement() { |
| 132 | - PreparedStatement prepared = session.prepare("SELECT v from test where k=?"); | |
| 125 | + PreparedStatement prepared = session().prepare("SELECT v from test where k=?"); | |
| 133 | 126 | BoundStatement bs = prepared.bind(KEY); |
| 134 | 127 | |
| 135 | - ResultSet result = session.execute(bs.setFetchSize(20)); | |
| 128 | + ResultSet result = session().execute(bs.setFetchSize(20)); | |
| 136 | 129 | int pageSize = result.getAvailableWithoutFetching(); |
| 137 | 130 | PagingState pagingState = result.getExecutionInfo().getPagingState(); |
| 138 | 131 | |
| 139 | - result = session.execute(bs.setFetchSize(20).setPagingState(pagingState)); | |
| 132 | + result = session().execute(bs.setFetchSize(20).setPagingState(pagingState)); | |
| 140 | 133 | |
| 141 | 134 | //We have the result starting from the next page we stopped |
| 142 | 135 | assertThat(result.one().getInt("v")).isEqualTo(pageSize); |
| @@ -152,14 +145,14 @@ | ||
| 152 | 145 | @Test(groups = "short", expectedExceptions = {PagingStateException.class}) |
| 153 | 146 | @CassandraVersion(major = 2.0) |
| 154 | 147 | public void should_not_be_able_to_use_state_with_different_bound_statement() { |
| 155 | - PreparedStatement prepared = session.prepare("SELECT v from test where k=?"); | |
| 148 | + PreparedStatement prepared = session().prepare("SELECT v from test where k=?"); | |
| 156 | 149 | BoundStatement bs0 = prepared.bind(KEY); |
| 157 | 150 | |
| 158 | - ResultSet result = session.execute(bs0.setFetchSize(20)); | |
| 151 | + ResultSet result = session().execute(bs0.setFetchSize(20)); | |
| 159 | 152 | PagingState pagingState = result.getExecutionInfo().getPagingState(); |
| 160 | 153 | |
| 161 | 154 | BoundStatement bs1 = prepared.bind("different_key"); |
| 162 | - session.execute(bs1.setFetchSize(20).setPagingState(pagingState)); | |
| 155 | + session().execute(bs1.setFetchSize(20).setPagingState(pagingState)); | |
| 163 | 156 | } |
| 164 | 157 | |
| 165 | 158 | /** |
| @@ -172,7 +165,7 @@ | ||
| 172 | 165 | @Test(groups = "short") |
| 173 | 166 | public void should_return_no_rows_when_paged_to_end() { |
| 174 | 167 | SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); |
| 175 | - ResultSet result = session.execute(st.setFetchSize(20)); | |
| 168 | + ResultSet result = session().execute(st.setFetchSize(20)); | |
| 176 | 169 | |
| 177 | 170 | // Consume enough of the iterator to cause all the results to be paged in. |
| 178 | 171 | Iterator<Row> rowIt = result.iterator(); |
| @@ -183,7 +176,7 @@ | ||
| 183 | 176 | String savedPagingStateString = result.getExecutionInfo().getPagingState().toString(); |
| 184 | 177 | |
| 185 | 178 | st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); |
| 186 | - result = session.execute(st.setFetchSize(20).setPagingState(PagingState.fromString(savedPagingStateString))); | |
| 179 | + result = session().execute(st.setFetchSize(20).setPagingState(PagingState.fromString(savedPagingStateString))); | |
| 187 | 180 | |
| 188 | 181 | assertThat(result.one()).isNull(); |
| 189 | 182 | } |
| @@ -220,12 +213,12 @@ | ||
| 220 | 213 | @Test(groups = "short") |
| 221 | 214 | public void should_complete_when_using_unsafe_paging_state() { |
| 222 | 215 | SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); |
| 223 | - ResultSet result = session.execute(st.setFetchSize(20)); | |
| 216 | + ResultSet result = session().execute(st.setFetchSize(20)); | |
| 224 | 217 | int pageSize = result.getAvailableWithoutFetching(); |
| 225 | 218 | byte[] savedPagingState = result.getExecutionInfo().getPagingStateUnsafe(); |
| 226 | 219 | |
| 227 | 220 | st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); |
| 228 | - result = session.execute(st.setFetchSize(20).setPagingStateUnsafe(savedPagingState)); | |
| 221 | + result = session().execute(st.setFetchSize(20).setPagingStateUnsafe(savedPagingState)); | |
| 229 | 222 | |
| 230 | 223 | //We have the result starting from the next page we stopped |
| 231 | 224 | assertThat(result.one().getInt("v")).isEqualTo(pageSize); |
modified driver-core/src/test/java/com/datastax/driver/core/PoolingOptionsIntegrationTest.java +5 −5
| @@ -58,21 +58,21 @@ | ||
| 58 | 58 | */ |
| 59 | 59 | @Test(groups = "short") |
| 60 | 60 | public void should_be_able_to_use_custom_initialization_executor() { |
| 61 | - cluster.init(); | |
| 61 | + cluster().init(); | |
| 62 | 62 | // Ensure executor used. |
| 63 | 63 | verify(executor, atLeastOnce()).execute(any(Runnable.class)); |
| 64 | 64 | |
| 65 | 65 | // Reset invocation count. |
| 66 | 66 | reset(); |
| 67 | 67 | |
| 68 | - Session session = cluster.connect(); | |
| 68 | + Session session = cluster().connect(); | |
| 69 | 69 | |
| 70 | 70 | // Ensure executor used again to establish core connections. |
| 71 | 71 | verify(executor, atLeastOnce()).execute(any(Runnable.class)); |
| 72 | 72 | |
| 73 | 73 | // Expect core connections + control connection. |
| 74 | - assertThat(cluster.getMetrics().getOpenConnections().getValue()).isEqualTo( | |
| 75 | - TestUtils.numberOfLocalCoreConnections(cluster) + 1); | |
| 74 | + assertThat(cluster().getMetrics().getOpenConnections().getValue()).isEqualTo( | |
| 75 | + TestUtils.numberOfLocalCoreConnections(cluster()) + 1); | |
| 76 | 76 | |
| 77 | 77 | reset(); |
| 78 | 78 | |
| @@ -82,6 +82,6 @@ | ||
| 82 | 82 | verify(executor, atLeastOnce()).execute(any(Runnable.class)); |
| 83 | 83 | |
| 84 | 84 | // Only the control connection should remain. |
| 85 | - assertThat(cluster.getMetrics().getOpenConnections().getValue()).isEqualTo(1); | |
| 85 | + assertThat(cluster().getMetrics().getOpenConnections().getValue()).isEqualTo(1); | |
| 86 | 86 | } |
| 87 | 87 | } |
modified driver-core/src/test/java/com/datastax/driver/core/PreparedIdTest.java +5 −8
| @@ -15,18 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import com.google.common.collect.Lists; | |
| 19 | 18 | import org.testng.annotations.Test; |
| 20 | 19 | |
| 21 | -import java.util.Collection; | |
| 22 | - | |
| 23 | 20 | import static com.datastax.driver.core.Assertions.assertThat; |
| 24 | 21 | |
| 25 | 22 | public class PreparedIdTest extends CCMTestsSupport { |
| 26 | 23 | |
| 27 | 24 | @Override |
| 28 | - public Collection<String> createTestFixtures() { | |
| 29 | - return Lists.newArrayList( | |
| 25 | + public void onTestContextInitialized() { | |
| 26 | + execute( | |
| 30 | 27 | "CREATE TABLE foo(k1 int, k2 int, k3 int, v int, PRIMARY KEY ((k1, k2, k3)))" |
| 31 | 28 | ); |
| 32 | 29 | } |
| @@ -38,7 +35,7 @@ | ||
| 38 | 35 | */ |
| 39 | 36 | @Test(groups = "short") |
| 40 | 37 | public void should_have_routing_key_indexes_when_all_bound() { |
| 41 | - PreparedStatement pst = session.prepare("INSERT INTO foo (k3, k1, k2, v) VALUES (?, ?, ?, ?)"); | |
| 38 | + PreparedStatement pst = session().prepare("INSERT INTO foo (k3, k1, k2, v) VALUES (?, ?, ?, ?)"); | |
| 42 | 39 | assertThat(pst.getPreparedId().routingKeyIndexes).containsExactly(1, 2, 0); |
| 43 | 40 | } |
| 44 | 41 | |
| @@ -49,7 +46,7 @@ | ||
| 49 | 46 | */ |
| 50 | 47 | @Test(groups = "short") |
| 51 | 48 | public void should_not_have_routing_key_indexes_when_some_not_bound() { |
| 52 | - PreparedStatement pst = session.prepare("INSERT INTO foo (k3, k1, k2, v) VALUES (1, ?, ?, ?)"); | |
| 49 | + PreparedStatement pst = session().prepare("INSERT INTO foo (k3, k1, k2, v) VALUES (1, ?, ?, ?)"); | |
| 53 | 50 | assertThat(pst.getPreparedId().routingKeyIndexes).isNull(); |
| 54 | 51 | } |
| 55 | 52 | |
| @@ -60,7 +57,7 @@ | ||
| 60 | 57 | */ |
| 61 | 58 | @Test(groups = "short") |
| 62 | 59 | public void should_not_have_routing_key_indexes_when_none_bound() { |
| 63 | - PreparedStatement pst = session.prepare("INSERT INTO foo (k3, k1, k2, v) VALUES (1, 1, 1, 1)"); | |
| 60 | + PreparedStatement pst = session().prepare("INSERT INTO foo (k3, k1, k2, v) VALUES (1, 1, 1, 1)"); | |
| 64 | 61 | assertThat(pst.getPreparedId().routingKeyIndexes).isNull(); |
| 65 | 62 | } |
| 66 | 63 | } |
modified driver-core/src/test/java/com/datastax/driver/core/PreparedStatementTest.java +86 −90
| @@ -51,8 +51,11 @@ | ||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | @Override |
| 54 | - public Collection<String> createTestFixtures() { | |
| 54 | + public void onTestContextInitialized() { | |
| 55 | + execute(createTestFixtures()); | |
| 56 | + } | |
| 55 | 57 | |
| 58 | + private List<String> createTestFixtures() { | |
| 56 | 59 | List<String> defs = new ArrayList<String>(4); |
| 57 | 60 | |
| 58 | 61 | StringBuilder sb = new StringBuilder(); |
| @@ -105,7 +108,6 @@ | ||
| 105 | 108 | |
| 106 | 109 | defs.add(String.format("CREATE TABLE %s (k text PRIMARY KEY, i int)", SIMPLE_TABLE)); |
| 107 | 110 | defs.add(String.format("CREATE TABLE %s (k text PRIMARY KEY, v text)", SIMPLE_TABLE2)); |
| 108 | - | |
| 109 | 111 | return defs; |
| 110 | 112 | } |
| 111 | 113 | |
| @@ -118,13 +120,13 @@ | ||
| 118 | 120 | continue; |
| 119 | 121 | |
| 120 | 122 | String name = "c_" + type; |
| 121 | - PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_native', ?)", ALL_NATIVE_TABLE, name)); | |
| 123 | + PreparedStatement ps = session().prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_native', ?)", ALL_NATIVE_TABLE, name)); | |
| 122 | 124 | BoundStatement bs = ps.bind(); |
| 123 | 125 | setValue(bs, name, type, getFixedValue(type)); |
| 124 | - session.execute(bs); | |
| 126 | + session().execute(bs); | |
| 125 | 127 | |
| 126 | - Row row = session.execute(String.format("SELECT %s FROM %s WHERE k='prepared_native'", name, ALL_NATIVE_TABLE)).one(); | |
| 127 | - assertEquals(getValue(row, name, type, cluster.getConfiguration().getCodecRegistry()), getFixedValue(type), "For type " + type); | |
| 128 | + Row row = session().execute(String.format("SELECT %s FROM %s WHERE k='prepared_native'", name, ALL_NATIVE_TABLE)).one(); | |
| 129 | + assertEquals(getValue(row, name, type, cluster().getConfiguration().getCodecRegistry()), getFixedValue(type), "For type " + type); | |
| 128 | 130 | } |
| 129 | 131 | } |
| 130 | 132 | |
| @@ -140,13 +142,13 @@ | ||
| 140 | 142 | continue; |
| 141 | 143 | |
| 142 | 144 | String name = "c_" + type; |
| 143 | - PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_native', ?)", ALL_NATIVE_TABLE, name)); | |
| 145 | + PreparedStatement ps = session().prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_native', ?)", ALL_NATIVE_TABLE, name)); | |
| 144 | 146 | BoundStatement bs = ps.bind(); |
| 145 | 147 | setValue(bs, name, type, getFixedValue2(type)); |
| 146 | - session.execute(bs); | |
| 148 | + session().execute(bs); | |
| 147 | 149 | |
| 148 | - Row row = session.execute(String.format("SELECT %s FROM %s WHERE k='prepared_native'", name, ALL_NATIVE_TABLE)).one(); | |
| 149 | - assertEquals(getValue(row, name, type, cluster.getConfiguration().getCodecRegistry()), getFixedValue2(type), "For type " + type); | |
| 150 | + Row row = session().execute(String.format("SELECT %s FROM %s WHERE k='prepared_native'", name, ALL_NATIVE_TABLE)).one(); | |
| 151 | + assertEquals(getValue(row, name, type, cluster().getConfiguration().getCodecRegistry()), getFixedValue2(type), "For type " + type); | |
| 150 | 152 | } |
| 151 | 153 | } |
| 152 | 154 | |
| @@ -162,13 +164,13 @@ | ||
| 162 | 164 | String name = "c_list_" + rawType; |
| 163 | 165 | DataType type = DataType.list(rawType); |
| 164 | 166 | List<Object> value = (List<Object>) getFixedValue(type); |
| 165 | - PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_list', ?)", ALL_LIST_TABLE, name)); | |
| 167 | + PreparedStatement ps = session().prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_list', ?)", ALL_LIST_TABLE, name)); | |
| 166 | 168 | BoundStatement bs = ps.bind(); |
| 167 | 169 | setValue(bs, name, type, value); |
| 168 | - session.execute(bs); | |
| 170 | + session().execute(bs); | |
| 169 | 171 | |
| 170 | - Row row = session.execute(String.format("SELECT %s FROM %s WHERE k='prepared_list'", name, ALL_LIST_TABLE)).one(); | |
| 171 | - assertEquals(getValue(row, name, type, cluster.getConfiguration().getCodecRegistry()), value, "For type " + type); | |
| 172 | + Row row = session().execute(String.format("SELECT %s FROM %s WHERE k='prepared_list'", name, ALL_LIST_TABLE)).one(); | |
| 173 | + assertEquals(getValue(row, name, type, cluster().getConfiguration().getCodecRegistry()), value, "For type " + type); | |
| 172 | 174 | } |
| 173 | 175 | } |
| 174 | 176 | |
| @@ -187,13 +189,13 @@ | ||
| 187 | 189 | String name = "c_list_" + rawType; |
| 188 | 190 | DataType type = DataType.list(rawType); |
| 189 | 191 | List<Object> value = (List<Object>) getFixedValue2(type); |
| 190 | - PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_list', ?)", ALL_LIST_TABLE, name)); | |
| 192 | + PreparedStatement ps = session().prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_list', ?)", ALL_LIST_TABLE, name)); | |
| 191 | 193 | BoundStatement bs = ps.bind(); |
| 192 | 194 | setValue(bs, name, type, value); |
| 193 | - session.execute(bs); | |
| 195 | + session().execute(bs); | |
| 194 | 196 | |
| 195 | - Row row = session.execute(String.format("SELECT %s FROM %s WHERE k='prepared_list'", name, ALL_LIST_TABLE)).one(); | |
| 196 | - assertEquals(getValue(row, name, type, cluster.getConfiguration().getCodecRegistry()), value, "For type " + type); | |
| 197 | + Row row = session().execute(String.format("SELECT %s FROM %s WHERE k='prepared_list'", name, ALL_LIST_TABLE)).one(); | |
| 198 | + assertEquals(getValue(row, name, type, cluster().getConfiguration().getCodecRegistry()), value, "For type " + type); | |
| 197 | 199 | } |
| 198 | 200 | } |
| 199 | 201 | |
| @@ -209,13 +211,13 @@ | ||
| 209 | 211 | String name = "c_set_" + rawType; |
| 210 | 212 | DataType type = DataType.set(rawType); |
| 211 | 213 | Set<Object> value = (Set<Object>) getFixedValue(type); |
| 212 | - PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_set', ?)", ALL_SET_TABLE, name)); | |
| 214 | + PreparedStatement ps = session().prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_set', ?)", ALL_SET_TABLE, name)); | |
| 213 | 215 | BoundStatement bs = ps.bind(); |
| 214 | 216 | setValue(bs, name, type, value); |
| 215 | - session.execute(bs); | |
| 217 | + session().execute(bs); | |
| 216 | 218 | |
| 217 | - Row row = session.execute(String.format("SELECT %s FROM %s WHERE k='prepared_set'", name, ALL_SET_TABLE)).one(); | |
| 218 | - assertEquals(getValue(row, name, type, cluster.getConfiguration().getCodecRegistry()), value, "For type " + type); | |
| 219 | + Row row = session().execute(String.format("SELECT %s FROM %s WHERE k='prepared_set'", name, ALL_SET_TABLE)).one(); | |
| 220 | + assertEquals(getValue(row, name, type, cluster().getConfiguration().getCodecRegistry()), value, "For type " + type); | |
| 219 | 221 | } |
| 220 | 222 | } |
| 221 | 223 | |
| @@ -234,13 +236,13 @@ | ||
| 234 | 236 | String name = "c_set_" + rawType; |
| 235 | 237 | DataType type = DataType.set(rawType); |
| 236 | 238 | Set<Object> value = (Set<Object>) getFixedValue2(type); |
| 237 | - PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_set', ?)", ALL_SET_TABLE, name)); | |
| 239 | + PreparedStatement ps = session().prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_set', ?)", ALL_SET_TABLE, name)); | |
| 238 | 240 | BoundStatement bs = ps.bind(); |
| 239 | 241 | setValue(bs, name, type, value); |
| 240 | - session.execute(bs); | |
| 242 | + session().execute(bs); | |
| 241 | 243 | |
| 242 | - Row row = session.execute(String.format("SELECT %s FROM %s WHERE k='prepared_set'", name, ALL_SET_TABLE)).one(); | |
| 243 | - assertEquals(getValue(row, name, type, cluster.getConfiguration().getCodecRegistry()), value, "For type " + type); | |
| 244 | + Row row = session().execute(String.format("SELECT %s FROM %s WHERE k='prepared_set'", name, ALL_SET_TABLE)).one(); | |
| 245 | + assertEquals(getValue(row, name, type, cluster().getConfiguration().getCodecRegistry()), value, "For type " + type); | |
| 244 | 246 | } |
| 245 | 247 | } |
| 246 | 248 | |
| @@ -261,13 +263,13 @@ | ||
| 261 | 263 | String name = "c_map_" + rawKeyType + '_' + rawValueType; |
| 262 | 264 | DataType type = DataType.map(rawKeyType, rawValueType); |
| 263 | 265 | Map<Object, Object> value = (Map<Object, Object>) getFixedValue(type); |
| 264 | - PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_map', ?)", ALL_MAP_TABLE, name)); | |
| 266 | + PreparedStatement ps = session().prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_map', ?)", ALL_MAP_TABLE, name)); | |
| 265 | 267 | BoundStatement bs = ps.bind(); |
| 266 | 268 | setValue(bs, name, type, value); |
| 267 | - session.execute(bs); | |
| 269 | + session().execute(bs); | |
| 268 | 270 | |
| 269 | - Row row = session.execute(String.format("SELECT %s FROM %s WHERE k='prepared_map'", name, ALL_MAP_TABLE)).one(); | |
| 270 | - assertEquals(getValue(row, name, type, cluster.getConfiguration().getCodecRegistry()), value, "For type " + type); | |
| 271 | + Row row = session().execute(String.format("SELECT %s FROM %s WHERE k='prepared_map'", name, ALL_MAP_TABLE)).one(); | |
| 272 | + assertEquals(getValue(row, name, type, cluster().getConfiguration().getCodecRegistry()), value, "For type " + type); | |
| 271 | 273 | } |
| 272 | 274 | } |
| 273 | 275 | } |
| @@ -292,13 +294,13 @@ | ||
| 292 | 294 | String name = "c_map_" + rawKeyType + '_' + rawValueType; |
| 293 | 295 | DataType type = DataType.map(rawKeyType, rawValueType); |
| 294 | 296 | Map<Object, Object> value = (Map<Object, Object>) getFixedValue2(type); |
| 295 | - PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_map', ?)", ALL_MAP_TABLE, name)); | |
| 297 | + PreparedStatement ps = session().prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_map', ?)", ALL_MAP_TABLE, name)); | |
| 296 | 298 | BoundStatement bs = ps.bind(); |
| 297 | 299 | setValue(bs, name, type, value); |
| 298 | - session.execute(bs); | |
| 300 | + session().execute(bs); | |
| 299 | 301 | |
| 300 | - Row row = session.execute(String.format("SELECT %s FROM %s WHERE k='prepared_map'", name, ALL_MAP_TABLE)).one(); | |
| 301 | - assertEquals(getValue(row, name, type, cluster.getConfiguration().getCodecRegistry()), value, "For type " + type); | |
| 302 | + Row row = session().execute(String.format("SELECT %s FROM %s WHERE k='prepared_map'", name, ALL_MAP_TABLE)).one(); | |
| 303 | + assertEquals(getValue(row, name, type, cluster().getConfiguration().getCodecRegistry()), value, "For type " + type); | |
| 302 | 304 | } |
| 303 | 305 | } |
| 304 | 306 | } |
| @@ -306,16 +308,16 @@ | ||
| 306 | 308 | @Test(groups = "short") |
| 307 | 309 | public void prepareWithNullValuesTest() throws Exception { |
| 308 | 310 | |
| 309 | - PreparedStatement ps = session.prepare("INSERT INTO " + SIMPLE_TABLE2 + "(k, v) VALUES (?, ?)"); | |
| 311 | + PreparedStatement ps = session().prepare("INSERT INTO " + SIMPLE_TABLE2 + "(k, v) VALUES (?, ?)"); | |
| 310 | 312 | |
| 311 | - session.execute(ps.bind("prepWithNull1", null)); | |
| 313 | + session().execute(ps.bind("prepWithNull1", null)); | |
| 312 | 314 | |
| 313 | 315 | BoundStatement bs = ps.bind(); |
| 314 | 316 | bs.setString("k", "prepWithNull2"); |
| 315 | 317 | bs.setString("v", null); |
| 316 | - session.execute(bs); | |
| 318 | + session().execute(bs); | |
| 317 | 319 | |
| 318 | - ResultSet rs = session.execute("SELECT * FROM " + SIMPLE_TABLE2 + " WHERE k IN ('prepWithNull1', 'prepWithNull2')"); | |
| 320 | + ResultSet rs = session().execute("SELECT * FROM " + SIMPLE_TABLE2 + " WHERE k IN ('prepWithNull1', 'prepWithNull2')"); | |
| 319 | 321 | Row r1 = rs.one(); |
| 320 | 322 | Row r2 = rs.one(); |
| 321 | 323 | assertTrue(rs.isExhausted()); |
| @@ -334,7 +336,7 @@ | ||
| 334 | 336 | toPrepare.setConsistencyLevel(ConsistencyLevel.QUORUM); |
| 335 | 337 | toPrepare.enableTracing(); |
| 336 | 338 | |
| 337 | - PreparedStatement prepared = session.prepare(toPrepare); | |
| 339 | + PreparedStatement prepared = session().prepare(toPrepare); | |
| 338 | 340 | BoundStatement bs = prepared.bind("someValue"); |
| 339 | 341 | |
| 340 | 342 | assertEquals(ConsistencyLevel.QUORUM, bs.getConsistencyLevel()); |
| @@ -356,17 +358,17 @@ | ||
| 356 | 358 | public void batchTest() throws Exception { |
| 357 | 359 | |
| 358 | 360 | try { |
| 359 | - PreparedStatement ps1 = session.prepare("INSERT INTO " + SIMPLE_TABLE2 + "(k, v) VALUES (?, ?)"); | |
| 360 | - PreparedStatement ps2 = session.prepare("INSERT INTO " + SIMPLE_TABLE2 + "(k, v) VALUES (?, 'bar')"); | |
| 361 | + PreparedStatement ps1 = session().prepare("INSERT INTO " + SIMPLE_TABLE2 + "(k, v) VALUES (?, ?)"); | |
| 362 | + PreparedStatement ps2 = session().prepare("INSERT INTO " + SIMPLE_TABLE2 + "(k, v) VALUES (?, 'bar')"); | |
| 361 | 363 | |
| 362 | 364 | BatchStatement bs = new BatchStatement(); |
| 363 | 365 | bs.add(ps1.bind("one", "foo")); |
| 364 | 366 | bs.add(ps2.bind("two")); |
| 365 | 367 | bs.add(new SimpleStatement("INSERT INTO " + SIMPLE_TABLE2 + " (k, v) VALUES ('three', 'foobar')")); |
| 366 | 368 | |
| 367 | - session.execute(bs); | |
| 369 | + session().execute(bs); | |
| 368 | 370 | |
| 369 | - List<Row> all = session.execute("SELECT * FROM " + SIMPLE_TABLE2).all(); | |
| 371 | + List<Row> all = session().execute("SELECT * FROM " + SIMPLE_TABLE2).all(); | |
| 370 | 372 | |
| 371 | 373 | assertEquals("three", all.get(0).getString("k")); |
| 372 | 374 | assertEquals("foobar", all.get(0).getString("v")); |
| @@ -378,29 +380,29 @@ | ||
| 378 | 380 | assertEquals("bar", all.get(2).getString("v")); |
| 379 | 381 | } catch (UnsupportedFeatureException e) { |
| 380 | 382 | // This is expected when testing the protocol v1 |
| 381 | - if (cluster.getConfiguration().getProtocolOptions().getProtocolVersion() != ProtocolVersion.V1) | |
| 383 | + if (cluster().getConfiguration().getProtocolOptions().getProtocolVersion() != ProtocolVersion.V1) | |
| 382 | 384 | throw e; |
| 383 | 385 | } |
| 384 | 386 | } |
| 385 | 387 | |
| 386 | 388 | @Test(groups = "short") |
| 387 | 389 | public void should_set_routing_key_on_case_insensitive_keyspace_and_table() { |
| 388 | - session.execute(String.format("CREATE TABLE %s.foo (i int PRIMARY KEY)", keyspace)); | |
| 390 | + session().execute(String.format("CREATE TABLE %s.foo (i int PRIMARY KEY)", keyspace)); | |
| 389 | 391 | |
| 390 | - PreparedStatement ps = session.prepare(String.format("INSERT INTO %s.foo (i) VALUES (?)", keyspace)); | |
| 392 | + PreparedStatement ps = session().prepare(String.format("INSERT INTO %s.foo (i) VALUES (?)", keyspace)); | |
| 391 | 393 | BoundStatement bs = ps.bind(1); |
| 392 | 394 | assertThat(bs.getRoutingKey(ProtocolVersion.NEWEST_SUPPORTED, CodecRegistry.DEFAULT_INSTANCE)).isNotNull(); |
| 393 | 395 | } |
| 394 | 396 | |
| 395 | 397 | @Test(groups = "short") |
| 396 | 398 | public void should_set_routing_key_on_case_sensitive_keyspace_and_table() { |
| 397 | - session.execute("CREATE KEYSPACE \"Test\" WITH replication = { " | |
| 399 | + session().execute("CREATE KEYSPACE \"Test\" WITH replication = { " | |
| 398 | 400 | + " 'class': 'SimpleStrategy'," |
| 399 | 401 | + " 'replication_factor': '1'" |
| 400 | 402 | + "}"); |
| 401 | - session.execute("CREATE TABLE \"Test\".\"Foo\" (i int PRIMARY KEY)"); | |
| 403 | + session().execute("CREATE TABLE \"Test\".\"Foo\" (i int PRIMARY KEY)"); | |
| 402 | 404 | |
| 403 | - PreparedStatement ps = session.prepare("INSERT INTO \"Test\".\"Foo\" (i) VALUES (?)"); | |
| 405 | + PreparedStatement ps = session().prepare("INSERT INTO \"Test\".\"Foo\" (i) VALUES (?)"); | |
| 404 | 406 | BoundStatement bs = ps.bind(1); |
| 405 | 407 | assertThat(bs.getRoutingKey(ProtocolVersion.NEWEST_SUPPORTED, CodecRegistry.DEFAULT_INSTANCE)).isNotNull(); |
| 406 | 408 | } |
| @@ -408,15 +410,15 @@ | ||
| 408 | 410 | @Test(groups = "short", expectedExceptions = InvalidQueryException.class) |
| 409 | 411 | public void should_fail_when_prepared_on_another_cluster() throws Exception { |
| 410 | 412 | Cluster otherCluster = Cluster.builder() |
| 411 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 412 | - .withPort(ccm.getBinaryPort()) | |
| 413 | + .addContactPoints(getContactPoints()) | |
| 414 | + .withPort(ccm().getBinaryPort()) | |
| 413 | 415 | .build(); |
| 414 | 416 | try { |
| 415 | 417 | PreparedStatement pst = otherCluster.connect().prepare("select * from system.peers where inet = ?"); |
| 416 | 418 | BoundStatement bs = pst.bind().setInet(0, InetAddress.getByName("localhost")); |
| 417 | 419 | |
| 418 | 420 | // We expect that the error gets detected without a roundtrip to the server, so use executeAsync |
| 419 | - session.executeAsync(bs); | |
| 421 | + session().executeAsync(bs); | |
| 420 | 422 | } finally { |
| 421 | 423 | otherCluster.close(); |
| 422 | 424 | } |
| @@ -434,11 +436,11 @@ | ||
| 434 | 436 | */ |
| 435 | 437 | @Test(groups = "short") |
| 436 | 438 | public void should_not_allow_unbound_value_on_bound_statement_when_protocol_lesser_than_v4() { |
| 437 | - Cluster cluster = Cluster.builder() | |
| 438 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 439 | - .withPort(ccm.getBinaryPort()) | |
| 439 | + Cluster cluster = register(Cluster.builder() | |
| 440 | + .addContactPoints(getContactPoints()) | |
| 441 | + .withPort(ccm().getBinaryPort()) | |
| 440 | 442 | .withProtocolVersion(TestUtils.getDesiredProtocolVersion(ProtocolVersion.V3)) |
| 441 | - .build(); | |
| 443 | + .build()); | |
| 442 | 444 | Session session = cluster.connect(); |
| 443 | 445 | try { |
| 444 | 446 | PreparedStatement ps = session.prepare("INSERT INTO " + keyspace + "." + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); |
| @@ -448,9 +450,6 @@ | ||
| 448 | 450 | fail("Should not have executed statement with UNSET values in protocol V3"); |
| 449 | 451 | } catch (IllegalStateException e) { |
| 450 | 452 | assertThat(e.getMessage()).contains("Unset value at index 1"); |
| 451 | - } finally { | |
| 452 | - session.close(); | |
| 453 | - cluster.close(); | |
| 454 | 453 | } |
| 455 | 454 | } |
| 456 | 455 | |
| @@ -467,11 +466,11 @@ | ||
| 467 | 466 | @Test(groups = "short") |
| 468 | 467 | @CassandraVersion(major = 2.0) |
| 469 | 468 | public void should_not_allow_unbound_value_on_batch_statement_when_protocol_lesser_than_v4() { |
| 470 | - Cluster cluster = Cluster.builder() | |
| 471 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 472 | - .withPort(ccm.getBinaryPort()) | |
| 469 | + Cluster cluster = register(Cluster.builder() | |
| 470 | + .addContactPoints(getContactPoints()) | |
| 471 | + .withPort(ccm().getBinaryPort()) | |
| 473 | 472 | .withProtocolVersion(TestUtils.getDesiredProtocolVersion(ProtocolVersion.V3)) |
| 474 | - .build(); | |
| 473 | + .build()); | |
| 475 | 474 | Session session = cluster.connect(); |
| 476 | 475 | try { |
| 477 | 476 | PreparedStatement ps = session.prepare("INSERT INTO " + keyspace + "." + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); |
| @@ -482,9 +481,6 @@ | ||
| 482 | 481 | fail("Should not have executed statement with UNSET values in protocol V3"); |
| 483 | 482 | } catch (IllegalStateException e) { |
| 484 | 483 | assertThat(e.getMessage()).contains("Unset value at index 1"); |
| 485 | - } finally { | |
| 486 | - session.close(); | |
| 487 | - cluster.close(); | |
| 488 | 484 | } |
| 489 | 485 | } |
| 490 | 486 | |
| @@ -500,18 +496,18 @@ | ||
| 500 | 496 | @Test(groups = "short") |
| 501 | 497 | @CassandraVersion(major = 2.2) |
| 502 | 498 | public void should_not_create_tombstone_when_unbound_value_on_bound_statement_and_protocol_v4() { |
| 503 | - PreparedStatement prepared = session.prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); | |
| 499 | + PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); | |
| 504 | 500 | BoundStatement st1 = prepared.bind(); |
| 505 | 501 | st1.setString(0, "foo"); |
| 506 | 502 | st1.setInt(1, 1234); |
| 507 | - session.execute(st1); | |
| 503 | + session().execute(st1); | |
| 508 | 504 | BoundStatement st2 = prepared.bind(); |
| 509 | 505 | st2.setString(0, "foo"); |
| 510 | 506 | // i is UNSET |
| 511 | - session.execute(st2); | |
| 507 | + session().execute(st2); | |
| 512 | 508 | Statement st3 = new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'"); |
| 513 | 509 | st3.enableTracing(); |
| 514 | - ResultSet rows = session.execute(st3); | |
| 510 | + ResultSet rows = session().execute(st3); | |
| 515 | 511 | assertThat(rows.one().getInt("i")).isEqualTo(1234); |
| 516 | 512 | // sleep 10 seconds to make sure the trace will be complete |
| 517 | 513 | Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); |
| @@ -530,16 +526,16 @@ | ||
| 530 | 526 | @Test(groups = "short") |
| 531 | 527 | @CassandraVersion(major = 2.2) |
| 532 | 528 | public void should_unset_value_by_index() { |
| 533 | - PreparedStatement prepared = session.prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); | |
| 529 | + PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); | |
| 534 | 530 | BoundStatement bound = prepared.bind(); |
| 535 | 531 | bound.setString(0, "foo"); |
| 536 | 532 | bound.setInt(1, 1234); |
| 537 | 533 | |
| 538 | 534 | bound.unset(1); |
| 539 | 535 | assertThat(bound.isSet(1)).isFalse(); |
| 540 | - session.execute(bound); | |
| 536 | + session().execute(bound); | |
| 541 | 537 | |
| 542 | - ResultSet rows = session.execute( | |
| 538 | + ResultSet rows = session().execute( | |
| 543 | 539 | new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'") |
| 544 | 540 | .enableTracing()); |
| 545 | 541 | |
| @@ -561,16 +557,16 @@ | ||
| 561 | 557 | @Test(groups = "short") |
| 562 | 558 | @CassandraVersion(major = 2.2) |
| 563 | 559 | public void should_unset_value_by_name() { |
| 564 | - PreparedStatement prepared = session.prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (:k, :i)"); | |
| 560 | + PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (:k, :i)"); | |
| 565 | 561 | BoundStatement bound = prepared.bind(); |
| 566 | 562 | bound.setString("k", "foo"); |
| 567 | 563 | bound.setInt("i", 1234); |
| 568 | 564 | |
| 569 | 565 | bound.unset("i"); |
| 570 | 566 | assertThat(bound.isSet("i")).isFalse(); |
| 571 | - session.execute(bound); | |
| 567 | + session().execute(bound); | |
| 572 | 568 | |
| 573 | - ResultSet rows = session.execute( | |
| 569 | + ResultSet rows = session().execute( | |
| 574 | 570 | new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'") |
| 575 | 571 | .enableTracing()); |
| 576 | 572 | |
| @@ -593,18 +589,18 @@ | ||
| 593 | 589 | @Test(groups = "short") |
| 594 | 590 | @CassandraVersion(major = 2.2) |
| 595 | 591 | public void should_not_create_tombstone_when_unbound_value_on_batch_statement_and_protocol_v4() { |
| 596 | - PreparedStatement prepared = session.prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); | |
| 592 | + PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); | |
| 597 | 593 | BoundStatement st1 = prepared.bind(); |
| 598 | 594 | st1.setString(0, "foo"); |
| 599 | 595 | st1.setInt(1, 1234); |
| 600 | - session.execute(new BatchStatement().add(st1)); | |
| 596 | + session().execute(new BatchStatement().add(st1)); | |
| 601 | 597 | BoundStatement st2 = prepared.bind(); |
| 602 | 598 | st2.setString(0, "foo"); |
| 603 | 599 | // i is UNSET |
| 604 | - session.execute(new BatchStatement().add(st2)); | |
| 600 | + session().execute(new BatchStatement().add(st2)); | |
| 605 | 601 | Statement st3 = new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'"); |
| 606 | 602 | st3.enableTracing(); |
| 607 | - ResultSet rows = session.execute(st3); | |
| 603 | + ResultSet rows = session().execute(st3); | |
| 608 | 604 | assertThat(rows.one().getInt("i")).isEqualTo(1234); |
| 609 | 605 | // sleep 10 seconds to make sure the trace will be complete |
| 610 | 606 | Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); |
| @@ -621,14 +617,14 @@ | ||
| 621 | 617 | */ |
| 622 | 618 | @Test(groups = "long") |
| 623 | 619 | public void should_create_tombstone_when_null_value_on_bound_statement() { |
| 624 | - PreparedStatement prepared = session.prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); | |
| 620 | + PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); | |
| 625 | 621 | BoundStatement st1 = prepared.bind(); |
| 626 | 622 | st1.setString(0, "foo"); |
| 627 | 623 | st1.setToNull(1); |
| 628 | - session.execute(st1); | |
| 624 | + session().execute(st1); | |
| 629 | 625 | Statement st2 = new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'"); |
| 630 | 626 | st2.enableTracing(); |
| 631 | - ResultSet rows = session.execute(st2); | |
| 627 | + ResultSet rows = session().execute(st2); | |
| 632 | 628 | assertThat(rows.one().isNull(0)).isTrue(); |
| 633 | 629 | // sleep 10 seconds to make sure the trace will be complete |
| 634 | 630 | Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); |
| @@ -646,14 +642,14 @@ | ||
| 646 | 642 | @Test(groups = "short") |
| 647 | 643 | @CassandraVersion(major = 2.0) |
| 648 | 644 | public void should_create_tombstone_when_null_value_on_batch_statement() { |
| 649 | - PreparedStatement prepared = session.prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); | |
| 645 | + PreparedStatement prepared = session().prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); | |
| 650 | 646 | BoundStatement st1 = prepared.bind(); |
| 651 | 647 | st1.setString(0, "foo"); |
| 652 | 648 | st1.setToNull(1); |
| 653 | - session.execute(new BatchStatement().add(st1)); | |
| 649 | + session().execute(new BatchStatement().add(st1)); | |
| 654 | 650 | Statement st2 = new SimpleStatement("SELECT i from " + SIMPLE_TABLE + " where k = 'foo'"); |
| 655 | 651 | st2.enableTracing(); |
| 656 | - ResultSet rows = session.execute(st2); | |
| 652 | + ResultSet rows = session().execute(st2); | |
| 657 | 653 | assertThat(rows.one().isNull(0)).isTrue(); |
| 658 | 654 | // sleep 10 seconds to make sure the trace will be complete |
| 659 | 655 | Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); |
| @@ -671,7 +667,7 @@ | ||
| 671 | 667 | |
| 672 | 668 | @Test(groups = "short") |
| 673 | 669 | public void should_propagate_idempotence_in_statements() { |
| 674 | - session.execute(String.format("CREATE TABLE %s.idempotencetest (i int PRIMARY KEY)", keyspace)); | |
| 670 | + session().execute(String.format("CREATE TABLE %s.idempotencetest (i int PRIMARY KEY)", keyspace)); | |
| 675 | 671 | |
| 676 | 672 | SimpleStatement statement; |
| 677 | 673 | PreparedStatement prepared; |
| @@ -679,21 +675,21 @@ | ||
| 679 | 675 | |
| 680 | 676 | statement = new SimpleStatement(String.format("SELECT * FROM %s.idempotencetest WHERE i = ?", keyspace)); |
| 681 | 677 | |
| 682 | - prepared = session.prepare(statement); | |
| 678 | + prepared = session().prepare(statement); | |
| 683 | 679 | bound = prepared.bind(1); |
| 684 | 680 | |
| 685 | 681 | assertThat(prepared.isIdempotent()).isNull(); |
| 686 | 682 | assertThat(bound.isIdempotent()).isNull(); |
| 687 | 683 | |
| 688 | 684 | statement.setIdempotent(true); |
| 689 | - prepared = session.prepare(statement); | |
| 685 | + prepared = session().prepare(statement); | |
| 690 | 686 | bound = prepared.bind(1); |
| 691 | 687 | |
| 692 | 688 | assertThat(prepared.isIdempotent()).isTrue(); |
| 693 | 689 | assertThat(bound.isIdempotent()).isTrue(); |
| 694 | 690 | |
| 695 | 691 | statement.setIdempotent(false); |
| 696 | - prepared = session.prepare(statement); | |
| 692 | + prepared = session().prepare(statement); | |
| 697 | 693 | bound = prepared.bind(1); |
| 698 | 694 | |
| 699 | 695 | assertThat(prepared.isIdempotent()).isFalse(); |
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerTest.java +72 −72
| @@ -123,8 +123,8 @@ | ||
| 123 | 123 | |
| 124 | 124 | @AfterMethod(groups = {"short", "unit"}, alwaysRun = true) |
| 125 | 125 | public void unregisterQueryLogger() { |
| 126 | - if (cluster != null && queryLogger != null) { | |
| 127 | - cluster.unregister(queryLogger); | |
| 126 | + if (cluster() != null && queryLogger != null) { | |
| 127 | + cluster().unregister(queryLogger); | |
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
| @@ -137,9 +137,9 @@ | ||
| 137 | 137 | queryLogger = QueryLogger.builder() |
| 138 | 138 | .withConstantThreshold(Long.MAX_VALUE) |
| 139 | 139 | .build(); |
| 140 | - cluster.register(queryLogger); | |
| 140 | + cluster().register(queryLogger); | |
| 141 | 141 | String query = "SELECT c_text FROM test WHERE pk = 42"; |
| 142 | - session.execute(query); | |
| 142 | + session().execute(query); | |
| 143 | 143 | // then |
| 144 | 144 | String line = normalAppender.waitAndGet(10000); |
| 145 | 145 | assertThat(line) |
| @@ -156,11 +156,11 @@ | ||
| 156 | 156 | queryLogger = QueryLogger.builder() |
| 157 | 157 | .withConstantThreshold(Long.MAX_VALUE) |
| 158 | 158 | .build(); |
| 159 | - cluster.register(queryLogger); | |
| 159 | + cluster().register(queryLogger); | |
| 160 | 160 | String query = "SELECT * FROM test where pk = ?"; |
| 161 | - PreparedStatement ps = session.prepare(query); | |
| 161 | + PreparedStatement ps = session().prepare(query); | |
| 162 | 162 | BoundStatement bs = ps.bind(42); |
| 163 | - session.execute(bs); | |
| 163 | + session().execute(bs); | |
| 164 | 164 | // then |
| 165 | 165 | String line = normalAppender.waitAndGet(10000); |
| 166 | 166 | assertThat(line) |
| @@ -179,16 +179,16 @@ | ||
| 179 | 179 | .withConstantThreshold(Long.MAX_VALUE) |
| 180 | 180 | .withMaxQueryStringLength(Integer.MAX_VALUE) |
| 181 | 181 | .build(); |
| 182 | - cluster.register(queryLogger); | |
| 182 | + cluster().register(queryLogger); | |
| 183 | 183 | // when |
| 184 | 184 | String query1 = "INSERT INTO test (pk) VALUES (?)"; |
| 185 | 185 | String query2 = "UPDATE test SET c_int = ? WHERE pk = 42"; |
| 186 | - PreparedStatement ps1 = session.prepare(query1); | |
| 187 | - PreparedStatement ps2 = session.prepare(query2); | |
| 186 | + PreparedStatement ps1 = session().prepare(query1); | |
| 187 | + PreparedStatement ps2 = session().prepare(query2); | |
| 188 | 188 | BatchStatement batch = new BatchStatement(); |
| 189 | 189 | batch.add(ps1.bind(42)); |
| 190 | 190 | batch.add(ps2.bind(1234)); |
| 191 | - session.execute(batch); | |
| 191 | + session().execute(batch); | |
| 192 | 192 | // then |
| 193 | 193 | String line = normalAppender.waitAndGet(10000); |
| 194 | 194 | assertThat(line) |
| @@ -210,16 +210,16 @@ | ||
| 210 | 210 | .withConstantThreshold(Long.MAX_VALUE) |
| 211 | 211 | .withMaxQueryStringLength(Integer.MAX_VALUE) |
| 212 | 212 | .build(); |
| 213 | - cluster.register(queryLogger); | |
| 213 | + cluster().register(queryLogger); | |
| 214 | 214 | // when |
| 215 | 215 | String query1 = "INSERT INTO test (pk) VALUES (?)"; |
| 216 | 216 | String query2 = "UPDATE test SET c_int = ? WHERE pk = 42"; |
| 217 | - PreparedStatement ps1 = session.prepare(query1); | |
| 218 | - PreparedStatement ps2 = session.prepare(query2); | |
| 217 | + PreparedStatement ps1 = session().prepare(query1); | |
| 218 | + PreparedStatement ps2 = session().prepare(query2); | |
| 219 | 219 | BatchStatement batch = new BatchStatement(UNLOGGED); |
| 220 | 220 | batch.add(ps1.bind(42)); |
| 221 | 221 | batch.add(ps2.bind(1234)); |
| 222 | - session.execute(batch); | |
| 222 | + session().execute(batch); | |
| 223 | 223 | // then |
| 224 | 224 | String line = normalAppender.waitAndGet(10000); |
| 225 | 225 | assertThat(line) |
| @@ -236,7 +236,7 @@ | ||
| 236 | 236 | @CassandraVersion(major = 2.0) |
| 237 | 237 | public void should_log_counter_batch_statements() throws Exception { |
| 238 | 238 | // Create a special table for testing with counters. |
| 239 | - session.execute( | |
| 239 | + session().execute( | |
| 240 | 240 | "CREATE TABLE IF NOT EXISTS counter_test (pk int PRIMARY KEY, c_count COUNTER, c_count2 COUNTER)"); |
| 241 | 241 | |
| 242 | 242 | // given |
| @@ -245,16 +245,16 @@ | ||
| 245 | 245 | .withConstantThreshold(Long.MAX_VALUE) |
| 246 | 246 | .withMaxQueryStringLength(Integer.MAX_VALUE) |
| 247 | 247 | .build(); |
| 248 | - cluster.register(queryLogger); | |
| 248 | + cluster().register(queryLogger); | |
| 249 | 249 | // when |
| 250 | 250 | String query1 = "UPDATE counter_test SET c_count = c_count + ? WHERE pk = 42"; |
| 251 | 251 | String query2 = "UPDATE counter_test SET c_count2 = c_count2 + ? WHERE pk = 42"; |
| 252 | - PreparedStatement ps1 = session.prepare(query1); | |
| 253 | - PreparedStatement ps2 = session.prepare(query2); | |
| 252 | + PreparedStatement ps1 = session().prepare(query1); | |
| 253 | + PreparedStatement ps2 = session().prepare(query2); | |
| 254 | 254 | BatchStatement batch = new BatchStatement(COUNTER); |
| 255 | 255 | batch.add(ps1.bind(1234L)); |
| 256 | 256 | batch.add(ps2.bind(5678L)); |
| 257 | - session.execute(batch); | |
| 257 | + session().execute(batch); | |
| 258 | 258 | // then |
| 259 | 259 | String line = normalAppender.waitAndGet(10000); |
| 260 | 260 | assertThat(line) |
| @@ -356,12 +356,12 @@ | ||
| 356 | 356 | .withConstantThreshold(Long.MAX_VALUE) |
| 357 | 357 | .withMaxQueryStringLength(Integer.MAX_VALUE) |
| 358 | 358 | .build(); |
| 359 | - cluster.register(queryLogger); | |
| 359 | + cluster().register(queryLogger); | |
| 360 | 360 | // when |
| 361 | 361 | String query = "SELECT * FROM test where pk = ?"; |
| 362 | - PreparedStatement ps = session.prepare(query); | |
| 362 | + PreparedStatement ps = session().prepare(query); | |
| 363 | 363 | BoundStatement bs = ps.bind(42); |
| 364 | - session.execute(bs); | |
| 364 | + session().execute(bs); | |
| 365 | 365 | // then |
| 366 | 366 | String line = normalAppender.waitAndGet(10000); |
| 367 | 367 | assertThat(line) |
| @@ -384,14 +384,14 @@ | ||
| 384 | 384 | .withConstantThreshold(Long.MAX_VALUE) |
| 385 | 385 | .withMaxQueryStringLength(Integer.MAX_VALUE) |
| 386 | 386 | .build(); |
| 387 | - cluster.register(queryLogger); | |
| 387 | + cluster().register(queryLogger); | |
| 388 | 388 | // when |
| 389 | 389 | String query = "UPDATE test SET c_text = :param1 WHERE pk = :param2"; |
| 390 | - PreparedStatement ps = session.prepare(query); | |
| 390 | + PreparedStatement ps = session().prepare(query); | |
| 391 | 391 | BoundStatement bs = ps.bind(); |
| 392 | 392 | bs.setString("param1", "foo"); |
| 393 | 393 | bs.setInt("param2", 42); |
| 394 | - session.execute(bs); | |
| 394 | + session().execute(bs); | |
| 395 | 395 | // then |
| 396 | 396 | String line = normalAppender.waitAndGet(10000); |
| 397 | 397 | assertThat(line) |
| @@ -407,14 +407,14 @@ | ||
| 407 | 407 | // given |
| 408 | 408 | normal.setLevel(TRACE); |
| 409 | 409 | queryLogger = QueryLogger.builder().build(); |
| 410 | - cluster.register(queryLogger); | |
| 410 | + cluster().register(queryLogger); | |
| 411 | 411 | // when |
| 412 | 412 | String query = "UPDATE test SET c_text = ? WHERE pk = ?"; |
| 413 | - PreparedStatement ps = session.prepare(query); | |
| 413 | + PreparedStatement ps = session().prepare(query); | |
| 414 | 414 | BoundStatement bs = ps.bind(); |
| 415 | 415 | bs.setString("c_text", "foo"); |
| 416 | 416 | bs.setInt("pk", 42); |
| 417 | - session.execute(bs); | |
| 417 | + session().execute(bs); | |
| 418 | 418 | // then |
| 419 | 419 | String line = normalAppender.waitAndGet(10000); |
| 420 | 420 | assertThat(line) |
| @@ -430,14 +430,14 @@ | ||
| 430 | 430 | // given |
| 431 | 431 | normal.setLevel(TRACE); |
| 432 | 432 | queryLogger = QueryLogger.builder().build(); |
| 433 | - cluster.register(queryLogger); | |
| 433 | + cluster().register(queryLogger); | |
| 434 | 434 | // when |
| 435 | 435 | String query = "UPDATE test SET c_text = ? WHERE pk = ?"; |
| 436 | - PreparedStatement ps = session.prepare(query); | |
| 436 | + PreparedStatement ps = session().prepare(query); | |
| 437 | 437 | BoundStatement bs = ps.bind(); |
| 438 | 438 | bs.setString("c_text", null); |
| 439 | 439 | bs.setInt("pk", 42); |
| 440 | - session.execute(bs); | |
| 440 | + session().execute(bs); | |
| 441 | 441 | // then |
| 442 | 442 | String line = normalAppender.waitAndGet(10000); |
| 443 | 443 | assertThat(line) |
| @@ -454,13 +454,13 @@ | ||
| 454 | 454 | // given |
| 455 | 455 | normal.setLevel(TRACE); |
| 456 | 456 | queryLogger = QueryLogger.builder().build(); |
| 457 | - cluster.register(queryLogger); | |
| 457 | + cluster().register(queryLogger); | |
| 458 | 458 | // when |
| 459 | 459 | String query = "UPDATE test SET c_text = ? WHERE pk = ?"; |
| 460 | - PreparedStatement ps = session.prepare(query); | |
| 460 | + PreparedStatement ps = session().prepare(query); | |
| 461 | 461 | BoundStatement bs = ps.bind(); |
| 462 | 462 | bs.setInt("pk", 42); |
| 463 | - session.execute(bs); | |
| 463 | + session().execute(bs); | |
| 464 | 464 | // then |
| 465 | 465 | String line = normalAppender.waitAndGet(10000); |
| 466 | 466 | assertThat(line) |
| @@ -477,14 +477,14 @@ | ||
| 477 | 477 | // given |
| 478 | 478 | normal.setLevel(TRACE); |
| 479 | 479 | queryLogger = QueryLogger.builder().build(); |
| 480 | - cluster.register(queryLogger); | |
| 480 | + cluster().register(queryLogger); | |
| 481 | 481 | // when |
| 482 | 482 | String query1 = "UPDATE test SET c_text = ? WHERE pk = ?"; |
| 483 | 483 | String query2 = "UPDATE test SET c_int = ? WHERE pk = ?"; |
| 484 | 484 | BatchStatement batch = new BatchStatement(); |
| 485 | - batch.add(session.prepare(query1).bind("foo", 42)); | |
| 486 | - batch.add(session.prepare(query2).bind(12345, 43)); | |
| 487 | - session.execute(batch); | |
| 485 | + batch.add(session().prepare(query1).bind("foo", 42)); | |
| 486 | + batch.add(session().prepare(query2).bind(12345, 43)); | |
| 487 | + session().execute(batch); | |
| 488 | 488 | // then |
| 489 | 489 | String line = normalAppender.waitAndGet(10000); |
| 490 | 490 | assertThat(line) |
| @@ -506,19 +506,19 @@ | ||
| 506 | 506 | queryLogger = QueryLogger.builder() |
| 507 | 507 | .withMaxParameterValueLength(Integer.MAX_VALUE) |
| 508 | 508 | .build(); |
| 509 | - cluster.register(queryLogger); | |
| 509 | + cluster().register(queryLogger); | |
| 510 | 510 | // when |
| 511 | 511 | String query = "UPDATE test SET " + assignments + " WHERE pk = 42"; |
| 512 | - PreparedStatement ps = session.prepare(query); | |
| 512 | + PreparedStatement ps = session().prepare(query); | |
| 513 | 513 | BoundStatement bs = ps.bind(values.toArray()); |
| 514 | - session.execute(bs); | |
| 514 | + session().execute(bs); | |
| 515 | 515 | // then |
| 516 | 516 | String line = normalAppender.waitAndGet(10000); |
| 517 | 517 | assertThat(line) |
| 518 | 518 | .contains("Query completed normally") |
| 519 | 519 | .contains(ipOfNode(1)) |
| 520 | 520 | .contains(query); |
| 521 | - CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); | |
| 521 | + CodecRegistry codecRegistry = cluster().getConfiguration().getCodecRegistry(); | |
| 522 | 522 | for (DataType type : dataTypes) { |
| 523 | 523 | TypeCodec<Object> codec = codecRegistry.codecFor(type); |
| 524 | 524 | assertThat(line).contains(codec.format(getFixedValue(type))); |
| @@ -534,10 +534,10 @@ | ||
| 534 | 534 | queryLogger = QueryLogger.builder() |
| 535 | 535 | .withMaxQueryStringLength(5) |
| 536 | 536 | .build(); |
| 537 | - cluster.register(queryLogger); | |
| 537 | + cluster().register(queryLogger); | |
| 538 | 538 | // when |
| 539 | 539 | String query = "SELECT * FROM test WHERE pk = 42"; |
| 540 | - session.execute(query); | |
| 540 | + session().execute(query); | |
| 541 | 541 | // then |
| 542 | 542 | String line = normalAppender.waitAndGet(10000); |
| 543 | 543 | assertThat(line) |
| @@ -555,14 +555,14 @@ | ||
| 555 | 555 | queryLogger = QueryLogger.builder() |
| 556 | 556 | .withMaxQueryStringLength(5) |
| 557 | 557 | .build(); |
| 558 | - cluster.register(queryLogger); | |
| 558 | + cluster().register(queryLogger); | |
| 559 | 559 | // when |
| 560 | 560 | String query1 = "UPDATE test SET c_text = ? WHERE pk = ?"; |
| 561 | 561 | String query2 = "UPDATE test SET c_int = ? WHERE pk = ?"; |
| 562 | 562 | BatchStatement batch = new BatchStatement(); |
| 563 | - batch.add(session.prepare(query1).bind("foo", 42)); | |
| 564 | - batch.add(session.prepare(query2).bind(12345, 43)); | |
| 565 | - session.execute(batch); | |
| 563 | + batch.add(session().prepare(query1).bind("foo", 42)); | |
| 564 | + batch.add(session().prepare(query2).bind(12345, 43)); | |
| 565 | + session().execute(batch); | |
| 566 | 566 | // then |
| 567 | 567 | String line = normalAppender.waitAndGet(10000); |
| 568 | 568 | assertThat(line) |
| @@ -581,10 +581,10 @@ | ||
| 581 | 581 | queryLogger = QueryLogger.builder() |
| 582 | 582 | .withMaxQueryStringLength(-1) |
| 583 | 583 | .build(); |
| 584 | - cluster.register(queryLogger); | |
| 584 | + cluster().register(queryLogger); | |
| 585 | 585 | // when |
| 586 | 586 | String query = "SELECT * FROM test WHERE pk = 42"; |
| 587 | - session.execute(query); | |
| 587 | + session().execute(query); | |
| 588 | 588 | // then |
| 589 | 589 | String line = normalAppender.waitAndGet(10000); |
| 590 | 590 | assertThat(line) |
| @@ -602,14 +602,14 @@ | ||
| 602 | 602 | queryLogger = QueryLogger.builder() |
| 603 | 603 | .withMaxParameterValueLength(5) |
| 604 | 604 | .build(); |
| 605 | - cluster.register(queryLogger); | |
| 605 | + cluster().register(queryLogger); | |
| 606 | 606 | // when |
| 607 | 607 | String query = "UPDATE test SET c_int = ? WHERE pk = ?"; |
| 608 | - PreparedStatement ps = session.prepare(query); | |
| 608 | + PreparedStatement ps = session().prepare(query); | |
| 609 | 609 | BoundStatement bs = ps.bind(); |
| 610 | 610 | bs.setInt("c_int", 123456); |
| 611 | 611 | bs.setInt("pk", 42); |
| 612 | - session.execute(bs); | |
| 612 | + session().execute(bs); | |
| 613 | 613 | // then |
| 614 | 614 | String line = normalAppender.waitAndGet(10000); |
| 615 | 615 | assertThat(line) |
| @@ -626,14 +626,14 @@ | ||
| 626 | 626 | queryLogger = QueryLogger.builder() |
| 627 | 627 | .withMaxParameterValueLength(6) |
| 628 | 628 | .build(); |
| 629 | - cluster.register(queryLogger); | |
| 629 | + cluster().register(queryLogger); | |
| 630 | 630 | // when |
| 631 | 631 | String query = "UPDATE test SET c_blob = ? WHERE pk = ?"; |
| 632 | - PreparedStatement ps = session.prepare(query); | |
| 632 | + PreparedStatement ps = session().prepare(query); | |
| 633 | 633 | BoundStatement bs = ps.bind(); |
| 634 | 634 | bs.setBytes("c_blob", ByteBuffer.wrap(Bytes.toArray(Lists.newArrayList(1, 2, 3)))); |
| 635 | 635 | bs.setInt("pk", 42); |
| 636 | - session.execute(bs); | |
| 636 | + session().execute(bs); | |
| 637 | 637 | // then |
| 638 | 638 | String line = normalAppender.waitAndGet(10000); |
| 639 | 639 | assertThat(line) |
| @@ -650,14 +650,14 @@ | ||
| 650 | 650 | queryLogger = QueryLogger.builder() |
| 651 | 651 | .withMaxParameterValueLength(-1) |
| 652 | 652 | .build(); |
| 653 | - cluster.register(queryLogger); | |
| 653 | + cluster().register(queryLogger); | |
| 654 | 654 | // when |
| 655 | 655 | String query = "UPDATE test SET c_int = ? WHERE pk = ?"; |
| 656 | - PreparedStatement ps = session.prepare(query); | |
| 656 | + PreparedStatement ps = session().prepare(query); | |
| 657 | 657 | BoundStatement bs = ps.bind(); |
| 658 | 658 | bs.setInt("c_int", 123456); |
| 659 | 659 | bs.setInt("pk", 42); |
| 660 | - session.execute(bs); | |
| 660 | + session().execute(bs); | |
| 661 | 661 | // then |
| 662 | 662 | String line = normalAppender.waitAndGet(10000); |
| 663 | 663 | assertThat(line) |
| @@ -674,14 +674,14 @@ | ||
| 674 | 674 | queryLogger = QueryLogger.builder() |
| 675 | 675 | .withMaxLoggedParameters(1) |
| 676 | 676 | .build(); |
| 677 | - cluster.register(queryLogger); | |
| 677 | + cluster().register(queryLogger); | |
| 678 | 678 | // when |
| 679 | 679 | String query = "UPDATE test SET c_int = ? WHERE pk = ?"; |
| 680 | - PreparedStatement ps = session.prepare(query); | |
| 680 | + PreparedStatement ps = session().prepare(query); | |
| 681 | 681 | BoundStatement bs = ps.bind(); |
| 682 | 682 | bs.setInt("c_int", 123456); |
| 683 | 683 | bs.setInt("pk", 42); |
| 684 | - session.execute(bs); | |
| 684 | + session().execute(bs); | |
| 685 | 685 | // then |
| 686 | 686 | String line = normalAppender.waitAndGet(10000); |
| 687 | 687 | assertThat(line) |
| @@ -700,14 +700,14 @@ | ||
| 700 | 700 | queryLogger = QueryLogger.builder() |
| 701 | 701 | .withMaxLoggedParameters(1) |
| 702 | 702 | .build(); |
| 703 | - cluster.register(queryLogger); | |
| 703 | + cluster().register(queryLogger); | |
| 704 | 704 | // when |
| 705 | 705 | String query1 = "UPDATE test SET c_text = ? WHERE pk = ?"; |
| 706 | 706 | String query2 = "UPDATE test SET c_int = ? WHERE pk = ?"; |
| 707 | 707 | BatchStatement batch = new BatchStatement(); |
| 708 | - batch.add(session.prepare(query1).bind("foo", 42)); | |
| 709 | - batch.add(session.prepare(query2).bind(12345, 43)); | |
| 710 | - session.execute(batch); | |
| 708 | + batch.add(session().prepare(query1).bind("foo", 42)); | |
| 709 | + batch.add(session().prepare(query2).bind(12345, 43)); | |
| 710 | + session().execute(batch); | |
| 711 | 711 | // then |
| 712 | 712 | String line = normalAppender.waitAndGet(10000); |
| 713 | 713 | assertThat(line) |
| @@ -729,14 +729,14 @@ | ||
| 729 | 729 | queryLogger = QueryLogger.builder() |
| 730 | 730 | .withMaxLoggedParameters(-1) |
| 731 | 731 | .build(); |
| 732 | - cluster.register(queryLogger); | |
| 732 | + cluster().register(queryLogger); | |
| 733 | 733 | // when |
| 734 | 734 | String query = "UPDATE test SET c_int = ? WHERE pk = ?"; |
| 735 | - PreparedStatement ps = session.prepare(query); | |
| 735 | + PreparedStatement ps = session().prepare(query); | |
| 736 | 736 | BoundStatement bs = ps.bind(); |
| 737 | 737 | bs.setInt("c_int", 123456); |
| 738 | 738 | bs.setInt("pk", 42); |
| 739 | - session.execute(bs); | |
| 739 | + session().execute(bs); | |
| 740 | 740 | // then |
| 741 | 741 | String line = normalAppender.waitAndGet(10000); |
| 742 | 742 | assertThat(line) |
| @@ -747,8 +747,8 @@ | ||
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | @Override |
| 750 | - public List<String> createTestFixtures() { | |
| 751 | - return Lists.newArrayList("CREATE TABLE test (pk int PRIMARY KEY, " + definitions + ")"); | |
| 750 | + public void onTestContextInitialized() { | |
| 751 | + execute("CREATE TABLE test (pk int PRIMARY KEY, " + definitions + ")"); | |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | } |
modified driver-core/src/test/java/com/datastax/driver/core/QueryTimestampTest.java +25 −28
| @@ -18,12 +18,9 @@ | ||
| 18 | 18 | import com.datastax.driver.core.Metrics.Errors; |
| 19 | 19 | import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy; |
| 20 | 20 | import com.datastax.driver.core.utils.CassandraVersion; |
| 21 | -import com.google.common.collect.Lists; | |
| 22 | 21 | import org.testng.annotations.BeforeMethod; |
| 23 | 22 | import org.testng.annotations.Test; |
| 24 | 23 | |
| 25 | -import java.util.Collection; | |
| 26 | - | |
| 27 | 24 | import static org.testng.Assert.assertEquals; |
| 28 | 25 | import static org.testng.Assert.assertTrue; |
| 29 | 26 | |
| @@ -33,13 +30,13 @@ | ||
| 33 | 30 | @CassandraVersion(major = 2.1) |
| 34 | 31 | public class QueryTimestampTest extends CCMTestsSupport { |
| 35 | 32 | |
| 33 | + private volatile long timestampFromGenerator; | |
| 34 | + | |
| 36 | 35 | @Override |
| 37 | - public Collection<String> createTestFixtures() { | |
| 38 | - return Lists.newArrayList("CREATE TABLE foo (k int PRIMARY KEY, v int)"); | |
| 36 | + public void onTestContextInitialized() { | |
| 37 | + execute("CREATE TABLE foo (k int PRIMARY KEY, v int)"); | |
| 39 | 38 | } |
| 40 | 39 | |
| 41 | - private volatile long timestampFromGenerator; | |
| 42 | - | |
| 43 | 40 | @Override |
| 44 | 41 | public Cluster.Builder createClusterBuilder() { |
| 45 | 42 | return Cluster.builder() |
| @@ -54,16 +51,16 @@ | ||
| 54 | 51 | |
| 55 | 52 | @BeforeMethod(groups = "short") |
| 56 | 53 | public void cleanData() { |
| 57 | - session.execute("TRUNCATE foo"); | |
| 54 | + session().execute("TRUNCATE foo"); | |
| 58 | 55 | } |
| 59 | 56 | |
| 60 | 57 | @Test(groups = "short") |
| 61 | 58 | public void should_use_CQL_timestamp_over_anything_else() { |
| 62 | 59 | timestampFromGenerator = 10; |
| 63 | 60 | String query = "INSERT INTO foo (k, v) VALUES (1, 1) USING TIMESTAMP 20"; |
| 64 | - session.execute(new SimpleStatement(query).setDefaultTimestamp(30)); | |
| 61 | + session().execute(new SimpleStatement(query).setDefaultTimestamp(30)); | |
| 65 | 62 | |
| 66 | - long writeTime = session.execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 63 | + long writeTime = session().execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 67 | 64 | assertEquals(writeTime, 20); |
| 68 | 65 | } |
| 69 | 66 | |
| @@ -71,9 +68,9 @@ | ||
| 71 | 68 | public void should_use_statement_timestamp_over_generator() { |
| 72 | 69 | timestampFromGenerator = 10; |
| 73 | 70 | String query = "INSERT INTO foo (k, v) VALUES (1, 1)"; |
| 74 | - session.execute(new SimpleStatement(query).setDefaultTimestamp(30)); | |
| 71 | + session().execute(new SimpleStatement(query).setDefaultTimestamp(30)); | |
| 75 | 72 | |
| 76 | - long writeTime = session.execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 73 | + long writeTime = session().execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 77 | 74 | assertEquals(writeTime, 30); |
| 78 | 75 | } |
| 79 | 76 | |
| @@ -81,9 +78,9 @@ | ||
| 81 | 78 | public void should_use_generator_timestamp_if_none_other_specified() { |
| 82 | 79 | timestampFromGenerator = 10; |
| 83 | 80 | String query = "INSERT INTO foo (k, v) VALUES (1, 1)"; |
| 84 | - session.execute(query); | |
| 81 | + session().execute(query); | |
| 85 | 82 | |
| 86 | - long writeTime = session.execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 83 | + long writeTime = session().execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 87 | 84 | assertEquals(writeTime, 10); |
| 88 | 85 | } |
| 89 | 86 | |
| @@ -92,9 +89,9 @@ | ||
| 92 | 89 | timestampFromGenerator = Long.MIN_VALUE; |
| 93 | 90 | long clientTime = System.currentTimeMillis() * 1000; |
| 94 | 91 | String query = "INSERT INTO foo (k, v) VALUES (1, 1)"; |
| 95 | - session.execute(query); | |
| 92 | + session().execute(query); | |
| 96 | 93 | |
| 97 | - long writeTime = session.execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 94 | + long writeTime = session().execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 98 | 95 | assertTrue(writeTime >= clientTime); |
| 99 | 96 | } |
| 100 | 97 | |
| @@ -104,10 +101,10 @@ | ||
| 104 | 101 | batch.add(new SimpleStatement("INSERT INTO foo (k, v) VALUES (1, 1)")); |
| 105 | 102 | batch.add(new SimpleStatement("INSERT INTO foo (k, v) VALUES (2, 1) USING TIMESTAMP 20")); |
| 106 | 103 | batch.setDefaultTimestamp(10); |
| 107 | - session.execute(batch); | |
| 104 | + session().execute(batch); | |
| 108 | 105 | |
| 109 | - long writeTime1 = session.execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 110 | - long writeTime2 = session.execute("SELECT writeTime(v) FROM foo WHERE k = 2").one().getLong(0); | |
| 106 | + long writeTime1 = session().execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 107 | + long writeTime2 = session().execute("SELECT writeTime(v) FROM foo WHERE k = 2").one().getLong(0); | |
| 111 | 108 | assertEquals(writeTime1, 10); |
| 112 | 109 | assertEquals(writeTime2, 20); |
| 113 | 110 | } |
| @@ -118,10 +115,10 @@ | ||
| 118 | 115 | BatchStatement batch = new BatchStatement(); |
| 119 | 116 | batch.add(new SimpleStatement("INSERT INTO foo (k, v) VALUES (1, 1)")); |
| 120 | 117 | batch.add(new SimpleStatement("INSERT INTO foo (k, v) VALUES (2, 1) USING TIMESTAMP 20")); |
| 121 | - session.execute(batch); | |
| 118 | + session().execute(batch); | |
| 122 | 119 | |
| 123 | - long writeTime1 = session.execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 124 | - long writeTime2 = session.execute("SELECT writeTime(v) FROM foo WHERE k = 2").one().getLong(0); | |
| 120 | + long writeTime1 = session().execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 121 | + long writeTime2 = session().execute("SELECT writeTime(v) FROM foo WHERE k = 2").one().getLong(0); | |
| 125 | 122 | assertEquals(writeTime1, 10); |
| 126 | 123 | assertEquals(writeTime2, 20); |
| 127 | 124 | } |
| @@ -133,10 +130,10 @@ | ||
| 133 | 130 | BatchStatement batch = new BatchStatement(); |
| 134 | 131 | batch.add(new SimpleStatement("INSERT INTO foo (k, v) VALUES (1, 1)")); |
| 135 | 132 | batch.add(new SimpleStatement("INSERT INTO foo (k, v) VALUES (2, 1) USING TIMESTAMP 20")); |
| 136 | - session.execute(batch); | |
| 133 | + session().execute(batch); | |
| 137 | 134 | |
| 138 | - long writeTime1 = session.execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 139 | - long writeTime2 = session.execute("SELECT writeTime(v) FROM foo WHERE k = 2").one().getLong(0); | |
| 135 | + long writeTime1 = session().execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 136 | + long writeTime2 = session().execute("SELECT writeTime(v) FROM foo WHERE k = 2").one().getLong(0); | |
| 140 | 137 | assertTrue(writeTime1 >= clientTime); |
| 141 | 138 | assertEquals(writeTime2, 20); |
| 142 | 139 | } |
| @@ -149,12 +146,12 @@ | ||
| 149 | 146 | // will retry it at ONE. |
| 150 | 147 | statement.setConsistencyLevel(ConsistencyLevel.TWO); |
| 151 | 148 | |
| 152 | - session.execute(statement); | |
| 149 | + session().execute(statement); | |
| 153 | 150 | |
| 154 | - Errors metrics = session.getCluster().getMetrics().getErrorMetrics(); | |
| 151 | + Errors metrics = session().getCluster().getMetrics().getErrorMetrics(); | |
| 155 | 152 | assertEquals(metrics.getRetriesOnUnavailable().getCount(), 1); |
| 156 | 153 | |
| 157 | - long writeTime = session.execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 154 | + long writeTime = session().execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); | |
| 158 | 155 | assertEquals(writeTime, 10); |
| 159 | 156 | } |
| 160 | 157 | } |
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +8 −16
| @@ -45,9 +45,8 @@ | ||
| 45 | 45 | |
| 46 | 46 | @Test(groups = "long") |
| 47 | 47 | public void should_ignore_recommissioned_node_on_reconnection_attempt() throws Exception { |
| 48 | - mainCcmBuilder = CCMBridge.builder().withNodes(3).notStarted(); | |
| 48 | + mainCcmBuilder = CCMBridge.builder().withNodes(3); | |
| 49 | 49 | mainCcm = CCMCache.get(mainCcmBuilder); |
| 50 | - mainCcm.start(); | |
| 51 | 50 | |
| 52 | 51 | // node1 will be our "recommissioned" node, for now we just stop it so that it stays in the peers table. |
| 53 | 52 | mainCcm.stop(1); |
| @@ -67,9 +66,8 @@ | ||
| 67 | 66 | .withStoragePort(mainCcm.getStoragePort()) |
| 68 | 67 | .withThriftPort(mainCcm.getThriftPort()) |
| 69 | 68 | .withBinaryPort(mainCcm.getBinaryPort()) |
| 70 | - .withNodes(1).notStarted(); | |
| 69 | + .withNodes(1); | |
| 71 | 70 | otherCcm = CCMCache.get(otherCcmBuilder); |
| 72 | - otherCcm.start(); | |
| 73 | 71 | otherCcm.waitForUp(1); |
| 74 | 72 | |
| 75 | 73 | // Give the driver the time to notice the node is back up and try to connect to it. |
| @@ -80,9 +78,8 @@ | ||
| 80 | 78 | |
| 81 | 79 | @Test(groups = "long") |
| 82 | 80 | public void should_ignore_recommissioned_node_on_control_connection_reconnect() throws Exception { |
| 83 | - mainCcmBuilder = CCMBridge.builder().withNodes(2).notStarted(); | |
| 81 | + mainCcmBuilder = CCMBridge.builder().withNodes(2); | |
| 84 | 82 | mainCcm = CCMCache.get(mainCcmBuilder); |
| 85 | - mainCcm.start(); | |
| 86 | 83 | mainCcm.stop(1); |
| 87 | 84 | mainCcm.waitForDown(1); |
| 88 | 85 | |
| @@ -99,9 +96,8 @@ | ||
| 99 | 96 | .withStoragePort(mainCcm.getStoragePort()) |
| 100 | 97 | .withThriftPort(mainCcm.getThriftPort()) |
| 101 | 98 | .withBinaryPort(mainCcm.getBinaryPort()) |
| 102 | - .withNodes(1).notStarted(); | |
| 99 | + .withNodes(1); | |
| 103 | 100 | otherCcm = CCMCache.get(otherCcmBuilder); |
| 104 | - otherCcm.start(); | |
| 105 | 101 | otherCcm.waitForUp(1); |
| 106 | 102 | |
| 107 | 103 | // Stop node2, the control connection gets defunct |
| @@ -115,9 +111,8 @@ | ||
| 115 | 111 | @Test(groups = "long") |
| 116 | 112 | public void should_ignore_recommissioned_node_on_session_init() throws Exception { |
| 117 | 113 | // Simulate the bug before starting the cluster |
| 118 | - mainCcmBuilder = CCMBridge.builder().withNodes(2).notStarted(); | |
| 114 | + mainCcmBuilder = CCMBridge.builder().withNodes(2); | |
| 119 | 115 | mainCcm = CCMCache.get(mainCcmBuilder); |
| 120 | - mainCcm.start(); | |
| 121 | 116 | mainCcm.stop(1); |
| 122 | 117 | mainCcm.waitForDown(1); |
| 123 | 118 | |
| @@ -125,9 +120,8 @@ | ||
| 125 | 120 | .withStoragePort(mainCcm.getStoragePort()) |
| 126 | 121 | .withThriftPort(mainCcm.getThriftPort()) |
| 127 | 122 | .withBinaryPort(mainCcm.getBinaryPort()) |
| 128 | - .withNodes(1).notStarted(); | |
| 123 | + .withNodes(1); | |
| 129 | 124 | otherCcm = CCMCache.get(otherCcmBuilder); |
| 130 | - otherCcm.start(); | |
| 131 | 125 | otherCcm.waitForUp(1); |
| 132 | 126 | |
| 133 | 127 | // Start the driver, it should only connect to node 2 |
| @@ -154,9 +148,8 @@ | ||
| 154 | 148 | @CassandraVersion(major = 2.0) |
| 155 | 149 | public void should_ignore_node_that_does_not_support_protocol_version_on_session_init() throws Exception { |
| 156 | 150 | // Simulate the bug before starting the cluster |
| 157 | - mainCcmBuilder = CCMBridge.builder().withNodes(2).notStarted(); | |
| 151 | + mainCcmBuilder = CCMBridge.builder().withNodes(2); | |
| 158 | 152 | mainCcm = CCMCache.get(mainCcmBuilder); |
| 159 | - mainCcm.start(); | |
| 160 | 153 | mainCcm.stop(1); |
| 161 | 154 | mainCcm.waitForDown(1); |
| 162 | 155 | |
| @@ -164,9 +157,8 @@ | ||
| 164 | 157 | .withStoragePort(mainCcm.getStoragePort()) |
| 165 | 158 | .withThriftPort(mainCcm.getThriftPort()) |
| 166 | 159 | .withBinaryPort(mainCcm.getBinaryPort()) |
| 167 | - .withVersion("1.2.19").notStarted(); | |
| 160 | + .withVersion("1.2.19"); | |
| 168 | 161 | otherCcm = CCMCache.get(otherCcmBuilder); |
| 169 | - otherCcm.start(); | |
| 170 | 162 | otherCcm.waitForUp(1); |
| 171 | 163 | |
| 172 | 164 | // Start the driver, it should only connect to node 2 |
modified driver-core/src/test/java/com/datastax/driver/core/ReconnectionPolicyTest.java +8 −8
| @@ -46,12 +46,12 @@ | ||
| 46 | 46 | public void exponentialReconnectionPolicyTest() throws Throwable { |
| 47 | 47 | |
| 48 | 48 | // Ensure that ExponentialReconnectionPolicy is what we should be testing |
| 49 | - if (!(cluster.getConfiguration().getPolicies().getReconnectionPolicy() instanceof ExponentialReconnectionPolicy)) { | |
| 49 | + if (!(cluster().getConfiguration().getPolicies().getReconnectionPolicy() instanceof ExponentialReconnectionPolicy)) { | |
| 50 | 50 | fail("Set policy does not match retrieved policy."); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Test basic getters |
| 54 | - ExponentialReconnectionPolicy reconnectionPolicy = (ExponentialReconnectionPolicy) cluster.getConfiguration().getPolicies().getReconnectionPolicy(); | |
| 54 | + ExponentialReconnectionPolicy reconnectionPolicy = (ExponentialReconnectionPolicy) cluster().getConfiguration().getPolicies().getReconnectionPolicy(); | |
| 55 | 55 | assertTrue(reconnectionPolicy.getBaseDelayMs() == 2 * 1000); |
| 56 | 56 | assertTrue(reconnectionPolicy.getMaxDelayMs() == 5 * 60 * 1000); |
| 57 | 57 | |
| @@ -112,12 +112,12 @@ | ||
| 112 | 112 | public void constantReconnectionPolicyTest() throws Throwable { |
| 113 | 113 | |
| 114 | 114 | // Ensure that ConstantReconnectionPolicy is what we should be testing |
| 115 | - if (!(cluster.getConfiguration().getPolicies().getReconnectionPolicy() instanceof ConstantReconnectionPolicy)) { | |
| 115 | + if (!(cluster().getConfiguration().getPolicies().getReconnectionPolicy() instanceof ConstantReconnectionPolicy)) { | |
| 116 | 116 | fail("Set policy does not match retrieved policy."); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // Test basic getters |
| 120 | - ConstantReconnectionPolicy reconnectionPolicy = (ConstantReconnectionPolicy) cluster.getConfiguration().getPolicies().getReconnectionPolicy(); | |
| 120 | + ConstantReconnectionPolicy reconnectionPolicy = (ConstantReconnectionPolicy) cluster().getConfiguration().getPolicies().getReconnectionPolicy(); | |
| 121 | 121 | assertTrue(reconnectionPolicy.getConstantDelayMs() == 10 * 1000); |
| 122 | 122 | |
| 123 | 123 | // Test erroneous instantiations |
| @@ -153,7 +153,7 @@ | ||
| 153 | 153 | // Ensure a basic test works |
| 154 | 154 | assertQueried(TestUtils.IP_PREFIX + '1', 12); |
| 155 | 155 | resetCoordinators(); |
| 156 | - ccm.forceStop(1); | |
| 156 | + ccm().forceStop(1); | |
| 157 | 157 | |
| 158 | 158 | // Start timing and ensure that the node is down |
| 159 | 159 | long startTime = 0; |
| @@ -172,7 +172,7 @@ | ||
| 172 | 172 | |
| 173 | 173 | // Restart node at restartTime |
| 174 | 174 | if (!restarted && thisTime - startTime > restartTime) { |
| 175 | - ccm.start(1); | |
| 175 | + ccm().start(1); | |
| 176 | 176 | restarted = true; |
| 177 | 177 | } |
| 178 | 178 | |
| @@ -197,7 +197,7 @@ | ||
| 197 | 197 | resetCoordinators(); |
| 198 | 198 | |
| 199 | 199 | // Ensure the reconnection times reset |
| 200 | - ccm.forceStop(1); | |
| 200 | + ccm().forceStop(1); | |
| 201 | 201 | |
| 202 | 202 | // Start timing and ensure that the node is down |
| 203 | 203 | startTime = 0; |
| @@ -215,7 +215,7 @@ | ||
| 215 | 215 | |
| 216 | 216 | // Restart node at restartTime |
| 217 | 217 | if (!restarted && thisTime - startTime > restartTime) { |
| 218 | - ccm.start(1); | |
| 218 | + ccm().start(1); | |
| 219 | 219 | restarted = true; |
| 220 | 220 | } |
| 221 | 221 |
modified driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java +31 −31
| @@ -50,8 +50,8 @@ | ||
| 50 | 50 | @Test(groups = "long") |
| 51 | 51 | public void should_reconnect_after_full_connectivity_loss() throws InterruptedException { |
| 52 | 52 | Cluster cluster = register(Cluster.builder() |
| 53 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 54 | - .withPort(ccm.getBinaryPort()) | |
| 53 | + .addContactPoints(getContactPoints().get(0)) | |
| 54 | + .withPort(ccm().getBinaryPort()) | |
| 55 | 55 | .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)) |
| 56 | 56 | .build()); |
| 57 | 57 | cluster.connect(); |
| @@ -60,12 +60,12 @@ | ||
| 60 | 60 | |
| 61 | 61 | // Stop all nodes. We won't get notifications anymore, so the only mechanism to |
| 62 | 62 | // reconnect is the background reconnection attempts. |
| 63 | - ccm.stop(2); | |
| 64 | - ccm.stop(1); | |
| 63 | + ccm().stop(2); | |
| 64 | + ccm().stop(1); | |
| 65 | 65 | |
| 66 | - ccm.waitForDown(2); | |
| 67 | - ccm.start(2); | |
| 68 | - ccm.waitForUp(2); | |
| 66 | + ccm().waitForDown(2); | |
| 67 | + ccm().start(2); | |
| 68 | + ccm().waitForUp(2); | |
| 69 | 69 | |
| 70 | 70 | assertThat(cluster).host(2).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS * 2, SECONDS); |
| 71 | 71 | |
| @@ -83,14 +83,14 @@ | ||
| 83 | 83 | public void should_keep_reconnecting_on_authentication_error() throws InterruptedException { |
| 84 | 84 | // For C* 1.2, sleep before attempting to connect as there is a small delay between |
| 85 | 85 | // user being created. |
| 86 | - if (ccm.getVersion().getMajor() < 2) { | |
| 86 | + if (ccm().getVersion().getMajor() < 2) { | |
| 87 | 87 | Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); |
| 88 | 88 | } |
| 89 | 89 | CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)); |
| 90 | 90 | CountingAuthProvider authProvider = new CountingAuthProvider("cassandra", "cassandra"); |
| 91 | 91 | Cluster cluster = register(Cluster.builder() |
| 92 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 93 | - .withPort(ccm.getBinaryPort()) | |
| 92 | + .addContactPoints(getContactPoints().get(0)) | |
| 93 | + .withPort(ccm().getBinaryPort()) | |
| 94 | 94 | // Start with the correct auth so that we can initialize the server |
| 95 | 95 | .withAuthProvider(authProvider) |
| 96 | 96 | .withReconnectionPolicy(reconnectionPolicy) |
| @@ -100,11 +100,11 @@ | ||
| 100 | 100 | assertThat(cluster).usesControlHost(1); |
| 101 | 101 | |
| 102 | 102 | // Stop the server, set wrong credentials and restart |
| 103 | - ccm.stop(1); | |
| 104 | - ccm.waitForDown(1); | |
| 103 | + ccm().stop(1); | |
| 104 | + ccm().waitForDown(1); | |
| 105 | 105 | authProvider.setPassword("wrongPassword"); |
| 106 | - ccm.start(1); | |
| 107 | - ccm.waitForUp(1); | |
| 106 | + ccm().start(1); | |
| 107 | + ccm().waitForUp(1); | |
| 108 | 108 | |
| 109 | 109 | // Wait a few iterations to ensure that our authProvider has returned the wrong credentials at least once |
| 110 | 110 | // NB: authentication errors show up in the logs |
| @@ -130,13 +130,13 @@ | ||
| 130 | 130 | CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)); |
| 131 | 131 | |
| 132 | 132 | Cluster cluster = register(Cluster.builder() |
| 133 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 134 | - .withPort(ccm.getBinaryPort()) | |
| 133 | + .addContactPoints(getContactPoints().get(0)) | |
| 134 | + .withPort(ccm().getBinaryPort()) | |
| 135 | 135 | .withReconnectionPolicy(reconnectionPolicy).build()); |
| 136 | 136 | cluster.connect(); |
| 137 | 137 | |
| 138 | 138 | // Stop a node and cancel the reconnection attempts to it |
| 139 | - ccm.stop(2); | |
| 139 | + ccm().stop(2); | |
| 140 | 140 | Host host2 = TestUtils.findHost(cluster, 2); |
| 141 | 141 | host2.getReconnectionAttemptFuture().cancel(false); |
| 142 | 142 | |
| @@ -146,8 +146,8 @@ | ||
| 146 | 146 | assertThat(reconnectionPolicy.count.get()).isEqualTo(initialCount); |
| 147 | 147 | |
| 148 | 148 | // Restart the node, which will trigger an UP notification |
| 149 | - ccm.start(2); | |
| 150 | - ccm.waitForUp(2); | |
| 149 | + ccm().start(2); | |
| 150 | + ccm().waitForUp(2); | |
| 151 | 151 | |
| 152 | 152 | // The driver should now see the node as UP again |
| 153 | 153 | assertThat(cluster).host(2).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS * 2, SECONDS); |
| @@ -158,8 +158,8 @@ | ||
| 158 | 158 | public void should_trigger_one_time_reconnect() throws InterruptedException, IOException { |
| 159 | 159 | TogglabePolicy loadBalancingPolicy = new TogglabePolicy(new RoundRobinPolicy()); |
| 160 | 160 | Cluster cluster = register(Cluster.builder() |
| 161 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 162 | - .withPort(ccm.getBinaryPort()) | |
| 161 | + .addContactPointsWithPorts(ccm().addressOfNode(1)) | |
| 162 | + .withPort(ccm().getBinaryPort()) | |
| 163 | 163 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 164 | 164 | .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)) |
| 165 | 165 | .build()); |
| @@ -170,8 +170,8 @@ | ||
| 170 | 170 | loadBalancingPolicy.returnEmptyQueryPlan = true; |
| 171 | 171 | |
| 172 | 172 | // Stop the node, ignore it and cancel reconnection attempts to it |
| 173 | - ccm.stop(1); | |
| 174 | - ccm.waitForDown(1); | |
| 173 | + ccm().stop(1); | |
| 174 | + ccm().waitForDown(1); | |
| 175 | 175 | assertThat(cluster).host(1).goesDownWithin(20, SECONDS); |
| 176 | 176 | Host host1 = TestUtils.findHost(cluster, 1); |
| 177 | 177 | loadBalancingPolicy.setDistance(TestUtils.findHost(cluster, 1), HostDistance.IGNORED); |
| @@ -189,8 +189,8 @@ | ||
| 189 | 189 | // Restart the node (this will not trigger an UP notification thanks to our |
| 190 | 190 | // hack to disable the control connection reconnects). The host should stay |
| 191 | 191 | // down for the driver. |
| 192 | - ccm.start(1); | |
| 193 | - ccm.waitForUp(1); | |
| 192 | + ccm().start(1); | |
| 193 | + ccm().waitForUp(1); | |
| 194 | 194 | assertThat(cluster).host(1).hasState(State.DOWN); |
| 195 | 195 | |
| 196 | 196 | TimeUnit.SECONDS.sleep(Cluster.NEW_NODE_DELAY_SECONDS); |
| @@ -214,8 +214,8 @@ | ||
| 214 | 214 | // Spy SocketOptions.getKeepAlive to count how many connections were instantiated. |
| 215 | 215 | SocketOptions socketOptions = spy(new SocketOptions()); |
| 216 | 216 | Cluster cluster = register(Cluster.builder() |
| 217 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 218 | - .withPort(ccm.getBinaryPort()) | |
| 217 | + .addContactPoints(getContactPoints().get(0)) | |
| 218 | + .withPort(ccm().getBinaryPort()) | |
| 219 | 219 | .withReconnectionPolicy(new ConstantReconnectionPolicy(5000)) |
| 220 | 220 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 221 | 221 | .withSocketOptions(socketOptions) |
| @@ -235,14 +235,14 @@ | ||
| 235 | 235 | loadBalancingPolicy.returnEmptyQueryPlan = true; |
| 236 | 236 | |
| 237 | 237 | // Stop the node and cancel the reconnection attempts to it |
| 238 | - ccm.stop(1); | |
| 239 | - ccm.waitForDown(1); | |
| 238 | + ccm().stop(1); | |
| 239 | + ccm().waitForDown(1); | |
| 240 | 240 | assertThat(cluster).host(1).goesDownWithin(20, SECONDS); |
| 241 | 241 | Host host1 = TestUtils.findHost(cluster, 1); |
| 242 | 242 | host1.getReconnectionAttemptFuture().cancel(false); |
| 243 | 243 | |
| 244 | - ccm.start(1); | |
| 245 | - ccm.waitForUp(1); | |
| 244 | + ccm().start(1); | |
| 245 | + ccm().waitForUp(1); | |
| 246 | 246 | |
| 247 | 247 | // Reset the spy and count the number of connections attempts for 1 reconnect |
| 248 | 248 | reset(socketOptions); |
modified driver-core/src/test/java/com/datastax/driver/core/RefreshConnectedHostTest.java +8 −8
| @@ -41,9 +41,9 @@ | ||
| 41 | 41 | LimitingLoadBalancingPolicy loadBalancingPolicy = new LimitingLoadBalancingPolicy(new RoundRobinPolicy(), 2, 1); |
| 42 | 42 | |
| 43 | 43 | PoolingOptions poolingOptions = Mockito.spy(new PoolingOptions()); |
| 44 | - cluster = register(Cluster.builder() | |
| 45 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 46 | - .withPort(ccm.getBinaryPort()) | |
| 44 | + Cluster cluster = register(Cluster.builder() | |
| 45 | + .addContactPoints(getContactPoints().get(0)) | |
| 46 | + .withPort(ccm().getBinaryPort()) | |
| 47 | 47 | .withPoolingOptions(poolingOptions) |
| 48 | 48 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 49 | 49 | .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) |
| @@ -63,9 +63,9 @@ | ||
| 63 | 63 | .isAtDistance(HostDistance.LOCAL); |
| 64 | 64 | |
| 65 | 65 | // Add and bring host 3 up, its presence should be acknowledged but it should be ignored |
| 66 | - ccm.add(3); | |
| 67 | - ccm.start(3); | |
| 68 | - ccm.waitForUp(3); | |
| 66 | + ccm().add(3); | |
| 67 | + ccm().start(3); | |
| 68 | + ccm().waitForUp(3); | |
| 69 | 69 | |
| 70 | 70 | assertThat(cluster).host(1) |
| 71 | 71 | .hasState(State.UP) |
| @@ -81,8 +81,8 @@ | ||
| 81 | 81 | assertThat(session).hasNoPoolFor(3); |
| 82 | 82 | |
| 83 | 83 | // Kill host 2, host 3 should take its place |
| 84 | - ccm.stop(2); | |
| 85 | - TestUtils.waitFor(TestUtils.ipOfNode(3), cluster); | |
| 84 | + ccm().stop(2); | |
| 85 | + TestUtils.waitForUp(TestUtils.ipOfNode(3), cluster); | |
| 86 | 86 | |
| 87 | 87 | assertThat(cluster).host(1) |
| 88 | 88 | .hasState(State.UP) |
modified driver-core/src/test/java/com/datastax/driver/core/SSLEncryptionTest.java +6 −6
| @@ -74,8 +74,8 @@ | ||
| 74 | 74 | @Test(groups = "short", expectedExceptions = {NoHostAvailableException.class}) |
| 75 | 75 | public void should_not_connect_without_ssl_but_node_uses_ssl() throws Exception { |
| 76 | 76 | Cluster cluster = register(Cluster.builder() |
| 77 | - .addContactPointsWithPorts(this.getInitialContactPoints()) | |
| 78 | - .withPort(ccm.getBinaryPort()) | |
| 77 | + .addContactPoints(getContactPoints()) | |
| 78 | + .withPort(ccm().getBinaryPort()) | |
| 79 | 79 | .build()); |
| 80 | 80 | cluster.connect(); |
| 81 | 81 | } |
| @@ -93,15 +93,15 @@ | ||
| 93 | 93 | @Test(groups = "long", dataProvider = "sslImplementation", dataProviderClass = SSLTestBase.class) |
| 94 | 94 | public void should_reconnect_with_ssl_on_node_up(SslImplementation sslImplementation) throws Exception { |
| 95 | 95 | Cluster cluster = register(Cluster.builder() |
| 96 | - .addContactPointsWithPorts(this.getInitialContactPoints()) | |
| 97 | - .withPort(ccm.getBinaryPort()) | |
| 96 | + .addContactPoints(this.getContactPoints()) | |
| 97 | + .withPort(ccm().getBinaryPort()) | |
| 98 | 98 | .withSSL(getSSLOptions(sslImplementation, true, true)) |
| 99 | 99 | .build()); |
| 100 | 100 | |
| 101 | 101 | cluster.connect(); |
| 102 | 102 | |
| 103 | - ccm.stop(1); | |
| 104 | - ccm.start(1); | |
| 103 | + ccm().stop(1); | |
| 104 | + ccm().start(1); | |
| 105 | 105 | |
| 106 | 106 | assertThat(cluster).host(1).comesUpWithin(TestUtils.TEST_BASE_NODE_WAIT, TimeUnit.SECONDS); |
| 107 | 107 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SSLTestBase.java +4 −4
| @@ -55,8 +55,8 @@ | ||
| 55 | 55 | */ |
| 56 | 56 | protected void connectWithSSLOptions(SSLOptions sslOptions) throws Exception { |
| 57 | 57 | Cluster cluster = register(Cluster.builder() |
| 58 | - .addContactPointsWithPorts(this.getInitialContactPoints()) | |
| 59 | - .withPort(ccm.getBinaryPort()) | |
| 58 | + .addContactPoints(getContactPoints()) | |
| 59 | + .withPort(ccm().getBinaryPort()) | |
| 60 | 60 | .withSSL(sslOptions) |
| 61 | 61 | .build()); |
| 62 | 62 | cluster.connect(); |
| @@ -73,8 +73,8 @@ | ||
| 73 | 73 | */ |
| 74 | 74 | protected void connectWithSSL() throws Exception { |
| 75 | 75 | Cluster cluster = register(Cluster.builder() |
| 76 | - .addContactPointsWithPorts(this.getInitialContactPoints()) | |
| 77 | - .withPort(ccm.getBinaryPort()) | |
| 76 | + .addContactPoints(getContactPoints()) | |
| 77 | + .withPort(ccm().getBinaryPort()) | |
| 78 | 78 | .withSSL() |
| 79 | 79 | .build()); |
| 80 | 80 | cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraTestBase.java +5 −22
| @@ -19,15 +19,12 @@ | ||
| 19 | 19 | import org.scassandra.http.client.ActivityClient; |
| 20 | 20 | import org.scassandra.http.client.CurrentClient; |
| 21 | 21 | import org.scassandra.http.client.PrimingClient; |
| 22 | -import org.slf4j.Logger; | |
| 23 | -import org.slf4j.LoggerFactory; | |
| 24 | 22 | import org.testng.annotations.AfterClass; |
| 25 | 23 | import org.testng.annotations.AfterMethod; |
| 26 | 24 | import org.testng.annotations.BeforeClass; |
| 27 | 25 | import org.testng.annotations.BeforeMethod; |
| 28 | 26 | |
| 29 | 27 | import java.net.InetSocketAddress; |
| 30 | -import java.util.Collections; | |
| 31 | 28 | |
| 32 | 29 | import static org.assertj.core.api.Assertions.fail; |
| 33 | 30 | |
| @@ -41,8 +38,6 @@ | ||
| 41 | 38 | */ |
| 42 | 39 | public abstract class ScassandraTestBase { |
| 43 | 40 | |
| 44 | - private static final Logger logger = LoggerFactory.getLogger(ScassandraTestBase.class); | |
| 45 | - | |
| 46 | 41 | protected Scassandra scassandra; |
| 47 | 42 | |
| 48 | 43 | protected InetSocketAddress hostAddress; |
| @@ -80,28 +75,16 @@ | ||
| 80 | 75 | } |
| 81 | 76 | |
| 82 | 77 | protected Cluster.Builder createClusterBuilder() { |
| 83 | - Cluster.Builder builder = Cluster.builder() | |
| 78 | + return Cluster.builder() | |
| 79 | + .withPort(scassandra.getBinaryPort()) | |
| 80 | + .addContactPoints(hostAddress.getAddress()) | |
| 84 | 81 | .withPort(scassandra.getBinaryPort()) |
| 85 | - .addContactPoints(Collections.singletonList(hostAddress.getAddress())) | |
| 86 | 82 | // Scassandra does not support V3 yet, and V4 may cause the server to crash |
| 87 | - .withProtocolVersion(ProtocolVersion.V2) | |
| 83 | + .withProtocolVersion(TestUtils.getDesiredProtocolVersion(ProtocolVersion.V2)) | |
| 88 | 84 | .withPoolingOptions(new PoolingOptions() |
| 89 | 85 | .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) |
| 90 | 86 | .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) |
| 91 | - .setHeartbeatIntervalSeconds(0)) | |
| 92 | - .withPort(scassandra.getBinaryPort()); | |
| 93 | - return builder; | |
| 94 | - } | |
| 95 | - | |
| 96 | - /** | |
| 97 | - * An overrideable method for building on to the Cluster.Builder used for this | |
| 98 | - * class. | |
| 99 | - * | |
| 100 | - * @param builder | |
| 101 | - * @return | |
| 102 | - */ | |
| 103 | - protected Cluster.Builder configure(Cluster.Builder builder) { | |
| 104 | - return builder; | |
| 87 | + .setHeartbeatIntervalSeconds(0)); | |
| 105 | 88 | } |
| 106 | 89 | |
| 107 | 90 | protected Host retrieveSingleHost(Cluster cluster) { |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaAgreementTest.java +9 −9
| @@ -34,32 +34,32 @@ | ||
| 34 | 34 | |
| 35 | 35 | @Test(groups = "short") |
| 36 | 36 | public void should_set_flag_on_successful_agreement() { |
| 37 | - ProtocolOptions protocolOptions = cluster.getConfiguration().getProtocolOptions(); | |
| 37 | + ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions(); | |
| 38 | 38 | protocolOptions.maxSchemaAgreementWaitSeconds = 10; |
| 39 | - ResultSet rs = session.execute(String.format(CREATE_TABLE, COUNTER.getAndIncrement())); | |
| 39 | + ResultSet rs = session().execute(String.format(CREATE_TABLE, COUNTER.getAndIncrement())); | |
| 40 | 40 | assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isTrue(); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | @Test(groups = "short") |
| 44 | 44 | public void should_set_flag_on_non_schema_altering_statement() { |
| 45 | - ProtocolOptions protocolOptions = cluster.getConfiguration().getProtocolOptions(); | |
| 45 | + ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions(); | |
| 46 | 46 | protocolOptions.maxSchemaAgreementWaitSeconds = 10; |
| 47 | - ResultSet rs = session.execute("select release_version from system.local"); | |
| 47 | + ResultSet rs = session().execute("select release_version from system.local"); | |
| 48 | 48 | assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isTrue(); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | @Test(groups = "short") |
| 52 | 52 | public void should_unset_flag_on_failed_agreement() { |
| 53 | 53 | // Setting to 0 results in no query being set, so agreement fails |
| 54 | - ProtocolOptions protocolOptions = cluster.getConfiguration().getProtocolOptions(); | |
| 54 | + ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions(); | |
| 55 | 55 | protocolOptions.maxSchemaAgreementWaitSeconds = 0; |
| 56 | - ResultSet rs = session.execute(String.format(CREATE_TABLE, COUNTER.getAndIncrement())); | |
| 56 | + ResultSet rs = session().execute(String.format(CREATE_TABLE, COUNTER.getAndIncrement())); | |
| 57 | 57 | assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isFalse(); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | @Test(groups = "short") |
| 61 | 61 | public void should_check_agreement_through_cluster_metadata() { |
| 62 | - Cluster controlCluster = register(TestUtils.buildControlCluster(cluster, ccm)); | |
| 62 | + Cluster controlCluster = register(TestUtils.buildControlCluster(cluster(), ccm())); | |
| 63 | 63 | Session controlSession = controlCluster.connect(); |
| 64 | 64 | |
| 65 | 65 | Row localRow = controlSession.execute("SELECT schema_version FROM system.local").one(); |
| @@ -71,11 +71,11 @@ | ||
| 71 | 71 | assertThat(localVersion).isEqualTo(peerVersion); |
| 72 | 72 | |
| 73 | 73 | // Now check the method under test: |
| 74 | - assertThat(cluster.getMetadata().checkSchemaAgreement()).isTrue(); | |
| 74 | + assertThat(cluster().getMetadata().checkSchemaAgreement()).isTrue(); | |
| 75 | 75 | |
| 76 | 76 | // Insert a fake version to simulate a disagreement: |
| 77 | 77 | forceSchemaVersion(controlSession, peerAddress, UUIDs.random()); |
| 78 | - assertThat(cluster.getMetadata().checkSchemaAgreement()).isFalse(); | |
| 78 | + assertThat(cluster().getMetadata().checkSchemaAgreement()).isFalse(); | |
| 79 | 79 | |
| 80 | 80 | forceSchemaVersion(controlSession, peerAddress, peerVersion); |
| 81 | 81 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesCCTest.java +5 −5
| @@ -56,15 +56,15 @@ | ||
| 56 | 56 | Cluster cluster = register( |
| 57 | 57 | Cluster.builder() |
| 58 | 58 | .withLoadBalancingPolicy(lbPolicy) |
| 59 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 60 | - .withPort(ccm.getBinaryPort()) | |
| 59 | + .addContactPoints(getContactPoints().get(0)) | |
| 60 | + .withPort(ccm().getBinaryPort()) | |
| 61 | 61 | .build()); |
| 62 | 62 | // Put cluster2 control connection on node 2 so it doesn't go down (to prevent noise for debugging). |
| 63 | 63 | Cluster cluster2 = register( |
| 64 | 64 | Cluster.builder() |
| 65 | 65 | .withLoadBalancingPolicy(lbPolicy) |
| 66 | - .addContactPointsWithPorts(ccm.addressOfNode(2)) | |
| 67 | - .withPort(ccm.getBinaryPort()) | |
| 66 | + .addContactPoints(getContactPoints().get(1)) | |
| 67 | + .withPort(ccm().getBinaryPort()) | |
| 68 | 68 | .build()); |
| 69 | 69 | SchemaChangeListener listener = mock(SchemaChangeListener.class); |
| 70 | 70 | |
| @@ -93,7 +93,7 @@ | ||
| 93 | 93 | lbPolicy.returnEmptyQueryPlan = true; |
| 94 | 94 | |
| 95 | 95 | // Stop node 1, which hosts the control connection. |
| 96 | - ccm.stop(1); | |
| 96 | + ccm().stop(1); | |
| 97 | 97 | assertThat(cluster).host(1).goesDownWithin(20, TimeUnit.SECONDS); |
| 98 | 98 | |
| 99 | 99 | // Ensure control connection is down. |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +10 −5
| @@ -24,6 +24,7 @@ | ||
| 24 | 24 | import org.testng.annotations.*; |
| 25 | 25 | |
| 26 | 26 | import java.util.List; |
| 27 | +import java.util.concurrent.TimeUnit; | |
| 27 | 28 | |
| 28 | 29 | import static com.datastax.driver.core.Assertions.assertThat; |
| 29 | 30 | import static com.datastax.driver.core.Metadata.handleId; |
| @@ -45,7 +46,7 @@ | ||
| 45 | 46 | /** |
| 46 | 47 | * The maximum time that the test will wait to check that listeners have been notified |
| 47 | 48 | */ |
| 48 | - private static final int NOTIF_TIMEOUT_MS = 120000; | |
| 49 | + private static final long NOTIF_TIMEOUT_MS = TimeUnit.MINUTES.toMillis(1); | |
| 49 | 50 | |
| 50 | 51 | Cluster cluster1; |
| 51 | 52 | Cluster cluster2; // a second cluster to check that other clients also get notified |
| @@ -66,12 +67,14 @@ | ||
| 66 | 67 | @BeforeClass(groups = "short") |
| 67 | 68 | public void setup() throws InterruptedException { |
| 68 | 69 | Cluster.Builder builder = Cluster.builder() |
| 69 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 70 | + .addContactPoints(getContactPoints()) | |
| 71 | + .withPort(ccm().getBinaryPort()) | |
| 70 | 72 | .withQueryOptions(nonDebouncingQueryOptions()); |
| 71 | 73 | cluster1 = builder.build(); |
| 72 | 74 | cluster2 = builder.build(); |
| 73 | 75 | schemaDisabledCluster = spy(Cluster.builder() |
| 74 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 76 | + .addContactPoints(getContactPoints()) | |
| 77 | + .withPort(ccm().getBinaryPort()) | |
| 75 | 78 | .withClusterName("schema-disabled") |
| 76 | 79 | .withQueryOptions(nonDebouncingQueryOptions() |
| 77 | 80 | .setMetadataEnabled(false) |
| @@ -512,7 +515,8 @@ | ||
| 512 | 515 | @Test(groups = "short", expectedExceptions = IllegalStateException.class) |
| 513 | 516 | public void should_throw_illegal_state_exception_on_newToken_with_metadata_disabled() { |
| 514 | 517 | Cluster cluster = Cluster.builder() |
| 515 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 518 | + .addContactPoints(getContactPoints()) | |
| 519 | + .withPort(ccm().getBinaryPort()) | |
| 516 | 520 | .withQueryOptions(nonDebouncingQueryOptions() |
| 517 | 521 | .setMetadataEnabled(false) |
| 518 | 522 | ).build(); |
| @@ -536,7 +540,8 @@ | ||
| 536 | 540 | @Test(groups = "short", expectedExceptions = IllegalStateException.class) |
| 537 | 541 | public void should_throw_illegal_state_exception_on_newTokenRange_with_metadata_disabled() { |
| 538 | 542 | Cluster cluster = Cluster.builder() |
| 539 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 543 | + .addContactPoints(getContactPoints()) | |
| 544 | + .withPort(ccm().getBinaryPort()) | |
| 540 | 545 | .withQueryOptions(nonDebouncingQueryOptions() |
| 541 | 546 | .setMetadataEnabled(false) |
| 542 | 547 | ).build(); |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaRefreshDebouncerTest.java +21 −25
| @@ -54,10 +54,11 @@ | ||
| 54 | 54 | queryOptions.setRefreshSchemaIntervalMillis(DEBOUNCE_TIME); |
| 55 | 55 | queryOptions.setMaxPendingRefreshSchemaRequests(5); |
| 56 | 56 | // Create a separate cluster that will receive the schema events on its control connection. |
| 57 | - cluster2 = Cluster.builder() | |
| 58 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 57 | + cluster2 = register(Cluster.builder() | |
| 58 | + .addContactPoints(getContactPoints()) | |
| 59 | + .withPort(ccm().getBinaryPort()) | |
| 59 | 60 | .withQueryOptions(queryOptions) |
| 60 | - .build(); | |
| 61 | + .build()); | |
| 61 | 62 | session2 = cluster2.connect(); |
| 62 | 63 | |
| 63 | 64 | // Create a spy of the Cluster's control connection and replace it with the spy. |
| @@ -72,11 +73,6 @@ | ||
| 72 | 73 | reset(controlConnection); |
| 73 | 74 | } |
| 74 | 75 | |
| 75 | - @AfterMethod(groups = "short") | |
| 76 | - public void beforeMethod() { | |
| 77 | - cluster2.close(); | |
| 78 | - } | |
| 79 | - | |
| 80 | 76 | /** |
| 81 | 77 | * Ensures that when a CREATED and UPDATED schema_change events are received on a control |
| 82 | 78 | * connection for the same keyspace within {@link QueryOptions#getRefreshSchemaIntervalMillis()} |
| @@ -88,9 +84,9 @@ | ||
| 88 | 84 | */ |
| 89 | 85 | @Test(groups = "short") |
| 90 | 86 | public void should_debounce_and_coalesce_create_and_alter_keyspace_into_refresh_keyspace() throws Exception { |
| 91 | - String keyspace = "sdaccaak"; | |
| 92 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); | |
| 93 | - session.execute(String.format("ALTER KEYSPACE %s WITH DURABLE_WRITES=false", keyspace)); | |
| 87 | + String keyspace = TestUtils.generateIdentifier("ks_"); | |
| 88 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); | |
| 89 | + session().execute(String.format("ALTER KEYSPACE %s WITH DURABLE_WRITES=false", keyspace)); | |
| 94 | 90 | |
| 95 | 91 | ArgumentCaptor<KeyspaceMetadata> captor = forClass(KeyspaceMetadata.class); |
| 96 | 92 | verify(listener, timeout(DEBOUNCE_TIME * 2).only()).onKeyspaceAdded(captor.capture()); |
| @@ -119,17 +115,17 @@ | ||
| 119 | 115 | */ |
| 120 | 116 | @Test(groups = "short") |
| 121 | 117 | public void should_debounce_and_coalesce_create_keyspace_and_table_into_refresh_keyspace() throws Exception { |
| 122 | - String keyspace = "sdacckt"; | |
| 118 | + String keyspace = TestUtils.generateIdentifier("ks_"); | |
| 123 | 119 | String table = "tbl1"; |
| 124 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); | |
| 125 | - session.execute(String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", keyspace + "." + table)); | |
| 120 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); | |
| 121 | + session().execute(String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", keyspace + "." + table)); | |
| 126 | 122 | |
| 127 | 123 | ArgumentCaptor<KeyspaceMetadata> keyspaceCaptor = forClass(KeyspaceMetadata.class); |
| 128 | 124 | verify(listener, timeout(DEBOUNCE_TIME * 2).times(1)).onKeyspaceAdded(keyspaceCaptor.capture()); |
| 129 | 125 | assertThat(keyspaceCaptor.getValue()).hasName(keyspace); |
| 130 | 126 | |
| 131 | 127 | ArgumentCaptor<TableMetadata> tableCaptor = forClass(TableMetadata.class); |
| 132 | - verify(listener, times(1)).onTableAdded(tableCaptor.capture()); | |
| 128 | + verify(listener, timeout(DEBOUNCE_TIME * 2).times(1)).onTableAdded(tableCaptor.capture()); | |
| 133 | 129 | assertThat(tableCaptor.getValue()).hasName(table); |
| 134 | 130 | |
| 135 | 131 | // Verify the schema refresh was debounced and coalesced when a keyspace event and table event |
| @@ -154,7 +150,7 @@ | ||
| 154 | 150 | */ |
| 155 | 151 | @Test(groups = "short") |
| 156 | 152 | public void should_debounce_and_coalesce_tables_in_same_keyspace_into_refresh_keyspace() throws Exception { |
| 157 | - String keyspace = "sdactisk"; | |
| 153 | + String keyspace = TestUtils.generateIdentifier("ks_"); | |
| 158 | 154 | session2.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); |
| 159 | 155 | // Reset invocations as creating keyspace causes a keyspace refresh. |
| 160 | 156 | reset(controlConnection); |
| @@ -162,7 +158,7 @@ | ||
| 162 | 158 | |
| 163 | 159 | int tableCount = 3; |
| 164 | 160 | for (int i = 0; i < tableCount; i++) { |
| 165 | - session.execute(String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", keyspace + "." + "tbl" + i)); | |
| 161 | + session().execute(String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", keyspace + "." + "tbl" + i)); | |
| 166 | 162 | } |
| 167 | 163 | |
| 168 | 164 | verify(listener, timeout(DEBOUNCE_TIME * 3).times(3)).onTableAdded(any(TableMetadata.class)); |
| @@ -194,10 +190,10 @@ | ||
| 194 | 190 | */ |
| 195 | 191 | @Test(groups = "short") |
| 196 | 192 | public void should_debounce_and_coalesce_multiple_alter_events_on_same_table_into_refresh_table() throws Exception { |
| 197 | - if (ccm.getVersion().getMajor() > 2 || ccm.getVersion().getMajor() == 2 && ccm.getVersion().getMinor() > 1) | |
| 193 | + if (ccm().getVersion().getMajor() > 2 || ccm().getVersion().getMajor() == 2 && ccm().getVersion().getMinor() > 1) | |
| 198 | 194 | throw new SkipException("Disabled in Cassandra 2.2+ because of CASSANDRA-9996"); |
| 199 | 195 | |
| 200 | - String keyspace = "sdacmaeost"; | |
| 196 | + String keyspace = TestUtils.generateIdentifier("ks_"); | |
| 201 | 197 | String table = "tbl1"; |
| 202 | 198 | String comment = "I am changing this table."; |
| 203 | 199 | String columnName = "added_column"; |
| @@ -207,8 +203,8 @@ | ||
| 207 | 203 | reset(controlConnection); |
| 208 | 204 | reset(listener); |
| 209 | 205 | |
| 210 | - session.execute(String.format("ALTER TABLE %s.%s WITH comment = '%s'", keyspace, table, comment)); | |
| 211 | - session.execute(String.format("ALTER TABLE %s.%s ADD %s int", keyspace, table, columnName)); | |
| 206 | + session().execute(String.format("ALTER TABLE %s.%s WITH comment = '%s'", keyspace, table, comment)); | |
| 207 | + session().execute(String.format("ALTER TABLE %s.%s ADD %s int", keyspace, table, columnName)); | |
| 212 | 208 | |
| 213 | 209 | ArgumentCaptor<TableMetadata> original = forClass(TableMetadata.class); |
| 214 | 210 | ArgumentCaptor<TableMetadata> captor = forClass(TableMetadata.class); |
| @@ -250,9 +246,9 @@ | ||
| 250 | 246 | */ |
| 251 | 247 | @Test(groups = "short") |
| 252 | 248 | public void should_debounce_and_coalesce_multiple_keyspace_creates_into_refresh_entire_schema() throws Exception { |
| 253 | - String prefix = "sdacmkc"; | |
| 249 | + String prefix = TestUtils.generateIdentifier("ks_"); | |
| 254 | 250 | for (int i = 0; i < 3; i++) { |
| 255 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, prefix + i, 1)); | |
| 251 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, prefix + i, 1)); | |
| 256 | 252 | } |
| 257 | 253 | |
| 258 | 254 | verify(listener, timeout(DEBOUNCE_TIME * 3).times(3)).onKeyspaceAdded(any(KeyspaceMetadata.class)); |
| @@ -276,9 +272,9 @@ | ||
| 276 | 272 | */ |
| 277 | 273 | @Test(groups = "short") |
| 278 | 274 | public void should_refresh_when_max_pending_requests_reached() throws Exception { |
| 279 | - String prefix = "srwmprr"; | |
| 275 | + String prefix = TestUtils.generateIdentifier("ks_"); | |
| 280 | 276 | for (int i = 0; i < 5; i++) { |
| 281 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, prefix + i, 1)); | |
| 277 | + session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, prefix + i, 1)); | |
| 282 | 278 | } |
| 283 | 279 | |
| 284 | 280 | // Event should be processed immediately as we hit our threshold. |
modified driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +21 −21
| @@ -39,9 +39,9 @@ | ||
| 39 | 39 | // Checking for JAVA-342 |
| 40 | 40 | channelMonitor = new SocketChannelMonitor(); |
| 41 | 41 | channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS); |
| 42 | - cluster = register(Cluster.builder() | |
| 43 | - .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 44 | - .withPort(ccm.getBinaryPort()) | |
| 42 | + Cluster cluster = register(Cluster.builder() | |
| 43 | + .addContactPoints(getContactPoints().get(0)) | |
| 44 | + .withPort(ccm().getBinaryPort()) | |
| 45 | 45 | .withNettyOptions(channelMonitor.nettyOptions()) |
| 46 | 46 | .withQueryOptions(nonDebouncingQueryOptions()) |
| 47 | 47 | .build()); |
| @@ -50,45 +50,45 @@ | ||
| 50 | 50 | |
| 51 | 51 | assertThat(cluster.manager.sessions.size()).isEqualTo(0); |
| 52 | 52 | // Should be 1 control connection after initialization. |
| 53 | - assertOpenConnections(1); | |
| 53 | + assertOpenConnections(1, cluster); | |
| 54 | 54 | |
| 55 | 55 | // ensure sessions.size() returns with 1 control connection + core pool size. |
| 56 | 56 | int corePoolSize = TestUtils.numberOfLocalCoreConnections(cluster); |
| 57 | 57 | Session session = cluster.connect(); |
| 58 | 58 | |
| 59 | 59 | assertThat(cluster.manager.sessions.size()).isEqualTo(1); |
| 60 | - assertOpenConnections(1 + corePoolSize); | |
| 60 | + assertOpenConnections(1 + corePoolSize, cluster); | |
| 61 | 61 | |
| 62 | 62 | // ensure sessions.size() returns to 0 with only 1 active connection (the control connection) |
| 63 | 63 | session.close(); |
| 64 | 64 | assertThat(cluster.manager.sessions.size()).isEqualTo(0); |
| 65 | - assertOpenConnections(1); | |
| 65 | + assertOpenConnections(1, cluster); | |
| 66 | 66 | |
| 67 | 67 | // ensure bootstrapping a node does not create additional connections |
| 68 | - ccm.add(2); | |
| 69 | - ccm.start(2); | |
| 70 | - ccm.waitForUp(2); | |
| 68 | + ccm().add(2); | |
| 69 | + ccm().start(2); | |
| 70 | + ccm().waitForUp(2); | |
| 71 | 71 | assertThat(cluster).host(2).comesUpWithin(2, MINUTES); |
| 72 | 72 | |
| 73 | 73 | assertThat(cluster.manager.sessions.size()).isEqualTo(0); |
| 74 | - assertOpenConnections(1); | |
| 74 | + assertOpenConnections(1, cluster); | |
| 75 | 75 | |
| 76 | 76 | // ensure a new session gets registered and core connections are established |
| 77 | 77 | // there should be corePoolSize more connections to accommodate for the new host. |
| 78 | 78 | Session thisSession = cluster.connect(); |
| 79 | 79 | assertThat(cluster.manager.sessions.size()).isEqualTo(1); |
| 80 | - assertOpenConnections(1 + (corePoolSize * 2)); | |
| 80 | + assertOpenConnections(1 + (corePoolSize * 2), cluster); | |
| 81 | 81 | |
| 82 | 82 | // ensure bootstrapping a node does not create additional connections that won't get cleaned up |
| 83 | 83 | thisSession.close(); |
| 84 | 84 | |
| 85 | 85 | assertThat(cluster.manager.sessions.size()).isEqualTo(0); |
| 86 | - assertOpenConnections(1); | |
| 86 | + assertOpenConnections(1, cluster); | |
| 87 | 87 | cluster.close(); |
| 88 | 88 | // Ensure no channels remain open. |
| 89 | 89 | channelMonitor.stop(); |
| 90 | 90 | channelMonitor.report(); |
| 91 | - assertThat(channelMonitor.openChannels(newArrayList(ccm.addressOfNode(1), ccm.addressOfNode(2))).size()).isEqualTo(0); | |
| 91 | + assertThat(channelMonitor.openChannels(newArrayList(ccm().addressOfNode(1), ccm().addressOfNode(2))).size()).isEqualTo(0); | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | @Test(groups = "short") |
| @@ -96,16 +96,16 @@ | ||
| 96 | 96 | // Checking for JAVA-806 |
| 97 | 97 | channelMonitor = new SocketChannelMonitor(); |
| 98 | 98 | channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS); |
| 99 | - cluster = register(Cluster.builder() | |
| 100 | - .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 101 | - .withPort(ccm.getBinaryPort()) | |
| 99 | + Cluster cluster = register(Cluster.builder() | |
| 100 | + .addContactPoints(getContactPoints().get(0)) | |
| 101 | + .withPort(ccm().getBinaryPort()) | |
| 102 | 102 | .withNettyOptions(channelMonitor.nettyOptions()) |
| 103 | 103 | .build()); |
| 104 | 104 | cluster.init(); |
| 105 | 105 | assertThat(cluster.manager.sessions.size()).isEqualTo(0); |
| 106 | 106 | try { |
| 107 | 107 | // Should be 1 control connection after initialization. |
| 108 | - assertOpenConnections(1); | |
| 108 | + assertOpenConnections(1, cluster); | |
| 109 | 109 | cluster.connect("wrong_keyspace"); |
| 110 | 110 | fail("Should not have connected to a wrong keyspace"); |
| 111 | 111 | } catch (InvalidQueryException e) { |
| @@ -116,11 +116,11 @@ | ||
| 116 | 116 | // Ensure no channels remain open. |
| 117 | 117 | channelMonitor.stop(); |
| 118 | 118 | channelMonitor.report(); |
| 119 | - assertThat(channelMonitor.openChannels(ccm.addressOfNode(1), ccm.addressOfNode(2)).size()).isEqualTo(0); | |
| 119 | + assertThat(channelMonitor.openChannels(ccm().addressOfNode(1), ccm().addressOfNode(2)).size()).isEqualTo(0); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - private void assertOpenConnections(int expected) { | |
| 123 | - assertThat((cluster.getMetrics().getOpenConnections().getValue())).isEqualTo(expected); | |
| 124 | - assertThat(channelMonitor.openChannels(ccm.addressOfNode(1), ccm.addressOfNode(2)).size()).isEqualTo(expected); | |
| 122 | + private void assertOpenConnections(int expected, Cluster cluster) { | |
| 123 | + assertThat(cluster.getMetrics().getOpenConnections().getValue()).isEqualTo(expected); | |
| 124 | + assertThat(channelMonitor.openChannels(ccm().addressOfNode(1), ccm().addressOfNode(2)).size()).isEqualTo(expected); | |
| 125 | 125 | } |
| 126 | 126 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SessionStressTest.java +10 −8
| @@ -92,7 +92,9 @@ | ||
| 92 | 92 | public void sessions_should_not_leak_connections() { |
| 93 | 93 | // override inherited field with a new cluster object and ensure 0 sessions and connections |
| 94 | 94 | channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS); |
| 95 | - stressCluster = Cluster.builder().addContactPointsWithPorts(getInitialContactPoints()) | |
| 95 | + stressCluster = Cluster.builder() | |
| 96 | + .addContactPoints(getContactPoints()) | |
| 97 | + .withPort(ccm().getBinaryPort()) | |
| 96 | 98 | .withPoolingOptions(new PoolingOptions().setCoreConnectionsPerHost(HostDistance.LOCAL, 1)) |
| 97 | 99 | .withNettyOptions(channelMonitor.nettyOptions()).build(); |
| 98 | 100 | |
| @@ -109,13 +111,13 @@ | ||
| 109 | 111 | assertEquals(stressCluster.manager.sessions.size(), 1); |
| 110 | 112 | int coreConnections = TestUtils.numberOfLocalCoreConnections(stressCluster); |
| 111 | 113 | assertEquals((int) stressCluster.getMetrics().getOpenConnections().getValue(), 1 + coreConnections); |
| 112 | - assertEquals(channelMonitor.openChannels(getInitialContactPoints()).size(), 1 + coreConnections); | |
| 114 | + assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), 1 + coreConnections); | |
| 113 | 115 | |
| 114 | 116 | // Closing the session keeps the control connection opened |
| 115 | 117 | session.close(); |
| 116 | 118 | assertEquals(stressCluster.manager.sessions.size(), 0); |
| 117 | 119 | assertEquals((int) stressCluster.getMetrics().getOpenConnections().getValue(), 1); |
| 118 | - assertEquals(channelMonitor.openChannels(getInitialContactPoints()).size(), 1); | |
| 120 | + assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), 1); | |
| 119 | 121 | |
| 120 | 122 | int nbOfSessions = 2000; |
| 121 | 123 | int halfOfTheSessions = nbOfSessions / 2; |
| @@ -132,7 +134,7 @@ | ||
| 132 | 134 | assertEquals(stressCluster.manager.sessions.size(), nbOfSessions); |
| 133 | 135 | assertEquals((int) stressCluster.getMetrics().getOpenConnections().getValue(), |
| 134 | 136 | coreConnections * nbOfSessions + 1); |
| 135 | - assertEquals(channelMonitor.openChannels(getInitialContactPoints()).size(), coreConnections * nbOfSessions + 1); | |
| 137 | + assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), coreConnections * nbOfSessions + 1); | |
| 136 | 138 | |
| 137 | 139 | // Close half of the sessions asynchronously |
| 138 | 140 | logger.info("Closing {}/{} sessions.", halfOfTheSessions, nbOfSessions); |
| @@ -142,7 +144,7 @@ | ||
| 142 | 144 | assertEquals(stressCluster.manager.sessions.size(), halfOfTheSessions); |
| 143 | 145 | assertEquals((int) stressCluster.getMetrics().getOpenConnections().getValue(), |
| 144 | 146 | coreConnections * (nbOfSessions / 2) + 1); |
| 145 | - assertEquals(channelMonitor.openChannels(getInitialContactPoints()).size(), | |
| 147 | + assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), | |
| 146 | 148 | coreConnections * (nbOfSessions / 2) + 1); |
| 147 | 149 | |
| 148 | 150 | // Close and open the same number of sessions concurrently |
| @@ -160,7 +162,7 @@ | ||
| 160 | 162 | assertEquals(stressCluster.manager.sessions.size(), halfOfTheSessions); |
| 161 | 163 | assertEquals((int) stressCluster.getMetrics().getOpenConnections().getValue(), |
| 162 | 164 | coreConnections * (nbOfSessions / 2) + 1); |
| 163 | - assertEquals(channelMonitor.openChannels(getInitialContactPoints()).size(), | |
| 165 | + assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), | |
| 164 | 166 | coreConnections * (nbOfSessions / 2) + 1); |
| 165 | 167 | |
| 166 | 168 | // Close the remaining sessions |
| @@ -170,7 +172,7 @@ | ||
| 170 | 172 | // Check that we have a clean state |
| 171 | 173 | assertEquals(stressCluster.manager.sessions.size(), 0); |
| 172 | 174 | assertEquals((int) stressCluster.getMetrics().getOpenConnections().getValue(), 1); |
| 173 | - assertEquals(channelMonitor.openChannels(getInitialContactPoints()).size(), 1); | |
| 175 | + assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), 1); | |
| 174 | 176 | |
| 175 | 177 | // On OSX, the TCP connections are released after 15s by default (sysctl -a net.inet.tcp.msl) |
| 176 | 178 | logger.info("Sleeping {} seconds so that TCP connections are released by the OS", sleepTime); |
| @@ -181,7 +183,7 @@ | ||
| 181 | 183 | stressCluster = null; |
| 182 | 184 | |
| 183 | 185 | // Ensure no channels remain open. |
| 184 | - assertEquals(channelMonitor.openChannels(getInitialContactPoints()).size(), 0); | |
| 186 | + assertEquals(channelMonitor.openChannels(getContactPointsWithPorts()).size(), 0); | |
| 185 | 187 | |
| 186 | 188 | channelMonitor.stop(); |
| 187 | 189 | channelMonitor.report(); |
modified driver-core/src/test/java/com/datastax/driver/core/SessionTest.java +24 −25
| @@ -18,8 +18,6 @@ | ||
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | 19 | import org.testng.annotations.Test; |
| 20 | 20 | |
| 21 | -import java.util.Arrays; | |
| 22 | -import java.util.Collection; | |
| 23 | 21 | import java.util.List; |
| 24 | 22 | import java.util.Locale; |
| 25 | 23 | import java.util.concurrent.CountDownLatch; |
| @@ -41,8 +39,8 @@ | ||
| 41 | 39 | private static final String COUNTER_TABLE = "counters"; |
| 42 | 40 | |
| 43 | 41 | @Override |
| 44 | - public Collection<String> createTestFixtures() { | |
| 45 | - return Arrays.asList(String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", TABLE1), | |
| 42 | + public void onTestContextInitialized() { | |
| 43 | + execute(String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", TABLE1), | |
| 46 | 44 | String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", TABLE2), |
| 47 | 45 | String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", TABLE3), |
| 48 | 46 | String.format("CREATE TABLE %s (k text PRIMARY KEY, c counter)", COUNTER_TABLE)); |
| @@ -52,16 +50,16 @@ | ||
| 52 | 50 | public void executeTest() throws Exception { |
| 53 | 51 | // Simple calls to all versions of the execute/executeAsync methods |
| 54 | 52 | String key = "execute_test"; |
| 55 | - ResultSet rs = session.execute(String.format(Locale.US, "INSERT INTO %s (k, t, i, f) VALUES ('%s', '%s', %d, %f)", TABLE1, key, "foo", 42, 24.03f)); | |
| 53 | + ResultSet rs = session().execute(String.format(Locale.US, "INSERT INTO %s (k, t, i, f) VALUES ('%s', '%s', %d, %f)", TABLE1, key, "foo", 42, 24.03f)); | |
| 56 | 54 | assertTrue(rs.isExhausted()); |
| 57 | 55 | |
| 58 | 56 | // execute |
| 59 | - checkExecuteResultSet(session.execute(String.format(TestUtils.SELECT_ALL_FORMAT, TABLE1)), key); | |
| 60 | - checkExecuteResultSet(session.execute(new SimpleStatement(String.format(TestUtils.SELECT_ALL_FORMAT, TABLE1)).setConsistencyLevel(ConsistencyLevel.ONE)), key); | |
| 57 | + checkExecuteResultSet(session().execute(String.format(TestUtils.SELECT_ALL_FORMAT, TABLE1)), key); | |
| 58 | + checkExecuteResultSet(session().execute(new SimpleStatement(String.format(TestUtils.SELECT_ALL_FORMAT, TABLE1)).setConsistencyLevel(ConsistencyLevel.ONE)), key); | |
| 61 | 59 | |
| 62 | 60 | // executeAsync |
| 63 | - checkExecuteResultSet(session.executeAsync(String.format(TestUtils.SELECT_ALL_FORMAT, TABLE1)).getUninterruptibly(), key); | |
| 64 | - checkExecuteResultSet(session.executeAsync(new SimpleStatement(String.format(TestUtils.SELECT_ALL_FORMAT, TABLE1)).setConsistencyLevel(ConsistencyLevel.ONE)).getUninterruptibly(), key); | |
| 61 | + checkExecuteResultSet(session().executeAsync(String.format(TestUtils.SELECT_ALL_FORMAT, TABLE1)).getUninterruptibly(), key); | |
| 62 | + checkExecuteResultSet(session().executeAsync(new SimpleStatement(String.format(TestUtils.SELECT_ALL_FORMAT, TABLE1)).setConsistencyLevel(ConsistencyLevel.ONE)).getUninterruptibly(), key); | |
| 65 | 63 | } |
| 66 | 64 | |
| 67 | 65 | @Test(groups = "short") |
| @@ -69,19 +67,19 @@ | ||
| 69 | 67 | // Simple calls to all versions of the execute/executeAsync methods for prepared statements |
| 70 | 68 | // Note: the goal is only to exercice the Session methods, PreparedStatementTest have better prepared statement tests. |
| 71 | 69 | String key = "execute_prepared_test"; |
| 72 | - ResultSet rs = session.execute(String.format(Locale.US, "INSERT INTO %s (k, t, i, f) VALUES ('%s', '%s', %d, %f)", TABLE2, key, "foo", 42, 24.03f)); | |
| 70 | + ResultSet rs = session().execute(String.format(Locale.US, "INSERT INTO %s (k, t, i, f) VALUES ('%s', '%s', %d, %f)", TABLE2, key, "foo", 42, 24.03f)); | |
| 73 | 71 | assertTrue(rs.isExhausted()); |
| 74 | 72 | |
| 75 | - PreparedStatement p = session.prepare(String.format(TestUtils.SELECT_ALL_FORMAT + " WHERE k = ?", TABLE2)); | |
| 73 | + PreparedStatement p = session().prepare(String.format(TestUtils.SELECT_ALL_FORMAT + " WHERE k = ?", TABLE2)); | |
| 76 | 74 | BoundStatement bs = p.bind(key); |
| 77 | 75 | |
| 78 | 76 | // executePrepared |
| 79 | - checkExecuteResultSet(session.execute(bs), key); | |
| 80 | - checkExecuteResultSet(session.execute(bs.setConsistencyLevel(ConsistencyLevel.ONE)), key); | |
| 77 | + checkExecuteResultSet(session().execute(bs), key); | |
| 78 | + checkExecuteResultSet(session().execute(bs.setConsistencyLevel(ConsistencyLevel.ONE)), key); | |
| 81 | 79 | |
| 82 | 80 | // executePreparedAsync |
| 83 | - checkExecuteResultSet(session.executeAsync(bs).getUninterruptibly(), key); | |
| 84 | - checkExecuteResultSet(session.executeAsync(bs.setConsistencyLevel(ConsistencyLevel.ONE)).getUninterruptibly(), key); | |
| 81 | + checkExecuteResultSet(session().executeAsync(bs).getUninterruptibly(), key); | |
| 82 | + checkExecuteResultSet(session().executeAsync(bs.setConsistencyLevel(ConsistencyLevel.ONE)).getUninterruptibly(), key); | |
| 85 | 83 | } |
| 86 | 84 | |
| 87 | 85 | private static void checkExecuteResultSet(ResultSet rs, String key) { |
| @@ -96,12 +94,12 @@ | ||
| 96 | 94 | |
| 97 | 95 | @Test(groups = "short") |
| 98 | 96 | public void executePreparedCounterTest() throws Exception { |
| 99 | - PreparedStatement p = session.prepare("UPDATE " + COUNTER_TABLE + " SET c = c + ? WHERE k = ?"); | |
| 97 | + PreparedStatement p = session().prepare("UPDATE " + COUNTER_TABLE + " SET c = c + ? WHERE k = ?"); | |
| 100 | 98 | |
| 101 | - session.execute(p.bind(1L, "row")); | |
| 102 | - session.execute(p.bind(1L, "row")); | |
| 99 | + session().execute(p.bind(1L, "row")); | |
| 100 | + session().execute(p.bind(1L, "row")); | |
| 103 | 101 | |
| 104 | - ResultSet rs = session.execute("SELECT * FROM " + COUNTER_TABLE); | |
| 102 | + ResultSet rs = session().execute("SELECT * FROM " + COUNTER_TABLE); | |
| 105 | 103 | List<Row> rows = rs.all(); |
| 106 | 104 | assertEquals(rows.size(), 1); |
| 107 | 105 | assertEquals(rows.get(0).getLong("c"), 2L); |
| @@ -109,7 +107,7 @@ | ||
| 109 | 107 | |
| 110 | 108 | /** |
| 111 | 109 | * Validates that a session can be established using snappy compression and executes some queries that inserts and |
| 112 | - * retrieves data using that session. | |
| 110 | + * retrieves data using that session(). | |
| 113 | 111 | * |
| 114 | 112 | * @test_category connection:compression |
| 115 | 113 | * @expected_result session established and queries made successfully using it. |
| @@ -121,7 +119,7 @@ | ||
| 121 | 119 | |
| 122 | 120 | /** |
| 123 | 121 | * Validates that a session can be established using lz4 compression and executes some queries that inserts and |
| 124 | - * retrieves data using that session. | |
| 122 | + * retrieves data using that session(). | |
| 125 | 123 | * |
| 126 | 124 | * @test_category connection:compression |
| 127 | 125 | * @expected_result session established and queries made successfully using it. |
| @@ -133,9 +131,9 @@ | ||
| 133 | 131 | } |
| 134 | 132 | |
| 135 | 133 | public void compressionTest(ProtocolOptions.Compression compression) { |
| 136 | - cluster.getConfiguration().getProtocolOptions().setCompression(compression); | |
| 134 | + cluster().getConfiguration().getProtocolOptions().setCompression(compression); | |
| 137 | 135 | try { |
| 138 | - Session compressedSession = cluster.connect(keyspace); | |
| 136 | + Session compressedSession = cluster().connect(keyspace); | |
| 139 | 137 | |
| 140 | 138 | // Simple calls to all versions of the execute/executeAsync methods |
| 141 | 139 | String key = "execute_compressed_test_" + compression; |
| @@ -153,7 +151,7 @@ | ||
| 153 | 151 | checkExecuteResultSet(compressedSession.executeAsync(new SimpleStatement(SELECT_ALL).setConsistencyLevel(ConsistencyLevel.ONE)).getUninterruptibly(), key); |
| 154 | 152 | |
| 155 | 153 | } finally { |
| 156 | - cluster.getConfiguration().getProtocolOptions().setCompression(ProtocolOptions.Compression.NONE); | |
| 154 | + cluster().getConfiguration().getProtocolOptions().setCompression(ProtocolOptions.Compression.NONE); | |
| 157 | 155 | } |
| 158 | 156 | } |
| 159 | 157 | |
| @@ -167,7 +165,8 @@ | ||
| 167 | 165 | // Use our own cluster and session (not the ones provided by the parent class) because we want an uninitialized cluster |
| 168 | 166 | // (note the use of newSession below) |
| 169 | 167 | final Cluster cluster = Cluster.builder() |
| 170 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 168 | + .addContactPoints(getContactPoints()) | |
| 169 | + .withPort(ccm().getBinaryPort()) | |
| 171 | 170 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 172 | 171 | .build(); |
| 173 | 172 | try { |
modified driver-core/src/test/java/com/datastax/driver/core/SimpleStatementIntegrationTest.java +9 −11
| @@ -19,18 +19,16 @@ | ||
| 19 | 19 | import com.datastax.driver.core.exceptions.UnsupportedFeatureException; |
| 20 | 20 | import com.datastax.driver.core.utils.CassandraVersion; |
| 21 | 21 | import com.google.common.collect.ImmutableMap; |
| 22 | -import com.google.common.collect.Lists; | |
| 23 | 22 | import org.testng.SkipException; |
| 24 | 23 | import org.testng.annotations.Test; |
| 25 | 24 | |
| 26 | -import java.util.Collection; | |
| 27 | - | |
| 28 | 25 | import static org.assertj.core.api.Assertions.assertThat; |
| 29 | 26 | |
| 30 | 27 | public class SimpleStatementIntegrationTest extends CCMTestsSupport { |
| 28 | + | |
| 31 | 29 | @Override |
| 32 | - public Collection<String> createTestFixtures() { | |
| 33 | - return Lists.newArrayList( | |
| 30 | + public void onTestContextInitialized() { | |
| 31 | + execute( | |
| 34 | 32 | "CREATE TABLE users(id int, id2 int, name text, primary key (id, id2))", |
| 35 | 33 | "INSERT INTO users(id, id2, name) VALUES (1, 2, 'test')" |
| 36 | 34 | ); |
| @@ -44,7 +42,7 @@ | ||
| 44 | 42 | ImmutableMap.<String, Object>of("id", 1, "id2", 2)); |
| 45 | 43 | |
| 46 | 44 | // When |
| 47 | - Row row = session.execute(statement).one(); | |
| 45 | + Row row = session().execute(statement).one(); | |
| 48 | 46 | |
| 49 | 47 | // Then |
| 50 | 48 | assertThat(row).isNotNull(); |
| @@ -59,7 +57,7 @@ | ||
| 59 | 57 | ImmutableMap.<String, Object>of("id2", 2)); |
| 60 | 58 | |
| 61 | 59 | // When |
| 62 | - session.execute(statement).one(); | |
| 60 | + session().execute(statement).one(); | |
| 63 | 61 | |
| 64 | 62 | // Then - The driver does allow this because it doesn't know what parameters are required, but C* should |
| 65 | 63 | // throw an InvalidQueryException. |
| @@ -73,7 +71,7 @@ | ||
| 73 | 71 | ImmutableMap.<String, Object>of("id", 2.7, "id2", 2)); |
| 74 | 72 | |
| 75 | 73 | // When |
| 76 | - session.execute(statement).one(); | |
| 74 | + session().execute(statement).one(); | |
| 77 | 75 | |
| 78 | 76 | // Then - The driver does allow this because it doesn't know the type information, but C* should throw an |
| 79 | 77 | // InvalidQueryException. |
| @@ -81,7 +79,7 @@ | ||
| 81 | 79 | |
| 82 | 80 | public void useNamedValuesWithProtocol(ProtocolVersion version) { |
| 83 | 81 | Cluster vCluster = createClusterBuilder() |
| 84 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 82 | + .addContactPoints(getContactPoints()) | |
| 85 | 83 | .withProtocolVersion(version).build(); |
| 86 | 84 | try { |
| 87 | 85 | Session vSession = vCluster.connect(this.keyspace); |
| @@ -101,7 +99,7 @@ | ||
| 101 | 99 | @Test(groups = "short", expectedExceptions = UnsupportedFeatureException.class) |
| 102 | 100 | @CassandraVersion(major = 2.0) |
| 103 | 101 | public void should_fail_if_query_with_named_values_if_protocol_is_V2() { |
| 104 | - if (ccm.getVersion().getMajor() >= 3) { | |
| 102 | + if (ccm().getVersion().getMajor() >= 3) { | |
| 105 | 103 | throw new SkipException("Skipping since Cassandra 3.0+ does not support protocol v2"); |
| 106 | 104 | } |
| 107 | 105 | useNamedValuesWithProtocol(ProtocolVersion.V2); |
| @@ -109,7 +107,7 @@ | ||
| 109 | 107 | |
| 110 | 108 | @Test(groups = "short", expectedExceptions = UnsupportedFeatureException.class) |
| 111 | 109 | public void should_fail_if_query_with_named_values_if_protocol_is_V1() { |
| 112 | - if (ccm.getVersion().getMajor() >= 3) { | |
| 110 | + if (ccm().getVersion().getMajor() >= 3) { | |
| 113 | 111 | throw new SkipException("Skipping since Cassandra 3.0+ does not support protocol v1"); |
| 114 | 112 | } |
| 115 | 113 | useNamedValuesWithProtocol(ProtocolVersion.V1); |
modified driver-core/src/test/java/com/datastax/driver/core/SingleConnectionPoolTest.java +4 −4
| @@ -32,17 +32,17 @@ | ||
| 32 | 32 | public void should_throttle_requests() { |
| 33 | 33 | // Throttle to a very low value. Even a single thread can generate a higher throughput. |
| 34 | 34 | final int maxRequests = 10; |
| 35 | - cluster.getConfiguration().getPoolingOptions() | |
| 35 | + cluster().getConfiguration().getPoolingOptions() | |
| 36 | 36 | .setMaxRequestsPerConnection(HostDistance.LOCAL, maxRequests); |
| 37 | 37 | |
| 38 | 38 | // Track in flight requests in a dedicated thread every second |
| 39 | 39 | final AtomicBoolean excessInflightQueriesSpotted = new AtomicBoolean(false); |
| 40 | - final Host host = cluster.getMetadata().getHost(ccm.addressOfNode(1)); | |
| 40 | + final Host host = cluster().getMetadata().getHost(ccm().addressOfNode(1)); | |
| 41 | 41 | ScheduledExecutorService openConnectionsWatcherExecutor = Executors.newScheduledThreadPool(1); |
| 42 | 42 | final Runnable openConnectionsWatcher = new Runnable() { |
| 43 | 43 | @Override |
| 44 | 44 | public void run() { |
| 45 | - int inFlight = session.getState().getInFlightQueries(host); | |
| 45 | + int inFlight = session().getState().getInFlightQueries(host); | |
| 46 | 46 | if (inFlight > maxRequests) |
| 47 | 47 | excessInflightQueriesSpotted.set(true); |
| 48 | 48 | } |
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | |
| 52 | 52 | // Generate the load |
| 53 | 53 | for (int i = 0; i < 10000; i++) |
| 54 | - session.executeAsync("SELECT release_version FROM system.local"); | |
| 54 | + session().executeAsync("SELECT release_version FROM system.local"); | |
| 55 | 55 | |
| 56 | 56 | openConnectionsWatcherExecutor.shutdownNow(); |
| 57 | 57 | if (excessInflightQueriesSpotted.get()) { |
modified driver-core/src/test/java/com/datastax/driver/core/SingleTokenIntegrationTest.java +3 −2
| @@ -35,7 +35,8 @@ | ||
| 35 | 35 | */ |
| 36 | 36 | @Test(groups = "short") |
| 37 | 37 | public void should_return_single_non_empty_range_when_cluster_has_one_single_token() { |
| 38 | - Metadata metadata = cluster.getMetadata(); | |
| 38 | + cluster().manager.controlConnection.refreshNodeListAndTokenMap(); | |
| 39 | + Metadata metadata = cluster().getMetadata(); | |
| 39 | 40 | Set<TokenRange> tokenRanges = metadata.getTokenRanges(); |
| 40 | 41 | assertThat(tokenRanges).hasSize(1); |
| 41 | 42 | TokenRange tokenRange = tokenRanges.iterator().next(); |
| @@ -46,7 +47,7 @@ | ||
| 46 | 47 | .isNotWrappedAround(); |
| 47 | 48 | |
| 48 | 49 | Set<Host> hostsForRange = metadata.getReplicas(keyspace, tokenRange); |
| 49 | - Host host1 = TestUtils.findHost(cluster, 1); | |
| 50 | + Host host1 = TestUtils.findHost(cluster(), 1); | |
| 50 | 51 | assertThat(hostsForRange).containsOnly(host1); |
| 51 | 52 | |
| 52 | 53 | ByteBuffer randomPartitionKey = Bytes.fromHexString("0xCAFEBABE"); |
modified driver-core/src/test/java/com/datastax/driver/core/SpeculativeExecutionIntegrationTest.java +4 −7
| @@ -17,12 +17,9 @@ | ||
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.policies.ConstantSpeculativeExecutionPolicy; |
| 19 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 20 | -import com.google.common.collect.Lists; | |
| 21 | 20 | import org.mockito.Mockito; |
| 22 | 21 | import org.testng.annotations.Test; |
| 23 | 22 | |
| 24 | -import java.util.Collection; | |
| 25 | - | |
| 26 | 23 | import static org.assertj.core.api.Assertions.assertThat; |
| 27 | 24 | import static org.mockito.Mockito.times; |
| 28 | 25 | |
| @@ -35,8 +32,8 @@ | ||
| 35 | 32 | TimestampGenerator timestampGenerator; |
| 36 | 33 | |
| 37 | 34 | @Override |
| 38 | - public Collection<String> createTestFixtures() { | |
| 39 | - return Lists.newArrayList("create table foo(k int primary key, v int)"); | |
| 35 | + public void onTestContextInitialized() { | |
| 36 | + execute("create table foo(k int primary key, v int)"); | |
| 40 | 37 | } |
| 41 | 38 | |
| 42 | 39 | @Override |
| @@ -59,7 +56,7 @@ | ||
| 59 | 56 | @Test(groups = "short") |
| 60 | 57 | @CassandraVersion(major = 2.1) |
| 61 | 58 | public void should_use_same_default_timestamp_for_all_executions() { |
| 62 | - Metrics.Errors errors = cluster.getMetrics().getErrorMetrics(); | |
| 59 | + Metrics.Errors errors = cluster().getMetrics().getErrorMetrics(); | |
| 63 | 60 | |
| 64 | 61 | Mockito.reset(timestampGenerator); |
| 65 | 62 | long execStartCount = errors.getSpeculativeExecutions().getCount(); |
| @@ -68,7 +65,7 @@ | ||
| 68 | 65 | for (int k = 0; k < 1000; k++) { |
| 69 | 66 | batch.add(new SimpleStatement("insert into foo(k,v) values (?,1)", k)); |
| 70 | 67 | } |
| 71 | - session.execute(batch); | |
| 68 | + session().execute(batch); | |
| 72 | 69 | |
| 73 | 70 | assertThat(errors.getSpeculativeExecutions().getCount()).isEqualTo(execStartCount + 1); |
| 74 | 71 | Mockito.verify(timestampGenerator, times(1)).next(); |
modified driver-core/src/test/java/com/datastax/driver/core/StateListenerTest.java +6 −6
| @@ -35,23 +35,23 @@ | ||
| 35 | 35 | @Test(groups = "long") |
| 36 | 36 | public void should_receive_events_when_node_states_change() throws InterruptedException { |
| 37 | 37 | TestListener listener = new TestListener(); |
| 38 | - cluster.register(listener); | |
| 38 | + cluster().register(listener); | |
| 39 | 39 | |
| 40 | 40 | listener.setExpectedEvent(ADD); |
| 41 | - ccm.add(2); | |
| 42 | - ccm.start(2); | |
| 41 | + ccm().add(2); | |
| 42 | + ccm().start(2); | |
| 43 | 43 | listener.waitForEvent(); |
| 44 | 44 | |
| 45 | 45 | listener.setExpectedEvent(DOWN); |
| 46 | - ccm.forceStop(1); | |
| 46 | + ccm().forceStop(1); | |
| 47 | 47 | listener.waitForEvent(); |
| 48 | 48 | |
| 49 | 49 | listener.setExpectedEvent(UP); |
| 50 | - ccm.start(1); | |
| 50 | + ccm().start(1); | |
| 51 | 51 | listener.waitForEvent(); |
| 52 | 52 | |
| 53 | 53 | listener.setExpectedEvent(REMOVE); |
| 54 | - ccm.decommission(2); | |
| 54 | + ccm().decommission(2); | |
| 55 | 55 | listener.waitForEvent(); |
| 56 | 56 | } |
| 57 | 57 |
modified driver-core/src/test/java/com/datastax/driver/core/StatementWrapperTest.java +6 −6
| @@ -43,10 +43,10 @@ | ||
| 43 | 43 | loadBalancingPolicy.customStatementsHandled.set(0); |
| 44 | 44 | |
| 45 | 45 | SimpleStatement s = new SimpleStatement("select * from system.local"); |
| 46 | - session.execute(s); | |
| 46 | + session().execute(s); | |
| 47 | 47 | assertThat(loadBalancingPolicy.customStatementsHandled.get()).isEqualTo(0); |
| 48 | 48 | |
| 49 | - session.execute(new CustomStatement(s)); | |
| 49 | + session().execute(new CustomStatement(s)); | |
| 50 | 50 | assertThat(loadBalancingPolicy.customStatementsHandled.get()).isEqualTo(1); |
| 51 | 51 | } |
| 52 | 52 | |
| @@ -55,10 +55,10 @@ | ||
| 55 | 55 | speculativeExecutionPolicy.customStatementsHandled.set(0); |
| 56 | 56 | |
| 57 | 57 | SimpleStatement s = new SimpleStatement("select * from system.local"); |
| 58 | - session.execute(s); | |
| 58 | + session().execute(s); | |
| 59 | 59 | assertThat(speculativeExecutionPolicy.customStatementsHandled.get()).isEqualTo(0); |
| 60 | 60 | |
| 61 | - session.execute(new CustomStatement(s)); | |
| 61 | + session().execute(new CustomStatement(s)); | |
| 62 | 62 | assertThat(speculativeExecutionPolicy.customStatementsHandled.get()).isEqualTo(1); |
| 63 | 63 | } |
| 64 | 64 | |
| @@ -71,10 +71,10 @@ | ||
| 71 | 71 | Statement s = new SimpleStatement("select * from system.local") |
| 72 | 72 | .setConsistencyLevel(ConsistencyLevel.TWO); |
| 73 | 73 | |
| 74 | - session.execute(s); | |
| 74 | + session().execute(s); | |
| 75 | 75 | assertThat(retryPolicy.customStatementsHandled.get()).isEqualTo(0); |
| 76 | 76 | |
| 77 | - session.execute(new CustomStatement(s)); | |
| 77 | + session().execute(new CustomStatement(s)); | |
| 78 | 78 | assertThat(retryPolicy.customStatementsHandled.get()).isEqualTo(1); |
| 79 | 79 | } |
| 80 | 80 |
modified driver-core/src/test/java/com/datastax/driver/core/TableMetadataTest.java +28 −28
| @@ -41,8 +41,8 @@ | ||
| 41 | 41 | + " PRIMARY KEY (k)\n" |
| 42 | 42 | + ");", keyspace); |
| 43 | 43 | // when |
| 44 | - session.execute(cql); | |
| 45 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("static"); | |
| 44 | + session().execute(cql); | |
| 45 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("static"); | |
| 46 | 46 | // then |
| 47 | 47 | assertThat(table).isNotNull().hasName("static").hasNumberOfColumns(4).isNotCompactStorage(); |
| 48 | 48 | assertThat(table.getColumns().get(0)).isNotNull().hasName("k").isPartitionKey().hasType(text()); |
| @@ -63,8 +63,8 @@ | ||
| 63 | 63 | + " PRIMARY KEY (k, c1, c2)\n" |
| 64 | 64 | + ") WITH CLUSTERING ORDER BY (c1 ASC, c2 DESC);", keyspace); |
| 65 | 65 | // when |
| 66 | - session.execute(cql); | |
| 67 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("sparse"); | |
| 66 | + session().execute(cql); | |
| 67 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("sparse"); | |
| 68 | 68 | // then |
| 69 | 69 | assertThat(table).isNotNull().hasName("sparse").hasNumberOfColumns(5).isNotCompactStorage(); |
| 70 | 70 | assertThat(table.getColumns().get(0)).isNotNull().hasName("k").isPartitionKey().hasType(text()); |
| @@ -83,8 +83,8 @@ | ||
| 83 | 83 | + " PRIMARY KEY (k)\n" |
| 84 | 84 | + ");", keyspace); |
| 85 | 85 | // when |
| 86 | - session.execute(cql); | |
| 87 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("counters"); | |
| 86 | + session().execute(cql); | |
| 87 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("counters"); | |
| 88 | 88 | // then |
| 89 | 89 | assertThat(table).isNotNull().hasName("counters").hasNumberOfColumns(2).isNotCompactStorage(); |
| 90 | 90 | assertThat(table.getColumns().get(0)).isNotNull().hasName("k").isPartitionKey().hasType(text()); |
| @@ -102,8 +102,8 @@ | ||
| 102 | 102 | + " PRIMARY KEY (k)\n" |
| 103 | 103 | + ") WITH COMPACT STORAGE;", keyspace); |
| 104 | 104 | // when |
| 105 | - session.execute(cql); | |
| 106 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("compact_static"); | |
| 105 | + session().execute(cql); | |
| 106 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("compact_static"); | |
| 107 | 107 | // then |
| 108 | 108 | assertThat(table).isNotNull().hasName("compact_static").hasNumberOfColumns(4).isCompactStorage(); |
| 109 | 109 | assertThat(table.getColumns().get(0)).isNotNull().hasName("k").isPartitionKey().hasType(text()); |
| @@ -121,8 +121,8 @@ | ||
| 121 | 121 | + " PRIMARY KEY (k, c)\n" |
| 122 | 122 | + " ) WITH COMPACT STORAGE;", keyspace); |
| 123 | 123 | // when |
| 124 | - session.execute(cql); | |
| 125 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("dense"); | |
| 124 | + session().execute(cql); | |
| 125 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("dense"); | |
| 126 | 126 | // then |
| 127 | 127 | assertThat(table).isNotNull().hasName("dense").hasNumberOfColumns(2).isCompactStorage(); |
| 128 | 128 | assertThat(table.getColumns().get(0)).isNotNull().hasName("k").isPartitionKey().hasType(cint()); |
| @@ -139,8 +139,8 @@ | ||
| 139 | 139 | + " PRIMARY KEY (k, c)\n" |
| 140 | 140 | + ") WITH COMPACT STORAGE;", keyspace); |
| 141 | 141 | // when |
| 142 | - session.execute(cql); | |
| 143 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("compact_dynamic"); | |
| 142 | + session().execute(cql); | |
| 143 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("compact_dynamic"); | |
| 144 | 144 | // then |
| 145 | 145 | assertThat(table).isNotNull().hasName("compact_dynamic").hasNumberOfColumns(3).isCompactStorage(); |
| 146 | 146 | assertThat(table.getColumns().get(0)).isNotNull().hasName("k").isPartitionKey().hasType(text()); |
| @@ -160,8 +160,8 @@ | ||
| 160 | 160 | + " PRIMARY KEY (k, c1, c2, c3)\n" |
| 161 | 161 | + ") WITH COMPACT STORAGE;", keyspace); |
| 162 | 162 | // when |
| 163 | - session.execute(cql); | |
| 164 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("compact_composite"); | |
| 163 | + session().execute(cql); | |
| 164 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("compact_composite"); | |
| 165 | 165 | // then |
| 166 | 166 | assertThat(table).isNotNull().hasName("compact_composite").hasNumberOfColumns(5).isCompactStorage(); |
| 167 | 167 | assertThat(table.getColumns().get(0)).isNotNull().hasName("k").isPartitionKey().hasType(text()); |
| @@ -173,7 +173,7 @@ | ||
| 173 | 173 | |
| 174 | 174 | @Test(groups = "short") |
| 175 | 175 | public void should_parse_table_options() { |
| 176 | - VersionNumber version = TestUtils.findHost(cluster, 1).getCassandraVersion(); | |
| 176 | + VersionNumber version = TestUtils.findHost(cluster(), 1).getCassandraVersion(); | |
| 177 | 177 | |
| 178 | 178 | // given |
| 179 | 179 | String cql; |
| @@ -223,8 +223,8 @@ | ||
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | // when |
| 226 | - session.execute(cql); | |
| 227 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("with_options"); | |
| 226 | + session().execute(cql); | |
| 227 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("with_options"); | |
| 228 | 228 | |
| 229 | 229 | // then |
| 230 | 230 | assertThat(table).isNotNull().hasName("with_options").hasNumberOfColumns(4).isNotCompactStorage(); |
| @@ -421,8 +421,8 @@ | ||
| 421 | 421 | keyspace); |
| 422 | 422 | |
| 423 | 423 | // when |
| 424 | - session.execute(cql); | |
| 425 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("new_compression_options"); | |
| 424 | + session().execute(cql); | |
| 425 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("new_compression_options"); | |
| 426 | 426 | |
| 427 | 427 | // then |
| 428 | 428 | assertThat(table.getOptions().getCompression()) |
| @@ -438,8 +438,8 @@ | ||
| 438 | 438 | + ") WITH comment = 'comment with single quote '' should work'", |
| 439 | 439 | keyspace); |
| 440 | 440 | // when |
| 441 | - session.execute(cql); | |
| 442 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("single_quote"); | |
| 441 | + session().execute(cql); | |
| 442 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("single_quote"); | |
| 443 | 443 | // then |
| 444 | 444 | assertThat(table.getOptions().getComment()).isEqualTo("comment with single quote ' should work"); |
| 445 | 445 | assertThat(table.asCQLQuery()).contains("comment = 'comment with single quote '' should work'"); |
| @@ -454,10 +454,10 @@ | ||
| 454 | 454 | "CREATE INDEX test_d on test_cd (d);", |
| 455 | 455 | }; |
| 456 | 456 | for (String statement : statements) |
| 457 | - session.execute(statement); | |
| 457 | + session().execute(statement); | |
| 458 | 458 | |
| 459 | - TableMetadata table_ab = cluster.getMetadata().getKeyspace(keyspace).getTable("test_ab"); | |
| 460 | - TableMetadata table_cd = cluster.getMetadata().getKeyspace(keyspace).getTable("test_cd"); | |
| 459 | + TableMetadata table_ab = cluster().getMetadata().getKeyspace(keyspace).getTable("test_ab"); | |
| 460 | + TableMetadata table_cd = cluster().getMetadata().getKeyspace(keyspace).getTable("test_cd"); | |
| 461 | 461 | |
| 462 | 462 | assertThat(table_ab.getIndexes().size()).isEqualTo(1); |
| 463 | 463 | assertThat(table_ab.getIndexes()).extracting("name").containsOnly("test_b"); |
| @@ -485,15 +485,15 @@ | ||
| 485 | 485 | + " v timeuuid,\n" |
| 486 | 486 | + " PRIMARY KEY (k, c)\n" |
| 487 | 487 | + ");", keyspace); |
| 488 | - session.execute(cql); | |
| 488 | + session().execute(cql); | |
| 489 | 489 | |
| 490 | 490 | // Manually change column value in system_schema.tables and force a schema refresh on that table. |
| 491 | 491 | ImmutableMap<String, ByteBuffer> extensions = ImmutableMap.of("Hello", ByteBuffer.wrap("World".getBytes("UTF-8"))); |
| 492 | - session.execute("update system_schema.tables set extensions=? where keyspace_name=? and table_name=?", extensions, keyspace, "table_with_extensions"); | |
| 493 | - cluster.manager.controlConnection.refreshSchema(SchemaElement.TABLE, keyspace, "table_with_extensions", null); | |
| 492 | + session().execute("update system_schema.tables set extensions=? where keyspace_name=? and table_name=?", extensions, keyspace, "table_with_extensions"); | |
| 493 | + cluster().manager.controlConnection.refreshSchema(SchemaElement.TABLE, keyspace, "table_with_extensions", null); | |
| 494 | 494 | |
| 495 | 495 | // when retrieving the table's metadata. |
| 496 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("table_with_extensions"); | |
| 496 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("table_with_extensions"); | |
| 497 | 497 | // then the table's options should contain populated extensions. |
| 498 | 498 | assertThat(table.getOptions().getExtensions()).isEqualTo(extensions); |
| 499 | 499 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +60 −35
| @@ -35,12 +35,14 @@ | ||
| 35 | 35 | import java.net.*; |
| 36 | 36 | import java.nio.ByteBuffer; |
| 37 | 37 | import java.util.*; |
| 38 | -import java.util.concurrent.Callable; | |
| 39 | -import java.util.concurrent.CountDownLatch; | |
| 40 | -import java.util.concurrent.TimeUnit; | |
| 38 | +import java.util.concurrent.*; | |
| 41 | 39 | import java.util.concurrent.atomic.AtomicInteger; |
| 42 | 40 | import java.util.concurrent.locks.ReentrantLock; |
| 43 | 41 | |
| 42 | +import static com.datastax.driver.core.ConditionChecker.check; | |
| 43 | +import static java.util.concurrent.TimeUnit.MINUTES; | |
| 44 | +import static java.util.concurrent.TimeUnit.SECONDS; | |
| 45 | + | |
| 44 | 46 | /** |
| 45 | 47 | * A number of static fields/methods handy for tests. |
| 46 | 48 | */ |
| @@ -61,15 +63,10 @@ | ||
| 61 | 63 | public static final String CREATE_KEYSPACE_SIMPLE_FORMAT = "CREATE KEYSPACE %s WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : %d }"; |
| 62 | 64 | public static final String CREATE_KEYSPACE_GENERIC_FORMAT = "CREATE KEYSPACE %s WITH replication = { 'class' : '%s', %s }"; |
| 63 | 65 | |
| 64 | - public static final String SIMPLE_KEYSPACE = "ks"; | |
| 65 | - public static final String SIMPLE_TABLE = "test"; | |
| 66 | - | |
| 67 | 66 | public static final String SELECT_ALL_FORMAT = "SELECT * FROM %s"; |
| 68 | 67 | |
| 69 | 68 | public static final int TEST_BASE_NODE_WAIT = SystemProperties.getInt("com.datastax.driver.TEST_BASE_NODE_WAIT", 60); |
| 70 | 69 | |
| 71 | - private static final AtomicInteger KS_COUNTER = new AtomicInteger(1); | |
| 72 | - | |
| 73 | 70 | public static void setValue(SettableByIndexData<?> data, int i, DataType type, Object value) { |
| 74 | 71 | switch (type.getName()) { |
| 75 | 72 | case ASCII: |
| @@ -470,28 +467,20 @@ | ||
| 470 | 467 | // Wait for a node to be up and running |
| 471 | 468 | // This is used because there is some delay between when a node has been |
| 472 | 469 | // added through ccm and when it's actually available for querying |
| 473 | - public static void waitFor(String node, Cluster cluster) { | |
| 470 | + public static void waitForUp(String node, Cluster cluster) { | |
| 474 | 471 | waitFor(node, cluster, TEST_BASE_NODE_WAIT, false); |
| 475 | 472 | } |
| 476 | 473 | |
| 477 | - public static void waitFor(String node, Cluster cluster, int maxTry) { | |
| 478 | - waitFor(node, cluster, maxTry, false); | |
| 474 | + public static void waitForUp(String node, Cluster cluster, int timeoutSeconds) { | |
| 475 | + waitFor(node, cluster, timeoutSeconds, false); | |
| 479 | 476 | } |
| 480 | 477 | |
| 481 | 478 | public static void waitForDown(String node, Cluster cluster) { |
| 482 | 479 | waitFor(node, cluster, TEST_BASE_NODE_WAIT * 3, true); |
| 483 | 480 | } |
| 484 | 481 | |
| 485 | - public static void waitForDown(String node, Cluster cluster, int maxTry) { | |
| 486 | - waitFor(node, cluster, maxTry, true); | |
| 487 | - } | |
| 488 | - | |
| 489 | - public static void waitForDecommission(String node, Cluster cluster) { | |
| 490 | - waitFor(node, cluster, TEST_BASE_NODE_WAIT / 2, true); | |
| 491 | - } | |
| 492 | - | |
| 493 | - public static void waitForDecommission(String node, Cluster cluster, int maxTry) { | |
| 494 | - waitFor(node, cluster, maxTry, true); | |
| 482 | + public static void waitForDown(String node, Cluster cluster, int timeoutSeconds) { | |
| 483 | + waitFor(node, cluster, timeoutSeconds, true); | |
| 495 | 484 | } |
| 496 | 485 | |
| 497 | 486 | private static void waitFor(String node, Cluster cluster, int timeoutSeconds, boolean waitForDown) { |
| @@ -503,23 +492,30 @@ | ||
| 503 | 492 | // tried doing an actual query, the driver won't realize that last node is dead until |
| 504 | 493 | // keep alive kicks in, but that's a fairly long time. So we cheat and trigger a force |
| 505 | 494 | // the detection by forcing a request. |
| 506 | - if (waitForDown) { | |
| 495 | + if (waitForDown) | |
| 507 | 496 | Futures.getUnchecked(cluster.manager.submitSchemaRefresh(null, null, null, null)); |
| 508 | - } | |
| 509 | 497 | if (waitForDown) { |
| 510 | - ConditionChecker.awaitUntil(new HostIsDownCondition(cluster, node), timeoutSeconds * 1000); | |
| 498 | + check() | |
| 499 | + .every(1, SECONDS) | |
| 500 | + .before(timeoutSeconds, SECONDS) | |
| 501 | + .that(new HostIsDown(cluster, node)) | |
| 502 | + .becomesTrue(); | |
| 511 | 503 | } else { |
| 512 | - ConditionChecker.awaitUntil(new HostIsUpCondition(cluster, node), timeoutSeconds * 1000); | |
| 504 | + check() | |
| 505 | + .every(1, SECONDS) | |
| 506 | + .before(timeoutSeconds, SECONDS) | |
| 507 | + .that(new HostIsUp(cluster, node)) | |
| 508 | + .becomesTrue(); | |
| 513 | 509 | } |
| 514 | 510 | } |
| 515 | 511 | |
| 516 | - private static class HostIsDownCondition implements Callable<Boolean> { | |
| 512 | + private static class HostIsDown implements Callable<Boolean> { | |
| 517 | 513 | |
| 518 | 514 | private final Cluster cluster; |
| 519 | 515 | |
| 520 | 516 | private final String ip; |
| 521 | 517 | |
| 522 | - public HostIsDownCondition(Cluster cluster, String ip) { | |
| 518 | + public HostIsDown(Cluster cluster, String ip) { | |
| 523 | 519 | this.cluster = cluster; |
| 524 | 520 | this.ip = ip; |
| 525 | 521 | } |
| @@ -531,13 +527,13 @@ | ||
| 531 | 527 | } |
| 532 | 528 | } |
| 533 | 529 | |
| 534 | - private static class HostIsUpCondition implements Callable<Boolean> { | |
| 530 | + private static class HostIsUp implements Callable<Boolean> { | |
| 535 | 531 | |
| 536 | 532 | private final Cluster cluster; |
| 537 | 533 | |
| 538 | 534 | private final String ip; |
| 539 | 535 | |
| 540 | - public HostIsUpCondition(Cluster cluster, String ip) { | |
| 536 | + public HostIsUp(Cluster cluster, String ip) { | |
| 541 | 537 | this.cluster = cluster; |
| 542 | 538 | this.ip = ip; |
| 543 | 539 | } |
| @@ -660,8 +656,20 @@ | ||
| 660 | 656 | return ScassandraFactory.createServer(ipOfNode(1), binaryPort, ipOfNode(1), adminPort); |
| 661 | 657 | } |
| 662 | 658 | |
| 663 | - public static String getAvailableKeyspaceName() { | |
| 664 | - return SIMPLE_KEYSPACE + "_" + KS_COUNTER.getAndIncrement(); | |
| 659 | + private static final ConcurrentMap<String, AtomicInteger> IDENTIFIERS = new ConcurrentHashMap<String, AtomicInteger>(); | |
| 660 | + | |
| 661 | + /** | |
| 662 | + * Generates a unique CQL identifier with the given prefix. | |
| 663 | + * | |
| 664 | + * @param prefix The prefix for the identifier | |
| 665 | + * @return a unique CQL identifier. | |
| 666 | + */ | |
| 667 | + public static String generateIdentifier(String prefix) { | |
| 668 | + AtomicInteger seq = new AtomicInteger(0); | |
| 669 | + AtomicInteger previous = IDENTIFIERS.putIfAbsent(prefix, seq); | |
| 670 | + if (previous != null) | |
| 671 | + seq = previous; | |
| 672 | + return prefix + seq.incrementAndGet(); | |
| 665 | 673 | } |
| 666 | 674 | |
| 667 | 675 | // use ports in the ephemeral range |
| @@ -718,11 +726,11 @@ | ||
| 718 | 726 | }; |
| 719 | 727 | |
| 720 | 728 | public static void waitUntilPortIsUp(InetSocketAddress address) { |
| 721 | - ConditionChecker.awaitUntil(address, PORT_IS_UP, TimeUnit.SECONDS.toMillis(10)); | |
| 729 | + check().before(5, MINUTES).that(address, PORT_IS_UP).becomesTrue(); | |
| 722 | 730 | } |
| 723 | 731 | |
| 724 | 732 | public static void waitUntilPortIsDown(InetSocketAddress address) { |
| 725 | - ConditionChecker.awaitWhile(address, PORT_IS_UP, TimeUnit.SECONDS.toMillis(10)); | |
| 733 | + check().before(5, MINUTES).that(address, PORT_IS_UP).becomesFalse(); | |
| 726 | 734 | } |
| 727 | 735 | |
| 728 | 736 | public static boolean pingPort(InetAddress address, int port) { |
| @@ -780,7 +788,7 @@ | ||
| 780 | 788 | Host controlHost = cluster.manager.controlConnection.connectedHost(); |
| 781 | 789 | List<InetSocketAddress> singleAddress = Collections.singletonList(controlHost.getSocketAddress()); |
| 782 | 790 | return Cluster.builder() |
| 783 | - .addContactPointsWithPorts(singleAddress) | |
| 791 | + .addContactPoints(controlHost.getSocketAddress().getAddress()) | |
| 784 | 792 | .withPort(ccm.getBinaryPort()) |
| 785 | 793 | .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), singleAddress)) |
| 786 | 794 | .build(); |
| @@ -803,10 +811,16 @@ | ||
| 803 | 811 | public static NettyOptions nonQuietClusterCloseOptions = new NettyOptions() { |
| 804 | 812 | @Override |
| 805 | 813 | public void onClusterClose(EventLoopGroup eventLoopGroup) { |
| 806 | - eventLoopGroup.shutdownGracefully(0, 15, TimeUnit.SECONDS).syncUninterruptibly(); | |
| 814 | + eventLoopGroup.shutdownGracefully(0, 15, SECONDS).syncUninterruptibly(); | |
| 807 | 815 | } |
| 808 | 816 | }; |
| 809 | 817 | |
| 818 | + /** | |
| 819 | + * Executes a task and catches any exception. | |
| 820 | + * | |
| 821 | + * @param task The task to execute. | |
| 822 | + * @param logException Whether to log the exception, if any. | |
| 823 | + */ | |
| 810 | 824 | public static void executeNoFail(Runnable task, boolean logException) { |
| 811 | 825 | try { |
| 812 | 826 | task.run(); |
| @@ -816,6 +830,12 @@ | ||
| 816 | 830 | } |
| 817 | 831 | } |
| 818 | 832 | |
| 833 | + /** | |
| 834 | + * Executes a task and catches any exception. | |
| 835 | + * | |
| 836 | + * @param task The task to execute. | |
| 837 | + * @param logException Whether to log the exception, if any. | |
| 838 | + */ | |
| 819 | 839 | public static void executeNoFail(Callable<?> task, boolean logException) { |
| 820 | 840 | try { |
| 821 | 841 | task.call(); |
| @@ -825,6 +845,11 @@ | ||
| 825 | 845 | } |
| 826 | 846 | } |
| 827 | 847 | |
| 848 | + /** | |
| 849 | + * Returns the system's free memory in megabytes. | |
| 850 | + * <p/> | |
| 851 | + * This includes the free physical memory + the free swap memory. | |
| 852 | + */ | |
| 828 | 853 | public static long getFreeMemoryMB() { |
| 829 | 854 | OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); |
| 830 | 855 | return (bean.getFreePhysicalMemorySize() + bean.getFreeSwapSpaceSize()) / 1024 / 1024; |
modified driver-core/src/test/java/com/datastax/driver/core/TimeoutStressTest.java +20 −21
| @@ -18,7 +18,6 @@ | ||
| 18 | 18 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 19 | 19 | import com.datastax.driver.core.policies.ConstantReconnectionPolicy; |
| 20 | 20 | import com.datastax.driver.core.utils.SocketChannelMonitor; |
| 21 | -import com.google.common.collect.Lists; | |
| 22 | 21 | import com.google.common.util.concurrent.FutureCallback; |
| 23 | 22 | import com.google.common.util.concurrent.Futures; |
| 24 | 23 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
| @@ -71,8 +70,8 @@ | ||
| 71 | 70 | } |
| 72 | 71 | |
| 73 | 72 | @Override |
| 74 | - public Collection<String> createTestFixtures() { | |
| 75 | - return Lists.newArrayList( | |
| 73 | + public void onTestContextInitialized() { | |
| 74 | + execute( | |
| 76 | 75 | "create table record (\n" |
| 77 | 76 | + " name text,\n" |
| 78 | 77 | + " phone text,\n" |
| @@ -109,13 +108,13 @@ | ||
| 109 | 108 | @Test(groups = "stress") |
| 110 | 109 | public void host_state_should_be_maintained_with_timeouts() throws Exception { |
| 111 | 110 | insertRecords(); |
| 112 | - session.close(); | |
| 111 | + session().close(); | |
| 113 | 112 | |
| 114 | 113 | // Set very low timeouts. |
| 115 | - cluster.getConfiguration().getSocketOptions().setConnectTimeoutMillis(CONNECTION_TIMEOUT_IN_MS); | |
| 116 | - cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(READ_TIMEOUT_IN_MS); | |
| 117 | - session = cluster.connect(keyspace); | |
| 118 | - PreparedStatement statement = session.prepare("select * from record where name=? limit 1000;"); | |
| 114 | + cluster().getConfiguration().getSocketOptions().setConnectTimeoutMillis(CONNECTION_TIMEOUT_IN_MS); | |
| 115 | + cluster().getConfiguration().getSocketOptions().setReadTimeoutMillis(READ_TIMEOUT_IN_MS); | |
| 116 | + Session newSession = cluster().connect(keyspace); | |
| 117 | + PreparedStatement statement = newSession.prepare("select * from record where name=? limit 1000;"); | |
| 119 | 118 | |
| 120 | 119 | int workers = Runtime.getRuntime().availableProcessors(); |
| 121 | 120 | ExecutorService workerPool = Executors.newFixedThreadPool(workers, |
| @@ -124,12 +123,12 @@ | ||
| 124 | 123 | AtomicBoolean stopped = new AtomicBoolean(false); |
| 125 | 124 | |
| 126 | 125 | // Ensure that we never exceed MaxConnectionsPerHost * nodes + 1 control connection. |
| 127 | - int maxConnections = TestUtils.numberOfLocalCoreConnections(cluster) * getInitialContactPoints().size() + 1; | |
| 126 | + int maxConnections = TestUtils.numberOfLocalCoreConnections(cluster()) * getContactPoints().size() + 1; | |
| 128 | 127 | |
| 129 | 128 | try { |
| 130 | 129 | Semaphore concurrentQueries = new Semaphore(CONCURRENT_QUERIES); |
| 131 | 130 | for (int i = 0; i < workers; i++) { |
| 132 | - workerPool.submit(new TimeoutStressWorker(session, statement, concurrentQueries, stopped)); | |
| 131 | + workerPool.submit(new TimeoutStressWorker(newSession, statement, concurrentQueries, stopped)); | |
| 133 | 132 | } |
| 134 | 133 | |
| 135 | 134 | long startTime = System.currentTimeMillis(); |
| @@ -138,7 +137,7 @@ | ||
| 138 | 137 | channelMonitor.report(); |
| 139 | 138 | // Some connections that are being closed may have had active requests which are delegated to the |
| 140 | 139 | // reaper for cleanup later. |
| 141 | - Collection<SocketChannel> openChannels = channelMonitor.openChannels(getInitialContactPoints()); | |
| 140 | + Collection<SocketChannel> openChannels = channelMonitor.openChannels(getContactPointsWithPorts()); | |
| 142 | 141 | |
| 143 | 142 | // Ensure that we don't exceed maximum connections. Log as warning as there will be a bit of a timing |
| 144 | 143 | // factor between retrieving open connections and checking the reaper. |
| @@ -152,28 +151,28 @@ | ||
| 152 | 151 | stopped.set(true); |
| 153 | 152 | |
| 154 | 153 | // Reset socket timeouts to allow pool to recover. |
| 155 | - cluster.getConfiguration().getSocketOptions() | |
| 154 | + cluster().getConfiguration().getSocketOptions() | |
| 156 | 155 | .setConnectTimeoutMillis(SocketOptions.DEFAULT_CONNECT_TIMEOUT_MILLIS); |
| 157 | - cluster.getConfiguration().getSocketOptions() | |
| 156 | + cluster().getConfiguration().getSocketOptions() | |
| 158 | 157 | .setReadTimeoutMillis(SocketOptions.DEFAULT_READ_TIMEOUT_MILLIS); |
| 159 | 158 | |
| 160 | 159 | logger.debug("Sleeping 20 seconds to allow connection reaper to clean up connections " + |
| 161 | 160 | "and for the pools to recover."); |
| 162 | 161 | Uninterruptibles.sleepUninterruptibly(20, TimeUnit.SECONDS); |
| 163 | 162 | |
| 164 | - Collection<SocketChannel> openChannels = channelMonitor.openChannels(getInitialContactPoints()); | |
| 163 | + Collection<SocketChannel> openChannels = channelMonitor.openChannels(getContactPointsWithPorts()); | |
| 165 | 164 | assertThat(openChannels.size()) |
| 166 | 165 | .as("Number of open connections does not meet expected: %s", openChannels) |
| 167 | 166 | .isLessThanOrEqualTo(maxConnections); |
| 168 | 167 | |
| 169 | 168 | // Each host should be in an up state. |
| 170 | - assertThat(cluster).host(1).comesUpWithin(0, TimeUnit.SECONDS); | |
| 171 | - assertThat(cluster).host(2).comesUpWithin(0, TimeUnit.SECONDS); | |
| 172 | - assertThat(cluster).host(3).comesUpWithin(0, TimeUnit.SECONDS); | |
| 169 | + assertThat(cluster()).host(1).comesUpWithin(0, TimeUnit.SECONDS); | |
| 170 | + assertThat(cluster()).host(2).comesUpWithin(0, TimeUnit.SECONDS); | |
| 171 | + assertThat(cluster()).host(3).comesUpWithin(0, TimeUnit.SECONDS); | |
| 173 | 172 | |
| 174 | - session.close(); | |
| 173 | + newSession.close(); | |
| 175 | 174 | |
| 176 | - openChannels = channelMonitor.openChannels(getInitialContactPoints()); | |
| 175 | + openChannels = channelMonitor.openChannels(getContactPointsWithPorts()); | |
| 177 | 176 | assertThat(openChannels.size()) |
| 178 | 177 | .as("Number of open connections does not meet expected: %s", openChannels) |
| 179 | 178 | .isEqualTo(1); |
| @@ -184,12 +183,12 @@ | ||
| 184 | 183 | |
| 185 | 184 | private void insertRecords() { |
| 186 | 185 | int records = 30000; |
| 187 | - PreparedStatement insertStmt = session.prepare("insert into record (name, phone, value) values (?, ?, ?)"); | |
| 186 | + PreparedStatement insertStmt = session().prepare("insert into record (name, phone, value) values (?, ?, ?)"); | |
| 188 | 187 | |
| 189 | 188 | for (int i = 0; i < records; i++) { |
| 190 | 189 | if (i % 1000 == 0) |
| 191 | 190 | logger.debug("Inserting record {}.", i); |
| 192 | - session.execute(insertStmt.bind("0", Integer.toString(i), "test")); | |
| 191 | + session().execute(insertStmt.bind("0", Integer.toString(i), "test")); | |
| 193 | 192 | } |
| 194 | 193 | logger.debug("Inserts complete."); |
| 195 | 194 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TokenIntegrationTest.java +41 −37
| @@ -25,7 +25,10 @@ | ||
| 25 | 25 | import com.google.common.collect.Lists; |
| 26 | 26 | import org.testng.annotations.Test; |
| 27 | 27 | |
| 28 | -import java.util.*; | |
| 28 | +import java.util.Collections; | |
| 29 | +import java.util.HashSet; | |
| 30 | +import java.util.List; | |
| 31 | +import java.util.Set; | |
| 29 | 32 | |
| 30 | 33 | import static com.datastax.driver.core.Assertions.assertThat; |
| 31 | 34 | |
| @@ -54,18 +57,19 @@ | ||
| 54 | 57 | public Cluster.Builder createClusterBuilder() { |
| 55 | 58 | // Only connect to node 1, which makes it easier to query system tables in should_expose_tokens_per_host() |
| 56 | 59 | LoadBalancingPolicy lbp = new WhiteListPolicy(new RoundRobinPolicy(), |
| 57 | - Collections.singleton(ccm.addressOfNode(1))); | |
| 60 | + Collections.singleton(ccm().addressOfNode(1))); | |
| 58 | 61 | return Cluster.builder() |
| 59 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 62 | + .addContactPoints(getContactPoints().get(0)) | |
| 63 | + .withPort(ccm().getBinaryPort()) | |
| 60 | 64 | .withLoadBalancingPolicy(lbp) |
| 61 | 65 | .withQueryOptions(TestUtils.nonDebouncingQueryOptions()); |
| 62 | 66 | } |
| 63 | 67 | |
| 64 | 68 | @Override |
| 65 | - public Collection<String> createTestFixtures() { | |
| 66 | - ks1 = TestUtils.getAvailableKeyspaceName(); | |
| 67 | - ks2 = TestUtils.getAvailableKeyspaceName(); | |
| 68 | - return Lists.newArrayList( | |
| 69 | + public void onTestContextInitialized() { | |
| 70 | + ks1 = TestUtils.generateIdentifier("ks_"); | |
| 71 | + ks2 = TestUtils.generateIdentifier("ks_"); | |
| 72 | + execute( | |
| 69 | 73 | String.format("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", ks1), |
| 70 | 74 | String.format("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2}", ks2), |
| 71 | 75 | String.format("USE %s", ks1), |
| @@ -89,18 +93,18 @@ | ||
| 89 | 93 | */ |
| 90 | 94 | @Test(groups = "short") |
| 91 | 95 | public void should_expose_token_ranges() throws Exception { |
| 92 | - Metadata metadata = cluster.getMetadata(); | |
| 96 | + Metadata metadata = cluster().getMetadata(); | |
| 93 | 97 | |
| 94 | 98 | // Find the replica for a given partition key |
| 95 | 99 | int testKey = 1; |
| 96 | - Set<Host> replicas = metadata.getReplicas(ks1, TypeCodec.cint().serialize(testKey, cluster.getConfiguration().getProtocolOptions().getProtocolVersion())); | |
| 100 | + Set<Host> replicas = metadata.getReplicas(ks1, TypeCodec.cint().serialize(testKey, cluster().getConfiguration().getProtocolOptions().getProtocolVersion())); | |
| 97 | 101 | assertThat(replicas).hasSize(1); |
| 98 | 102 | Host replica = replicas.iterator().next(); |
| 99 | 103 | |
| 100 | 104 | // Iterate the cluster's token ranges. For each one, use a range query to ask Cassandra which partition keys |
| 101 | 105 | // are in this range. |
| 102 | 106 | |
| 103 | - PreparedStatement rangeStmt = session.prepare("SELECT i FROM foo WHERE token(i) > ? and token(i) <= ?"); | |
| 107 | + PreparedStatement rangeStmt = session().prepare("SELECT i FROM foo WHERE token(i) > ? and token(i) <= ?"); | |
| 104 | 108 | |
| 105 | 109 | TokenRange foundRange = null; |
| 106 | 110 | for (TokenRange range : metadata.getTokenRanges()) { |
| @@ -124,7 +128,7 @@ | ||
| 124 | 128 | List<Row> rows = Lists.newArrayList(); |
| 125 | 129 | for (TokenRange subRange : range.unwrap()) { |
| 126 | 130 | Statement statement = rangeStmt.bind(subRange.getStart(), subRange.getEnd()); |
| 127 | - rows.addAll(session.execute(statement).all()); | |
| 131 | + rows.addAll(session().execute(statement).all()); | |
| 128 | 132 | } |
| 129 | 133 | return rows; |
| 130 | 134 | } |
| @@ -154,7 +158,7 @@ | ||
| 154 | 158 | @Test(groups = "short") |
| 155 | 159 | public void should_get_token_from_row_and_set_token_in_query() { |
| 156 | 160 | // get by index: |
| 157 | - Row row = session.execute("SELECT token(i) FROM foo WHERE i = 1").one(); | |
| 161 | + Row row = session().execute("SELECT token(i) FROM foo WHERE i = 1").one(); | |
| 158 | 162 | Token token = row.getToken(0); |
| 159 | 163 | assertThat(token.getType()).isEqualTo(expectedTokenType); |
| 160 | 164 | |
| @@ -162,14 +166,14 @@ | ||
| 162 | 166 | row.getPartitionKeyToken() |
| 163 | 167 | ).isEqualTo(token); |
| 164 | 168 | |
| 165 | - PreparedStatement pst = session.prepare("SELECT * FROM foo WHERE token(i) = ?"); | |
| 166 | - row = session.execute(pst.bind(token)).one(); | |
| 169 | + PreparedStatement pst = session().prepare("SELECT * FROM foo WHERE token(i) = ?"); | |
| 170 | + row = session().execute(pst.bind(token)).one(); | |
| 167 | 171 | assertThat(row.getInt(0)).isEqualTo(1); |
| 168 | 172 | |
| 169 | - row = session.execute(pst.bind().setToken(0, token)).one(); | |
| 173 | + row = session().execute(pst.bind().setToken(0, token)).one(); | |
| 170 | 174 | assertThat(row.getInt(0)).isEqualTo(1); |
| 171 | 175 | |
| 172 | - row = session.execute(pst.bind().setPartitionKeyToken(token)).one(); | |
| 176 | + row = session().execute(pst.bind().setPartitionKeyToken(token)).one(); | |
| 173 | 177 | assertThat(row.getInt(0)).isEqualTo(1); |
| 174 | 178 | } |
| 175 | 179 | |
| @@ -190,15 +194,15 @@ | ||
| 190 | 194 | @Test(groups = "short") |
| 191 | 195 | @CassandraVersion(major = 2) |
| 192 | 196 | public void should_get_token_from_row_and_set_token_in_query_with_binding_and_aliasing() { |
| 193 | - Row row = session.execute("SELECT token(i) AS t FROM foo WHERE i = 1").one(); | |
| 197 | + Row row = session().execute("SELECT token(i) AS t FROM foo WHERE i = 1").one(); | |
| 194 | 198 | Token token = row.getToken("t"); |
| 195 | 199 | assertThat(token.getType()).isEqualTo(expectedTokenType); |
| 196 | 200 | |
| 197 | - PreparedStatement pst = session.prepare("SELECT * FROM foo WHERE token(i) = :myToken"); | |
| 198 | - row = session.execute(pst.bind().setToken("myToken", token)).one(); | |
| 201 | + PreparedStatement pst = session().prepare("SELECT * FROM foo WHERE token(i) = :myToken"); | |
| 202 | + row = session().execute(pst.bind().setToken("myToken", token)).one(); | |
| 199 | 203 | assertThat(row.getInt(0)).isEqualTo(1); |
| 200 | 204 | |
| 201 | - row = session.execute("SELECT * FROM foo WHERE token(i) = ?", token).one(); | |
| 205 | + row = session().execute("SELECT * FROM foo WHERE token(i) = ?", token).one(); | |
| 202 | 206 | assertThat(row.getInt(0)).isEqualTo(1); |
| 203 | 207 | } |
| 204 | 208 | |
| @@ -214,7 +218,7 @@ | ||
| 214 | 218 | */ |
| 215 | 219 | @Test(groups = "short", expectedExceptions = InvalidTypeException.class) |
| 216 | 220 | public void should_raise_exception_when_get_token_on_non_token() { |
| 217 | - Row row = session.execute("SELECT i FROM foo WHERE i = 1").one(); | |
| 221 | + Row row = session().execute("SELECT i FROM foo WHERE i = 1").one(); | |
| 218 | 222 | row.getToken(0); |
| 219 | 223 | } |
| 220 | 224 | |
| @@ -238,7 +242,7 @@ | ||
| 238 | 242 | public void should_expose_token_ranges_per_host() { |
| 239 | 243 | checkRangesPerHost(ks1, 1); |
| 240 | 244 | checkRangesPerHost(ks2, 2); |
| 241 | - assertThat(cluster).hasValidTokenRanges(); | |
| 245 | + assertThat(cluster()).hasValidTokenRanges(); | |
| 242 | 246 | } |
| 243 | 247 | |
| 244 | 248 | private void checkRangesPerHost(String keyspace, int replicationFactor) { |
| @@ -246,8 +250,8 @@ | ||
| 246 | 250 | |
| 247 | 251 | // Get each host's ranges, the count should match the replication factor |
| 248 | 252 | for (int i = 1; i <= 3; i++) { |
| 249 | - Host host = TestUtils.findHost(cluster, i); | |
| 250 | - Set<TokenRange> hostRanges = cluster.getMetadata().getTokenRanges(keyspace, host); | |
| 253 | + Host host = TestUtils.findHost(cluster(), i); | |
| 254 | + Set<TokenRange> hostRanges = cluster().getMetadata().getTokenRanges(keyspace, host); | |
| 251 | 255 | // Special case: When using vnodes the tokens are not evenly assigned to each replica. |
| 252 | 256 | if (!useVnodes) { |
| 253 | 257 | assertThat(hostRanges).hasSize(replicationFactor * numTokens); |
| @@ -263,7 +267,7 @@ | ||
| 263 | 267 | assertThat(allRanges).hasSize(3 * numTokens); |
| 264 | 268 | |
| 265 | 269 | // And the ranges should cover the whole ring and no ranges intersect. |
| 266 | - assertThat(cluster).hasValidTokenRanges(keyspace); | |
| 270 | + assertThat(cluster()).hasValidTokenRanges(keyspace); | |
| 267 | 271 | } |
| 268 | 272 | |
| 269 | 273 | /** |
| @@ -282,19 +286,19 @@ | ||
| 282 | 286 | */ |
| 283 | 287 | @Test(groups = "short") |
| 284 | 288 | public void should_expose_tokens_per_host() { |
| 285 | - for (Host host : cluster.getMetadata().allHosts()) { | |
| 289 | + for (Host host : cluster().getMetadata().allHosts()) { | |
| 286 | 290 | assertThat(host.getTokens()).hasSize(numTokens); |
| 287 | 291 | // Check against the info in the system tables, which is a bit weak since it's exactly how the metadata is |
| 288 | 292 | // constructed in the first place, but there's not much else we can do. |
| 289 | 293 | // Note that this relies on all queries going to node 1, which is why we use a WhiteList LBP in setup(). |
| 290 | - boolean isControlHost = host.getSocketAddress().equals(cluster.manager.controlConnection.connectionRef.get().address); | |
| 294 | + boolean isControlHost = host.getSocketAddress().equals(cluster().manager.controlConnection.connectionRef.get().address); | |
| 291 | 295 | Row row; |
| 292 | 296 | if (isControlHost) { |
| 293 | - row = session.execute("select tokens from system.local").one(); | |
| 297 | + row = session().execute("select tokens from system.local").one(); | |
| 294 | 298 | } else { |
| 295 | 299 | // non-control hosts are populated from system.peers and their broadcast address should be known |
| 296 | 300 | assertThat(host.getBroadcastAddress()).isNotNull(); |
| 297 | - row = session.execute("select tokens from system.peers where peer = '" + host.getBroadcastAddress().getHostAddress() + "'").one(); | |
| 301 | + row = session().execute("select tokens from system.peers where peer = '" + host.getBroadcastAddress().getHostAddress() + "'").one(); | |
| 298 | 302 | } |
| 299 | 303 | Set<String> tokenStrings = row.getSet("tokens", String.class); |
| 300 | 304 | assertThat(tokenStrings).hasSize(numTokens); |
| @@ -323,17 +327,17 @@ | ||
| 323 | 327 | */ |
| 324 | 328 | @Test(groups = "short") |
| 325 | 329 | public void should_only_unwrap_one_range_for_all_ranges() { |
| 326 | - Set<TokenRange> ranges = cluster.getMetadata().getTokenRanges(); | |
| 330 | + Set<TokenRange> ranges = cluster().getMetadata().getTokenRanges(); | |
| 327 | 331 | |
| 328 | 332 | assertOnlyOneWrapped(ranges); |
| 329 | 333 | |
| 330 | 334 | Iterable<TokenRange> splitRanges = Iterables.concat(Iterables.transform(ranges, |
| 331 | - new Function<TokenRange, Iterable<TokenRange>>() { | |
| 332 | - @Override | |
| 333 | - public Iterable<TokenRange> apply(TokenRange input) { | |
| 334 | - return input.splitEvenly(10); | |
| 335 | - } | |
| 336 | - }) | |
| 335 | + new Function<TokenRange, Iterable<TokenRange>>() { | |
| 336 | + @Override | |
| 337 | + public Iterable<TokenRange> apply(TokenRange input) { | |
| 338 | + return input.splitEvenly(10); | |
| 339 | + } | |
| 340 | + }) | |
| 337 | 341 | ); |
| 338 | 342 | |
| 339 | 343 | assertOnlyOneWrapped(splitRanges); |
| @@ -363,7 +367,7 @@ | ||
| 363 | 367 | |
| 364 | 368 | @Test(groups = "short") |
| 365 | 369 | public void should_expose_token_and_range_creation_methods() { |
| 366 | - Metadata metadata = cluster.getMetadata(); | |
| 370 | + Metadata metadata = cluster().getMetadata(); | |
| 367 | 371 | |
| 368 | 372 | // Pick a random range |
| 369 | 373 | TokenRange range = metadata.getTokenRanges().iterator().next(); |
modified driver-core/src/test/java/com/datastax/driver/core/TracingTest.java +5 −12
| @@ -18,11 +18,8 @@ | ||
| 18 | 18 | import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy; |
| 19 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 20 | 20 | import com.google.common.util.concurrent.Uninterruptibles; |
| 21 | -import org.testng.annotations.BeforeClass; | |
| 22 | 21 | import org.testng.annotations.Test; |
| 23 | 22 | |
| 24 | -import java.util.Collection; | |
| 25 | -import java.util.Collections; | |
| 26 | 23 | import java.util.List; |
| 27 | 24 | import java.util.UUID; |
| 28 | 25 | import java.util.concurrent.TimeUnit; |
| @@ -40,14 +37,10 @@ | ||
| 40 | 37 | } |
| 41 | 38 | |
| 42 | 39 | @Override |
| 43 | - public Collection<String> createTestFixtures() { | |
| 44 | - return Collections.singletonList("CREATE TABLE test (k text, v int, PRIMARY KEY (k, v))"); | |
| 45 | - } | |
| 46 | - | |
| 47 | - @BeforeClass(groups = "short") | |
| 48 | - public void initData() { | |
| 40 | + public void onTestContextInitialized() { | |
| 41 | + execute("CREATE TABLE test (k text, v int, PRIMARY KEY (k, v))"); | |
| 49 | 42 | for (int i = 0; i < 100; i++) { |
| 50 | - session.execute(String.format("INSERT INTO test (k, v) VALUES ('%s', %d)", KEY, i)); | |
| 43 | + execute(String.format("INSERT INTO test (k, v) VALUES ('%s', %d)", KEY, i)); | |
| 51 | 44 | } |
| 52 | 45 | } |
| 53 | 46 | |
| @@ -61,7 +54,7 @@ | ||
| 61 | 54 | @Test(groups = "short") |
| 62 | 55 | public void should_have_a_different_tracingId_for_each_page() { |
| 63 | 56 | SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); |
| 64 | - ResultSet result = session.execute(st.setFetchSize(40).enableTracing()); | |
| 57 | + ResultSet result = session().execute(st.setFetchSize(40).enableTracing()); | |
| 65 | 58 | result.all(); |
| 66 | 59 | // sleep 10 seconds to make sure the trace will be complete |
| 67 | 60 | Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); |
| @@ -93,7 +86,7 @@ | ||
| 93 | 86 | SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); |
| 94 | 87 | st.setConsistencyLevel(ConsistencyLevel.THREE).enableTracing(); |
| 95 | 88 | |
| 96 | - ResultSet result = session.execute(st); | |
| 89 | + ResultSet result = session().execute(st); | |
| 97 | 90 | // sleep 10 seconds to make sure the trace will be complete |
| 98 | 91 | Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); |
| 99 | 92 |
modified driver-core/src/test/java/com/datastax/driver/core/TupleTest.java +76 −76
| @@ -33,13 +33,13 @@ | ||
| 33 | 33 | ProtocolVersion protocolVersion = TestUtils.getDesiredProtocolVersion(); |
| 34 | 34 | |
| 35 | 35 | @Override |
| 36 | - public Collection<String> createTestFixtures() { | |
| 37 | - return Collections.singleton("CREATE TABLE t (k int PRIMARY KEY, v frozen<tuple<int, text, float>>)"); | |
| 36 | + public void onTestContextInitialized() { | |
| 37 | + execute("CREATE TABLE t (k int PRIMARY KEY, v frozen<tuple<int, text, float>>)"); | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | @Test(groups = "short") |
| 41 | 41 | public void simpleValueTest() throws Exception { |
| 42 | - TupleType t = cluster.getMetadata().newTupleType(DataType.cint(), DataType.text(), DataType.cfloat()); | |
| 42 | + TupleType t = cluster().getMetadata().newTupleType(DataType.cint(), DataType.text(), DataType.cfloat()); | |
| 43 | 43 | TupleValue v = t.newValue(); |
| 44 | 44 | v.setInt(0, 1); |
| 45 | 45 | v.setString(1, "a"); |
| @@ -58,17 +58,17 @@ | ||
| 58 | 58 | |
| 59 | 59 | @Test(groups = "short") |
| 60 | 60 | public void simpleWriteReadTest() throws Exception { |
| 61 | - session.execute("USE " + keyspace); | |
| 62 | - PreparedStatement ins = session.prepare("INSERT INTO t(k, v) VALUES (?, ?)"); | |
| 63 | - PreparedStatement sel = session.prepare("SELECT * FROM t WHERE k=?"); | |
| 61 | + session().execute("USE " + keyspace); | |
| 62 | + PreparedStatement ins = session().prepare("INSERT INTO t(k, v) VALUES (?, ?)"); | |
| 63 | + PreparedStatement sel = session().prepare("SELECT * FROM t WHERE k=?"); | |
| 64 | 64 | |
| 65 | - TupleType t = cluster.getMetadata().newTupleType(DataType.cint(), DataType.text(), DataType.cfloat()); | |
| 65 | + TupleType t = cluster().getMetadata().newTupleType(DataType.cint(), DataType.text(), DataType.cfloat()); | |
| 66 | 66 | |
| 67 | 67 | int k = 1; |
| 68 | 68 | TupleValue v = t.newValue(1, "a", 1.0f); |
| 69 | 69 | |
| 70 | - session.execute(ins.bind(k, v)); | |
| 71 | - TupleValue v2 = session.execute(sel.bind(k)).one().getTupleValue("v"); | |
| 70 | + session().execute(ins.bind(k, v)); | |
| 71 | + TupleValue v2 = session().execute(sel.bind(k)).one().getTupleValue("v"); | |
| 72 | 72 | |
| 73 | 73 | assertEquals(v2, v); |
| 74 | 74 | |
| @@ -76,8 +76,8 @@ | ||
| 76 | 76 | k = 2; |
| 77 | 77 | v = t.newValue(2, "b", 2.0f); |
| 78 | 78 | |
| 79 | - session.execute("INSERT INTO t(k, v) VALUES (?, ?)", k, v); | |
| 80 | - v2 = session.execute(sel.bind(k)).one().getTupleValue("v"); | |
| 79 | + session().execute("INSERT INTO t(k, v) VALUES (?, ?)", k, v); | |
| 80 | + v2 = session().execute(sel.bind(k)).one().getTupleValue("v"); | |
| 81 | 81 | |
| 82 | 82 | assertEquals(v2, v); |
| 83 | 83 | } |
| @@ -90,17 +90,17 @@ | ||
| 90 | 90 | */ |
| 91 | 91 | @Test(groups = "short") |
| 92 | 92 | public void tupleTypeTest() throws Exception { |
| 93 | - session.execute("CREATE KEYSPACE test_tuple_type " + | |
| 93 | + session().execute("CREATE KEYSPACE test_tuple_type " + | |
| 94 | 94 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 95 | - session.execute("USE test_tuple_type"); | |
| 96 | - session.execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<tuple<ascii, int, boolean>>)"); | |
| 95 | + session().execute("USE test_tuple_type"); | |
| 96 | + session().execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<tuple<ascii, int, boolean>>)"); | |
| 97 | 97 | |
| 98 | - TupleType t = cluster.getMetadata().newTupleType(DataType.ascii(), DataType.cint(), DataType.cboolean()); | |
| 98 | + TupleType t = cluster().getMetadata().newTupleType(DataType.ascii(), DataType.cint(), DataType.cboolean()); | |
| 99 | 99 | |
| 100 | 100 | // test non-prepared statement |
| 101 | 101 | TupleValue complete = t.newValue("foo", 123, true); |
| 102 | - session.execute("INSERT INTO mytable (a, b) VALUES (0, ?)", complete); | |
| 103 | - TupleValue r = session.execute("SELECT b FROM mytable WHERE a=0").one().getTupleValue("b"); | |
| 102 | + session().execute("INSERT INTO mytable (a, b) VALUES (0, ?)", complete); | |
| 103 | + TupleValue r = session().execute("SELECT b FROM mytable WHERE a=0").one().getTupleValue("b"); | |
| 104 | 104 | assertEquals(r, complete); |
| 105 | 105 | |
| 106 | 106 | // test incomplete tuples |
| @@ -112,11 +112,11 @@ | ||
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | // test incomplete tuples with new TupleType |
| 115 | - TupleType t1 = cluster.getMetadata().newTupleType(DataType.ascii(), DataType.cint()); | |
| 115 | + TupleType t1 = cluster().getMetadata().newTupleType(DataType.ascii(), DataType.cint()); | |
| 116 | 116 | TupleValue partial = t1.newValue("bar", 456); |
| 117 | 117 | TupleValue partionResult = t.newValue("bar", 456, null); |
| 118 | - session.execute("INSERT INTO mytable (a, b) VALUES (0, ?)", partial); | |
| 119 | - r = session.execute("SELECT b FROM mytable WHERE a=0").one().getTupleValue("b"); | |
| 118 | + session().execute("INSERT INTO mytable (a, b) VALUES (0, ?)", partial); | |
| 119 | + r = session().execute("SELECT b FROM mytable WHERE a=0").one().getTupleValue("b"); | |
| 120 | 120 | assertEquals(r, partionResult); |
| 121 | 121 | |
| 122 | 122 | // test single value tuples |
| @@ -128,23 +128,23 @@ | ||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // test single value tuples with new TupleType |
| 131 | - TupleType t2 = cluster.getMetadata().newTupleType(DataType.ascii()); | |
| 131 | + TupleType t2 = cluster().getMetadata().newTupleType(DataType.ascii()); | |
| 132 | 132 | TupleValue subpartial = t2.newValue("zoo"); |
| 133 | 133 | TupleValue subpartialResult = t.newValue("zoo", null, null); |
| 134 | - session.execute("INSERT INTO mytable (a, b) VALUES (0, ?)", subpartial); | |
| 135 | - r = session.execute("SELECT b FROM mytable WHERE a=0").one().getTupleValue("b"); | |
| 134 | + session().execute("INSERT INTO mytable (a, b) VALUES (0, ?)", subpartial); | |
| 135 | + r = session().execute("SELECT b FROM mytable WHERE a=0").one().getTupleValue("b"); | |
| 136 | 136 | assertEquals(r, subpartialResult); |
| 137 | 137 | |
| 138 | 138 | // test prepared statements |
| 139 | - PreparedStatement prepared = session.prepare("INSERT INTO mytable (a, b) VALUES (?, ?)"); | |
| 140 | - session.execute(prepared.bind(3, complete)); | |
| 141 | - session.execute(prepared.bind(4, partial)); | |
| 142 | - session.execute(prepared.bind(5, subpartial)); | |
| 143 | - | |
| 144 | - prepared = session.prepare("SELECT b FROM mytable WHERE a=?"); | |
| 145 | - assertEquals(session.execute(prepared.bind(3)).one().getTupleValue("b"), complete); | |
| 146 | - assertEquals(session.execute(prepared.bind(4)).one().getTupleValue("b"), partionResult); | |
| 147 | - assertEquals(session.execute(prepared.bind(5)).one().getTupleValue("b"), subpartialResult); | |
| 139 | + PreparedStatement prepared = session().prepare("INSERT INTO mytable (a, b) VALUES (?, ?)"); | |
| 140 | + session().execute(prepared.bind(3, complete)); | |
| 141 | + session().execute(prepared.bind(4, partial)); | |
| 142 | + session().execute(prepared.bind(5, subpartial)); | |
| 143 | + | |
| 144 | + prepared = session().prepare("SELECT b FROM mytable WHERE a=?"); | |
| 145 | + assertEquals(session().execute(prepared.bind(3)).one().getTupleValue("b"), complete); | |
| 146 | + assertEquals(session().execute(prepared.bind(4)).one().getTupleValue("b"), partionResult); | |
| 147 | + assertEquals(session().execute(prepared.bind(5)).one().getTupleValue("b"), subpartialResult); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
| @@ -156,9 +156,9 @@ | ||
| 156 | 156 | */ |
| 157 | 157 | @Test(groups = "short") |
| 158 | 158 | public void tupleTestTypeVaryingLengths() throws Exception { |
| 159 | - session.execute("CREATE KEYSPACE test_tuple_type_varying_lengths " + | |
| 159 | + session().execute("CREATE KEYSPACE test_tuple_type_varying_lengths " + | |
| 160 | 160 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 161 | - session.execute("USE test_tuple_type_varying_lengths"); | |
| 161 | + session().execute("USE test_tuple_type_varying_lengths"); | |
| 162 | 162 | |
| 163 | 163 | // programmatically create the table with tuples of said sizes |
| 164 | 164 | int[] lengths = {1, 2, 3, 384}; |
| @@ -170,7 +170,7 @@ | ||
| 170 | 170 | } |
| 171 | 171 | valueSchema.add(String.format(" v_%d frozen<tuple<%s>>", i, Joiner.on(',').join(ints))); |
| 172 | 172 | } |
| 173 | - session.execute(String.format("CREATE TABLE mytable (k int PRIMARY KEY, %s)", Joiner.on(',').join(valueSchema))); | |
| 173 | + session().execute(String.format("CREATE TABLE mytable (k int PRIMARY KEY, %s)", Joiner.on(',').join(valueSchema))); | |
| 174 | 174 | |
| 175 | 175 | // insert tuples into same key using different columns |
| 176 | 176 | // and verify the results |
| @@ -182,14 +182,14 @@ | ||
| 182 | 182 | dataTypes.add(DataType.cint()); |
| 183 | 183 | values.add(j); |
| 184 | 184 | } |
| 185 | - TupleType t = new TupleType(dataTypes, protocolVersion, cluster.getConfiguration().getCodecRegistry()); | |
| 185 | + TupleType t = new TupleType(dataTypes, protocolVersion, cluster().getConfiguration().getCodecRegistry()); | |
| 186 | 186 | TupleValue createdTuple = t.newValue(values.toArray()); |
| 187 | 187 | |
| 188 | 188 | // write tuple |
| 189 | - session.execute(String.format("INSERT INTO mytable (k, v_%s) VALUES (0, ?)", i), createdTuple); | |
| 189 | + session().execute(String.format("INSERT INTO mytable (k, v_%s) VALUES (0, ?)", i), createdTuple); | |
| 190 | 190 | |
| 191 | 191 | // read tuple |
| 192 | - TupleValue r = session.execute(String.format("SELECT v_%s FROM mytable WHERE k=0", i)).one().getTupleValue(String.format("v_%s", i)); | |
| 192 | + TupleValue r = session().execute(String.format("SELECT v_%s FROM mytable WHERE k=0", i)).one().getTupleValue(String.format("v_%s", i)); | |
| 193 | 193 | assertEquals(r, createdTuple); |
| 194 | 194 | } |
| 195 | 195 | } |
| @@ -204,12 +204,12 @@ | ||
| 204 | 204 | public void tupleSubtypesTest() throws Exception { |
| 205 | 205 | |
| 206 | 206 | List<DataType> DATA_TYPE_PRIMITIVES = Lists.newArrayList(PrimitiveTypeSamples.ALL.keySet()); |
| 207 | - session.execute("CREATE KEYSPACE test_tuple_subtypes " + | |
| 207 | + session().execute("CREATE KEYSPACE test_tuple_subtypes " + | |
| 208 | 208 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 209 | - session.execute("USE test_tuple_subtypes"); | |
| 209 | + session().execute("USE test_tuple_subtypes"); | |
| 210 | 210 | |
| 211 | 211 | // programmatically create the table with a tuple of all datatypes |
| 212 | - session.execute(String.format("CREATE TABLE mytable (k int PRIMARY KEY, v frozen<tuple<%s>>)", Joiner.on(',').join(DATA_TYPE_PRIMITIVES))); | |
| 212 | + session().execute(String.format("CREATE TABLE mytable (k int PRIMARY KEY, v frozen<tuple<%s>>)", Joiner.on(',').join(DATA_TYPE_PRIMITIVES))); | |
| 213 | 213 | |
| 214 | 214 | // insert tuples into same key using different columns |
| 215 | 215 | // and verify the results |
| @@ -237,16 +237,16 @@ | ||
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // actually create the tuples |
| 240 | - TupleType t = new TupleType(dataTypes, protocolVersion, cluster.getConfiguration().getCodecRegistry()); | |
| 241 | - TupleType t2 = new TupleType(completeDataTypes, protocolVersion, cluster.getConfiguration().getCodecRegistry()); | |
| 240 | + TupleType t = new TupleType(dataTypes, protocolVersion, cluster().getConfiguration().getCodecRegistry()); | |
| 241 | + TupleType t2 = new TupleType(completeDataTypes, protocolVersion, cluster().getConfiguration().getCodecRegistry()); | |
| 242 | 242 | TupleValue createdTuple = t.newValue(createdValues.toArray()); |
| 243 | 243 | TupleValue completeTuple = t2.newValue(completeValues.toArray()); |
| 244 | 244 | |
| 245 | 245 | // write tuple |
| 246 | - session.execute(String.format("INSERT INTO mytable (k, v) VALUES (%s, ?)", i), createdTuple); | |
| 246 | + session().execute(String.format("INSERT INTO mytable (k, v) VALUES (%s, ?)", i), createdTuple); | |
| 247 | 247 | |
| 248 | 248 | // read tuple |
| 249 | - TupleValue r = session.execute("SELECT v FROM mytable WHERE k=?", i).one().getTupleValue("v"); | |
| 249 | + TupleValue r = session().execute("SELECT v FROM mytable WHERE k=?", i).one().getTupleValue("v"); | |
| 250 | 250 | |
| 251 | 251 | assertEquals(r, completeTuple); |
| 252 | 252 | ++i; |
| @@ -263,9 +263,9 @@ | ||
| 263 | 263 | public void tupleNonPrimitiveSubTypesTest() throws Exception { |
| 264 | 264 | |
| 265 | 265 | List<DataType> DATA_TYPE_PRIMITIVES = Lists.newArrayList(PrimitiveTypeSamples.ALL.keySet()); |
| 266 | - session.execute("CREATE KEYSPACE test_tuple_non_primitive_subtypes " + | |
| 266 | + session().execute("CREATE KEYSPACE test_tuple_non_primitive_subtypes " + | |
| 267 | 267 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 268 | - session.execute("USE test_tuple_non_primitive_subtypes"); | |
| 268 | + session().execute("USE test_tuple_non_primitive_subtypes"); | |
| 269 | 269 | |
| 270 | 270 | ArrayList<String> values = new ArrayList<String>(); |
| 271 | 271 | |
| @@ -285,7 +285,7 @@ | ||
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | // create table |
| 288 | - session.execute(String.format("CREATE TABLE mytable (k int PRIMARY KEY, %s)", Joiner.on(',').join(values))); | |
| 288 | + session().execute(String.format("CREATE TABLE mytable (k int PRIMARY KEY, %s)", Joiner.on(',').join(values))); | |
| 289 | 289 | |
| 290 | 290 | |
| 291 | 291 | int i = 0; |
| @@ -298,14 +298,14 @@ | ||
| 298 | 298 | dataTypes.add(DataType.list(datatype)); |
| 299 | 299 | createdValues.add(Collections.singletonList(PrimitiveTypeSamples.ALL.get(datatype))); |
| 300 | 300 | |
| 301 | - TupleType t = new TupleType(dataTypes, protocolVersion, cluster.getConfiguration().getCodecRegistry()); | |
| 301 | + TupleType t = new TupleType(dataTypes, protocolVersion, cluster().getConfiguration().getCodecRegistry()); | |
| 302 | 302 | TupleValue createdTuple = t.newValue(createdValues.toArray()); |
| 303 | 303 | |
| 304 | 304 | // write tuple |
| 305 | - session.execute(String.format("INSERT INTO mytable (k, v_%s) VALUES (0, ?)", i), createdTuple); | |
| 305 | + session().execute(String.format("INSERT INTO mytable (k, v_%s) VALUES (0, ?)", i), createdTuple); | |
| 306 | 306 | |
| 307 | 307 | // read tuple |
| 308 | - TupleValue r = session.execute(String.format("SELECT v_%s FROM mytable WHERE k=0", i)) | |
| 308 | + TupleValue r = session().execute(String.format("SELECT v_%s FROM mytable WHERE k=0", i)) | |
| 309 | 309 | .one().getTupleValue(String.format("v_%s", i)); |
| 310 | 310 | |
| 311 | 311 | assertEquals(r, createdTuple); |
| @@ -321,14 +321,14 @@ | ||
| 321 | 321 | dataTypes.add(DataType.set(datatype)); |
| 322 | 322 | createdValues.add(new HashSet<Object>(Collections.singletonList(PrimitiveTypeSamples.ALL.get(datatype)))); |
| 323 | 323 | |
| 324 | - TupleType t = new TupleType(dataTypes, protocolVersion, cluster.getConfiguration().getCodecRegistry()); | |
| 324 | + TupleType t = new TupleType(dataTypes, protocolVersion, cluster().getConfiguration().getCodecRegistry()); | |
| 325 | 325 | TupleValue createdTuple = t.newValue(createdValues.toArray()); |
| 326 | 326 | |
| 327 | 327 | // write tuple |
| 328 | - session.execute(String.format("INSERT INTO mytable (k, v_%s) VALUES (0, ?)", i), createdTuple); | |
| 328 | + session().execute(String.format("INSERT INTO mytable (k, v_%s) VALUES (0, ?)", i), createdTuple); | |
| 329 | 329 | |
| 330 | 330 | // read tuple |
| 331 | - TupleValue r = session.execute(String.format("SELECT v_%s FROM mytable WHERE k=0", i)) | |
| 331 | + TupleValue r = session().execute(String.format("SELECT v_%s FROM mytable WHERE k=0", i)) | |
| 332 | 332 | .one().getTupleValue(String.format("v_%s", i)); |
| 333 | 333 | |
| 334 | 334 | assertEquals(r, createdTuple); |
| @@ -347,14 +347,14 @@ | ||
| 347 | 347 | dataTypes.add(DataType.map(datatype, datatype)); |
| 348 | 348 | createdValues.add(hm); |
| 349 | 349 | |
| 350 | - TupleType t = new TupleType(dataTypes, protocolVersion, cluster.getConfiguration().getCodecRegistry()); | |
| 350 | + TupleType t = new TupleType(dataTypes, protocolVersion, cluster().getConfiguration().getCodecRegistry()); | |
| 351 | 351 | TupleValue createdTuple = t.newValue(createdValues.toArray()); |
| 352 | 352 | |
| 353 | 353 | // write tuple |
| 354 | - session.execute(String.format("INSERT INTO mytable (k, v_%s) VALUES (0, ?)", i), createdTuple); | |
| 354 | + session().execute(String.format("INSERT INTO mytable (k, v_%s) VALUES (0, ?)", i), createdTuple); | |
| 355 | 355 | |
| 356 | 356 | // read tuple |
| 357 | - TupleValue r = session.execute(String.format("SELECT v_%s FROM mytable WHERE k=0", i)) | |
| 357 | + TupleValue r = session().execute(String.format("SELECT v_%s FROM mytable WHERE k=0", i)) | |
| 358 | 358 | .one().getTupleValue(String.format("v_%s", i)); |
| 359 | 359 | |
| 360 | 360 | assertEquals(r, createdTuple); |
| @@ -374,7 +374,7 @@ | ||
| 374 | 374 | DataType.cint(), DataType.text(), DataType.cfloat()); |
| 375 | 375 | TupleValue detachedValue = detachedType.newValue(1, "hello", 2.0f); |
| 376 | 376 | |
| 377 | - TupleType attachedType = cluster.getMetadata().newTupleType(DataType.cint(), DataType.text(), DataType.cfloat()); | |
| 377 | + TupleType attachedType = cluster().getMetadata().newTupleType(DataType.cint(), DataType.text(), DataType.cfloat()); | |
| 378 | 378 | TupleValue attachedValue = attachedType.newValue(1, "hello", 2.0f); |
| 379 | 379 | |
| 380 | 380 | assertThat(detachedValue).isEqualTo(attachedValue); |
| @@ -395,11 +395,11 @@ | ||
| 395 | 395 | */ |
| 396 | 396 | private TupleValue nestedTuplesCreatorHelper(int depth) { |
| 397 | 397 | if (depth == 1) { |
| 398 | - TupleType baseTuple = cluster.getMetadata().newTupleType(DataType.cint()); | |
| 398 | + TupleType baseTuple = cluster().getMetadata().newTupleType(DataType.cint()); | |
| 399 | 399 | return baseTuple.newValue(303); |
| 400 | 400 | } else { |
| 401 | 401 | TupleValue innerTuple = nestedTuplesCreatorHelper(depth - 1); |
| 402 | - TupleType t = cluster.getMetadata().newTupleType(innerTuple.getType()); | |
| 402 | + TupleType t = cluster().getMetadata().newTupleType(innerTuple.getType()); | |
| 403 | 403 | return t.newValue(innerTuple); |
| 404 | 404 | } |
| 405 | 405 | } |
| @@ -412,12 +412,12 @@ | ||
| 412 | 412 | */ |
| 413 | 413 | @Test(groups = "short") |
| 414 | 414 | public void nestedTuplesTest() throws Exception { |
| 415 | - session.execute("CREATE KEYSPACE test_nested_tuples " + | |
| 415 | + session().execute("CREATE KEYSPACE test_nested_tuples " + | |
| 416 | 416 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 417 | - session.execute("USE test_nested_tuples"); | |
| 417 | + session().execute("USE test_nested_tuples"); | |
| 418 | 418 | |
| 419 | 419 | // create a table with multiple sizes of nested tuples |
| 420 | - session.execute(String.format("CREATE TABLE mytable (" + | |
| 420 | + session().execute(String.format("CREATE TABLE mytable (" + | |
| 421 | 421 | "k int PRIMARY KEY, " + |
| 422 | 422 | "v_1 %s, " + |
| 423 | 423 | "v_2 %s, " + |
| @@ -432,10 +432,10 @@ | ||
| 432 | 432 | TupleValue createdTuple = nestedTuplesCreatorHelper(i); |
| 433 | 433 | |
| 434 | 434 | // write tuple |
| 435 | - session.execute(String.format("INSERT INTO mytable (k, v_%s) VALUES (?, ?)", i), i, createdTuple); | |
| 435 | + session().execute(String.format("INSERT INTO mytable (k, v_%s) VALUES (?, ?)", i), i, createdTuple); | |
| 436 | 436 | |
| 437 | 437 | // verify tuple was written and read correctly |
| 438 | - TupleValue r = session.execute(String.format("SELECT v_%s FROM mytable WHERE k=?", i), i) | |
| 438 | + TupleValue r = session().execute(String.format("SELECT v_%s FROM mytable WHERE k=?", i), i) | |
| 439 | 439 | .one().getTupleValue(String.format("v_%s", i)); |
| 440 | 440 | |
| 441 | 441 | assertEquals(r, createdTuple); |
| @@ -451,27 +451,27 @@ | ||
| 451 | 451 | @Test(groups = "short") |
| 452 | 452 | public void testTuplesWithNulls() throws Exception { |
| 453 | 453 | // create keyspace |
| 454 | - session.execute("CREATE KEYSPACE testTuplesWithNulls " + | |
| 454 | + session().execute("CREATE KEYSPACE testTuplesWithNulls " + | |
| 455 | 455 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 456 | - session.execute("USE testTuplesWithNulls"); | |
| 456 | + session().execute("USE testTuplesWithNulls"); | |
| 457 | 457 | |
| 458 | 458 | // create UDT |
| 459 | - session.execute("CREATE TYPE user (a text, b frozen<tuple<text, int, uuid, blob>>)"); | |
| 460 | - session.execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<user>)"); | |
| 459 | + session().execute("CREATE TYPE user (a text, b frozen<tuple<text, int, uuid, blob>>)"); | |
| 460 | + session().execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<user>)"); | |
| 461 | 461 | |
| 462 | 462 | // insert UDT data |
| 463 | - UserType userTypeDef = cluster.getMetadata().getKeyspace("testTuplesWithNulls").getUserType("user"); | |
| 463 | + UserType userTypeDef = cluster().getMetadata().getKeyspace("testTuplesWithNulls").getUserType("user"); | |
| 464 | 464 | UDTValue userType = userTypeDef.newValue(); |
| 465 | 465 | |
| 466 | - TupleType t = cluster.getMetadata().newTupleType(DataType.text(), DataType.cint(), DataType.uuid(), DataType.blob()); | |
| 466 | + TupleType t = cluster().getMetadata().newTupleType(DataType.text(), DataType.cint(), DataType.uuid(), DataType.blob()); | |
| 467 | 467 | TupleValue v = t.newValue(null, null, null, null); |
| 468 | 468 | userType.setTupleValue("b", v); |
| 469 | 469 | |
| 470 | - PreparedStatement ins = session.prepare("INSERT INTO mytable (a, b) VALUES (?, ?)"); | |
| 471 | - session.execute(ins.bind(0, userType)); | |
| 470 | + PreparedStatement ins = session().prepare("INSERT INTO mytable (a, b) VALUES (?, ?)"); | |
| 471 | + session().execute(ins.bind(0, userType)); | |
| 472 | 472 | |
| 473 | 473 | // retrieve and verify data |
| 474 | - ResultSet rs = session.execute("SELECT * FROM mytable"); | |
| 474 | + ResultSet rs = session().execute("SELECT * FROM mytable"); | |
| 475 | 475 | List<Row> rows = rs.all(); |
| 476 | 476 | assertEquals(1, rows.size()); |
| 477 | 477 | |
| @@ -483,10 +483,10 @@ | ||
| 483 | 483 | // test empty strings |
| 484 | 484 | v = t.newValue("", null, null, ByteBuffer.allocate(0)); |
| 485 | 485 | userType.setTupleValue("b", v); |
| 486 | - session.execute(ins.bind(0, userType)); | |
| 486 | + session().execute(ins.bind(0, userType)); | |
| 487 | 487 | |
| 488 | 488 | // retrieve and verify data |
| 489 | - rs = session.execute("SELECT * FROM mytable"); | |
| 489 | + rs = session().execute("SELECT * FROM mytable"); | |
| 490 | 490 | rows = rs.all(); |
| 491 | 491 | assertEquals(1, rows.size()); |
| 492 | 492 |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecCollectionsIntegrationTest.java +17 −18
| @@ -24,7 +24,6 @@ | ||
| 24 | 24 | |
| 25 | 25 | import java.math.BigDecimal; |
| 26 | 26 | import java.math.BigInteger; |
| 27 | -import java.util.Collection; | |
| 28 | 27 | import java.util.List; |
| 29 | 28 | import java.util.Map; |
| 30 | 29 | import java.util.Set; |
| @@ -46,15 +45,15 @@ | ||
| 46 | 45 | |
| 47 | 46 | private int n_int = 42; |
| 48 | 47 | private List<Integer> l_int = newArrayList(42, 43); |
| 49 | - private List<Long> l_bigint = newArrayList(42l, 43l); | |
| 48 | + private List<Long> l_bigint = newArrayList(42L, 43L); | |
| 50 | 49 | private Set<Float> s_float = newHashSet(42.42f, 43.43f); |
| 51 | 50 | private Set<Double> s_double = newHashSet(42.42d, 43.43d); |
| 52 | 51 | private Map<Integer, BigInteger> m_varint = ImmutableMap.of(42, new BigInteger("424242"), 43, new BigInteger("434343")); |
| 53 | 52 | private Map<Integer, BigDecimal> m_decimal = ImmutableMap.of(42, new BigDecimal("424242.42"), 43, new BigDecimal("434343.43")); |
| 54 | 53 | |
| 55 | 54 | @Override |
| 56 | - public Collection<String> createTestFixtures() { | |
| 57 | - return newArrayList( | |
| 55 | + public void onTestContextInitialized() { | |
| 56 | + execute( | |
| 58 | 57 | "CREATE TABLE IF NOT EXISTS \"myTable2\" (" |
| 59 | 58 | + "c_int int PRIMARY KEY, " |
| 60 | 59 | + "l_int list<int>, " |
| @@ -83,24 +82,24 @@ | ||
| 83 | 82 | |
| 84 | 83 | @Test(groups = "short") |
| 85 | 84 | public void should_use_collection_codecs_with_simple_statements() { |
| 86 | - session.execute(insertQuery, n_int, l_int, l_bigint, s_float, s_double, m_varint, m_decimal); | |
| 87 | - ResultSet rows = session.execute(selectQuery, n_int); | |
| 85 | + session().execute(insertQuery, n_int, l_int, l_bigint, s_float, s_double, m_varint, m_decimal); | |
| 86 | + ResultSet rows = session().execute(selectQuery, n_int); | |
| 88 | 87 | Row row = rows.one(); |
| 89 | 88 | assertRow(row); |
| 90 | 89 | } |
| 91 | 90 | |
| 92 | 91 | @Test(groups = "short") |
| 93 | 92 | public void should_use_collection_codecs_with_prepared_statements_1() { |
| 94 | - session.execute(session.prepare(insertQuery).bind(n_int, l_int, l_bigint, s_float, s_double, m_varint, m_decimal)); | |
| 95 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 96 | - ResultSet rows = session.execute(ps.bind(n_int)); | |
| 93 | + session().execute(session().prepare(insertQuery).bind(n_int, l_int, l_bigint, s_float, s_double, m_varint, m_decimal)); | |
| 94 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 95 | + ResultSet rows = session().execute(ps.bind(n_int)); | |
| 97 | 96 | Row row = rows.one(); |
| 98 | 97 | assertRow(row); |
| 99 | 98 | } |
| 100 | 99 | |
| 101 | 100 | @Test(groups = "short") |
| 102 | 101 | public void should_use_collection_codecs_with_prepared_statements_2() { |
| 103 | - session.execute(session.prepare(insertQuery).bind() | |
| 102 | + session().execute(session().prepare(insertQuery).bind() | |
| 104 | 103 | .setInt(0, n_int) |
| 105 | 104 | .setList(1, l_int) |
| 106 | 105 | .setList(2, l_bigint, Long.class) // variant with element type explicitly set |
| @@ -109,8 +108,8 @@ | ||
| 109 | 108 | .setMap(5, m_varint) |
| 110 | 109 | .setMap(6, m_decimal, Integer.class, BigDecimal.class) // variant with element type explicitly set |
| 111 | 110 | ); |
| 112 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 113 | - ResultSet rows = session.execute(ps.bind() | |
| 111 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 112 | + ResultSet rows = session().execute(ps.bind() | |
| 114 | 113 | .setInt(0, n_int) |
| 115 | 114 | ); |
| 116 | 115 | Row row = rows.one(); |
| @@ -119,7 +118,7 @@ | ||
| 119 | 118 | |
| 120 | 119 | @Test(groups = "short") |
| 121 | 120 | public void should_use_collection_codecs_with_prepared_statements_3() { |
| 122 | - session.execute(session.prepare(insertQuery).bind() | |
| 121 | + session().execute(session().prepare(insertQuery).bind() | |
| 123 | 122 | .setInt(0, n_int) |
| 124 | 123 | .set(1, l_int, TypeTokens.listOf(Integer.class)) |
| 125 | 124 | .set(2, l_bigint, TypeTokens.listOf(Long.class)) |
| @@ -128,8 +127,8 @@ | ||
| 128 | 127 | .set(5, m_varint, TypeTokens.mapOf(Integer.class, BigInteger.class)) |
| 129 | 128 | .set(6, m_decimal, TypeTokens.mapOf(Integer.class, BigDecimal.class)) |
| 130 | 129 | ); |
| 131 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 132 | - ResultSet rows = session.execute(ps.bind() | |
| 130 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 131 | + ResultSet rows = session().execute(ps.bind() | |
| 133 | 132 | .setInt(0, n_int) |
| 134 | 133 | ); |
| 135 | 134 | Row row = rows.one(); |
| @@ -138,7 +137,7 @@ | ||
| 138 | 137 | |
| 139 | 138 | @Test(groups = "short") |
| 140 | 139 | public void should_use_collection_codecs_with_built_statements() { |
| 141 | - session.execute(session.prepare(insertStmt).bind() | |
| 140 | + session().execute(session().prepare(insertStmt).bind() | |
| 142 | 141 | .setInt(0, n_int) |
| 143 | 142 | .set(1, l_int, TypeTokens.listOf(Integer.class)) |
| 144 | 143 | .set(2, l_bigint, TypeTokens.listOf(Long.class)) |
| @@ -147,8 +146,8 @@ | ||
| 147 | 146 | .set(5, m_varint, TypeTokens.mapOf(Integer.class, BigInteger.class)) |
| 148 | 147 | .set(6, m_decimal, TypeTokens.mapOf(Integer.class, BigDecimal.class)) |
| 149 | 148 | ); |
| 150 | - PreparedStatement ps = session.prepare(selectStmt); | |
| 151 | - ResultSet rows = session.execute(ps.bind() | |
| 149 | + PreparedStatement ps = session().prepare(selectStmt); | |
| 150 | + ResultSet rows = session().execute(ps.bind() | |
| 152 | 151 | .setInt(0, n_int) |
| 153 | 152 | ); |
| 154 | 153 | Row row = rows.one(); |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecEncapsulationIntegrationTest.java +16 −18
| @@ -27,10 +27,8 @@ | ||
| 27 | 27 | import java.math.BigDecimal; |
| 28 | 28 | import java.math.BigInteger; |
| 29 | 29 | import java.nio.ByteBuffer; |
| 30 | -import java.util.Collection; | |
| 31 | 30 | |
| 32 | 31 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 33 | -import static com.google.common.collect.Lists.newArrayList; | |
| 34 | 32 | import static org.assertj.core.api.Assertions.assertThat; |
| 35 | 33 | |
| 36 | 34 | public class TypeCodecEncapsulationIntegrationTest extends CCMTestsSupport { |
| @@ -59,8 +57,8 @@ | ||
| 59 | 57 | private BigDecimal n_decimal = new BigDecimal("424242.42"); |
| 60 | 58 | |
| 61 | 59 | @Override |
| 62 | - public Collection<String> createTestFixtures() { | |
| 63 | - return newArrayList( | |
| 60 | + public void onTestContextInitialized() { | |
| 61 | + execute( | |
| 64 | 62 | "CREATE TABLE \"myTable\" (" |
| 65 | 63 | + "c_int int, " |
| 66 | 64 | + "c_bigint bigint, " |
| @@ -106,36 +104,36 @@ | ||
| 106 | 104 | @Test(groups = "short") |
| 107 | 105 | @CassandraVersion(major = 2.0) |
| 108 | 106 | public void should_use_custom_codecs_with_simple_statements() { |
| 109 | - session.execute(insertQuery, | |
| 107 | + session().execute(insertQuery, | |
| 110 | 108 | n_int, |
| 111 | 109 | new NumberBox<Long>(n_bigint), |
| 112 | 110 | new NumberBox<Float>(n_float), |
| 113 | 111 | new NumberBox<Double>(n_double), |
| 114 | 112 | new NumberBox<BigInteger>(n_varint), |
| 115 | 113 | new NumberBox<BigDecimal>(n_decimal)); |
| 116 | - ResultSet rows = session.execute(selectQuery, n_int, new NumberBox<Long>(n_bigint)); | |
| 114 | + ResultSet rows = session().execute(selectQuery, n_int, new NumberBox<Long>(n_bigint)); | |
| 117 | 115 | Row row = rows.one(); |
| 118 | 116 | assertRow(row); |
| 119 | 117 | } |
| 120 | 118 | |
| 121 | 119 | @Test(groups = "short") |
| 122 | 120 | public void should_use_custom_codecs_with_prepared_statements_1() { |
| 123 | - session.execute(session.prepare(insertQuery).bind( | |
| 121 | + session().execute(session().prepare(insertQuery).bind( | |
| 124 | 122 | n_int, |
| 125 | 123 | new NumberBox<Long>(n_bigint), |
| 126 | 124 | new NumberBox<Float>(n_float), |
| 127 | 125 | new NumberBox<Double>(n_double), |
| 128 | 126 | new NumberBox<BigInteger>(n_varint), |
| 129 | 127 | new NumberBox<BigDecimal>(n_decimal))); |
| 130 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 131 | - ResultSet rows = session.execute(ps.bind(n_int, new NumberBox<Long>(n_bigint))); | |
| 128 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 129 | + ResultSet rows = session().execute(ps.bind(n_int, new NumberBox<Long>(n_bigint))); | |
| 132 | 130 | Row row = rows.one(); |
| 133 | 131 | assertRow(row); |
| 134 | 132 | } |
| 135 | 133 | |
| 136 | 134 | @Test(groups = "short") |
| 137 | 135 | public void should_use_custom_codecs_with_prepared_statements_2() { |
| 138 | - session.execute(session.prepare(insertQuery).bind() | |
| 136 | + session().execute(session().prepare(insertQuery).bind() | |
| 139 | 137 | .set(0, new NumberBox<Integer>(n_int), NUMBERBOX_OF_INTEGER_TOKEN) |
| 140 | 138 | .set(1, new NumberBox<Long>(n_bigint), NUMBERBOX_OF_LONG_TOKEN) |
| 141 | 139 | .set(2, new NumberBox<Float>(n_float), NUMBERBOX_OF_FLOAT_TOKEN) |
| @@ -143,8 +141,8 @@ | ||
| 143 | 141 | .set(4, new NumberBox<BigInteger>(n_varint), NUMBERBOX_OF_BIGINTEGER_TOKEN) |
| 144 | 142 | .set(5, new NumberBox<BigDecimal>(n_decimal), NUMBERBOX_OF_BIGDECIMAL_TOKEN) |
| 145 | 143 | ); |
| 146 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 147 | - ResultSet rows = session.execute(ps.bind() | |
| 144 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 145 | + ResultSet rows = session().execute(ps.bind() | |
| 148 | 146 | .set(0, new NumberBox<Integer>(n_int), NUMBERBOX_OF_INTEGER_TOKEN) |
| 149 | 147 | .set(1, new NumberBox<Long>(n_bigint), NUMBERBOX_OF_LONG_TOKEN) |
| 150 | 148 | ); |
| @@ -154,30 +152,30 @@ | ||
| 154 | 152 | |
| 155 | 153 | @Test(groups = "short") |
| 156 | 154 | public void should_use_custom_codecs_with_built_statements_1() { |
| 157 | - session.execute(session.prepare(insertStmt).bind( | |
| 155 | + session().execute(session().prepare(insertStmt).bind( | |
| 158 | 156 | n_int, |
| 159 | 157 | new NumberBox<Long>(n_bigint), |
| 160 | 158 | new NumberBox<Float>(n_float), |
| 161 | 159 | new NumberBox<Double>(n_double), |
| 162 | 160 | new NumberBox<BigInteger>(n_varint), |
| 163 | 161 | new NumberBox<BigDecimal>(n_decimal))); |
| 164 | - PreparedStatement ps = session.prepare(selectStmt); | |
| 165 | - ResultSet rows = session.execute(ps.bind(n_int, new NumberBox<Long>(n_bigint))); | |
| 162 | + PreparedStatement ps = session().prepare(selectStmt); | |
| 163 | + ResultSet rows = session().execute(ps.bind(n_int, new NumberBox<Long>(n_bigint))); | |
| 166 | 164 | Row row = rows.one(); |
| 167 | 165 | assertRow(row); |
| 168 | 166 | } |
| 169 | 167 | |
| 170 | 168 | @Test(groups = "short") |
| 171 | 169 | public void should_use_custom_codecs_with_built_statements_2() { |
| 172 | - session.execute(session.prepare(insertStmt).bind() | |
| 170 | + session().execute(session().prepare(insertStmt).bind() | |
| 173 | 171 | .set(0, new NumberBox<Integer>(n_int), NUMBERBOX_OF_INTEGER_TOKEN) |
| 174 | 172 | .set(1, new NumberBox<Long>(n_bigint), NUMBERBOX_OF_LONG_TOKEN) |
| 175 | 173 | .set(2, new NumberBox<Float>(n_float), NUMBERBOX_OF_FLOAT_TOKEN) |
| 176 | 174 | .set(3, new NumberBox<Double>(n_double), NUMBERBOX_OF_DOUBLE_TOKEN) |
| 177 | 175 | .set(4, new NumberBox<BigInteger>(n_varint), NUMBERBOX_OF_BIGINTEGER_TOKEN) |
| 178 | 176 | .set(5, new NumberBox<BigDecimal>(n_decimal), NUMBERBOX_OF_BIGDECIMAL_TOKEN)); |
| 179 | - PreparedStatement ps = session.prepare(selectStmt); | |
| 180 | - ResultSet rows = session.execute(ps.bind() | |
| 177 | + PreparedStatement ps = session().prepare(selectStmt); | |
| 178 | + ResultSet rows = session().execute(ps.bind() | |
| 181 | 179 | .set(0, new NumberBox<Integer>(n_int), NUMBERBOX_OF_INTEGER_TOKEN) |
| 182 | 180 | .set(1, new NumberBox<Long>(n_bigint), NUMBERBOX_OF_LONG_TOKEN)); |
| 183 | 181 |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecNestedCollectionsIntegrationTest.java +17 −17
| @@ -29,7 +29,6 @@ | ||
| 29 | 29 | import java.util.*; |
| 30 | 30 | |
| 31 | 31 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 32 | -import static com.google.common.collect.Lists.newArrayList; | |
| 33 | 32 | import static org.assertj.core.api.Assertions.assertThat; |
| 34 | 33 | |
| 35 | 34 | /** |
| @@ -54,9 +53,10 @@ | ||
| 54 | 53 | private TypeToken<Set<Map<MyInt, String>>> elementsType = new TypeToken<Set<Map<MyInt, String>>>() {}; |
| 55 | 54 | // @formatter:on |
| 56 | 55 | |
| 56 | + | |
| 57 | 57 | @Override |
| 58 | - public Collection<String> createTestFixtures() { | |
| 59 | - return newArrayList( | |
| 58 | + public void onTestContextInitialized() { | |
| 59 | + execute( | |
| 60 | 60 | "CREATE TABLE IF NOT EXISTS \"myTable\" (" |
| 61 | 61 | + "pk int PRIMARY KEY, " |
| 62 | 62 | + "v frozen<list<frozen<set<frozen<map<int,text>>>>>>" |
| @@ -91,29 +91,29 @@ | ||
| 91 | 91 | |
| 92 | 92 | @Test(groups = "short") |
| 93 | 93 | public void should_work_with_simple_statements() { |
| 94 | - session.execute(insertQuery, pk, v); | |
| 95 | - ResultSet rows = session.execute(selectQuery, pk); | |
| 94 | + session().execute(insertQuery, pk, v); | |
| 95 | + ResultSet rows = session().execute(selectQuery, pk); | |
| 96 | 96 | Row row = rows.one(); |
| 97 | 97 | assertRow(row); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | @Test(groups = "short") |
| 101 | 101 | public void should_work_with_prepared_statements_1() { |
| 102 | - session.execute(session.prepare(insertQuery).bind(pk, v)); | |
| 103 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 104 | - ResultSet rows = session.execute(ps.bind(pk)); | |
| 102 | + session().execute(session().prepare(insertQuery).bind(pk, v)); | |
| 103 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 104 | + ResultSet rows = session().execute(ps.bind(pk)); | |
| 105 | 105 | Row row = rows.one(); |
| 106 | 106 | assertRow(row); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | @Test(groups = "short") |
| 110 | 110 | public void should_work_with_prepared_statements_2() { |
| 111 | - session.execute(session.prepare(insertQuery).bind() | |
| 111 | + session().execute(session().prepare(insertQuery).bind() | |
| 112 | 112 | .setInt(0, pk) |
| 113 | 113 | .setList(1, v, elementsType) // variant with element type explicitly set |
| 114 | 114 | ); |
| 115 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 116 | - ResultSet rows = session.execute(ps.bind() | |
| 115 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 116 | + ResultSet rows = session().execute(ps.bind() | |
| 117 | 117 | .setInt(0, pk) |
| 118 | 118 | ); |
| 119 | 119 | Row row = rows.one(); |
| @@ -122,12 +122,12 @@ | ||
| 122 | 122 | |
| 123 | 123 | @Test(groups = "short") |
| 124 | 124 | public void should_work_with_prepared_statements_3() { |
| 125 | - session.execute(session.prepare(insertQuery).bind() | |
| 125 | + session().execute(session().prepare(insertQuery).bind() | |
| 126 | 126 | .setInt(0, pk) |
| 127 | 127 | .set(1, v, listType) |
| 128 | 128 | ); |
| 129 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 130 | - ResultSet rows = session.execute(ps.bind() | |
| 129 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 130 | + ResultSet rows = session().execute(ps.bind() | |
| 131 | 131 | .setInt(0, pk) |
| 132 | 132 | ); |
| 133 | 133 | Row row = rows.one(); |
| @@ -136,12 +136,12 @@ | ||
| 136 | 136 | |
| 137 | 137 | @Test(groups = "short") |
| 138 | 138 | public void should_work_with_built_statements() { |
| 139 | - session.execute(session.prepare(insertStmt).bind() | |
| 139 | + session().execute(session().prepare(insertStmt).bind() | |
| 140 | 140 | .setInt(0, pk) |
| 141 | 141 | .set(1, v, listType) |
| 142 | 142 | ); |
| 143 | - PreparedStatement ps = session.prepare(selectStmt); | |
| 144 | - ResultSet rows = session.execute(ps.bind() | |
| 143 | + PreparedStatement ps = session().prepare(selectStmt); | |
| 144 | + ResultSet rows = session().execute(ps.bind() | |
| 145 | 145 | .setInt(0, pk) |
| 146 | 146 | ); |
| 147 | 147 | Row row = rows.one(); |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecNestedUDTAndTupleIntegrationTest.java +17 −20
| @@ -16,11 +16,8 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | -import com.google.common.collect.Lists; | |
| 20 | 19 | import org.testng.annotations.Test; |
| 21 | 20 | |
| 22 | -import java.util.Collection; | |
| 23 | - | |
| 24 | 21 | import static org.assertj.core.api.Assertions.assertThat; |
| 25 | 22 | |
| 26 | 23 | /** |
| @@ -35,8 +32,8 @@ | ||
| 35 | 32 | public class TypeCodecNestedUDTAndTupleIntegrationTest extends CCMTestsSupport { |
| 36 | 33 | |
| 37 | 34 | @Override |
| 38 | - public Collection<String> createTestFixtures() { | |
| 39 | - return Lists.newArrayList( | |
| 35 | + public void onTestContextInitialized() { | |
| 36 | + execute( | |
| 40 | 37 | "CREATE TYPE IF NOT EXISTS \"udt3\" (f3 text)", |
| 41 | 38 | "CREATE TYPE IF NOT EXISTS \"udt2\" (f2 frozen<udt3>)", |
| 42 | 39 | "CREATE TYPE IF NOT EXISTS \"udt1\" (f1 frozen<udt2>)", |
| @@ -56,51 +53,51 @@ | ||
| 56 | 53 | |
| 57 | 54 | @Test(groups = "short") |
| 58 | 55 | public void should_set_registry_on_nested_udts() { |
| 59 | - ResultSet rows = session.execute("SELECT c1 FROM t1 WHERE pk = 1"); | |
| 56 | + ResultSet rows = session().execute("SELECT c1 FROM t1 WHERE pk = 1"); | |
| 60 | 57 | Row row = rows.one(); |
| 61 | 58 | // here the CodecRegistry will create a codec on-the-fly using the UserType received from the resultset metadata |
| 62 | 59 | UDTValue udt1 = row.getUDTValue("c1"); |
| 63 | - assertThat(udt1.getCodecRegistry()).isSameAs(cluster.getConfiguration().getCodecRegistry()); | |
| 60 | + assertThat(udt1.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry()); | |
| 64 | 61 | UDTValue udt2 = udt1.getUDTValue("f1"); |
| 65 | - assertThat(udt2.getCodecRegistry()).isSameAs(cluster.getConfiguration().getCodecRegistry()); | |
| 62 | + assertThat(udt2.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry()); | |
| 66 | 63 | UDTValue udt3 = udt2.getUDTValue("f2"); |
| 67 | - assertThat(udt3.getCodecRegistry()).isSameAs(cluster.getConfiguration().getCodecRegistry()); | |
| 64 | + assertThat(udt3.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry()); | |
| 68 | 65 | String f3 = udt3.getString("f3"); |
| 69 | 66 | assertThat(f3).isEqualTo("foo"); |
| 70 | 67 | } |
| 71 | 68 | |
| 72 | 69 | @Test(groups = "short") |
| 73 | 70 | public void should_set_registry_on_nested_tuples() { |
| 74 | - ResultSet rows = session.execute("SELECT c2 FROM t1 WHERE pk = 2"); | |
| 71 | + ResultSet rows = session().execute("SELECT c2 FROM t1 WHERE pk = 2"); | |
| 75 | 72 | Row row = rows.one(); |
| 76 | 73 | // here the CodecRegistry will create a codec on-the-fly using the TupleType received from the resultset metadata |
| 77 | 74 | TupleValue tuple1 = row.getTupleValue("c2"); |
| 78 | - assertThat(tuple1.getCodecRegistry()).isSameAs(cluster.getConfiguration().getCodecRegistry()); | |
| 75 | + assertThat(tuple1.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry()); | |
| 79 | 76 | TupleValue tuple2 = tuple1.getTupleValue(0); |
| 80 | - assertThat(tuple2.getCodecRegistry()).isSameAs(cluster.getConfiguration().getCodecRegistry()); | |
| 77 | + assertThat(tuple2.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry()); | |
| 81 | 78 | TupleValue tuple3 = tuple2.getTupleValue(0); |
| 82 | - assertThat(tuple3.getCodecRegistry()).isSameAs(cluster.getConfiguration().getCodecRegistry()); | |
| 79 | + assertThat(tuple3.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry()); | |
| 83 | 80 | String s = tuple3.getString(0); |
| 84 | 81 | assertThat(s).isEqualTo("foo"); |
| 85 | 82 | } |
| 86 | 83 | |
| 87 | 84 | @Test(groups = "short") |
| 88 | 85 | public void should_set_registry_on_nested_tuples_and_udts() { |
| 89 | - ResultSet rows = session.execute("SELECT c3 FROM t1 WHERE pk = 3"); | |
| 86 | + ResultSet rows = session().execute("SELECT c3 FROM t1 WHERE pk = 3"); | |
| 90 | 87 | Row row = rows.one(); |
| 91 | 88 | // here the CodecRegistry will create a codec on-the-fly using the TupleType received from the resultset metadata |
| 92 | 89 | TupleValue tuple1 = row.getTupleValue("c3"); |
| 93 | - assertThat(tuple1.getCodecRegistry()).isSameAs(cluster.getConfiguration().getCodecRegistry()); | |
| 90 | + assertThat(tuple1.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry()); | |
| 94 | 91 | TupleValue tuple2 = tuple1.getTupleValue(0); |
| 95 | - assertThat(tuple2.getCodecRegistry()).isSameAs(cluster.getConfiguration().getCodecRegistry()); | |
| 92 | + assertThat(tuple2.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry()); | |
| 96 | 93 | TupleValue tuple3 = tuple2.getTupleValue(0); |
| 97 | - assertThat(tuple3.getCodecRegistry()).isSameAs(cluster.getConfiguration().getCodecRegistry()); | |
| 94 | + assertThat(tuple3.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry()); | |
| 98 | 95 | UDTValue udt1 = tuple3.getUDTValue(0); |
| 99 | - assertThat(udt1.getCodecRegistry()).isSameAs(cluster.getConfiguration().getCodecRegistry()); | |
| 96 | + assertThat(udt1.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry()); | |
| 100 | 97 | UDTValue udt2 = udt1.getUDTValue("f1"); |
| 101 | - assertThat(udt2.getCodecRegistry()).isSameAs(cluster.getConfiguration().getCodecRegistry()); | |
| 98 | + assertThat(udt2.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry()); | |
| 102 | 99 | UDTValue udt3 = udt2.getUDTValue("f2"); |
| 103 | - assertThat(udt3.getCodecRegistry()).isSameAs(cluster.getConfiguration().getCodecRegistry()); | |
| 100 | + assertThat(udt3.getCodecRegistry()).isSameAs(cluster().getConfiguration().getCodecRegistry()); | |
| 104 | 101 | String f3 = udt3.getString("f3"); |
| 105 | 102 | assertThat(f3).isEqualTo("foo"); |
| 106 | 103 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecNumbersIntegrationTest.java +13 −16
| @@ -20,9 +20,7 @@ | ||
| 20 | 20 | |
| 21 | 21 | import java.math.BigDecimal; |
| 22 | 22 | import java.math.BigInteger; |
| 23 | -import java.util.Collection; | |
| 24 | 23 | |
| 25 | -import static com.google.common.collect.Lists.newArrayList; | |
| 26 | 24 | import static org.assertj.core.api.Assertions.assertThat; |
| 27 | 25 | |
| 28 | 26 | public class TypeCodecNumbersIntegrationTest extends CCMTestsSupport { |
| @@ -38,10 +36,9 @@ | ||
| 38 | 36 | private BigInteger n_varint = new BigInteger("424242"); |
| 39 | 37 | private BigDecimal n_decimal = new BigDecimal("424242.42"); |
| 40 | 38 | |
| 41 | - | |
| 42 | 39 | @Override |
| 43 | - public Collection<String> createTestFixtures() { | |
| 44 | - return newArrayList( | |
| 40 | + public void onTestContextInitialized() { | |
| 41 | + execute( | |
| 45 | 42 | "CREATE TABLE \"myTable\" (" |
| 46 | 43 | + "c_int int, " |
| 47 | 44 | + "c_bigint bigint, " |
| @@ -57,24 +54,24 @@ | ||
| 57 | 54 | @Test(groups = "short") |
| 58 | 55 | @CassandraVersion(major = 2.0) |
| 59 | 56 | public void should_use_defaut_codecs_with_simple_statements() { |
| 60 | - session.execute(insertQuery, n_int, n_bigint, n_float, n_double, n_varint, n_decimal); | |
| 61 | - ResultSet rows = session.execute(selectQuery, n_int, n_bigint); | |
| 57 | + session().execute(insertQuery, n_int, n_bigint, n_float, n_double, n_varint, n_decimal); | |
| 58 | + ResultSet rows = session().execute(selectQuery, n_int, n_bigint); | |
| 62 | 59 | Row row = rows.one(); |
| 63 | 60 | assertRow(row); |
| 64 | 61 | } |
| 65 | 62 | |
| 66 | 63 | @Test(groups = "short") |
| 67 | 64 | public void should_use_defaut_codecs_with_prepared_statements_1() { |
| 68 | - session.execute(session.prepare(insertQuery).bind(n_int, n_bigint, n_float, n_double, n_varint, n_decimal)); | |
| 69 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 70 | - ResultSet rows = session.execute(ps.bind(n_int, n_bigint)); | |
| 65 | + session().execute(session().prepare(insertQuery).bind(n_int, n_bigint, n_float, n_double, n_varint, n_decimal)); | |
| 66 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 67 | + ResultSet rows = session().execute(ps.bind(n_int, n_bigint)); | |
| 71 | 68 | Row row = rows.one(); |
| 72 | 69 | assertRow(row); |
| 73 | 70 | } |
| 74 | 71 | |
| 75 | 72 | @Test(groups = "short") |
| 76 | 73 | public void should_use_default_codecs_with_prepared_statements_2() { |
| 77 | - session.execute(session.prepare(insertQuery).bind() | |
| 74 | + session().execute(session().prepare(insertQuery).bind() | |
| 78 | 75 | .setInt(0, n_int) |
| 79 | 76 | .setLong(1, n_bigint) |
| 80 | 77 | .setFloat(2, n_float) |
| @@ -82,8 +79,8 @@ | ||
| 82 | 79 | .setVarint(4, n_varint) |
| 83 | 80 | .setDecimal(5, n_decimal) |
| 84 | 81 | ); |
| 85 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 86 | - ResultSet rows = session.execute(ps.bind() | |
| 82 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 83 | + ResultSet rows = session().execute(ps.bind() | |
| 87 | 84 | .setInt(0, n_int) |
| 88 | 85 | .setLong(1, n_bigint) |
| 89 | 86 | ); |
| @@ -93,7 +90,7 @@ | ||
| 93 | 90 | |
| 94 | 91 | @Test(groups = "short") |
| 95 | 92 | public void should_use_default_codecs_with_prepared_statements_3() { |
| 96 | - session.execute(session.prepare(insertQuery).bind() | |
| 93 | + session().execute(session().prepare(insertQuery).bind() | |
| 97 | 94 | .set(0, n_int, Integer.class) |
| 98 | 95 | .set(1, n_bigint, Long.class) |
| 99 | 96 | .set(2, n_float, Float.class) |
| @@ -101,8 +98,8 @@ | ||
| 101 | 98 | .set(4, n_varint, BigInteger.class) |
| 102 | 99 | .set(5, n_decimal, BigDecimal.class) |
| 103 | 100 | ); |
| 104 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 105 | - ResultSet rows = session.execute(ps.bind() | |
| 101 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 102 | + ResultSet rows = session().execute(ps.bind() | |
| 106 | 103 | .setInt(0, n_int) |
| 107 | 104 | .setLong(1, n_bigint) |
| 108 | 105 | ); |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecOverlappingJavaTypeIntegrationTest.java +8 −9
| @@ -19,7 +19,6 @@ | ||
| 19 | 19 | import org.testng.annotations.Test; |
| 20 | 20 | |
| 21 | 21 | import java.nio.ByteBuffer; |
| 22 | -import java.util.Collection; | |
| 23 | 22 | |
| 24 | 23 | import static com.google.common.collect.Lists.newArrayList; |
| 25 | 24 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -36,8 +35,8 @@ | ||
| 36 | 35 | private static final String selectQuery = "SELECT c_int, l_int, c_text FROM \"myTable\" WHERE c_int = ?"; |
| 37 | 36 | |
| 38 | 37 | @Override |
| 39 | - public Collection<String> createTestFixtures() { | |
| 40 | - return newArrayList( | |
| 38 | + public void onTestContextInitialized() { | |
| 39 | + execute( | |
| 41 | 40 | "CREATE TABLE \"myTable\" (" |
| 42 | 41 | + "c_int int PRIMARY KEY, " |
| 43 | 42 | + "l_int list<int>, " |
| @@ -54,22 +53,22 @@ | ||
| 54 | 53 | |
| 55 | 54 | @Test(groups = "short") |
| 56 | 55 | public void should_use_custom_codecs_with_prepared_statements() { |
| 57 | - PreparedStatement ps = session.prepare(insertQuery); | |
| 58 | - session.execute( | |
| 56 | + PreparedStatement ps = session().prepare(insertQuery); | |
| 57 | + session().execute( | |
| 59 | 58 | ps.bind() |
| 60 | 59 | .setInt(0, 42) |
| 61 | 60 | .setList(1, newArrayList(42)) |
| 62 | 61 | .setString(2, "42") // here we have the CQL type so VarcharCodec will be used even if IntToStringCodec accepts it |
| 63 | 62 | ); |
| 64 | - session.execute( | |
| 63 | + session().execute( | |
| 65 | 64 | ps.bind() |
| 66 | 65 | .setString(0, "42") |
| 67 | 66 | .setList(1, newArrayList("42"), String.class) |
| 68 | 67 | .setString(2, "42") // here we have the CQL type so VarcharCodec will be used even if IntToStringCodec accepts it |
| 69 | 68 | ); |
| 70 | - ps = session.prepare(selectQuery); | |
| 71 | - assertRow(session.execute(ps.bind().setInt(0, 42)).one()); | |
| 72 | - assertRow(session.execute(ps.bind().setString(0, "42")).one()); | |
| 69 | + ps = session().prepare(selectQuery); | |
| 70 | + assertRow(session().execute(ps.bind().setInt(0, 42)).one()); | |
| 71 | + assertRow(session().execute(ps.bind().setString(0, "42")).one()); | |
| 73 | 72 | } |
| 74 | 73 | |
| 75 | 74 | private void assertRow(Row row) { |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecTupleIntegrationTest.java +22 −24
| @@ -16,10 +16,8 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | -import com.google.common.collect.Lists; | |
| 20 | 19 | import org.testng.annotations.Test; |
| 21 | 20 | |
| 22 | -import java.util.Collection; | |
| 23 | 21 | import java.util.UUID; |
| 24 | 22 | |
| 25 | 23 | import static com.datastax.driver.core.DataType.cfloat; |
| @@ -41,50 +39,50 @@ | ||
| 41 | 39 | private TupleValue partialLocationValueRetrieved; |
| 42 | 40 | |
| 43 | 41 | @Override |
| 44 | - public Collection<String> createTestFixtures() { | |
| 45 | - return Lists.newArrayList( | |
| 42 | + public void onTestContextInitialized() { | |
| 43 | + execute( | |
| 46 | 44 | "CREATE TABLE IF NOT EXISTS \"users\" (id uuid PRIMARY KEY, name text, location frozen<tuple<float,float>>)" |
| 47 | 45 | ); |
| 48 | 46 | } |
| 49 | 47 | |
| 50 | 48 | @Test(groups = "short") |
| 51 | 49 | public void should_handle_tuples_with_default_codecs() { |
| 52 | - setUpTupleTypes(cluster); | |
| 50 | + setUpTupleTypes(cluster()); | |
| 53 | 51 | // simple statement |
| 54 | - session.execute(insertQuery, uuid, "John Doe", locationValue); | |
| 55 | - ResultSet rows = session.execute(selectQuery, uuid); | |
| 52 | + session().execute(insertQuery, uuid, "John Doe", locationValue); | |
| 53 | + ResultSet rows = session().execute(selectQuery, uuid); | |
| 56 | 54 | Row row = rows.one(); |
| 57 | 55 | assertRow(row); |
| 58 | 56 | // prepared + values |
| 59 | - PreparedStatement ps = session.prepare(insertQuery); | |
| 60 | - session.execute(ps.bind(uuid, "John Doe", locationValue)); | |
| 61 | - rows = session.execute(selectQuery, uuid); | |
| 57 | + PreparedStatement ps = session().prepare(insertQuery); | |
| 58 | + session().execute(ps.bind(uuid, "John Doe", locationValue)); | |
| 59 | + rows = session().execute(selectQuery, uuid); | |
| 62 | 60 | row = rows.one(); |
| 63 | 61 | assertRow(row); |
| 64 | 62 | // bound with setTupleValue |
| 65 | - session.execute(ps.bind().setUUID(0, uuid).setString(1, "John Doe").setTupleValue("location", locationValue)); | |
| 66 | - rows = session.execute(selectQuery, uuid); | |
| 63 | + session().execute(ps.bind().setUUID(0, uuid).setString(1, "John Doe").setTupleValue("location", locationValue)); | |
| 64 | + rows = session().execute(selectQuery, uuid); | |
| 67 | 65 | row = rows.one(); |
| 68 | 66 | assertRow(row); |
| 69 | 67 | } |
| 70 | 68 | |
| 71 | 69 | @Test(groups = "short") |
| 72 | 70 | public void should_handle_partial_tuples_with_default_codecs() { |
| 73 | - setUpTupleTypes(cluster); | |
| 71 | + setUpTupleTypes(cluster()); | |
| 74 | 72 | // simple statement |
| 75 | - session.execute(insertQuery, uuid, "John Doe", partialLocationValueInserted); | |
| 76 | - ResultSet rows = session.execute(selectQuery, uuid); | |
| 73 | + session().execute(insertQuery, uuid, "John Doe", partialLocationValueInserted); | |
| 74 | + ResultSet rows = session().execute(selectQuery, uuid); | |
| 77 | 75 | Row row = rows.one(); |
| 78 | 76 | assertPartialRow(row); |
| 79 | 77 | // prepared + values |
| 80 | - PreparedStatement ps = session.prepare(insertQuery); | |
| 81 | - session.execute(ps.bind(uuid, "John Doe", partialLocationValueInserted)); | |
| 82 | - rows = session.execute(selectQuery, uuid); | |
| 78 | + PreparedStatement ps = session().prepare(insertQuery); | |
| 79 | + session().execute(ps.bind(uuid, "John Doe", partialLocationValueInserted)); | |
| 80 | + rows = session().execute(selectQuery, uuid); | |
| 83 | 81 | row = rows.one(); |
| 84 | 82 | assertPartialRow(row); |
| 85 | 83 | // bound with setTupleValue |
| 86 | - session.execute(ps.bind().setUUID(0, uuid).setString(1, "John Doe").setTupleValue("location", partialLocationValueInserted)); | |
| 87 | - rows = session.execute(selectQuery, uuid); | |
| 84 | + session().execute(ps.bind().setUUID(0, uuid).setString(1, "John Doe").setTupleValue("location", partialLocationValueInserted)); | |
| 85 | + rows = session().execute(selectQuery, uuid); | |
| 88 | 86 | row = rows.one(); |
| 89 | 87 | assertPartialRow(row); |
| 90 | 88 | } |
| @@ -93,8 +91,8 @@ | ||
| 93 | 91 | public void should_handle_tuples_with_custom_codecs() { |
| 94 | 92 | CodecRegistry codecRegistry = new CodecRegistry(); |
| 95 | 93 | Cluster cluster = register(Cluster.builder() |
| 96 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 97 | - .withPort(ccm.getBinaryPort()) | |
| 94 | + .addContactPoints(getContactPoints()) | |
| 95 | + .withPort(ccm().getBinaryPort()) | |
| 98 | 96 | .withCodecRegistry(codecRegistry) |
| 99 | 97 | .build()); |
| 100 | 98 | Session session = cluster.connect(keyspace); |
| @@ -123,8 +121,8 @@ | ||
| 123 | 121 | public void should_handle_partial_tuples_with_custom_codecs() { |
| 124 | 122 | CodecRegistry codecRegistry = new CodecRegistry(); |
| 125 | 123 | Cluster cluster = register(Cluster.builder() |
| 126 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 127 | - .withPort(ccm.getBinaryPort()) | |
| 124 | + .addContactPoints(getContactPoints()) | |
| 125 | + .withPort(ccm().getBinaryPort()) | |
| 128 | 126 | .withCodecRegistry(codecRegistry) |
| 129 | 127 | .build()); |
| 130 | 128 | Session session = cluster.connect(keyspace); |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecUDTIntegrationTest.java +12 −13
| @@ -20,7 +20,6 @@ | ||
| 20 | 20 | import com.google.common.collect.Sets; |
| 21 | 21 | import org.testng.annotations.Test; |
| 22 | 22 | |
| 23 | -import java.util.Collection; | |
| 24 | 23 | import java.util.List; |
| 25 | 24 | import java.util.Set; |
| 26 | 25 | import java.util.UUID; |
| @@ -45,8 +44,8 @@ | ||
| 45 | 44 | private UDTValue addressValue; |
| 46 | 45 | |
| 47 | 46 | @Override |
| 48 | - public Collection<String> createTestFixtures() { | |
| 49 | - return Lists.newArrayList( | |
| 47 | + public void onTestContextInitialized() { | |
| 48 | + execute( | |
| 50 | 49 | "CREATE TYPE IF NOT EXISTS \"phone\" (number text, tags set<text>)", |
| 51 | 50 | "CREATE TYPE IF NOT EXISTS \"address\" (street text, zipcode int, phones list<frozen<phone>>)", |
| 52 | 51 | "CREATE TABLE IF NOT EXISTS \"users\" (id uuid PRIMARY KEY, name text, address frozen<address>)" |
| @@ -55,21 +54,21 @@ | ||
| 55 | 54 | |
| 56 | 55 | @Test(groups = "short") |
| 57 | 56 | public void should_handle_udts_with_default_codecs() { |
| 58 | - setUpUserTypes(cluster); | |
| 57 | + setUpUserTypes(cluster()); | |
| 59 | 58 | // simple statement |
| 60 | - session.execute(insertQuery, uuid, "John Doe", addressValue); | |
| 61 | - ResultSet rows = session.execute(selectQuery, uuid); | |
| 59 | + session().execute(insertQuery, uuid, "John Doe", addressValue); | |
| 60 | + ResultSet rows = session().execute(selectQuery, uuid); | |
| 62 | 61 | Row row = rows.one(); |
| 63 | 62 | assertRow(row); |
| 64 | 63 | // prepared + values |
| 65 | - PreparedStatement ps = session.prepare(insertQuery); | |
| 66 | - session.execute(ps.bind(uuid, "John Doe", addressValue)); | |
| 67 | - rows = session.execute(selectQuery, uuid); | |
| 64 | + PreparedStatement ps = session().prepare(insertQuery); | |
| 65 | + session().execute(ps.bind(uuid, "John Doe", addressValue)); | |
| 66 | + rows = session().execute(selectQuery, uuid); | |
| 68 | 67 | row = rows.one(); |
| 69 | 68 | assertRow(row); |
| 70 | 69 | // bound with setUDTValue |
| 71 | - session.execute(ps.bind().setUUID(0, uuid).setString(1, "John Doe").setUDTValue(2, addressValue)); | |
| 72 | - rows = session.execute(selectQuery, uuid); | |
| 70 | + session().execute(ps.bind().setUUID(0, uuid).setString(1, "John Doe").setUDTValue(2, addressValue)); | |
| 71 | + rows = session().execute(selectQuery, uuid); | |
| 73 | 72 | row = rows.one(); |
| 74 | 73 | assertRow(row); |
| 75 | 74 | } |
| @@ -78,8 +77,8 @@ | ||
| 78 | 77 | public void should_handle_udts_with_custom_codecs() { |
| 79 | 78 | CodecRegistry codecRegistry = new CodecRegistry(); |
| 80 | 79 | Cluster cluster = register(Cluster.builder() |
| 81 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 82 | - .withPort(ccm.getBinaryPort()) | |
| 80 | + .addContactPoints(getContactPoints()) | |
| 81 | + .withPort(ccm().getBinaryPort()) | |
| 83 | 82 | .withCodecRegistry(codecRegistry) |
| 84 | 83 | .build()); |
| 85 | 84 | Session session = cluster.connect(keyspace); |
modified driver-core/src/test/java/com/datastax/driver/core/UnresolvedUserTypeTest.java +5 −7
| @@ -16,10 +16,8 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | -import com.google.common.collect.Lists; | |
| 20 | 19 | import org.testng.annotations.Test; |
| 21 | 20 | |
| 22 | -import java.util.Collection; | |
| 23 | 21 | import java.util.concurrent.ExecutionException; |
| 24 | 22 | |
| 25 | 23 | import static com.datastax.driver.core.Assertions.assertThat; |
| @@ -29,8 +27,8 @@ | ||
| 29 | 27 | public class UnresolvedUserTypeTest extends CCMTestsSupport { |
| 30 | 28 | |
| 31 | 29 | @Override |
| 32 | - public Collection<String> createTestFixtures() { | |
| 33 | - return Lists.newArrayList( | |
| 30 | + public void onTestContextInitialized() { | |
| 31 | + execute( | |
| 34 | 32 | /* |
| 35 | 33 | Creates the following acyclic graph (edges directed upwards |
| 36 | 34 | meaning "depends on"): |
| @@ -63,13 +61,13 @@ | ||
| 63 | 61 | |
| 64 | 62 | // Each CREATE TYPE statement in getTableDefinitions() has triggered a partial schema refresh that |
| 65 | 63 | // should have used previous UDT definitions for dependencies. |
| 66 | - checkUserTypes(cluster.getMetadata()); | |
| 64 | + checkUserTypes(cluster().getMetadata()); | |
| 67 | 65 | |
| 68 | 66 | // Create a different Cluster instance to force a full refresh where all UDTs are loaded at once. |
| 69 | 67 | // The parsing logic should sort them to make sure they are loaded in the right order. |
| 70 | 68 | Cluster newCluster = register(Cluster.builder() |
| 71 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 72 | - .withPort(ccm.getBinaryPort()) | |
| 69 | + .addContactPoints(getContactPoints()) | |
| 70 | + .withPort(ccm().getBinaryPort()) | |
| 73 | 71 | .build()); |
| 74 | 72 | checkUserTypes(newCluster.getMetadata()); |
| 75 | 73 | } |
modified driver-core/src/test/java/com/datastax/driver/core/UserTypesTest.java +82 −82
| @@ -46,11 +46,11 @@ | ||
| 46 | 46 | new ArrayList<DataType.Name>(EnumSet.of(DataType.Name.LIST, DataType.Name.SET, DataType.Name.MAP, DataType.Name.TUPLE)); |
| 47 | 47 | |
| 48 | 48 | @Override |
| 49 | - public Collection<String> createTestFixtures() { | |
| 49 | + public void onTestContextInitialized() { | |
| 50 | 50 | String type1 = "CREATE TYPE phone (alias text, number text)"; |
| 51 | 51 | String type2 = "CREATE TYPE \"\"\"User Address\"\"\" (street text, \"ZIP\"\"\" int, phones set<frozen<phone>>)"; |
| 52 | 52 | String table = "CREATE TABLE user (id int PRIMARY KEY, addr frozen<\"\"\"User Address\"\"\">)"; |
| 53 | - return Arrays.asList(type1, type2, table); | |
| 53 | + execute(type1, type2, table); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| @@ -61,20 +61,20 @@ | ||
| 61 | 61 | @Test(groups = "short") |
| 62 | 62 | public void simpleWriteReadTest() throws Exception { |
| 63 | 63 | int userId = 0; |
| 64 | - PreparedStatement ins = session.prepare("INSERT INTO user(id, addr) VALUES (?, ?)"); | |
| 65 | - PreparedStatement sel = session.prepare("SELECT * FROM user WHERE id=?"); | |
| 64 | + PreparedStatement ins = session().prepare("INSERT INTO user(id, addr) VALUES (?, ?)"); | |
| 65 | + PreparedStatement sel = session().prepare("SELECT * FROM user WHERE id=?"); | |
| 66 | 66 | |
| 67 | - UserType addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\"")); | |
| 68 | - UserType phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone"); | |
| 67 | + UserType addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\"")); | |
| 68 | + UserType phoneDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("phone"); | |
| 69 | 69 | |
| 70 | 70 | UDTValue phone1 = phoneDef.newValue().setString("alias", "home").setString("number", "0123548790"); |
| 71 | 71 | UDTValue phone2 = phoneDef.newValue().setString("alias", "work").setString("number", "0698265251"); |
| 72 | 72 | |
| 73 | 73 | UDTValue addr = addrDef.newValue().setString("street", "1600 Pennsylvania Ave NW").setInt(quote("ZIP\""), 20500).setSet("phones", ImmutableSet.of(phone1, phone2)); |
| 74 | 74 | |
| 75 | - session.execute(ins.bind(userId, addr)); | |
| 75 | + session().execute(ins.bind(userId, addr)); | |
| 76 | 76 | |
| 77 | - Row r = session.execute(sel.bind(userId)).one(); | |
| 77 | + Row r = session().execute(sel.bind(userId)).one(); | |
| 78 | 78 | |
| 79 | 79 | assertEquals(r.getInt("id"), 0); |
| 80 | 80 | assertEquals(r.getUDTValue("addr"), addr); |
| @@ -88,18 +88,18 @@ | ||
| 88 | 88 | @Test(groups = "short") |
| 89 | 89 | public void simpleUnpreparedWriteReadTest() throws Exception { |
| 90 | 90 | int userId = 1; |
| 91 | - session.execute("USE " + keyspace); | |
| 92 | - UserType addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\"")); | |
| 93 | - UserType phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone"); | |
| 91 | + session().execute("USE " + keyspace); | |
| 92 | + UserType addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\"")); | |
| 93 | + UserType phoneDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("phone"); | |
| 94 | 94 | |
| 95 | 95 | UDTValue phone1 = phoneDef.newValue().setString("alias", "home").setString("number", "0123548790"); |
| 96 | 96 | UDTValue phone2 = phoneDef.newValue().setString("alias", "work").setString("number", "0698265251"); |
| 97 | 97 | |
| 98 | 98 | UDTValue addr = addrDef.newValue().setString("street", "1600 Pennsylvania Ave NW").setInt(quote("ZIP\""), 20500).setSet("phones", ImmutableSet.of(phone1, phone2)); |
| 99 | 99 | |
| 100 | - session.execute("INSERT INTO user(id, addr) VALUES (?, ?)", userId, addr); | |
| 100 | + session().execute("INSERT INTO user(id, addr) VALUES (?, ?)", userId, addr); | |
| 101 | 101 | |
| 102 | - Row r = session.execute("SELECT * FROM user WHERE id=?", userId).one(); | |
| 102 | + Row r = session().execute("SELECT * FROM user WHERE id=?", userId).one(); | |
| 103 | 103 | |
| 104 | 104 | assertEquals(r.getInt("id"), 1); |
| 105 | 105 | assertEquals(r.getUDTValue("addr"), addr); |
| @@ -112,31 +112,31 @@ | ||
| 112 | 112 | */ |
| 113 | 113 | @Test(groups = "short") |
| 114 | 114 | public void nonExistingTypesTest() throws Exception { |
| 115 | - UserType addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("address1"); | |
| 116 | - UserType phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone1"); | |
| 115 | + UserType addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("address1"); | |
| 116 | + UserType phoneDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("phone1"); | |
| 117 | 117 | assertEquals(addrDef, null); |
| 118 | 118 | assertEquals(phoneDef, null); |
| 119 | 119 | |
| 120 | - addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\"")); | |
| 121 | - phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone"); | |
| 120 | + addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\"")); | |
| 121 | + phoneDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("phone"); | |
| 122 | 122 | assertNotEquals(addrDef, null); |
| 123 | 123 | assertNotEquals(phoneDef, null); |
| 124 | 124 | |
| 125 | 125 | // create keyspace |
| 126 | 126 | String nonExistingKeyspace = keyspace + "_nonEx"; |
| 127 | - session.execute("CREATE KEYSPACE " + nonExistingKeyspace + " " + | |
| 127 | + session().execute("CREATE KEYSPACE " + nonExistingKeyspace + " " + | |
| 128 | 128 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 129 | - session.execute("USE " + nonExistingKeyspace); | |
| 129 | + session().execute("USE " + nonExistingKeyspace); | |
| 130 | 130 | |
| 131 | - addrDef = cluster.getMetadata().getKeyspace(nonExistingKeyspace).getUserType(quote("\"User Address\"")); | |
| 132 | - phoneDef = cluster.getMetadata().getKeyspace(nonExistingKeyspace).getUserType("phone"); | |
| 131 | + addrDef = cluster().getMetadata().getKeyspace(nonExistingKeyspace).getUserType(quote("\"User Address\"")); | |
| 132 | + phoneDef = cluster().getMetadata().getKeyspace(nonExistingKeyspace).getUserType("phone"); | |
| 133 | 133 | assertEquals(addrDef, null); |
| 134 | 134 | assertEquals(phoneDef, null); |
| 135 | 135 | |
| 136 | - session.execute("USE " + keyspace); | |
| 136 | + session().execute("USE " + keyspace); | |
| 137 | 137 | |
| 138 | - addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\"")); | |
| 139 | - phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone"); | |
| 138 | + addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\"")); | |
| 139 | + phoneDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("phone"); | |
| 140 | 140 | assertNotEquals(addrDef, null); |
| 141 | 141 | assertNotEquals(phoneDef, null); |
| 142 | 142 | } |
| @@ -151,9 +151,9 @@ | ||
| 151 | 151 | public void udtSizesTest() throws Exception { |
| 152 | 152 | int MAX_TEST_LENGTH = 1024; |
| 153 | 153 | // create keyspace |
| 154 | - session.execute("CREATE KEYSPACE test_udt_sizes " + | |
| 154 | + session().execute("CREATE KEYSPACE test_udt_sizes " + | |
| 155 | 155 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 156 | - session.execute("USE test_udt_sizes"); | |
| 156 | + session().execute("USE test_udt_sizes"); | |
| 157 | 157 | |
| 158 | 158 | // create the seed udt |
| 159 | 159 | StringBuilder sb = new StringBuilder(); |
| @@ -163,13 +163,13 @@ | ||
| 163 | 163 | if (i + 1 < MAX_TEST_LENGTH) |
| 164 | 164 | sb.append(","); |
| 165 | 165 | } |
| 166 | - session.execute(String.format("CREATE TYPE lengthy_udt (%s)", sb.toString())); | |
| 166 | + session().execute(String.format("CREATE TYPE lengthy_udt (%s)", sb.toString())); | |
| 167 | 167 | |
| 168 | 168 | // create a table with multiple sizes of udts |
| 169 | - session.execute("CREATE TABLE mytable (k int PRIMARY KEY, v frozen<lengthy_udt>)"); | |
| 169 | + session().execute("CREATE TABLE mytable (k int PRIMARY KEY, v frozen<lengthy_udt>)"); | |
| 170 | 170 | |
| 171 | 171 | // hold onto the UserType for future use |
| 172 | - UserType udtDef = cluster.getMetadata().getKeyspace("test_udt_sizes").getUserType("lengthy_udt"); | |
| 172 | + UserType udtDef = cluster().getMetadata().getKeyspace("test_udt_sizes").getUserType("lengthy_udt"); | |
| 173 | 173 | |
| 174 | 174 | // verify inserts and reads |
| 175 | 175 | for (int i : Arrays.asList(0, 1, 2, 3, MAX_TEST_LENGTH)) { |
| @@ -180,10 +180,10 @@ | ||
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | // write udt |
| 183 | - session.execute("INSERT INTO mytable (k, v) VALUES (0, ?)", createdUDT); | |
| 183 | + session().execute("INSERT INTO mytable (k, v) VALUES (0, ?)", createdUDT); | |
| 184 | 184 | |
| 185 | 185 | // verify udt was written and read correctly |
| 186 | - UDTValue r = session.execute("SELECT v FROM mytable WHERE k=0") | |
| 186 | + UDTValue r = session().execute("SELECT v FROM mytable WHERE k=0") | |
| 187 | 187 | .one().getUDTValue("v"); |
| 188 | 188 | assertEquals(r.toString(), createdUDT.toString()); |
| 189 | 189 | } |
| @@ -198,9 +198,9 @@ | ||
| 198 | 198 | @Test(groups = "short") |
| 199 | 199 | public void testPrimitiveDatatypes() throws Exception { |
| 200 | 200 | // create keyspace |
| 201 | - session.execute("CREATE KEYSPACE testPrimitiveDatatypes " + | |
| 201 | + session().execute("CREATE KEYSPACE testPrimitiveDatatypes " + | |
| 202 | 202 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 203 | - session.execute("USE testPrimitiveDatatypes"); | |
| 203 | + session().execute("USE testPrimitiveDatatypes"); | |
| 204 | 204 | |
| 205 | 205 | // create UDT |
| 206 | 206 | List<String> alpha_type_list = new ArrayList<String>(); |
| @@ -210,11 +210,11 @@ | ||
| 210 | 210 | DATA_TYPE_PRIMITIVES.get(i).getName())); |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - session.execute(String.format("CREATE TYPE alldatatypes (%s)", Joiner.on(',').join(alpha_type_list))); | |
| 214 | - session.execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<alldatatypes>)"); | |
| 213 | + session().execute(String.format("CREATE TYPE alldatatypes (%s)", Joiner.on(',').join(alpha_type_list))); | |
| 214 | + session().execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<alldatatypes>)"); | |
| 215 | 215 | |
| 216 | 216 | // insert UDT data |
| 217 | - UserType alldatatypesDef = cluster.getMetadata().getKeyspace("testPrimitiveDatatypes").getUserType("alldatatypes"); | |
| 217 | + UserType alldatatypesDef = cluster().getMetadata().getKeyspace("testPrimitiveDatatypes").getUserType("alldatatypes"); | |
| 218 | 218 | UDTValue alldatatypes = alldatatypesDef.newValue(); |
| 219 | 219 | |
| 220 | 220 | for (int i = 0; i < DATA_TYPE_PRIMITIVES.size(); i++) { |
| @@ -283,11 +283,11 @@ | ||
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - PreparedStatement ins = session.prepare("INSERT INTO mytable (a, b) VALUES (?, ?)"); | |
| 287 | - session.execute(ins.bind(0, alldatatypes)); | |
| 286 | + PreparedStatement ins = session().prepare("INSERT INTO mytable (a, b) VALUES (?, ?)"); | |
| 287 | + session().execute(ins.bind(0, alldatatypes)); | |
| 288 | 288 | |
| 289 | 289 | // retrieve and verify data |
| 290 | - ResultSet rs = session.execute("SELECT * FROM mytable"); | |
| 290 | + ResultSet rs = session().execute("SELECT * FROM mytable"); | |
| 291 | 291 | List<Row> rows = rs.all(); |
| 292 | 292 | assertEquals(1, rows.size()); |
| 293 | 293 | |
| @@ -306,9 +306,9 @@ | ||
| 306 | 306 | @Test(groups = "short") |
| 307 | 307 | public void testNonPrimitiveDatatypes() throws Exception { |
| 308 | 308 | // create keyspace |
| 309 | - session.execute("CREATE KEYSPACE test_nonprimitive_datatypes " + | |
| 309 | + session().execute("CREATE KEYSPACE test_nonprimitive_datatypes " + | |
| 310 | 310 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 311 | - session.execute("USE test_nonprimitive_datatypes"); | |
| 311 | + session().execute("USE test_nonprimitive_datatypes"); | |
| 312 | 312 | |
| 313 | 313 | // counters are not allowed inside collections |
| 314 | 314 | DATA_TYPE_PRIMITIVES.remove(DataType.counter()); |
| @@ -335,11 +335,11 @@ | ||
| 335 | 335 | alpha_type_list.add(typeString); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - session.execute(String.format("CREATE TYPE alldatatypes (%s)", Joiner.on(',').join(alpha_type_list))); | |
| 339 | - session.execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<alldatatypes>)"); | |
| 338 | + session().execute(String.format("CREATE TYPE alldatatypes (%s)", Joiner.on(',').join(alpha_type_list))); | |
| 339 | + session().execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<alldatatypes>)"); | |
| 340 | 340 | |
| 341 | 341 | // insert UDT data |
| 342 | - UserType alldatatypesDef = cluster.getMetadata().getKeyspace("test_nonprimitive_datatypes").getUserType("alldatatypes"); | |
| 342 | + UserType alldatatypesDef = cluster().getMetadata().getKeyspace("test_nonprimitive_datatypes").getUserType("alldatatypes"); | |
| 343 | 343 | UDTValue alldatatypes = alldatatypesDef.newValue(); |
| 344 | 344 | |
| 345 | 345 | for (int i = 0; i < DATA_TYPE_NON_PRIMITIVE_NAMES.size(); i++) |
| @@ -360,15 +360,15 @@ | ||
| 360 | 360 | alldatatypes.setMap(index, ImmutableMap.of(sampleElement, sampleElement)); |
| 361 | 361 | break; |
| 362 | 362 | case TUPLE: |
| 363 | - alldatatypes.setTupleValue(index, cluster.getMetadata().newTupleType(dataType).newValue(sampleElement)); | |
| 363 | + alldatatypes.setTupleValue(index, cluster().getMetadata().newTupleType(dataType).newValue(sampleElement)); | |
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - PreparedStatement ins = session.prepare("INSERT INTO mytable (a, b) VALUES (?, ?)"); | |
| 368 | - session.execute(ins.bind(0, alldatatypes)); | |
| 367 | + PreparedStatement ins = session().prepare("INSERT INTO mytable (a, b) VALUES (?, ?)"); | |
| 368 | + session().execute(ins.bind(0, alldatatypes)); | |
| 369 | 369 | |
| 370 | 370 | // retrieve and verify data |
| 371 | - ResultSet rs = session.execute("SELECT * FROM mytable"); | |
| 371 | + ResultSet rs = session().execute("SELECT * FROM mytable"); | |
| 372 | 372 | List<Row> rows = rs.all(); |
| 373 | 373 | assertEquals(1, rows.size()); |
| 374 | 374 | |
| @@ -388,41 +388,41 @@ | ||
| 388 | 388 | public void udtNestedTest() throws Exception { |
| 389 | 389 | final int MAX_NESTING_DEPTH = 4; |
| 390 | 390 | // create keyspace |
| 391 | - session.execute("CREATE KEYSPACE udtNestedTest " + | |
| 391 | + session().execute("CREATE KEYSPACE udtNestedTest " + | |
| 392 | 392 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 393 | - session.execute("USE udtNestedTest"); | |
| 393 | + session().execute("USE udtNestedTest"); | |
| 394 | 394 | |
| 395 | 395 | // create UDT |
| 396 | - session.execute("CREATE TYPE depth_0 (age int, name text)"); | |
| 396 | + session().execute("CREATE TYPE depth_0 (age int, name text)"); | |
| 397 | 397 | |
| 398 | 398 | for (int i = 1; i <= MAX_NESTING_DEPTH; i++) { |
| 399 | - session.execute(String.format("CREATE TYPE depth_%s (value frozen<depth_%s>)", String.valueOf(i), String.valueOf(i - 1))); | |
| 399 | + session().execute(String.format("CREATE TYPE depth_%s (value frozen<depth_%s>)", String.valueOf(i), String.valueOf(i - 1))); | |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - session.execute(String.format("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<depth_0>, c frozen<depth_1>, d frozen<depth_2>, e frozen<depth_3>," + | |
| 402 | + session().execute(String.format("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<depth_0>, c frozen<depth_1>, d frozen<depth_2>, e frozen<depth_3>," + | |
| 403 | 403 | "f frozen<depth_%s>)", MAX_NESTING_DEPTH)); |
| 404 | 404 | |
| 405 | 405 | // insert UDT data |
| 406 | - UserType depthZeroDef = cluster.getMetadata().getKeyspace("udtNestedTest").getUserType("depth_0"); | |
| 406 | + UserType depthZeroDef = cluster().getMetadata().getKeyspace("udtNestedTest").getUserType("depth_0"); | |
| 407 | 407 | UDTValue depthZero = depthZeroDef.newValue().setInt("age", 42).setString("name", "Bob"); |
| 408 | 408 | |
| 409 | - UserType depthOneDef = cluster.getMetadata().getKeyspace("udtNestedTest").getUserType("depth_1"); | |
| 409 | + UserType depthOneDef = cluster().getMetadata().getKeyspace("udtNestedTest").getUserType("depth_1"); | |
| 410 | 410 | UDTValue depthOne = depthOneDef.newValue().setUDTValue("value", depthZero); |
| 411 | 411 | |
| 412 | - UserType depthTwoDef = cluster.getMetadata().getKeyspace("udtNestedTest").getUserType("depth_2"); | |
| 412 | + UserType depthTwoDef = cluster().getMetadata().getKeyspace("udtNestedTest").getUserType("depth_2"); | |
| 413 | 413 | UDTValue depthTwo = depthTwoDef.newValue().setUDTValue("value", depthOne); |
| 414 | 414 | |
| 415 | - UserType depthThreeDef = cluster.getMetadata().getKeyspace("udtNestedTest").getUserType("depth_3"); | |
| 415 | + UserType depthThreeDef = cluster().getMetadata().getKeyspace("udtNestedTest").getUserType("depth_3"); | |
| 416 | 416 | UDTValue depthThree = depthThreeDef.newValue().setUDTValue("value", depthTwo); |
| 417 | 417 | |
| 418 | - UserType depthFourDef = cluster.getMetadata().getKeyspace("udtNestedTest").getUserType("depth_4"); | |
| 418 | + UserType depthFourDef = cluster().getMetadata().getKeyspace("udtNestedTest").getUserType("depth_4"); | |
| 419 | 419 | UDTValue depthFour = depthFourDef.newValue().setUDTValue("value", depthThree); |
| 420 | 420 | |
| 421 | - PreparedStatement ins = session.prepare("INSERT INTO mytable (a, b, c, d, e, f) VALUES (?, ?, ?, ?, ?, ?)"); | |
| 422 | - session.execute(ins.bind(0, depthZero, depthOne, depthTwo, depthThree, depthFour)); | |
| 421 | + PreparedStatement ins = session().prepare("INSERT INTO mytable (a, b, c, d, e, f) VALUES (?, ?, ?, ?, ?, ?)"); | |
| 422 | + session().execute(ins.bind(0, depthZero, depthOne, depthTwo, depthThree, depthFour)); | |
| 423 | 423 | |
| 424 | 424 | // retrieve and verify data |
| 425 | - ResultSet rs = session.execute("SELECT * FROM mytable"); | |
| 425 | + ResultSet rs = session().execute("SELECT * FROM mytable"); | |
| 426 | 426 | List<Row> rows = rs.all(); |
| 427 | 427 | assertEquals(1, rows.size()); |
| 428 | 428 | |
| @@ -445,23 +445,23 @@ | ||
| 445 | 445 | @Test(groups = "short") |
| 446 | 446 | public void testUdtsWithNulls() throws Exception { |
| 447 | 447 | // create keyspace |
| 448 | - session.execute("CREATE KEYSPACE testUdtsWithNulls " + | |
| 448 | + session().execute("CREATE KEYSPACE testUdtsWithNulls " + | |
| 449 | 449 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 450 | - session.execute("USE testUdtsWithNulls"); | |
| 450 | + session().execute("USE testUdtsWithNulls"); | |
| 451 | 451 | |
| 452 | 452 | // create UDT |
| 453 | - session.execute("CREATE TYPE user (a text, b int, c uuid, d blob)"); | |
| 454 | - session.execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<user>)"); | |
| 453 | + session().execute("CREATE TYPE user (a text, b int, c uuid, d blob)"); | |
| 454 | + session().execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<user>)"); | |
| 455 | 455 | |
| 456 | 456 | // insert UDT data |
| 457 | - UserType userTypeDef = cluster.getMetadata().getKeyspace("testUdtsWithNulls").getUserType("user"); | |
| 457 | + UserType userTypeDef = cluster().getMetadata().getKeyspace("testUdtsWithNulls").getUserType("user"); | |
| 458 | 458 | UDTValue userType = userTypeDef.newValue().setString("a", null).setInt("b", 0).setUUID("c", null).setBytes("d", null); |
| 459 | 459 | |
| 460 | - PreparedStatement ins = session.prepare("INSERT INTO mytable (a, b) VALUES (?, ?)"); | |
| 461 | - session.execute(ins.bind(0, userType)); | |
| 460 | + PreparedStatement ins = session().prepare("INSERT INTO mytable (a, b) VALUES (?, ?)"); | |
| 461 | + session().execute(ins.bind(0, userType)); | |
| 462 | 462 | |
| 463 | 463 | // retrieve and verify data |
| 464 | - ResultSet rs = session.execute("SELECT * FROM mytable"); | |
| 464 | + ResultSet rs = session().execute("SELECT * FROM mytable"); | |
| 465 | 465 | List<Row> rows = rs.all(); |
| 466 | 466 | assertEquals(1, rows.size()); |
| 467 | 467 | |
| @@ -472,10 +472,10 @@ | ||
| 472 | 472 | |
| 473 | 473 | // test empty strings |
| 474 | 474 | userType = userTypeDef.newValue().setString("a", "").setInt("b", 0).setUUID("c", null).setBytes("d", ByteBuffer.allocate(0)); |
| 475 | - session.execute(ins.bind(0, userType)); | |
| 475 | + session().execute(ins.bind(0, userType)); | |
| 476 | 476 | |
| 477 | 477 | // retrieve and verify data |
| 478 | - rs = session.execute("SELECT * FROM mytable"); | |
| 478 | + rs = session().execute("SELECT * FROM mytable"); | |
| 479 | 479 | rows = rs.all(); |
| 480 | 480 | assertEquals(1, rows.size()); |
| 481 | 481 | |
| @@ -493,38 +493,38 @@ | ||
| 493 | 493 | @Test(groups = "short") |
| 494 | 494 | public void testUdtsWithCollectionNulls() throws Exception { |
| 495 | 495 | // create keyspace |
| 496 | - session.execute("CREATE KEYSPACE testUdtsWithCollectionNulls " + | |
| 496 | + session().execute("CREATE KEYSPACE testUdtsWithCollectionNulls " + | |
| 497 | 497 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 498 | - session.execute("USE testUdtsWithCollectionNulls"); | |
| 498 | + session().execute("USE testUdtsWithCollectionNulls"); | |
| 499 | 499 | |
| 500 | 500 | // create UDT |
| 501 | - session.execute("CREATE TYPE user (a List<text>, b Set<text>, c Map<text, text>, d frozen<Tuple<text>>)"); | |
| 502 | - session.execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<user>)"); | |
| 501 | + session().execute("CREATE TYPE user (a List<text>, b Set<text>, c Map<text, text>, d frozen<Tuple<text>>)"); | |
| 502 | + session().execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<user>)"); | |
| 503 | 503 | |
| 504 | 504 | // insert null UDT data |
| 505 | - PreparedStatement ins = session.prepare("INSERT INTO mytable (a, b) " + | |
| 505 | + PreparedStatement ins = session().prepare("INSERT INTO mytable (a, b) " + | |
| 506 | 506 | "VALUES (0, { a: ?, b: ?, c: ?, d: ? })"); |
| 507 | - session.execute(ins.bind().setList(0, null).setSet(1, null).setMap(2, null).setTupleValue(3, null)); | |
| 507 | + session().execute(ins.bind().setList(0, null).setSet(1, null).setMap(2, null).setTupleValue(3, null)); | |
| 508 | 508 | |
| 509 | 509 | // retrieve and verify data |
| 510 | - ResultSet rs = session.execute("SELECT * FROM mytable"); | |
| 510 | + ResultSet rs = session().execute("SELECT * FROM mytable"); | |
| 511 | 511 | List<Row> rows = rs.all(); |
| 512 | 512 | assertEquals(1, rows.size()); |
| 513 | 513 | |
| 514 | 514 | Row row = rows.get(0); |
| 515 | 515 | assertEquals(row.getInt("a"), 0); |
| 516 | 516 | |
| 517 | - UserType userTypeDef = cluster.getMetadata().getKeyspace("testUdtsWithCollectionNulls").getUserType("user"); | |
| 517 | + UserType userTypeDef = cluster().getMetadata().getKeyspace("testUdtsWithCollectionNulls").getUserType("user"); | |
| 518 | 518 | UDTValue userType = userTypeDef.newValue().setList("a", null).setSet("b", null).setMap("c", null).setTupleValue("d", null); |
| 519 | 519 | assertEquals(row.getUDTValue("b"), userType); |
| 520 | 520 | |
| 521 | 521 | // test missing UDT args |
| 522 | - ins = session.prepare("INSERT INTO mytable (a, b) " + | |
| 522 | + ins = session().prepare("INSERT INTO mytable (a, b) " + | |
| 523 | 523 | "VALUES (1, { a: ? })"); |
| 524 | - session.execute(ins.bind().setList(0, new ArrayList<Object>())); | |
| 524 | + session().execute(ins.bind().setList(0, new ArrayList<Object>())); | |
| 525 | 525 | |
| 526 | 526 | // retrieve and verify data |
| 527 | - rs = session.execute("SELECT * FROM mytable"); | |
| 527 | + rs = session().execute("SELECT * FROM mytable"); | |
| 528 | 528 | rows = rs.all(); |
| 529 | 529 | assertEquals(2, rows.size()); |
| 530 | 530 |
modified driver-core/src/test/java/com/datastax/driver/core/WarningsTest.java +3 −7
| @@ -17,10 +17,8 @@ | ||
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | 19 | import com.google.common.base.Strings; |
| 20 | -import com.google.common.collect.Lists; | |
| 21 | 20 | import org.testng.annotations.Test; |
| 22 | 21 | |
| 23 | -import java.util.Collection; | |
| 24 | 22 | import java.util.List; |
| 25 | 23 | |
| 26 | 24 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -33,16 +31,14 @@ | ||
| 33 | 31 | private static final int BATCH_SIZE_WARN_THRESHOLD_IN_BYTES = 5 * 1024; |
| 34 | 32 | |
| 35 | 33 | @Override |
| 36 | - public Collection<String> createTestFixtures() { | |
| 37 | - return Lists.newArrayList( | |
| 38 | - "CREATE TABLE foo(k int primary key, v text)" | |
| 39 | - ); | |
| 34 | + public void onTestContextInitialized() { | |
| 35 | + execute("CREATE TABLE foo(k int primary key, v text)"); | |
| 40 | 36 | } |
| 41 | 37 | |
| 42 | 38 | @CassandraVersion(major = 2.2) |
| 43 | 39 | @Test(groups = "short") |
| 44 | 40 | public void should_expose_warnings_on_execution_info() { |
| 45 | - ResultSet rs = session.execute(String.format("BEGIN UNLOGGED BATCH INSERT INTO foo (k, v) VALUES (1, '%s') APPLY BATCH", | |
| 41 | + ResultSet rs = session().execute(String.format("BEGIN UNLOGGED BATCH INSERT INTO foo (k, v) VALUES (1, '%s') APPLY BATCH", | |
| 46 | 42 | Strings.repeat("1", BATCH_SIZE_WARN_THRESHOLD_IN_BYTES))); |
| 47 | 43 | |
| 48 | 44 | List<String> warnings = rs.getExecutionInfo().getWarnings(); |
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/ExceptionsTest.java +10 −10
| @@ -53,35 +53,35 @@ | ||
| 53 | 53 | }; |
| 54 | 54 | |
| 55 | 55 | // Create the schema once |
| 56 | - session.execute(cqlCommands[0]); | |
| 57 | - session.execute(cqlCommands[1]); | |
| 58 | - session.execute(cqlCommands[2]); | |
| 56 | + session().execute(cqlCommands[0]); | |
| 57 | + session().execute(cqlCommands[1]); | |
| 58 | + session().execute(cqlCommands[2]); | |
| 59 | 59 | |
| 60 | 60 | // Try creating the keyspace again |
| 61 | 61 | try { |
| 62 | - session.execute(cqlCommands[0]); | |
| 62 | + session().execute(cqlCommands[0]); | |
| 63 | 63 | } catch (AlreadyExistsException e) { |
| 64 | 64 | String expected = String.format("Keyspace %s already exists", keyspace.toLowerCase()); |
| 65 | 65 | assertEquals(e.getMessage(), expected); |
| 66 | 66 | assertEquals(e.getKeyspace(), keyspace.toLowerCase()); |
| 67 | 67 | assertEquals(e.getTable(), null); |
| 68 | 68 | assertEquals(e.wasTableCreation(), false); |
| 69 | - assertEquals(e.getHost(), ccm.addressOfNode(1).getAddress()); | |
| 70 | - assertEquals(e.getAddress(), ccm.addressOfNode(1)); | |
| 69 | + assertEquals(e.getHost(), ccm().addressOfNode(1).getAddress()); | |
| 70 | + assertEquals(e.getAddress(), ccm().addressOfNode(1)); | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - session.execute(cqlCommands[1]); | |
| 73 | + session().execute(cqlCommands[1]); | |
| 74 | 74 | |
| 75 | 75 | // Try creating the table again |
| 76 | 76 | try { |
| 77 | - session.execute(cqlCommands[2]); | |
| 77 | + session().execute(cqlCommands[2]); | |
| 78 | 78 | } catch (AlreadyExistsException e) { |
| 79 | 79 | // is released |
| 80 | 80 | assertEquals(e.getKeyspace(), keyspace.toLowerCase()); |
| 81 | 81 | assertEquals(e.getTable(), table.toLowerCase()); |
| 82 | 82 | assertEquals(e.wasTableCreation(), true); |
| 83 | - assertEquals(e.getHost(), ccm.addressOfNode(1).getAddress()); | |
| 84 | - assertEquals(e.getAddress(), ccm.addressOfNode(1)); | |
| 83 | + assertEquals(e.getHost(), ccm().addressOfNode(1).getAddress()); | |
| 84 | + assertEquals(e.getAddress(), ccm().addressOfNode(1)); | |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 |
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/FunctionExecutionExceptionTest.java +4 −6
| @@ -18,18 +18,16 @@ | ||
| 18 | 18 | import com.datastax.driver.core.CCMConfig; |
| 19 | 19 | import com.datastax.driver.core.CCMTestsSupport; |
| 20 | 20 | import com.datastax.driver.core.utils.CassandraVersion; |
| 21 | -import com.google.common.collect.Lists; | |
| 22 | 21 | import org.testng.annotations.Test; |
| 23 | 22 | |
| 24 | -import java.util.Collection; | |
| 25 | - | |
| 26 | 23 | @CassandraVersion(major = 2.2) |
| 27 | 24 | @CCMConfig(config = "enable_user_defined_functions:true") |
| 28 | 25 | public class FunctionExecutionExceptionTest extends CCMTestsSupport { |
| 29 | 26 | |
| 27 | + | |
| 30 | 28 | @Override |
| 31 | - public Collection<String> createTestFixtures() { | |
| 32 | - return Lists.newArrayList( | |
| 29 | + public void onTestContextInitialized() { | |
| 30 | + execute( | |
| 33 | 31 | "CREATE TABLE foo (k int primary key, i int, l list<int>)", |
| 34 | 32 | "INSERT INTO foo (k, i, l) VALUES (1, 1, [1])", |
| 35 | 33 | "CREATE FUNCTION element_at(l list<int>, i int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return (Integer) l.get(i);'" |
| @@ -38,6 +36,6 @@ | ||
| 38 | 36 | |
| 39 | 37 | @Test(groups = "short", expectedExceptions = FunctionExecutionException.class) |
| 40 | 38 | public void should_throw_when_function_execution_fails() { |
| 41 | - session.execute("SELECT element_at(l, i) FROM foo WHERE k = 1"); | |
| 39 | + session().execute("SELECT element_at(l, i) FROM foo WHERE k = 1"); | |
| 42 | 40 | } |
| 43 | 41 | } |
modified driver-core/src/test/java/com/datastax/driver/core/policies/CloseableLoadBalancingPolicyTest.java +3 −3
| @@ -30,8 +30,8 @@ | ||
| 30 | 30 | @Test(groups = "short") |
| 31 | 31 | public void should_be_invoked_at_shutdown() { |
| 32 | 32 | try { |
| 33 | - cluster.connect(); | |
| 34 | - cluster.close(); | |
| 33 | + cluster().connect(); | |
| 34 | + cluster().close(); | |
| 35 | 35 | } finally { |
| 36 | 36 | assertThat(policy.wasClosed).isTrue(); |
| 37 | 37 | } |
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | public Cluster.Builder createClusterBuilder() { |
| 42 | 42 | policy = new CloseMonitoringPolicy(Policies.defaultLoadBalancingPolicy()); |
| 43 | 43 | return Cluster.builder() |
| 44 | - .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 44 | + .addContactPoints(getContactPoints().get(0)) | |
| 45 | 45 | .withLoadBalancingPolicy(policy); |
| 46 | 46 | } |
| 47 | 47 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java +3 −3
| @@ -325,13 +325,13 @@ | ||
| 325 | 325 | // given: a 3 node cluster with a keyspace with RF 1. |
| 326 | 326 | Cluster cluster = register(Cluster.builder() |
| 327 | 327 | .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) |
| 328 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 329 | - .withPort(ccm.getBinaryPort()) | |
| 328 | + .addContactPoints(getContactPoints().get(0)) | |
| 329 | + .withPort(ccm().getBinaryPort()) | |
| 330 | 330 | .build()); |
| 331 | 331 | Session session = cluster.connect(); |
| 332 | 332 | |
| 333 | 333 | String table = "composite"; |
| 334 | - String ks = TestUtils.getAvailableKeyspaceName(); | |
| 334 | + String ks = TestUtils.generateIdentifier("ks_"); | |
| 335 | 335 | session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, ks, 1)); |
| 336 | 336 | session.execute("USE " + ks); |
| 337 | 337 | session.execute(String.format("CREATE TABLE %s (k1 int, k2 int, i int, PRIMARY KEY ((k1, k2)))", table)); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/WhiteListPolicyTest.java +1 −0
| @@ -109,6 +109,7 @@ | ||
| 109 | 109 | List<InetSocketAddress> whiteList = Lists.newArrayList(sCluster.address(2)); |
| 110 | 110 | Cluster cluster = Cluster.builder() |
| 111 | 111 | .addContactPointsWithPorts(sCluster.address(3)) |
| 112 | + .withPort(sCluster.getBinaryPort()) | |
| 112 | 113 | .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), whiteList)) |
| 113 | 114 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 114 | 115 | .build(); |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilder21ExecutionTest.java +10 −13
| @@ -22,9 +22,6 @@ | ||
| 22 | 22 | import com.datastax.driver.core.utils.CassandraVersion; |
| 23 | 23 | import org.testng.annotations.Test; |
| 24 | 24 | |
| 25 | -import java.util.Arrays; | |
| 26 | -import java.util.Collection; | |
| 27 | - | |
| 28 | 25 | import static com.datastax.driver.core.Assertions.assertThat; |
| 29 | 26 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 30 | 27 | |
| @@ -32,9 +29,9 @@ | ||
| 32 | 29 | public class QueryBuilder21ExecutionTest extends CCMTestsSupport { |
| 33 | 30 | |
| 34 | 31 | @Override |
| 35 | - public Collection<String> createTestFixtures() { | |
| 32 | + public void onTestContextInitialized() { | |
| 36 | 33 | // Taken from http://www.datastax.com/dev/blog/cql-in-2-1 |
| 37 | - return Arrays.asList( | |
| 34 | + execute( | |
| 38 | 35 | "CREATE TABLE products (id int PRIMARY KEY, description text, price int, categories set<text>, buyers list<int>, features_keys map<text, text>, features_values map<text, text>)", |
| 39 | 36 | "CREATE INDEX cat_index ON products(categories)", |
| 40 | 37 | "CREATE INDEX buyers_index ON products(buyers)", |
| @@ -51,11 +48,11 @@ | ||
| 51 | 48 | |
| 52 | 49 | @Test(groups = "short") |
| 53 | 50 | public void should_handle_contains_on_set_with_index() { |
| 54 | - PreparedStatement byCategory = session.prepare(select("id", "description", "categories") | |
| 51 | + PreparedStatement byCategory = session().prepare(select("id", "description", "categories") | |
| 55 | 52 | .from("products") |
| 56 | 53 | .where(contains("categories", bindMarker("category")))); |
| 57 | 54 | |
| 58 | - ResultSet results = session.execute(byCategory.bind().setString("category", "hdtv")); | |
| 55 | + ResultSet results = session().execute(byCategory.bind().setString("category", "hdtv")); | |
| 59 | 56 | |
| 60 | 57 | assertThat(results.getAvailableWithoutFetching()).isEqualTo(2); |
| 61 | 58 | for (Row row : results) { |
| @@ -65,11 +62,11 @@ | ||
| 65 | 62 | |
| 66 | 63 | @Test(groups = "short") |
| 67 | 64 | public void should_handle_contains_on_list_with_index() { |
| 68 | - PreparedStatement byBuyer = session.prepare(select("id", "description", "buyers") | |
| 65 | + PreparedStatement byBuyer = session().prepare(select("id", "description", "buyers") | |
| 69 | 66 | .from("products") |
| 70 | 67 | .where(contains("buyers", bindMarker("buyer")))); |
| 71 | 68 | |
| 72 | - ResultSet results = session.execute(byBuyer.bind().setInt("buyer", 4)); | |
| 69 | + ResultSet results = session().execute(byBuyer.bind().setInt("buyer", 4)); | |
| 73 | 70 | |
| 74 | 71 | Row row = results.one(); |
| 75 | 72 | assertThat(row).isNotNull(); |
| @@ -79,11 +76,11 @@ | ||
| 79 | 76 | |
| 80 | 77 | @Test(groups = "short") |
| 81 | 78 | public void should_handle_contains_on_map_with_index() { |
| 82 | - PreparedStatement byFeatures = session.prepare(select("id", "description", "features_values") | |
| 79 | + PreparedStatement byFeatures = session().prepare(select("id", "description", "features_values") | |
| 83 | 80 | .from("products") |
| 84 | 81 | .where(contains("features_values", bindMarker("feature")))); |
| 85 | 82 | |
| 86 | - ResultSet results = session.execute(byFeatures.bind().setString("feature", "LED")); | |
| 83 | + ResultSet results = session().execute(byFeatures.bind().setString("feature", "LED")); | |
| 87 | 84 | |
| 88 | 85 | Row row = results.one(); |
| 89 | 86 | assertThat(row).isNotNull(); |
| @@ -94,11 +91,11 @@ | ||
| 94 | 91 | |
| 95 | 92 | @Test(groups = "short") |
| 96 | 93 | public void should_handle_contains_key_on_map_with_index() { |
| 97 | - PreparedStatement byFeatures = session.prepare(select("id", "description", "features_keys") | |
| 94 | + PreparedStatement byFeatures = session().prepare(select("id", "description", "features_keys") | |
| 98 | 95 | .from("products") |
| 99 | 96 | .where(containsKey("features_keys", bindMarker("feature")))); |
| 100 | 97 | |
| 101 | - ResultSet results = session.execute(byFeatures.bind().setString("feature", "refresh-rate")); | |
| 98 | + ResultSet results = session().execute(byFeatures.bind().setString("feature", "refresh-rate")); | |
| 102 | 99 | |
| 103 | 100 | Row row = results.one(); |
| 104 | 101 | assertThat(row).isNotNull(); |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderExecutionTest.java +34 −31
| @@ -18,7 +18,10 @@ | ||
| 18 | 18 | import com.datastax.driver.core.*; |
| 19 | 19 | import org.testng.annotations.Test; |
| 20 | 20 | |
| 21 | -import java.util.*; | |
| 21 | +import java.util.Date; | |
| 22 | +import java.util.List; | |
| 23 | +import java.util.Map; | |
| 24 | +import java.util.Set; | |
| 22 | 25 | |
| 23 | 26 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 24 | 27 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -30,8 +33,8 @@ | ||
| 30 | 33 | private static final String TABLE1 = "test1"; |
| 31 | 34 | |
| 32 | 35 | @Override |
| 33 | - public Collection<String> createTestFixtures() { | |
| 34 | - return Arrays.asList( | |
| 36 | + public void onTestContextInitialized() { | |
| 37 | + execute( | |
| 35 | 38 | String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", TABLE1), |
| 36 | 39 | "CREATE TABLE dateTest (t timestamp PRIMARY KEY)", |
| 37 | 40 | "CREATE TABLE test_coll (k int PRIMARY KEY, a list<int>, b map<int,text>, c set<text>)"); |
| @@ -40,10 +43,10 @@ | ||
| 40 | 43 | @Test(groups = "short") |
| 41 | 44 | public void executeTest() throws Exception { |
| 42 | 45 | |
| 43 | - session.execute(insertInto(TABLE1).value("k", "k1").value("t", "This is a test").value("i", 3).value("f", 0.42)); | |
| 44 | - session.execute(update(TABLE1).with(set("t", "Another test")).where(eq("k", "k2"))); | |
| 46 | + session().execute(insertInto(TABLE1).value("k", "k1").value("t", "This is a test").value("i", 3).value("f", 0.42)); | |
| 47 | + session().execute(update(TABLE1).with(set("t", "Another test")).where(eq("k", "k2"))); | |
| 45 | 48 | |
| 46 | - List<Row> rows = session.execute(select().from(TABLE1).where(in("k", "k1", "k2"))).all(); | |
| 49 | + List<Row> rows = session().execute(select().from(TABLE1).where(in("k", "k1", "k2"))).all(); | |
| 47 | 50 | |
| 48 | 51 | assertEquals(2, rows.size()); |
| 49 | 52 | |
| @@ -64,9 +67,9 @@ | ||
| 64 | 67 | public void dateHandlingTest() throws Exception { |
| 65 | 68 | |
| 66 | 69 | Date d = new Date(); |
| 67 | - session.execute(insertInto("dateTest").value("t", d)); | |
| 70 | + session().execute(insertInto("dateTest").value("t", d)); | |
| 68 | 71 | String query = select().from("dateTest").where(eq(token("t"), fcall("token", d))).toString(); |
| 69 | - List<Row> rows = session.execute(query).all(); | |
| 72 | + List<Row> rows = session().execute(query).all(); | |
| 70 | 73 | |
| 71 | 74 | assertEquals(1, rows.size()); |
| 72 | 75 | |
| @@ -90,9 +93,9 @@ | ||
| 90 | 93 | public void batchNonBuiltStatementTest() throws Exception { |
| 91 | 94 | SimpleStatement simple = new SimpleStatement("INSERT INTO " + TABLE1 + " (k, t) VALUES ('batchTest1', 'val1')"); |
| 92 | 95 | RegularStatement built = insertInto(TABLE1).value("k", "batchTest2").value("t", "val2"); |
| 93 | - session.execute(batch().add(simple).add(built)); | |
| 96 | + session().execute(batch().add(simple).add(built)); | |
| 94 | 97 | |
| 95 | - List<Row> rows = session.execute(select().from(TABLE1).where(in("k", "batchTest1", "batchTest2"))).all(); | |
| 98 | + List<Row> rows = session().execute(select().from(TABLE1).where(in("k", "batchTest1", "batchTest2"))).all(); | |
| 96 | 99 | assertEquals(2, rows.size()); |
| 97 | 100 | |
| 98 | 101 | Row r1 = rows.get(0); |
| @@ -107,75 +110,75 @@ | ||
| 107 | 110 | @Test(groups = "short") |
| 108 | 111 | public void should_delete_list_element() throws Exception { |
| 109 | 112 | //given |
| 110 | - session.execute("INSERT INTO test_coll (k, a, b) VALUES (1, [1,2,3], null)"); | |
| 113 | + session().execute("INSERT INTO test_coll (k, a, b) VALUES (1, [1,2,3], null)"); | |
| 111 | 114 | //when |
| 112 | 115 | BuiltStatement statement = delete().listElt("a", 1).from("test_coll").where(eq("k", 1)); |
| 113 | - session.execute(statement); | |
| 116 | + session().execute(statement); | |
| 114 | 117 | //then |
| 115 | - List<Integer> actual = session.execute("SELECT a FROM test_coll WHERE k = 1").one().getList("a", Integer.class); | |
| 118 | + List<Integer> actual = session().execute("SELECT a FROM test_coll WHERE k = 1").one().getList("a", Integer.class); | |
| 116 | 119 | assertThat(actual).containsExactly(1, 3); |
| 117 | 120 | } |
| 118 | 121 | |
| 119 | 122 | @Test(groups = "short") |
| 120 | 123 | public void should_delete_list_element_with_bind_marker() throws Exception { |
| 121 | 124 | //given |
| 122 | - session.execute("INSERT INTO test_coll (k, a) VALUES (1, [1,2,3])"); | |
| 125 | + session().execute("INSERT INTO test_coll (k, a) VALUES (1, [1,2,3])"); | |
| 123 | 126 | //when |
| 124 | 127 | BuiltStatement statement = delete().listElt("a", bindMarker()).from("test_coll").where(eq("k", 1)); |
| 125 | - PreparedStatement ps = session.prepare(statement); | |
| 126 | - session.execute(ps.bind(1)); | |
| 128 | + PreparedStatement ps = session().prepare(statement); | |
| 129 | + session().execute(ps.bind(1)); | |
| 127 | 130 | //then |
| 128 | - List<Integer> actual = session.execute("SELECT a FROM test_coll WHERE k = 1").one().getList("a", Integer.class); | |
| 131 | + List<Integer> actual = session().execute("SELECT a FROM test_coll WHERE k = 1").one().getList("a", Integer.class); | |
| 129 | 132 | assertThat(actual).containsExactly(1, 3); |
| 130 | 133 | } |
| 131 | 134 | |
| 132 | 135 | @Test(groups = "short") |
| 133 | 136 | public void should_delete_set_element() throws Exception { |
| 134 | 137 | //given |
| 135 | - session.execute("INSERT INTO test_coll (k, c) VALUES (1, {'foo','bar','qix'})"); | |
| 138 | + session().execute("INSERT INTO test_coll (k, c) VALUES (1, {'foo','bar','qix'})"); | |
| 136 | 139 | //when |
| 137 | 140 | BuiltStatement statement = delete().setElt("c", "foo").from("test_coll").where(eq("k", 1)); |
| 138 | - session.execute(statement); | |
| 141 | + session().execute(statement); | |
| 139 | 142 | //then |
| 140 | - Set<String> actual = session.execute("SELECT c FROM test_coll WHERE k = 1").one().getSet("c", String.class); | |
| 143 | + Set<String> actual = session().execute("SELECT c FROM test_coll WHERE k = 1").one().getSet("c", String.class); | |
| 141 | 144 | assertThat(actual).containsOnly("bar", "qix"); |
| 142 | 145 | } |
| 143 | 146 | |
| 144 | 147 | @Test(groups = "short") |
| 145 | 148 | public void should_delete_set_element_with_bind_marker() throws Exception { |
| 146 | 149 | //given |
| 147 | - session.execute("INSERT INTO test_coll (k, c) VALUES (1, {'foo','bar','qix'})"); | |
| 150 | + session().execute("INSERT INTO test_coll (k, c) VALUES (1, {'foo','bar','qix'})"); | |
| 148 | 151 | //when |
| 149 | 152 | BuiltStatement statement = delete().setElt("c", bindMarker()).from("test_coll").where(eq("k", 1)); |
| 150 | - PreparedStatement ps = session.prepare(statement); | |
| 151 | - session.execute(ps.bind("foo")); | |
| 153 | + PreparedStatement ps = session().prepare(statement); | |
| 154 | + session().execute(ps.bind("foo")); | |
| 152 | 155 | //then |
| 153 | - Set<String> actual = session.execute("SELECT c FROM test_coll WHERE k = 1").one().getSet("c", String.class); | |
| 156 | + Set<String> actual = session().execute("SELECT c FROM test_coll WHERE k = 1").one().getSet("c", String.class); | |
| 154 | 157 | assertThat(actual).containsOnly("bar", "qix"); |
| 155 | 158 | } |
| 156 | 159 | |
| 157 | 160 | @Test(groups = "short") |
| 158 | 161 | public void should_delete_map_entry() throws Exception { |
| 159 | 162 | //given |
| 160 | - session.execute("INSERT INTO test_coll (k, b) VALUES (1, {1:'foo', 2:'bar'})"); | |
| 163 | + session().execute("INSERT INTO test_coll (k, b) VALUES (1, {1:'foo', 2:'bar'})"); | |
| 161 | 164 | //when |
| 162 | 165 | BuiltStatement statement = delete().mapElt("b", 1).from("test_coll").where(eq("k", 1)); |
| 163 | - session.execute(statement); | |
| 166 | + session().execute(statement); | |
| 164 | 167 | //then |
| 165 | - Map<Integer, String> actual = session.execute("SELECT b FROM test_coll WHERE k = 1").one().getMap("b", Integer.class, String.class); | |
| 168 | + Map<Integer, String> actual = session().execute("SELECT b FROM test_coll WHERE k = 1").one().getMap("b", Integer.class, String.class); | |
| 166 | 169 | assertThat(actual).containsExactly(entry(2, "bar")); |
| 167 | 170 | } |
| 168 | 171 | |
| 169 | 172 | @Test(groups = "short") |
| 170 | 173 | public void should_delete_map_entry_with_bind_marker() throws Exception { |
| 171 | 174 | //given |
| 172 | - session.execute("INSERT INTO test_coll (k, a, b) VALUES (1, null, {1:'foo', 2:'bar'})"); | |
| 175 | + session().execute("INSERT INTO test_coll (k, a, b) VALUES (1, null, {1:'foo', 2:'bar'})"); | |
| 173 | 176 | //when |
| 174 | 177 | BuiltStatement statement = delete().mapElt("b", bindMarker()).from("test_coll").where(eq("k", 1)); |
| 175 | - PreparedStatement ps = session.prepare(statement); | |
| 176 | - session.execute(ps.bind().setInt(0, 1)); | |
| 178 | + PreparedStatement ps = session().prepare(statement); | |
| 179 | + session().execute(ps.bind().setInt(0, 1)); | |
| 177 | 180 | //then |
| 178 | - Map<Integer, String> actual = session.execute("SELECT b FROM test_coll WHERE k = 1").one().getMap("b", Integer.class, String.class); | |
| 181 | + Map<Integer, String> actual = session().execute("SELECT b FROM test_coll WHERE k = 1").one().getMap("b", Integer.class, String.class); | |
| 179 | 182 | assertThat(actual).containsExactly(entry(2, "bar")); |
| 180 | 183 | } |
| 181 | 184 |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderITest.java +22 −23
| @@ -21,7 +21,6 @@ | ||
| 21 | 21 | import org.testng.annotations.Test; |
| 22 | 22 | |
| 23 | 23 | import java.util.Arrays; |
| 24 | -import java.util.Collection; | |
| 25 | 24 | import java.util.TreeSet; |
| 26 | 25 | |
| 27 | 26 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| @@ -34,8 +33,8 @@ | ||
| 34 | 33 | private static final String TABLE_INT = "test_int"; |
| 35 | 34 | |
| 36 | 35 | @Override |
| 37 | - public Collection<String> createTestFixtures() { | |
| 38 | - return Arrays.asList(String.format("CREATE TABLE %s (k text PRIMARY KEY, a int, b int)", TABLE_TEXT), | |
| 36 | + public void onTestContextInitialized() { | |
| 37 | + execute(String.format("CREATE TABLE %s (k text PRIMARY KEY, a int, b int)", TABLE_TEXT), | |
| 39 | 38 | String.format("CREATE TABLE %s (k int PRIMARY KEY, a int, b int)", TABLE_INT)); |
| 40 | 39 | } |
| 41 | 40 | |
| @@ -43,14 +42,14 @@ | ||
| 43 | 42 | public void remainingDeleteTests() throws Exception { |
| 44 | 43 | |
| 45 | 44 | Statement query; |
| 46 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable(TABLE_TEXT); | |
| 45 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable(TABLE_TEXT); | |
| 47 | 46 | assertNotNull(table); |
| 48 | 47 | |
| 49 | 48 | String expected = String.format("DELETE k FROM %s.test_text;", keyspace); |
| 50 | 49 | query = delete("k").from(table); |
| 51 | 50 | assertEquals(query.toString(), expected); |
| 52 | 51 | try { |
| 53 | - session.execute(query); | |
| 52 | + session().execute(query); | |
| 54 | 53 | fail(); |
| 55 | 54 | } catch (SyntaxError e) { |
| 56 | 55 | // Missing WHERE clause |
| @@ -65,16 +64,16 @@ | ||
| 65 | 64 | PreparedStatement ps; |
| 66 | 65 | BoundStatement bs; |
| 67 | 66 | |
| 68 | - session.execute("CREATE KEYSPACE foo WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};"); | |
| 69 | - session.execute("CREATE TABLE foo.foo ( k ascii PRIMARY KEY , i int, s ascii )"); | |
| 70 | - session.execute("USE foo"); | |
| 67 | + session().execute("CREATE KEYSPACE foo WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};"); | |
| 68 | + session().execute("CREATE TABLE foo.foo ( k ascii PRIMARY KEY , i int, s ascii )"); | |
| 69 | + session().execute("USE foo"); | |
| 71 | 70 | |
| 72 | 71 | query = "SELECT * FROM foo WHERE k=?;"; |
| 73 | 72 | select = select().all().from("foo").where(eq("k", QueryBuilder.bindMarker())); |
| 74 | - ps = session.prepare(select.toString()); | |
| 73 | + ps = session().prepare(select.toString()); | |
| 75 | 74 | bs = ps.bind(); |
| 76 | 75 | assertEquals(select.toString(), query); |
| 77 | - session.execute(bs.setString("k", "4 AND c=5")); | |
| 76 | + session().execute(bs.setString("k", "4 AND c=5")); | |
| 78 | 77 | |
| 79 | 78 | query = "SELECT * FROM foo WHERE k='4'' AND c=''5';"; |
| 80 | 79 | select = select().all().from("foo").where(eq("k", "4' AND c='5")); |
| @@ -211,58 +210,58 @@ | ||
| 211 | 210 | @Test(groups = "short") |
| 212 | 211 | @CassandraVersion(major = 2.0, minor = 7, description = "DELETE..IF EXISTS only supported in 2.0.7+ (CASSANDRA-5708)") |
| 213 | 212 | public void conditionalDeletesTest() throws Exception { |
| 214 | - session.execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)", keyspace)); | |
| 213 | + session().execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)", keyspace)); | |
| 215 | 214 | |
| 216 | 215 | Statement delete; |
| 217 | 216 | Row row; |
| 218 | 217 | delete = delete().from(keyspace, TABLE_INT).where(eq("k", 2)).ifExists(); |
| 219 | - row = session.execute(delete).one(); | |
| 218 | + row = session().execute(delete).one(); | |
| 220 | 219 | assertFalse(row.getBool("[applied]")); |
| 221 | 220 | |
| 222 | 221 | delete = delete().from(keyspace, TABLE_INT).where(eq("k", 1)).ifExists(); |
| 223 | - row = session.execute(delete).one(); | |
| 222 | + row = session().execute(delete).one(); | |
| 224 | 223 | assertTrue(row.getBool("[applied]")); |
| 225 | 224 | |
| 226 | - session.execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)", keyspace)); | |
| 225 | + session().execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)", keyspace)); | |
| 227 | 226 | |
| 228 | 227 | delete = delete().from(keyspace, TABLE_INT).where(eq("k", 1)).onlyIf(eq("a", 1)).and(eq("b", 2)); |
| 229 | - row = session.execute(delete).one(); | |
| 228 | + row = session().execute(delete).one(); | |
| 230 | 229 | assertFalse(row.getBool("[applied]")); |
| 231 | 230 | |
| 232 | 231 | delete = delete().from(keyspace, TABLE_INT).where(eq("k", 1)).onlyIf(eq("a", 1)).and(eq("b", 1)); |
| 233 | - row = session.execute(delete).one(); | |
| 232 | + row = session().execute(delete).one(); | |
| 234 | 233 | assertTrue(row.getBool("[applied]")); |
| 235 | 234 | } |
| 236 | 235 | |
| 237 | 236 | @Test(groups = "short") |
| 238 | 237 | @CassandraVersion(major = 2.0, minor = 13, description = "Allow IF EXISTS for UPDATE statements (CASSANDRA-8610)") |
| 239 | 238 | public void conditionalUpdatesTest() throws Exception { |
| 240 | - session.execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)", keyspace)); | |
| 239 | + session().execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)", keyspace)); | |
| 241 | 240 | |
| 242 | 241 | Statement update; |
| 243 | 242 | Row row; |
| 244 | 243 | update = update(TABLE_INT).with(set("a", 2)).and(set("b", 2)).where(eq("k", 2)).ifExists(); |
| 245 | - row = session.execute(update).one(); | |
| 244 | + row = session().execute(update).one(); | |
| 246 | 245 | assertFalse(row.getBool("[applied]")); |
| 247 | 246 | |
| 248 | 247 | update = update(TABLE_INT).with(set("a", 2)).and(set("b", 2)).where(eq("k", 1)).ifExists(); |
| 249 | - row = session.execute(update).one(); | |
| 248 | + row = session().execute(update).one(); | |
| 250 | 249 | assertTrue(row.getBool("[applied]")); |
| 251 | 250 | |
| 252 | 251 | update = update(TABLE_INT).with(set("a", 2)).and(set("b", 2)).where(eq("k", 2)).onlyIf(eq("a", 1)).and(eq("b", 2)); |
| 253 | - row = session.execute(update).one(); | |
| 252 | + row = session().execute(update).one(); | |
| 254 | 253 | assertFalse(row.getBool("[applied]")); |
| 255 | 254 | |
| 256 | 255 | update = update(TABLE_INT).with(set("a", 3)).and(set("b", 3)).where(eq("k", 1)).onlyIf(eq("a", 2)).and(eq("b", 2)); |
| 257 | - row = session.execute(update).one(); | |
| 256 | + row = session().execute(update).one(); | |
| 258 | 257 | assertTrue(row.getBool("[applied]")); |
| 259 | 258 | |
| 260 | 259 | update = update(TABLE_INT).with(set("a", 4)).and(set("b", 4)).onlyIf(eq("a", 2)).and(eq("b", 2)).where(eq("k", 1)); |
| 261 | - row = session.execute(update).one(); | |
| 260 | + row = session().execute(update).one(); | |
| 262 | 261 | assertFalse(row.getBool("[applied]")); |
| 263 | 262 | |
| 264 | 263 | update = update(TABLE_INT).with(set("a", 4)).and(set("b", 4)).onlyIf(eq("a", 3)).and(eq("b", 3)).where(eq("k", 1)); |
| 265 | - row = session.execute(update).one(); | |
| 264 | + row = session().execute(update).one(); | |
| 266 | 265 | assertTrue(row.getBool("[applied]")); |
| 267 | 266 | } |
| 268 | 267 | } |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderRoutingKeyTest.java +16 −18
| @@ -19,8 +19,6 @@ | ||
| 19 | 19 | import org.testng.annotations.Test; |
| 20 | 20 | |
| 21 | 21 | import java.nio.ByteBuffer; |
| 22 | -import java.util.Arrays; | |
| 23 | -import java.util.Collection; | |
| 24 | 22 | |
| 25 | 23 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 26 | 24 | import static org.testng.Assert.assertEquals; |
| @@ -33,8 +31,8 @@ | ||
| 33 | 31 | private static final String TABLE_INT = "test_int"; |
| 34 | 32 | |
| 35 | 33 | @Override |
| 36 | - public Collection<String> createTestFixtures() { | |
| 37 | - return Arrays.asList(String.format("CREATE TABLE %s (k text PRIMARY KEY, a int, b int)", TABLE_TEXT), | |
| 34 | + public void onTestContextInitialized() { | |
| 35 | + execute(String.format("CREATE TABLE %s (k text PRIMARY KEY, a int, b int)", TABLE_TEXT), | |
| 38 | 36 | String.format("CREATE TABLE %s (k int PRIMARY KEY, a int, b int)", TABLE_INT)); |
| 39 | 37 | } |
| 40 | 38 | |
| @@ -42,19 +40,19 @@ | ||
| 42 | 40 | public void textRoutingKeyTest() throws Exception { |
| 43 | 41 | |
| 44 | 42 | BuiltStatement query; |
| 45 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable(TABLE_TEXT); | |
| 43 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable(TABLE_TEXT); | |
| 46 | 44 | assertNotNull(table); |
| 47 | - ProtocolVersion protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 45 | + ProtocolVersion protocolVersion = cluster().getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 48 | 46 | CodecRegistry codecRegistry = CodecRegistry.DEFAULT_INSTANCE; |
| 49 | 47 | |
| 50 | 48 | String txt = "If she weighs the same as a duck... she's made of wood."; |
| 51 | 49 | query = insertInto(table).values(new String[]{"k", "a", "b"}, new Object[]{txt, 1, 2}); |
| 52 | 50 | assertEquals(query.getRoutingKey(protocolVersion, codecRegistry), ByteBuffer.wrap(txt.getBytes())); |
| 53 | - session.execute(query); | |
| 51 | + session().execute(query); | |
| 54 | 52 | |
| 55 | 53 | query = select().from(table).where(eq("k", txt)); |
| 56 | 54 | assertEquals(query.getRoutingKey(protocolVersion, codecRegistry), ByteBuffer.wrap(txt.getBytes())); |
| 57 | - Row row = session.execute(query).one(); | |
| 55 | + Row row = session().execute(query).one(); | |
| 58 | 56 | assertEquals(row.getString("k"), txt); |
| 59 | 57 | assertEquals(row.getInt("a"), 1); |
| 60 | 58 | assertEquals(row.getInt("b"), 2); |
| @@ -64,20 +62,20 @@ | ||
| 64 | 62 | public void intRoutingKeyTest() throws Exception { |
| 65 | 63 | |
| 66 | 64 | BuiltStatement query; |
| 67 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable(TABLE_INT); | |
| 65 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable(TABLE_INT); | |
| 68 | 66 | assertNotNull(table); |
| 69 | - ProtocolVersion protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 67 | + ProtocolVersion protocolVersion = cluster().getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 70 | 68 | CodecRegistry codecRegistry = CodecRegistry.DEFAULT_INSTANCE; |
| 71 | 69 | |
| 72 | 70 | query = insertInto(table).values(new String[]{"k", "a", "b"}, new Object[]{42, 1, 2}); |
| 73 | 71 | ByteBuffer bb = ByteBuffer.allocate(4); |
| 74 | 72 | bb.putInt(0, 42); |
| 75 | 73 | assertEquals(query.getRoutingKey(protocolVersion, codecRegistry), bb); |
| 76 | - session.execute(query); | |
| 74 | + session().execute(query); | |
| 77 | 75 | |
| 78 | 76 | query = select().from(table).where(eq("k", 42)); |
| 79 | 77 | assertEquals(query.getRoutingKey(protocolVersion, codecRegistry), bb); |
| 80 | - Row row = session.execute(query).one(); | |
| 78 | + Row row = session().execute(query).one(); | |
| 81 | 79 | assertEquals(row.getInt("k"), 42); |
| 82 | 80 | assertEquals(row.getInt("a"), 1); |
| 83 | 81 | assertEquals(row.getInt("b"), 2); |
| @@ -87,9 +85,9 @@ | ||
| 87 | 85 | public void intRoutingBatchKeyTest() throws Exception { |
| 88 | 86 | |
| 89 | 87 | BuiltStatement query; |
| 90 | - TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable(TABLE_INT); | |
| 88 | + TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable(TABLE_INT); | |
| 91 | 89 | assertNotNull(table); |
| 92 | - ProtocolVersion protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 90 | + ProtocolVersion protocolVersion = cluster().getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 93 | 91 | CodecRegistry codecRegistry = CodecRegistry.DEFAULT_INSTANCE; |
| 94 | 92 | |
| 95 | 93 | ByteBuffer bb = ByteBuffer.allocate(4); |
| @@ -109,7 +107,7 @@ | ||
| 109 | 107 | .add(update(table).using(ttl(400))); |
| 110 | 108 | assertEquals(batch.getRoutingKey(protocolVersion, codecRegistry), bb); |
| 111 | 109 | assertEquals(batch.toString(), batch_query); |
| 112 | - // TODO: rs = session.execute(batch); // Not guaranteed to be valid CQL | |
| 110 | + // TODO: rs = session().execute(batch); // Not guaranteed to be valid CQL | |
| 113 | 111 | |
| 114 | 112 | batch_query = "BEGIN BATCH "; |
| 115 | 113 | batch_query += String.format("SELECT * FROM %s.test_int WHERE k=42;", keyspace); |
| @@ -117,7 +115,7 @@ | ||
| 117 | 115 | batch = batch(query); |
| 118 | 116 | assertEquals(batch.getRoutingKey(protocolVersion, codecRegistry), bb); |
| 119 | 117 | assertEquals(batch.toString(), batch_query); |
| 120 | - // TODO: rs = session.execute(batch); // Not guaranteed to be valid CQL | |
| 118 | + // TODO: rs = session().execute(batch); // Not guaranteed to be valid CQL | |
| 121 | 119 | |
| 122 | 120 | batch_query = "BEGIN BATCH "; |
| 123 | 121 | batch_query += "SELECT * FROM foo WHERE k=42;"; |
| @@ -125,7 +123,7 @@ | ||
| 125 | 123 | batch = batch().add(select().from("foo").where(eq("k", 42))); |
| 126 | 124 | assertEquals(batch.getRoutingKey(protocolVersion, codecRegistry), null); |
| 127 | 125 | assertEquals(batch.toString(), batch_query); |
| 128 | - // TODO: rs = session.execute(batch); // Not guaranteed to be valid CQL | |
| 126 | + // TODO: rs = session().execute(batch); // Not guaranteed to be valid CQL | |
| 129 | 127 | |
| 130 | 128 | batch_query = "BEGIN BATCH USING TIMESTAMP 42 "; |
| 131 | 129 | batch_query += "INSERT INTO foo.bar (a) VALUES (123);"; |
| @@ -133,6 +131,6 @@ | ||
| 133 | 131 | batch = batch().using(timestamp(42)).add(insertInto("foo", "bar").value("a", 123)); |
| 134 | 132 | assertEquals(batch.getRoutingKey(protocolVersion, codecRegistry), null); |
| 135 | 133 | assertEquals(batch.toString(), batch_query); |
| 136 | - // TODO: rs = session.execute(batch); // Not guaranteed to be valid CQL | |
| 134 | + // TODO: rs = session().execute(batch); // Not guaranteed to be valid CQL | |
| 137 | 135 | } |
| 138 | 136 | } |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTupleExecutionTest.java +2 −2
| @@ -35,7 +35,7 @@ | ||
| 35 | 35 | @Test(groups = "short") |
| 36 | 36 | public void should_handle_tuple() throws Exception { |
| 37 | 37 | String query = "INSERT INTO foo (k,x) VALUES (0,(1));"; |
| 38 | - TupleType tupleType = cluster.getMetadata().newTupleType(cint()); | |
| 38 | + TupleType tupleType = cluster().getMetadata().newTupleType(cint()); | |
| 39 | 39 | BuiltStatement insert = insertInto("foo").value("k", 0).value("x", tupleType.newValue(1)); |
| 40 | 40 | assertEquals(insert.toString(), query); |
| 41 | 41 | } |
| @@ -46,7 +46,7 @@ | ||
| 46 | 46 | String query; |
| 47 | 47 | BuiltStatement statement; |
| 48 | 48 | query = "UPDATE foo SET l=[(1,2)] WHERE k=1;"; |
| 49 | - TupleType tupleType = cluster.getMetadata().newTupleType(cint(), cint()); | |
| 49 | + TupleType tupleType = cluster().getMetadata().newTupleType(cint(), cint()); | |
| 50 | 50 | List<TupleValue> list = ImmutableList.of(tupleType.newValue(1, 2)); |
| 51 | 51 | statement = update("foo").with(set("l", list)).where(eq("k", 1)); |
| 52 | 52 | assertThat(statement.toString()).isEqualTo(query); |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderUDTExecutionTest.java +10 −12
| @@ -22,8 +22,6 @@ | ||
| 22 | 22 | import org.testng.annotations.Test; |
| 23 | 23 | |
| 24 | 24 | import java.net.InetAddress; |
| 25 | -import java.util.Arrays; | |
| 26 | -import java.util.Collection; | |
| 27 | 25 | import java.util.List; |
| 28 | 26 | import java.util.Map; |
| 29 | 27 | |
| @@ -35,22 +33,22 @@ | ||
| 35 | 33 | public class QueryBuilderUDTExecutionTest extends CCMTestsSupport { |
| 36 | 34 | |
| 37 | 35 | @Override |
| 38 | - public Collection<String> createTestFixtures() { | |
| 39 | - return Arrays.asList("CREATE TYPE udt (i int, a inet)", | |
| 36 | + public void onTestContextInitialized() { | |
| 37 | + execute("CREATE TYPE udt (i int, a inet)", | |
| 40 | 38 | "CREATE TABLE udtTest(k int PRIMARY KEY, t frozen<udt>, l list<frozen<udt>>, m map<int, frozen<udt>>)"); |
| 41 | 39 | } |
| 42 | 40 | |
| 43 | 41 | @Test(groups = "short") |
| 44 | 42 | public void insertUdtTest() throws Exception { |
| 45 | - UserType udtType = cluster.getMetadata().getKeyspace(keyspace).getUserType("udt"); | |
| 43 | + UserType udtType = cluster().getMetadata().getKeyspace(keyspace).getUserType("udt"); | |
| 46 | 44 | UDTValue udtValue = udtType.newValue().setInt("i", 2).setInet("a", InetAddress.getByName("localhost")); |
| 47 | 45 | |
| 48 | 46 | Statement insert = insertInto("udtTest").value("k", 1).value("t", udtValue); |
| 49 | 47 | assertEquals(insert.toString(), "INSERT INTO udtTest (k,t) VALUES (1,{i:2,a:'127.0.0.1'});"); |
| 50 | 48 | |
| 51 | - session.execute(insert); | |
| 49 | + session().execute(insert); | |
| 52 | 50 | |
| 53 | - List<Row> rows = session.execute(select().from("udtTest").where(eq("k", 1))).all(); | |
| 51 | + List<Row> rows = session().execute(select().from("udtTest").where(eq("k", 1))).all(); | |
| 54 | 52 | |
| 55 | 53 | assertEquals(rows.size(), 1); |
| 56 | 54 | |
| @@ -60,16 +58,16 @@ | ||
| 60 | 58 | |
| 61 | 59 | @Test(groups = "short") |
| 62 | 60 | public void should_handle_collections_of_UDT() throws Exception { |
| 63 | - UserType udtType = cluster.getMetadata().getKeyspace(keyspace).getUserType("udt"); | |
| 61 | + UserType udtType = cluster().getMetadata().getKeyspace(keyspace).getUserType("udt"); | |
| 64 | 62 | UDTValue udtValue = udtType.newValue().setInt("i", 2).setInet("a", InetAddress.getByName("localhost")); |
| 65 | 63 | UDTValue udtValue2 = udtType.newValue().setInt("i", 3).setInet("a", InetAddress.getByName("localhost")); |
| 66 | 64 | |
| 67 | 65 | Statement insert = insertInto("udtTest").value("k", 1).value("l", ImmutableList.of(udtValue)); |
| 68 | 66 | assertThat(insert.toString()).isEqualTo("INSERT INTO udtTest (k,l) VALUES (1,[{i:2,a:'127.0.0.1'}]);"); |
| 69 | 67 | |
| 70 | - session.execute(insert); | |
| 68 | + session().execute(insert); | |
| 71 | 69 | |
| 72 | - List<Row> rows = session.execute(select().from("udtTest").where(eq("k", 1))).all(); | |
| 70 | + List<Row> rows = session().execute(select().from("udtTest").where(eq("k", 1))).all(); | |
| 73 | 71 | |
| 74 | 72 | assertThat(rows.size()).isEqualTo(1); |
| 75 | 73 | |
| @@ -83,9 +81,9 @@ | ||
| 83 | 81 | assertThat(updateMap.toString()) |
| 84 | 82 | .isEqualTo("UPDATE udtTest SET m=m+{0:{i:2,a:'127.0.0.1'},2:{i:3,a:'127.0.0.1'}} WHERE k=1;"); |
| 85 | 83 | |
| 86 | - session.execute(updateMap); | |
| 84 | + session().execute(updateMap); | |
| 87 | 85 | |
| 88 | - rows = session.execute(select().from("udtTest").where(eq("k", 1))).all(); | |
| 86 | + rows = session().execute(select().from("udtTest").where(eq("k", 1))).all(); | |
| 89 | 87 | r1 = rows.get(0); |
| 90 | 88 | assertThat(r1.getMap("m", Integer.class, UDTValue.class)).isEqualTo(map); |
| 91 | 89 | } |
modified driver-core/src/test/java/com/datastax/driver/core/schemabuilder/SchemaBuilderIT.java +22 −22
| @@ -35,7 +35,7 @@ | ||
| 35 | 35 | @CassandraVersion(major = 2.1, minor = 2) |
| 36 | 36 | public void should_modify_table_metadata() { |
| 37 | 37 | // Create a table |
| 38 | - session.execute(SchemaBuilder.createTable("ks", "TableMetadata") | |
| 38 | + session().execute(SchemaBuilder.createTable("ks", "TableMetadata") | |
| 39 | 39 | .addPartitionKey("a", DataType.cint()) |
| 40 | 40 | .addPartitionKey("b", DataType.cint()) |
| 41 | 41 | .addClusteringColumn("c", DataType.cint()) |
| @@ -45,7 +45,7 @@ | ||
| 45 | 45 | ); |
| 46 | 46 | |
| 47 | 47 | // Modify the table metadata |
| 48 | - session.execute(SchemaBuilder.alterTable("TableMetadata") | |
| 48 | + session().execute(SchemaBuilder.alterTable("TableMetadata") | |
| 49 | 49 | .withOptions() |
| 50 | 50 | .defaultTimeToLive(1337) |
| 51 | 51 | .bloomFilterFPChance(0.42) |
| @@ -68,7 +68,7 @@ | ||
| 68 | 68 | .compressionOptions(snappy())); |
| 69 | 69 | |
| 70 | 70 | // Retrieve the metadata from Cassandra |
| 71 | - ResultSet rows = session.execute("SELECT " | |
| 71 | + ResultSet rows = session().execute("SELECT " | |
| 72 | 72 | + "bloom_filter_fp_chance, " |
| 73 | 73 | + "caching, " |
| 74 | 74 | + "cf_id, " |
| @@ -131,12 +131,12 @@ | ||
| 131 | 131 | @CassandraVersion(major = 2.1) |
| 132 | 132 | public void should_create_a_table_and_a_udt() { |
| 133 | 133 | // Create a UDT and a table |
| 134 | - session.execute(SchemaBuilder.createType("MyUDT") | |
| 134 | + session().execute(SchemaBuilder.createType("MyUDT") | |
| 135 | 135 | .ifNotExists() |
| 136 | 136 | .addColumn("x", DataType.cint()) |
| 137 | 137 | ); |
| 138 | 138 | UDTType myUDT = UDTType.frozen("MyUDT"); |
| 139 | - session.execute(SchemaBuilder.createTable("ks", "CreateTable") | |
| 139 | + session().execute(SchemaBuilder.createTable("ks", "CreateTable") | |
| 140 | 140 | .ifNotExists() |
| 141 | 141 | .addPartitionKey("a", DataType.cint()) |
| 142 | 142 | .addUDTPartitionKey("b", myUDT) |
| @@ -152,7 +152,7 @@ | ||
| 152 | 152 | ); |
| 153 | 153 | |
| 154 | 154 | // Check columns a to k |
| 155 | - ResultSet rows = session.execute( | |
| 155 | + ResultSet rows = session().execute( | |
| 156 | 156 | "SELECT column_name, type, validator " |
| 157 | 157 | + "FROM system.schema_columns " |
| 158 | 158 | + "WHERE keyspace_name='ks' AND columnfamily_name='createtable'"); |
| @@ -177,22 +177,22 @@ | ||
| 177 | 177 | @Test(groups = "short") |
| 178 | 178 | public void should_add_and_drop_a_column() { |
| 179 | 179 | // Create a table, add a column to it with an alter table statement and delete that column |
| 180 | - session.execute(SchemaBuilder.createTable("ks", "DropColumn") | |
| 180 | + session().execute(SchemaBuilder.createTable("ks", "DropColumn") | |
| 181 | 181 | .ifNotExists() |
| 182 | 182 | .addPartitionKey("a", DataType.cint()) |
| 183 | 183 | ); |
| 184 | 184 | |
| 185 | 185 | // Add and then drop a column |
| 186 | - session.execute(SchemaBuilder.alterTable("ks", "DropColumn") | |
| 186 | + session().execute(SchemaBuilder.alterTable("ks", "DropColumn") | |
| 187 | 187 | .addColumn("b") |
| 188 | 188 | .type(DataType.cint()) |
| 189 | 189 | ); |
| 190 | - session.execute(SchemaBuilder.alterTable("ks", "DropColumn") | |
| 190 | + session().execute(SchemaBuilder.alterTable("ks", "DropColumn") | |
| 191 | 191 | .dropColumn("b") |
| 192 | 192 | ); |
| 193 | 193 | |
| 194 | 194 | // Check that only column a exist |
| 195 | - ResultSet rows = session.execute( | |
| 195 | + ResultSet rows = session().execute( | |
| 196 | 196 | "SELECT column_name, type, validator " |
| 197 | 197 | + "FROM system.schema_columns " |
| 198 | 198 | + "WHERE keyspace_name='ks' AND columnfamily_name='dropcolumn'"); |
| @@ -214,15 +214,15 @@ | ||
| 214 | 214 | @Test(groups = "short") |
| 215 | 215 | public void should_drop_a_table() { |
| 216 | 216 | // Create a table |
| 217 | - session.execute(SchemaBuilder.createTable("ks", "DropTable") | |
| 217 | + session().execute(SchemaBuilder.createTable("ks", "DropTable") | |
| 218 | 218 | .addPartitionKey("a", DataType.cint()) |
| 219 | 219 | ); |
| 220 | 220 | |
| 221 | 221 | // Drop the table |
| 222 | - session.execute(SchemaBuilder.dropTable("ks", "DropTable")); | |
| 223 | - session.execute(SchemaBuilder.dropTable("DropTable").ifExists()); | |
| 222 | + session().execute(SchemaBuilder.dropTable("ks", "DropTable")); | |
| 223 | + session().execute(SchemaBuilder.dropTable("DropTable").ifExists()); | |
| 224 | 224 | |
| 225 | - ResultSet rows = session.execute( | |
| 225 | + ResultSet rows = session().execute( | |
| 226 | 226 | "SELECT columnfamily_name " |
| 227 | 227 | + "FROM system.schema_columnfamilies " |
| 228 | 228 | + "WHERE keyspace_name='ks' AND columnfamily_name='droptable'"); |
| @@ -234,24 +234,24 @@ | ||
| 234 | 234 | @Test(groups = "short") |
| 235 | 235 | public void should_create_an_index() { |
| 236 | 236 | // Create a table |
| 237 | - session.execute(SchemaBuilder.createTable("ks", "CreateIndex") | |
| 237 | + session().execute(SchemaBuilder.createTable("ks", "CreateIndex") | |
| 238 | 238 | .addPartitionKey("a", DataType.cint()) |
| 239 | 239 | .addClusteringColumn("b", DataType.cint()) |
| 240 | 240 | .addColumn("c", DataType.map(DataType.cint(), DataType.cint())) |
| 241 | 241 | ); |
| 242 | 242 | |
| 243 | 243 | // Create an index on a regular column of the table |
| 244 | - session.execute(SchemaBuilder.createIndex("ks_Index") | |
| 244 | + session().execute(SchemaBuilder.createIndex("ks_Index") | |
| 245 | 245 | .onTable("ks", "CreateIndex") |
| 246 | 246 | .andColumn("b") |
| 247 | 247 | ); |
| 248 | - session.execute(SchemaBuilder.createIndex("ks_IndexOnMap") | |
| 248 | + session().execute(SchemaBuilder.createIndex("ks_IndexOnMap") | |
| 249 | 249 | .onTable("ks", "CreateIndex") |
| 250 | 250 | .andKeysOfColumn("c") |
| 251 | 251 | ); |
| 252 | 252 | |
| 253 | 253 | // Verify that the indexes exist on the right columns |
| 254 | - ResultSet rows = session.execute( | |
| 254 | + ResultSet rows = session().execute( | |
| 255 | 255 | "SELECT column_name, index_name, index_options, index_type, component_index " |
| 256 | 256 | + "FROM system.schema_columns " |
| 257 | 257 | + "WHERE keyspace_name='ks' " |
| @@ -275,7 +275,7 @@ | ||
| 275 | 275 | @Test(groups = "short") |
| 276 | 276 | public void should_drop_an_index() { |
| 277 | 277 | // Create a table |
| 278 | - session.execute(SchemaBuilder.createTable("ks", "DropIndex") | |
| 278 | + session().execute(SchemaBuilder.createTable("ks", "DropIndex") | |
| 279 | 279 | .addPartitionKey("a", DataType.cint()) |
| 280 | 280 | .addClusteringColumn("b", DataType.cint()) |
| 281 | 281 | ); |
| @@ -284,7 +284,7 @@ | ||
| 284 | 284 | // Note: we have to pick a lower-case name because Cassandra uses the CamelCase index name at creation |
| 285 | 285 | // but a lowercase index name at deletion |
| 286 | 286 | // See : https://issues.apache.org/jira/browse/CASSANDRA-8365 |
| 287 | - session.execute(SchemaBuilder.createIndex("ks_index") | |
| 287 | + session().execute(SchemaBuilder.createIndex("ks_index") | |
| 288 | 288 | .onTable("ks", "DropIndex") |
| 289 | 289 | .andColumn("b") |
| 290 | 290 | ); |
| @@ -293,14 +293,14 @@ | ||
| 293 | 293 | assertThat(numberOfIndexedColumns()).isEqualTo(1); |
| 294 | 294 | |
| 295 | 295 | // Delete the index |
| 296 | - session.execute(SchemaBuilder.dropIndex("ks", "ks_index")); | |
| 296 | + session().execute(SchemaBuilder.dropIndex("ks", "ks_index")); | |
| 297 | 297 | |
| 298 | 298 | // Verify that only the PK index exists |
| 299 | 299 | assertThat(numberOfIndexedColumns()).isEqualTo(0); |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | private int numberOfIndexedColumns() { |
| 303 | - ResultSet columns = session.execute( | |
| 303 | + ResultSet columns = session().execute( | |
| 304 | 304 | "SELECT * " |
| 305 | 305 | + "FROM system.schema_columns " |
| 306 | 306 | + "WHERE keyspace_name='ks' " |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/arrays/ArrayCodecsTest.java +7 −9
| @@ -21,12 +21,10 @@ | ||
| 21 | 21 | import com.datastax.driver.mapping.annotations.Column; |
| 22 | 22 | import com.datastax.driver.mapping.annotations.PartitionKey; |
| 23 | 23 | import com.datastax.driver.mapping.annotations.Table; |
| 24 | -import com.google.common.collect.Lists; | |
| 25 | 24 | import com.google.common.primitives.Primitives; |
| 26 | 25 | import org.testng.annotations.DataProvider; |
| 27 | 26 | import org.testng.annotations.Test; |
| 28 | 27 | |
| 29 | -import java.util.Collection; | |
| 30 | 28 | import java.util.List; |
| 31 | 29 | |
| 32 | 30 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -39,8 +37,8 @@ | ||
| 39 | 37 | TypeCodec.varchar()); |
| 40 | 38 | |
| 41 | 39 | @Override |
| 42 | - public Collection<String> createTestFixtures() { | |
| 43 | - return Lists.newArrayList( | |
| 40 | + public void onTestContextInitialized() { | |
| 41 | + execute( | |
| 44 | 42 | "CREATE TABLE lists (" |
| 45 | 43 | + "pk int PRIMARY KEY, " |
| 46 | 44 | + "l_int list<int>, " |
| @@ -95,19 +93,19 @@ | ||
| 95 | 93 | |
| 96 | 94 | @Test(groups = "short", dataProvider = "ArrayCodecsTest-serializing") |
| 97 | 95 | public <A> void should_read_list_column_as_array(String columnName, Class<A> arrayClass, A expected) { |
| 98 | - Row row = session.execute(String.format("SELECT %s FROM lists WHERE pk = 1", columnName)).one(); | |
| 96 | + Row row = session().execute(String.format("SELECT %s FROM lists WHERE pk = 1", columnName)).one(); | |
| 99 | 97 | A actual = row.get(columnName, arrayClass); |
| 100 | 98 | assertThat(actual).isEqualTo(expected); |
| 101 | 99 | } |
| 102 | 100 | |
| 103 | 101 | @Test(groups = "short", dataProvider = "ArrayCodecsTest-serializing") |
| 104 | 102 | public <A> void should_set_list_column_with_array(String columnName, Class<A> arrayClass, A expected) { |
| 105 | - PreparedStatement ps = session.prepare(String.format("INSERT INTO lists (pk, %s) VALUES (?, ?)", columnName)); | |
| 103 | + PreparedStatement ps = session().prepare(String.format("INSERT INTO lists (pk, %s) VALUES (?, ?)", columnName)); | |
| 106 | 104 | BoundStatement bs = ps.bind() |
| 107 | 105 | .setInt(0, 2) |
| 108 | 106 | .set(columnName, expected, arrayClass); |
| 109 | - session.execute(bs); | |
| 110 | - Row row = session.execute(String.format("SELECT %s FROM lists WHERE pk = 2", columnName)).one(); | |
| 107 | + session().execute(bs); | |
| 108 | + Row row = session().execute(String.format("SELECT %s FROM lists WHERE pk = 2", columnName)).one(); | |
| 111 | 109 | List<?> list = row.getList(columnName, Primitives.wrap(arrayClass.getComponentType())); |
| 112 | 110 | assertThat(list.toArray()).isEqualTo(expected); |
| 113 | 111 | } |
| @@ -131,7 +129,7 @@ | ||
| 131 | 129 | @Test(groups = "short") |
| 132 | 130 | public void should_use_mapper_to_store_and_retrieve_values_with_custom_joda_codecs() { |
| 133 | 131 | // given |
| 134 | - MappingManager manager = new MappingManager(session); | |
| 132 | + MappingManager manager = new MappingManager(session()); | |
| 135 | 133 | Mapper<Mapped> mapper = manager.mapper(Mapped.class); |
| 136 | 134 | // when |
| 137 | 135 | Mapped pojo = new Mapped(); |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/date/SimpleDateCodecsTest.java +13 −11
| @@ -26,7 +26,9 @@ | ||
| 26 | 26 | import org.testng.annotations.BeforeClass; |
| 27 | 27 | import org.testng.annotations.Test; |
| 28 | 28 | |
| 29 | -import java.util.*; | |
| 29 | +import java.util.Date; | |
| 30 | +import java.util.List; | |
| 31 | +import java.util.Map; | |
| 30 | 32 | |
| 31 | 33 | import static com.google.common.collect.Lists.newArrayList; |
| 32 | 34 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -35,8 +37,8 @@ | ||
| 35 | 37 | public class SimpleDateCodecsTest extends CCMTestsSupport { |
| 36 | 38 | |
| 37 | 39 | @Override |
| 38 | - public Collection<String> createTestFixtures() { | |
| 39 | - return Collections.singletonList( | |
| 40 | + public void onTestContextInitialized() { | |
| 41 | + execute( | |
| 40 | 42 | "CREATE TABLE IF NOT EXISTS foo (" |
| 41 | 43 | + "c1 text PRIMARY KEY, " |
| 42 | 44 | + "cdate date, " |
| @@ -48,7 +50,7 @@ | ||
| 48 | 50 | |
| 49 | 51 | @BeforeClass(groups = "short") |
| 50 | 52 | public void registerCodecs() throws Exception { |
| 51 | - CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); | |
| 53 | + CodecRegistry codecRegistry = cluster().getConfiguration().getCodecRegistry(); | |
| 52 | 54 | codecRegistry |
| 53 | 55 | .register(SimpleDateCodec.instance) |
| 54 | 56 | .register(SimpleTimestampCodec.instance); |
| @@ -72,9 +74,9 @@ | ||
| 72 | 74 | LocalDate localDate = LocalDate.fromDaysSinceEpoch(days); |
| 73 | 75 | // when |
| 74 | 76 | // note: these codecs cannot work with simple statements! |
| 75 | - BoundStatement bs = session.prepare("insert into foo (c1, cdate) values (?, ?)").bind("should_map_date_to_days_since_epoch", days); | |
| 76 | - session.execute(bs); | |
| 77 | - ResultSet result = session.execute("select cdate from foo where c1=?", "should_map_date_to_days_since_epoch"); | |
| 77 | + BoundStatement bs = session().prepare("insert into foo (c1, cdate) values (?, ?)").bind("should_map_date_to_days_since_epoch", days); | |
| 78 | + session().execute(bs); | |
| 79 | + ResultSet result = session().execute("select cdate from foo where c1=?", "should_map_date_to_days_since_epoch"); | |
| 78 | 80 | // then |
| 79 | 81 | assertThat(result.getAvailableWithoutFetching()).isEqualTo(1); |
| 80 | 82 | Row row = result.one(); |
| @@ -101,9 +103,9 @@ | ||
| 101 | 103 | Date date = new Date(millis); |
| 102 | 104 | // when |
| 103 | 105 | // note: these codecs cannot work with simple statements! |
| 104 | - BoundStatement bs = session.prepare("insert into foo (c1, ctimestamp) values (?, ?)").bind("should_map_timestamp_to_millis_since_epoch", millis); | |
| 105 | - session.execute(bs); | |
| 106 | - ResultSet result = session.execute("select ctimestamp from foo where c1=?", "should_map_timestamp_to_millis_since_epoch"); | |
| 106 | + BoundStatement bs = session().prepare("insert into foo (c1, ctimestamp) values (?, ?)").bind("should_map_timestamp_to_millis_since_epoch", millis); | |
| 107 | + session().execute(bs); | |
| 108 | + ResultSet result = session().execute("select ctimestamp from foo where c1=?", "should_map_timestamp_to_millis_since_epoch"); | |
| 107 | 109 | // then |
| 108 | 110 | assertThat(result.getAvailableWithoutFetching()).isEqualTo(1); |
| 109 | 111 | Row row = result.one(); |
| @@ -116,7 +118,7 @@ | ||
| 116 | 118 | @Test(groups = "short") |
| 117 | 119 | public void should_use_mapper_to_store_and_retrieve_values_with_simple_date_codecs() { |
| 118 | 120 | // given |
| 119 | - MappingManager manager = new MappingManager(session); | |
| 121 | + MappingManager manager = new MappingManager(session()); | |
| 120 | 122 | Mapper<Mapped> mapper = manager.mapper(Mapped.class); |
| 121 | 123 | // when |
| 122 | 124 | Mapped pojo = new Mapped(); |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/enums/EnumCodecsTest.java +15 −16
| @@ -24,7 +24,6 @@ | ||
| 24 | 24 | import org.testng.annotations.BeforeMethod; |
| 25 | 25 | import org.testng.annotations.Test; |
| 26 | 26 | |
| 27 | -import java.util.Collection; | |
| 28 | 27 | import java.util.List; |
| 29 | 28 | import java.util.Map; |
| 30 | 29 | import java.util.Set; |
| @@ -60,8 +59,8 @@ | ||
| 60 | 59 | private UDTValue udtValue; |
| 61 | 60 | |
| 62 | 61 | @Override |
| 63 | - public Collection<String> createTestFixtures() { | |
| 64 | - return newArrayList( | |
| 62 | + public void onTestContextInitialized() { | |
| 63 | + execute( | |
| 65 | 64 | "CREATE TYPE IF NOT EXISTS udt1 (" |
| 66 | 65 | + "foo int," |
| 67 | 66 | + "bar text)", |
| @@ -89,11 +88,11 @@ | ||
| 89 | 88 | |
| 90 | 89 | @BeforeMethod(groups = "short") |
| 91 | 90 | public void before() { |
| 92 | - TupleType tup = cluster.getMetadata().newTupleType(cint(), text()); | |
| 91 | + TupleType tup = cluster().getMetadata().newTupleType(cint(), text()); | |
| 93 | 92 | tupleValue = tup.newValue() |
| 94 | 93 | .set(0, FOO_1, Foo.class) |
| 95 | 94 | .set(1, BAR_1, Bar.class); |
| 96 | - UserType udt = cluster.getMetadata().getKeyspace(keyspace).getUserType("udt1"); | |
| 95 | + UserType udt = cluster().getMetadata().getKeyspace(keyspace).getUserType("udt1"); | |
| 97 | 96 | udtValue = udt.newValue() |
| 98 | 97 | .set("foo", FOO_1, Foo.class) |
| 99 | 98 | .set("bar", BAR_1, Bar.class); |
| @@ -101,24 +100,24 @@ | ||
| 101 | 100 | |
| 102 | 101 | @Test(groups = "short") |
| 103 | 102 | public void should_use_enum_codecs_with_simple_statements() { |
| 104 | - session.execute(insertQuery, pk, FOO_1, foos, BAR_1, bars, foobars, tupleValue, udtValue); | |
| 105 | - ResultSet rows = session.execute(selectQuery, pk); | |
| 103 | + session().execute(insertQuery, pk, FOO_1, foos, BAR_1, bars, foobars, tupleValue, udtValue); | |
| 104 | + ResultSet rows = session().execute(selectQuery, pk); | |
| 106 | 105 | Row row = rows.one(); |
| 107 | 106 | assertRow(row); |
| 108 | 107 | } |
| 109 | 108 | |
| 110 | 109 | @Test(groups = "short") |
| 111 | 110 | public void should_use_enum_codecs_with_prepared_statements_1() { |
| 112 | - session.execute(session.prepare(insertQuery).bind(pk, FOO_1, foos, BAR_1, bars, foobars, tupleValue, udtValue)); | |
| 113 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 114 | - ResultSet rows = session.execute(ps.bind(pk)); | |
| 111 | + session().execute(session().prepare(insertQuery).bind(pk, FOO_1, foos, BAR_1, bars, foobars, tupleValue, udtValue)); | |
| 112 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 113 | + ResultSet rows = session().execute(ps.bind(pk)); | |
| 115 | 114 | Row row = rows.one(); |
| 116 | 115 | assertRow(row); |
| 117 | 116 | } |
| 118 | 117 | |
| 119 | 118 | @Test(groups = "short") |
| 120 | 119 | public void should_use_enum_codecs_with_prepared_statements_2() { |
| 121 | - session.execute(session.prepare(insertQuery).bind() | |
| 120 | + session().execute(session().prepare(insertQuery).bind() | |
| 122 | 121 | .setInt(0, pk) |
| 123 | 122 | .set(1, FOO_1, Foo.class) |
| 124 | 123 | .setList(2, foos, Foo.class) |
| @@ -128,8 +127,8 @@ | ||
| 128 | 127 | .setTupleValue(6, tupleValue) |
| 129 | 128 | .setUDTValue(7, udtValue) |
| 130 | 129 | ); |
| 131 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 132 | - ResultSet rows = session.execute(ps.bind() | |
| 130 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 131 | + ResultSet rows = session().execute(ps.bind() | |
| 133 | 132 | .setInt(0, pk) |
| 134 | 133 | ); |
| 135 | 134 | Row row = rows.one(); |
| @@ -139,7 +138,7 @@ | ||
| 139 | 138 | @Test(groups = "short") |
| 140 | 139 | public void should_use_mapper_to_store_and_retrieve_nulls_with_enum_codecs() { |
| 141 | 140 | // given |
| 142 | - MappingManager manager = new MappingManager(session); | |
| 141 | + MappingManager manager = new MappingManager(session()); | |
| 143 | 142 | Mapper<Mapped> mapper = manager.mapper(Mapped.class); |
| 144 | 143 | Mapped pojo = new Mapped(); |
| 145 | 144 | pojo.pk = 42; |
| @@ -154,7 +153,7 @@ | ||
| 154 | 153 | @Test(groups = "short") |
| 155 | 154 | public void should_use_mapper_to_store_and_retrieve_values_with_enum_codecs() { |
| 156 | 155 | // given |
| 157 | - MappingManager manager = new MappingManager(session); | |
| 156 | + MappingManager manager = new MappingManager(session()); | |
| 158 | 157 | Mapper<Mapped> mapper = manager.mapper(Mapped.class); |
| 159 | 158 | Mapped pojo = new Mapped(); |
| 160 | 159 | pojo.pk = 42; |
| @@ -173,7 +172,7 @@ | ||
| 173 | 172 | @Test(groups = "short") |
| 174 | 173 | public void should_use_accessor_to_store_and_retrieve_values_with_enum_codecs() { |
| 175 | 174 | // given |
| 176 | - MappedAccessor accessor = new MappingManager(session).createAccessor(MappedAccessor.class); | |
| 175 | + MappedAccessor accessor = new MappingManager(session()).createAccessor(MappedAccessor.class); | |
| 177 | 176 | Mapped expected = new Mapped(); |
| 178 | 177 | expected.pk = 42; |
| 179 | 178 | expected.foo = FOO_1; |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/guava/OptionalCodecTest.java +24 −26
| @@ -24,8 +24,6 @@ | ||
| 24 | 24 | import org.testng.annotations.Test; |
| 25 | 25 | |
| 26 | 26 | import java.math.BigDecimal; |
| 27 | -import java.util.Collection; | |
| 28 | -import java.util.Collections; | |
| 29 | 27 | import java.util.List; |
| 30 | 28 | |
| 31 | 29 | import static com.datastax.driver.core.TypeCodec.*; |
| @@ -43,8 +41,8 @@ | ||
| 43 | 41 | private BuiltStatement selectStmt; |
| 44 | 42 | |
| 45 | 43 | @Override |
| 46 | - public Collection<String> createTestFixtures() { | |
| 47 | - return Collections.singletonList("CREATE TABLE foo (c1 text, c2 text, c3 list<text>, c4 bigint, c5 decimal, PRIMARY KEY (c1, c2))"); | |
| 44 | + public void onTestContextInitialized() { | |
| 45 | + execute("CREATE TABLE foo (c1 text, c2 text, c3 list<text>, c4 bigint, c5 decimal, PRIMARY KEY (c1, c2))"); | |
| 48 | 46 | } |
| 49 | 47 | |
| 50 | 48 | @Override |
| @@ -73,15 +71,15 @@ | ||
| 73 | 71 | @Test(groups = "short") |
| 74 | 72 | @CassandraVersion(major = 2.2) |
| 75 | 73 | public void should_map_unset_value_to_absent() { |
| 76 | - PreparedStatement insertPrep = session.prepare(this.insertStmt); | |
| 77 | - PreparedStatement selectPrep = session.prepare(this.selectStmt); | |
| 74 | + PreparedStatement insertPrep = session().prepare(this.insertStmt); | |
| 75 | + PreparedStatement selectPrep = session().prepare(this.selectStmt); | |
| 78 | 76 | |
| 79 | 77 | BoundStatement bs = insertPrep.bind(); |
| 80 | 78 | bs.setString(0, "should_map_unset_value_to_absent"); |
| 81 | 79 | bs.setString(1, "1"); |
| 82 | - session.execute(bs); | |
| 80 | + session().execute(bs); | |
| 83 | 81 | |
| 84 | - ResultSet results = session.execute(selectPrep.bind("should_map_unset_value_to_absent")); | |
| 82 | + ResultSet results = session().execute(selectPrep.bind("should_map_unset_value_to_absent")); | |
| 85 | 83 | assertThat(results.getAvailableWithoutFetching()).isEqualTo(1); |
| 86 | 84 | |
| 87 | 85 | Row row = results.one(); |
| @@ -102,16 +100,16 @@ | ||
| 102 | 100 | */ |
| 103 | 101 | @Test(groups = "short") |
| 104 | 102 | public void should_map_absent_null_value_to_absent() { |
| 105 | - PreparedStatement insertPrep = session.prepare(this.insertStmt); | |
| 106 | - PreparedStatement selectPrep = session.prepare(this.selectStmt); | |
| 103 | + PreparedStatement insertPrep = session().prepare(this.insertStmt); | |
| 104 | + PreparedStatement selectPrep = session().prepare(this.selectStmt); | |
| 107 | 105 | |
| 108 | 106 | BoundStatement bs = insertPrep.bind(); |
| 109 | 107 | bs.setString(0, "should_map_absent_null_value_to_absent"); |
| 110 | 108 | bs.setString(1, "1"); |
| 111 | 109 | bs.set(2, Optional.<List<String>>absent(), optionalCodec.getJavaType()); |
| 112 | - session.execute(bs); | |
| 110 | + session().execute(bs); | |
| 113 | 111 | |
| 114 | - ResultSet results = session.execute(selectPrep.bind("should_map_absent_null_value_to_absent")); | |
| 112 | + ResultSet results = session().execute(selectPrep.bind("should_map_absent_null_value_to_absent")); | |
| 115 | 113 | assertThat(results.getAvailableWithoutFetching()).isEqualTo(1); |
| 116 | 114 | |
| 117 | 115 | Row row = results.one(); |
| @@ -134,8 +132,8 @@ | ||
| 134 | 132 | */ |
| 135 | 133 | @Test(groups = "short") |
| 136 | 134 | public void should_map_some_back_to_itself() { |
| 137 | - PreparedStatement insertPrep = session.prepare(this.insertStmt); | |
| 138 | - PreparedStatement selectPrep = session.prepare(this.selectStmt); | |
| 135 | + PreparedStatement insertPrep = session().prepare(this.insertStmt); | |
| 136 | + PreparedStatement selectPrep = session().prepare(this.selectStmt); | |
| 139 | 137 | |
| 140 | 138 | List<String> data = Lists.newArrayList("1", "2", "3"); |
| 141 | 139 | |
| @@ -143,9 +141,9 @@ | ||
| 143 | 141 | bs.setString(0, "should_map_some_back_to_itself"); |
| 144 | 142 | bs.setString(1, "1"); |
| 145 | 143 | bs.set(2, Optional.of(data), optionalCodec.getJavaType()); |
| 146 | - session.execute(bs); | |
| 144 | + session().execute(bs); | |
| 147 | 145 | |
| 148 | - ResultSet results = session.execute(selectPrep.bind("should_map_some_back_to_itself")); | |
| 146 | + ResultSet results = session().execute(selectPrep.bind("should_map_some_back_to_itself")); | |
| 149 | 147 | assertThat(results.getAvailableWithoutFetching()).isEqualTo(1); |
| 150 | 148 | |
| 151 | 149 | Row row = results.one(); |
| @@ -163,18 +161,18 @@ | ||
| 163 | 161 | @Test(groups = "short") |
| 164 | 162 | public void should_map_a_primitive_type_to_absent() { |
| 165 | 163 | OptionalCodec<Long> optionalLongCodec = new OptionalCodec<Long>(bigint()); |
| 166 | - cluster.getConfiguration().getCodecRegistry().register(optionalLongCodec); | |
| 164 | + cluster().getConfiguration().getCodecRegistry().register(optionalLongCodec); | |
| 167 | 165 | |
| 168 | - PreparedStatement stmt = session.prepare("insert into foo (c1, c2, c4) values (?,?,?)"); | |
| 166 | + PreparedStatement stmt = session().prepare("insert into foo (c1, c2, c4) values (?,?,?)"); | |
| 169 | 167 | |
| 170 | 168 | BoundStatement bs = stmt.bind(); |
| 171 | 169 | bs.setString(0, "should_map_a_primitive_type_to_absent"); |
| 172 | 170 | bs.setString(1, "1"); |
| 173 | 171 | bs.set(2, Optional.<Long>absent(), optionalLongCodec.getJavaType()); |
| 174 | - session.execute(bs); | |
| 172 | + session().execute(bs); | |
| 175 | 173 | |
| 176 | - PreparedStatement selectBigint = session.prepare("select c1, c4 from foo where c1=?"); | |
| 177 | - ResultSet results = session.execute(selectBigint.bind("should_map_a_primitive_type_to_absent")); | |
| 174 | + PreparedStatement selectBigint = session().prepare("select c1, c4 from foo where c1=?"); | |
| 175 | + ResultSet results = session().execute(selectBigint.bind("should_map_a_primitive_type_to_absent")); | |
| 178 | 176 | |
| 179 | 177 | assertThat(results.getAvailableWithoutFetching()).isEqualTo(1); |
| 180 | 178 | |
| @@ -187,18 +185,18 @@ | ||
| 187 | 185 | @Test(groups = "short") |
| 188 | 186 | public void should_map_a_nullable_type_to_absent() { |
| 189 | 187 | OptionalCodec<BigDecimal> optionalDecimalCodec = new OptionalCodec<BigDecimal>(decimal()); |
| 190 | - cluster.getConfiguration().getCodecRegistry().register(optionalDecimalCodec); | |
| 188 | + cluster().getConfiguration().getCodecRegistry().register(optionalDecimalCodec); | |
| 191 | 189 | |
| 192 | - PreparedStatement stmt = session.prepare("insert into foo (c1, c2, c5) values (?,?,?)"); | |
| 190 | + PreparedStatement stmt = session().prepare("insert into foo (c1, c2, c5) values (?,?,?)"); | |
| 193 | 191 | |
| 194 | 192 | BoundStatement bs = stmt.bind(); |
| 195 | 193 | bs.setString(0, "should_map_a_nullable_type_to_absent"); |
| 196 | 194 | bs.setString(1, "1"); |
| 197 | 195 | bs.set(2, Optional.<BigDecimal>absent(), optionalDecimalCodec.getJavaType()); |
| 198 | - session.execute(bs); | |
| 196 | + session().execute(bs); | |
| 199 | 197 | |
| 200 | - PreparedStatement selectDecimal = session.prepare("select c1, c5 from foo where c1=?"); | |
| 201 | - ResultSet results = session.execute(selectDecimal.bind("should_map_a_nullable_type_to_absent")); | |
| 198 | + PreparedStatement selectDecimal = session().prepare("select c1, c5 from foo where c1=?"); | |
| 199 | + ResultSet results = session().execute(selectDecimal.bind("should_map_a_nullable_type_to_absent")); | |
| 202 | 200 | |
| 203 | 201 | assertThat(results.getAvailableWithoutFetching()).isEqualTo(1); |
| 204 | 202 |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/jdk8/Jdk8TimeCodecsTest.java +18 −15
| @@ -30,7 +30,10 @@ | ||
| 30 | 30 | import java.time.LocalDate; |
| 31 | 31 | import java.time.LocalTime; |
| 32 | 32 | import java.time.ZonedDateTime; |
| 33 | -import java.util.*; | |
| 33 | +import java.util.Date; | |
| 34 | +import java.util.List; | |
| 35 | +import java.util.Map; | |
| 36 | +import java.util.Set; | |
| 34 | 37 | |
| 35 | 38 | import static com.datastax.driver.core.DataType.timestamp; |
| 36 | 39 | import static com.datastax.driver.core.DataType.varchar; |
| @@ -42,8 +45,8 @@ | ||
| 42 | 45 | public class Jdk8TimeCodecsTest extends CCMTestsSupport { |
| 43 | 46 | |
| 44 | 47 | @Override |
| 45 | - public Collection<String> createTestFixtures() { | |
| 46 | - return Collections.singletonList( | |
| 48 | + public void onTestContextInitialized() { | |
| 49 | + execute( | |
| 47 | 50 | "CREATE TABLE IF NOT EXISTS foo (" |
| 48 | 51 | + "c1 text PRIMARY KEY, " |
| 49 | 52 | + "cdate date, " |
| @@ -59,8 +62,8 @@ | ||
| 59 | 62 | |
| 60 | 63 | @BeforeClass(groups = "short") |
| 61 | 64 | public void registerCodecs() throws Exception { |
| 62 | - TupleType dateWithTimeZoneType = cluster.getMetadata().newTupleType(timestamp(), varchar()); | |
| 63 | - CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); | |
| 65 | + TupleType dateWithTimeZoneType = cluster().getMetadata().newTupleType(timestamp(), varchar()); | |
| 66 | + CodecRegistry codecRegistry = cluster().getConfiguration().getCodecRegistry(); | |
| 64 | 67 | codecRegistry |
| 65 | 68 | .register(LocalTimeCodec.instance) |
| 66 | 69 | .register(LocalDateCodec.instance) |
| @@ -84,8 +87,8 @@ | ||
| 84 | 87 | // given |
| 85 | 88 | LocalTime time = LocalTime.of(12, 16, 34, 999); |
| 86 | 89 | // when |
| 87 | - session.execute("insert into foo (c1, ctime) values (?, ?)", "should_map_time_to_localtime", time); | |
| 88 | - ResultSet result = session.execute("select ctime from foo where c1=?", "should_map_time_to_localtime"); | |
| 90 | + session().execute("insert into foo (c1, ctime) values (?, ?)", "should_map_time_to_localtime", time); | |
| 91 | + ResultSet result = session().execute("select ctime from foo where c1=?", "should_map_time_to_localtime"); | |
| 89 | 92 | // then |
| 90 | 93 | assertThat(result.getAvailableWithoutFetching()).isEqualTo(1); |
| 91 | 94 | Row row = result.one(); |
| @@ -110,8 +113,8 @@ | ||
| 110 | 113 | LocalDate localDate = LocalDate.of(2015, 1, 1); |
| 111 | 114 | com.datastax.driver.core.LocalDate driverLocalDate = com.datastax.driver.core.LocalDate.fromYearMonthDay(2015, 1, 1); |
| 112 | 115 | // when |
| 113 | - session.execute("insert into foo (c1, cdate) values (?, ?)", "should_map_date_to_localdate", localDate); | |
| 114 | - ResultSet result = session.execute("select cdate from foo where c1=?", "should_map_date_to_localdate"); | |
| 116 | + session().execute("insert into foo (c1, cdate) values (?, ?)", "should_map_date_to_localdate", localDate); | |
| 117 | + ResultSet result = session().execute("select cdate from foo where c1=?", "should_map_date_to_localdate"); | |
| 115 | 118 | // then |
| 116 | 119 | assertThat(result.getAvailableWithoutFetching()).isEqualTo(1); |
| 117 | 120 | Row row = result.one(); |
| @@ -135,8 +138,8 @@ | ||
| 135 | 138 | // given |
| 136 | 139 | Instant instant = Instant.parse("2010-06-30T01:20:30Z"); |
| 137 | 140 | // when |
| 138 | - session.execute("insert into foo (c1, ctimestamp) values (?, ?)", "should_map_timestamp_to_instant", instant); | |
| 139 | - ResultSet result = session.execute("select ctimestamp from foo where c1=?", "should_map_timestamp_to_instant"); | |
| 141 | + session().execute("insert into foo (c1, ctimestamp) values (?, ?)", "should_map_timestamp_to_instant", instant); | |
| 142 | + ResultSet result = session().execute("select ctimestamp from foo where c1=?", "should_map_timestamp_to_instant"); | |
| 140 | 143 | // then |
| 141 | 144 | assertThat(result.getAvailableWithoutFetching()).isEqualTo(1); |
| 142 | 145 | Row row = result.one(); |
| @@ -160,9 +163,9 @@ | ||
| 160 | 163 | // given |
| 161 | 164 | ZonedDateTime expected = ZonedDateTime.parse("2010-06-30T01:20+05:30"); |
| 162 | 165 | // when |
| 163 | - PreparedStatement insertStmt = session.prepare("insert into foo (c1, ctuple) values (?, ?)"); | |
| 164 | - session.execute(insertStmt.bind("should_map_tuple_to_instant", expected)); | |
| 165 | - ResultSet result = session.execute("select ctuple from foo where c1=?", "should_map_tuple_to_instant"); | |
| 166 | + PreparedStatement insertStmt = session().prepare("insert into foo (c1, ctuple) values (?, ?)"); | |
| 167 | + session().execute(insertStmt.bind("should_map_tuple_to_instant", expected)); | |
| 168 | + ResultSet result = session().execute("select ctuple from foo where c1=?", "should_map_tuple_to_instant"); | |
| 166 | 169 | // then |
| 167 | 170 | assertThat(result.getAvailableWithoutFetching()).isEqualTo(1); |
| 168 | 171 | Row row = result.one(); |
| @@ -177,7 +180,7 @@ | ||
| 177 | 180 | @Test(groups = "short") |
| 178 | 181 | public void should_use_mapper_to_store_and_retrieve_values_with_custom_jdk8_codecs() { |
| 179 | 182 | // given |
| 180 | - MappingManager manager = new MappingManager(session); | |
| 183 | + MappingManager manager = new MappingManager(session()); | |
| 181 | 184 | Mapper<Mapped> mapper = manager.mapper(Mapped.class); |
| 182 | 185 | // when |
| 183 | 186 | Mapped pojo = new Mapped(); |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/jdk8/OptionalCodecTest.java +24 −26
| @@ -23,8 +23,6 @@ | ||
| 23 | 23 | import org.testng.annotations.Test; |
| 24 | 24 | |
| 25 | 25 | import java.math.BigDecimal; |
| 26 | -import java.util.Collection; | |
| 27 | -import java.util.Collections; | |
| 28 | 26 | import java.util.List; |
| 29 | 27 | import java.util.Optional; |
| 30 | 28 | |
| @@ -43,8 +41,8 @@ | ||
| 43 | 41 | private BuiltStatement selectStmt; |
| 44 | 42 | |
| 45 | 43 | @Override |
| 46 | - public Collection<String> createTestFixtures() { | |
| 47 | - return Collections.singletonList("CREATE TABLE foo (c1 text, c2 text, c3 list<text>, c4 bigint, c5 decimal, PRIMARY KEY (c1, c2))"); | |
| 44 | + public void onTestContextInitialized() { | |
| 45 | + execute("CREATE TABLE foo (c1 text, c2 text, c3 list<text>, c4 bigint, c5 decimal, PRIMARY KEY (c1, c2))"); | |
| 48 | 46 | } |
| 49 | 47 | |
| 50 | 48 | @Override |
| @@ -73,15 +71,15 @@ | ||
| 73 | 71 | @Test(groups = "short") |
| 74 | 72 | @CassandraVersion(major = 2.2) |
| 75 | 73 | public void should_map_unset_value_to_empty() { |
| 76 | - PreparedStatement insertPrep = session.prepare(this.insertStmt); | |
| 77 | - PreparedStatement selectPrep = session.prepare(this.selectStmt); | |
| 74 | + PreparedStatement insertPrep = session().prepare(this.insertStmt); | |
| 75 | + PreparedStatement selectPrep = session().prepare(this.selectStmt); | |
| 78 | 76 | |
| 79 | 77 | BoundStatement bs = insertPrep.bind(); |
| 80 | 78 | bs.setString(0, "should_map_unset_value_to_empty"); |
| 81 | 79 | bs.setString(1, "1"); |
| 82 | - session.execute(bs); | |
| 80 | + session().execute(bs); | |
| 83 | 81 | |
| 84 | - ResultSet results = session.execute(selectPrep.bind("should_map_unset_value_to_empty")); | |
| 82 | + ResultSet results = session().execute(selectPrep.bind("should_map_unset_value_to_empty")); | |
| 85 | 83 | assertThat(results.getAvailableWithoutFetching()).isEqualTo(1); |
| 86 | 84 | |
| 87 | 85 | Row row = results.one(); |
| @@ -102,16 +100,16 @@ | ||
| 102 | 100 | */ |
| 103 | 101 | @Test(groups = "short") |
| 104 | 102 | public void should_map_absent_null_value_to_empty() { |
| 105 | - PreparedStatement insertPrep = session.prepare(this.insertStmt); | |
| 106 | - PreparedStatement selectPrep = session.prepare(this.selectStmt); | |
| 103 | + PreparedStatement insertPrep = session().prepare(this.insertStmt); | |
| 104 | + PreparedStatement selectPrep = session().prepare(this.selectStmt); | |
| 107 | 105 | |
| 108 | 106 | BoundStatement bs = insertPrep.bind(); |
| 109 | 107 | bs.setString(0, "should_map_absent_null_value_to_empty"); |
| 110 | 108 | bs.setString(1, "1"); |
| 111 | 109 | bs.set(2, Optional.<List<String>>empty(), optionalCodec.getJavaType()); |
| 112 | - session.execute(bs); | |
| 110 | + session().execute(bs); | |
| 113 | 111 | |
| 114 | - ResultSet results = session.execute(selectPrep.bind("should_map_absent_null_value_to_empty")); | |
| 112 | + ResultSet results = session().execute(selectPrep.bind("should_map_absent_null_value_to_empty")); | |
| 115 | 113 | assertThat(results.getAvailableWithoutFetching()).isEqualTo(1); |
| 116 | 114 | |
| 117 | 115 | Row row = results.one(); |
| @@ -134,8 +132,8 @@ | ||
| 134 | 132 | */ |
| 135 | 133 | @Test(groups = "short") |
| 136 | 134 | public void should_map_some_back_to_itself() { |
| 137 | - PreparedStatement insertPrep = session.prepare(this.insertStmt); | |
| 138 | - PreparedStatement selectPrep = session.prepare(this.selectStmt); | |
| 135 | + PreparedStatement insertPrep = session().prepare(this.insertStmt); | |
| 136 | + PreparedStatement selectPrep = session().prepare(this.selectStmt); | |
| 139 | 137 | |
| 140 | 138 | List<String> data = Lists.newArrayList("1", "2", "3"); |
| 141 | 139 | |
| @@ -143,9 +141,9 @@ | ||
| 143 | 141 | bs.setString(0, "should_map_some_back_to_itself"); |
| 144 | 142 | bs.setString(1, "1"); |
| 145 | 143 | bs.set(2, Optional.of(data), optionalCodec.getJavaType()); |
| 146 | - session.execute(bs); | |
| 144 | + session().execute(bs); | |
| 147 | 145 | |
| 148 | - ResultSet results = session.execute(selectPrep.bind("should_map_some_back_to_itself")); | |
| 146 | + ResultSet results = session().execute(selectPrep.bind("should_map_some_back_to_itself")); | |
| 149 | 147 | assertThat(results.getAvailableWithoutFetching()).isEqualTo(1); |
| 150 | 148 | |
| 151 | 149 | Row row = results.one(); |
| @@ -163,18 +161,18 @@ | ||
| 163 | 161 | @Test(groups = "short") |
| 164 | 162 | public void should_map_a_primitive_type_to_empty() { |
| 165 | 163 | OptionalCodec<Long> optionalLongCodec = new OptionalCodec<Long>(bigint()); |
| 166 | - cluster.getConfiguration().getCodecRegistry().register(optionalLongCodec); | |
| 164 | + cluster().getConfiguration().getCodecRegistry().register(optionalLongCodec); | |
| 167 | 165 | |
| 168 | - PreparedStatement stmt = session.prepare("insert into foo (c1, c2, c4) values (?,?,?)"); | |
| 166 | + PreparedStatement stmt = session().prepare("insert into foo (c1, c2, c4) values (?,?,?)"); | |
| 169 | 167 | |
| 170 | 168 | BoundStatement bs = stmt.bind(); |
| 171 | 169 | bs.setString(0, "should_map_a_primitive_type_to_empty"); |
| 172 | 170 | bs.setString(1, "1"); |
| 173 | 171 | bs.set(2, Optional.<Long>empty(), optionalLongCodec.getJavaType()); |
| 174 | - session.execute(bs); | |
| 172 | + session().execute(bs); | |
| 175 | 173 | |
| 176 | - PreparedStatement selectBigint = session.prepare("select c1, c4 from foo where c1=?"); | |
| 177 | - ResultSet results = session.execute(selectBigint.bind("should_map_a_primitive_type_to_empty")); | |
| 174 | + PreparedStatement selectBigint = session().prepare("select c1, c4 from foo where c1=?"); | |
| 175 | + ResultSet results = session().execute(selectBigint.bind("should_map_a_primitive_type_to_empty")); | |
| 178 | 176 | |
| 179 | 177 | assertThat(results.getAvailableWithoutFetching()).isEqualTo(1); |
| 180 | 178 | |
| @@ -187,18 +185,18 @@ | ||
| 187 | 185 | @Test(groups = "short") |
| 188 | 186 | public void should_map_a_nullable_type_to_empty() { |
| 189 | 187 | OptionalCodec<BigDecimal> optionalDecimalCodec = new OptionalCodec<BigDecimal>(decimal()); |
| 190 | - cluster.getConfiguration().getCodecRegistry().register(optionalDecimalCodec); | |
| 188 | + cluster().getConfiguration().getCodecRegistry().register(optionalDecimalCodec); | |
| 191 | 189 | |
| 192 | - PreparedStatement stmt = session.prepare("insert into foo (c1, c2, c5) values (?,?,?)"); | |
| 190 | + PreparedStatement stmt = session().prepare("insert into foo (c1, c2, c5) values (?,?,?)"); | |
| 193 | 191 | |
| 194 | 192 | BoundStatement bs = stmt.bind(); |
| 195 | 193 | bs.setString(0, "should_map_a_nullable_type_to_empty"); |
| 196 | 194 | bs.setString(1, "1"); |
| 197 | 195 | bs.set(2, Optional.<BigDecimal>empty(), optionalDecimalCodec.getJavaType()); |
| 198 | - session.execute(bs); | |
| 196 | + session().execute(bs); | |
| 199 | 197 | |
| 200 | - PreparedStatement selectDecimal = session.prepare("select c1, c5 from foo where c1=?"); | |
| 201 | - ResultSet results = session.execute(selectDecimal.bind("should_map_a_nullable_type_to_empty")); | |
| 198 | + PreparedStatement selectDecimal = session().prepare("select c1, c5 from foo where c1=?"); | |
| 199 | + ResultSet results = session().execute(selectDecimal.bind("should_map_a_nullable_type_to_empty")); | |
| 202 | 200 | |
| 203 | 201 | assertThat(results.getAvailableWithoutFetching()).isEqualTo(1); |
| 204 | 202 |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/joda/JodaTimeCodecsTest.java +17 −15
| @@ -30,7 +30,9 @@ | ||
| 30 | 30 | import org.testng.annotations.BeforeClass; |
| 31 | 31 | import org.testng.annotations.Test; |
| 32 | 32 | |
| 33 | -import java.util.*; | |
| 33 | +import java.util.List; | |
| 34 | +import java.util.Map; | |
| 35 | +import java.util.Set; | |
| 34 | 36 | |
| 35 | 37 | import static com.datastax.driver.core.DataType.timestamp; |
| 36 | 38 | import static com.datastax.driver.core.DataType.varchar; |
| @@ -44,8 +46,8 @@ | ||
| 44 | 46 | public class JodaTimeCodecsTest extends CCMTestsSupport { |
| 45 | 47 | |
| 46 | 48 | @Override |
| 47 | - public Collection<String> createTestFixtures() { | |
| 48 | - return Collections.singletonList( | |
| 49 | + public void onTestContextInitialized() { | |
| 50 | + execute( | |
| 49 | 51 | "CREATE TABLE IF NOT EXISTS foo (" |
| 50 | 52 | + "c1 text PRIMARY KEY, " |
| 51 | 53 | + "cdate date, " |
| @@ -61,8 +63,8 @@ | ||
| 61 | 63 | |
| 62 | 64 | @BeforeClass(groups = "short") |
| 63 | 65 | public void registerCodecs() throws Exception { |
| 64 | - TupleType dateWithTimeZoneType = cluster.getMetadata().newTupleType(timestamp(), varchar()); | |
| 65 | - CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); | |
| 66 | + TupleType dateWithTimeZoneType = cluster().getMetadata().newTupleType(timestamp(), varchar()); | |
| 67 | + CodecRegistry codecRegistry = cluster().getConfiguration().getCodecRegistry(); | |
| 66 | 68 | codecRegistry |
| 67 | 69 | .register(LocalTimeCodec.instance) |
| 68 | 70 | .register(LocalDateCodec.instance) |
| @@ -86,8 +88,8 @@ | ||
| 86 | 88 | // given |
| 87 | 89 | LocalTime time = new LocalTime(12, 16, 34, 999); |
| 88 | 90 | // when |
| 89 | - session.execute("insert into foo (c1, ctime) values (?, ?)", "should_map_time_to_localtime", time); | |
| 90 | - ResultSet result = session.execute("select ctime from foo where c1=?", "should_map_time_to_localtime"); | |
| 91 | + session().execute("insert into foo (c1, ctime) values (?, ?)", "should_map_time_to_localtime", time); | |
| 92 | + ResultSet result = session().execute("select ctime from foo where c1=?", "should_map_time_to_localtime"); | |
| 91 | 93 | // then |
| 92 | 94 | assertThat(result.getAvailableWithoutFetching()).isEqualTo(1); |
| 93 | 95 | Row row = result.one(); |
| @@ -112,8 +114,8 @@ | ||
| 112 | 114 | LocalDate localDate = new LocalDate(2015, 1, 1); |
| 113 | 115 | com.datastax.driver.core.LocalDate driverLocalDate = com.datastax.driver.core.LocalDate.fromYearMonthDay(2015, 1, 1); |
| 114 | 116 | // when |
| 115 | - session.execute("insert into foo (c1, cdate) values (?, ?)", "should_map_date_to_localdate", localDate); | |
| 116 | - ResultSet result = session.execute("select cdate from foo where c1=?", "should_map_date_to_localdate"); | |
| 117 | + session().execute("insert into foo (c1, cdate) values (?, ?)", "should_map_date_to_localdate", localDate); | |
| 118 | + ResultSet result = session().execute("select cdate from foo where c1=?", "should_map_date_to_localdate"); | |
| 117 | 119 | // then |
| 118 | 120 | assertThat(result.getAvailableWithoutFetching()).isEqualTo(1); |
| 119 | 121 | Row row = result.one(); |
| @@ -137,8 +139,8 @@ | ||
| 137 | 139 | // given |
| 138 | 140 | Instant instant = Instant.parse("2010-06-30T01:20+05:00"); |
| 139 | 141 | // when |
| 140 | - session.execute("insert into foo (c1, ctimestamp) values (?, ?)", "should_map_timestamp_to_datetime", instant); | |
| 141 | - ResultSet result = session.execute("select ctimestamp from foo where c1=?", "should_map_timestamp_to_datetime"); | |
| 142 | + session().execute("insert into foo (c1, ctimestamp) values (?, ?)", "should_map_timestamp_to_datetime", instant); | |
| 143 | + ResultSet result = session().execute("select ctimestamp from foo where c1=?", "should_map_timestamp_to_datetime"); | |
| 142 | 144 | // then |
| 143 | 145 | assertThat(result.getAvailableWithoutFetching()).isEqualTo(1); |
| 144 | 146 | Row row = result.one(); |
| @@ -162,9 +164,9 @@ | ||
| 162 | 164 | // given |
| 163 | 165 | DateTime expected = DateTime.parse("2010-06-30T01:20+05:30"); |
| 164 | 166 | // when |
| 165 | - PreparedStatement insertStmt = session.prepare("insert into foo (c1, ctuple) values (?, ?)"); | |
| 166 | - session.execute(insertStmt.bind("should_map_tuple_to_datetime", expected)); | |
| 167 | - ResultSet result = session.execute("select ctuple from foo where c1=?", "should_map_tuple_to_datetime"); | |
| 167 | + PreparedStatement insertStmt = session().prepare("insert into foo (c1, ctuple) values (?, ?)"); | |
| 168 | + session().execute(insertStmt.bind("should_map_tuple_to_datetime", expected)); | |
| 169 | + ResultSet result = session().execute("select ctuple from foo where c1=?", "should_map_tuple_to_datetime"); | |
| 168 | 170 | // then |
| 169 | 171 | assertThat(result.getAvailableWithoutFetching()).isEqualTo(1); |
| 170 | 172 | Row row = result.one(); |
| @@ -178,7 +180,7 @@ | ||
| 178 | 180 | @Test(groups = "short") |
| 179 | 181 | public void should_use_mapper_to_store_and_retrieve_values_with_custom_joda_codecs() { |
| 180 | 182 | // given |
| 181 | - MappingManager manager = new MappingManager(session); | |
| 183 | + MappingManager manager = new MappingManager(session()); | |
| 182 | 184 | Mapper<Mapped> mapper = manager.mapper(Mapped.class); |
| 183 | 185 | // when |
| 184 | 186 | Mapped pojo = new Mapped(); |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/json/JacksonJsonCodecTest.java +14 −15
| @@ -25,7 +25,6 @@ | ||
| 25 | 25 | import org.testng.annotations.Test; |
| 26 | 26 | |
| 27 | 27 | import java.util.ArrayList; |
| 28 | -import java.util.Collection; | |
| 29 | 28 | |
| 30 | 29 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 31 | 30 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -50,8 +49,8 @@ | ||
| 50 | 49 | private static final String notAJsonString = "this text is not json"; |
| 51 | 50 | |
| 52 | 51 | @Override |
| 53 | - public Collection<String> createTestFixtures() { | |
| 54 | - return Lists.newArrayList( | |
| 52 | + public void onTestContextInitialized() { | |
| 53 | + execute( | |
| 55 | 54 | "CREATE TABLE t1 (c1 text, c2 text, c3 list<text>, PRIMARY KEY (c1, c2))" |
| 56 | 55 | ); |
| 57 | 56 | } |
| @@ -84,8 +83,8 @@ | ||
| 84 | 83 | @Test(groups = "short") |
| 85 | 84 | @CassandraVersion(major = 2.0) |
| 86 | 85 | public void should_use_custom_codec_with_simple_statements() { |
| 87 | - session.execute(insertQuery, notAJsonString, alice, bobAndCharlie); | |
| 88 | - ResultSet rows = session.execute(selectQuery, notAJsonString, alice); | |
| 86 | + session().execute(insertQuery, notAJsonString, alice, bobAndCharlie); | |
| 87 | + ResultSet rows = session().execute(selectQuery, notAJsonString, alice); | |
| 89 | 88 | Row row = rows.one(); |
| 90 | 89 | assertRow(row); |
| 91 | 90 | } |
| @@ -100,8 +99,8 @@ | ||
| 100 | 99 | .from("t1") |
| 101 | 100 | .where(eq("c1", bindMarker())) |
| 102 | 101 | .and(eq("c2", bindMarker())); |
| 103 | - session.execute(session.prepare(insertStmt).bind(notAJsonString, alice, bobAndCharlie)); | |
| 104 | - ResultSet rows = session.execute(session.prepare(selectStmt).bind(notAJsonString, alice)); | |
| 102 | + session().execute(session().prepare(insertStmt).bind(notAJsonString, alice, bobAndCharlie)); | |
| 103 | + ResultSet rows = session().execute(session().prepare(selectStmt).bind(notAJsonString, alice)); | |
| 105 | 104 | Row row = rows.one(); |
| 106 | 105 | assertRow(row); |
| 107 | 106 | } |
| @@ -117,33 +116,33 @@ | ||
| 117 | 116 | .from("t1") |
| 118 | 117 | .where(eq("c1", notAJsonString)) |
| 119 | 118 | .and(eq("c2", alice)); |
| 120 | - session.execute(insertStmt); | |
| 121 | - ResultSet rows = session.execute(selectStmt); | |
| 119 | + session().execute(insertStmt); | |
| 120 | + ResultSet rows = session().execute(selectStmt); | |
| 122 | 121 | Row row = rows.one(); |
| 123 | 122 | assertRow(row); |
| 124 | 123 | } |
| 125 | 124 | |
| 126 | 125 | @Test(groups = "short") |
| 127 | 126 | public void should_use_custom_codec_with_prepared_statements_1() { |
| 128 | - session.execute(session.prepare(insertQuery).bind(notAJsonString, alice, bobAndCharlie)); | |
| 129 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 127 | + session().execute(session().prepare(insertQuery).bind(notAJsonString, alice, bobAndCharlie)); | |
| 128 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 130 | 129 | // this bind() method does not convey information about the java type of alice |
| 131 | 130 | // so the registry will look for a codec accepting varchar <-> ANY |
| 132 | 131 | // and will find jsonCodec because it is the first registered |
| 133 | - ResultSet rows = session.execute(ps.bind(notAJsonString, alice)); | |
| 132 | + ResultSet rows = session().execute(ps.bind(notAJsonString, alice)); | |
| 134 | 133 | Row row = rows.one(); |
| 135 | 134 | assertRow(row); |
| 136 | 135 | } |
| 137 | 136 | |
| 138 | 137 | @Test(groups = "short") |
| 139 | 138 | public void should_use_custom_codec_with_prepared_statements_2() { |
| 140 | - session.execute(session.prepare(insertQuery).bind() | |
| 139 | + session().execute(session().prepare(insertQuery).bind() | |
| 141 | 140 | .setString(0, notAJsonString) |
| 142 | 141 | .set(1, alice, User.class) |
| 143 | 142 | .setList(2, bobAndCharlie, User.class) |
| 144 | 143 | ); |
| 145 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 146 | - ResultSet rows = session.execute(ps.bind() | |
| 144 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 145 | + ResultSet rows = session().execute(ps.bind() | |
| 147 | 146 | .setString(0, notAJsonString) |
| 148 | 147 | // this set() method conveys information about the java type of alice |
| 149 | 148 | // so the registry will look for a codec accepting varchar <-> User |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/json/Jsr353JsonCodecTest.java +14 −16
| @@ -18,14 +18,12 @@ | ||
| 18 | 18 | import com.datastax.driver.core.*; |
| 19 | 19 | import com.datastax.driver.core.querybuilder.BuiltStatement; |
| 20 | 20 | import com.datastax.driver.core.utils.CassandraVersion; |
| 21 | -import com.google.common.collect.Lists; | |
| 22 | 21 | import org.testng.annotations.DataProvider; |
| 23 | 22 | import org.testng.annotations.Test; |
| 24 | 23 | |
| 25 | 24 | import javax.json.*; |
| 26 | 25 | import java.io.IOException; |
| 27 | 26 | import java.io.StringWriter; |
| 28 | -import java.util.Collection; | |
| 29 | 27 | |
| 30 | 28 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 31 | 29 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -46,8 +44,8 @@ | ||
| 46 | 44 | private static final String notAJsonString = "this text is not json"; |
| 47 | 45 | |
| 48 | 46 | @Override |
| 49 | - public Collection<String> createTestFixtures() { | |
| 50 | - return Lists.newArrayList( | |
| 47 | + public void onTestContextInitialized() { | |
| 48 | + execute( | |
| 51 | 49 | "CREATE TABLE t1 (c1 text, c2 text, PRIMARY KEY (c1, c2))" |
| 52 | 50 | ); |
| 53 | 51 | } |
| @@ -86,8 +84,8 @@ | ||
| 86 | 84 | @Test(groups = "short", dataProvider = "Jsr353JsonCodecTest") |
| 87 | 85 | @CassandraVersion(major = 2.0) |
| 88 | 86 | public void should_use_custom_codec_with_simple_statements(JsonStructure object) throws IOException { |
| 89 | - session.execute(insertQuery, notAJsonString, object); | |
| 90 | - ResultSet rows = session.execute(selectQuery, notAJsonString, object); | |
| 87 | + session().execute(insertQuery, notAJsonString, object); | |
| 88 | + ResultSet rows = session().execute(selectQuery, notAJsonString, object); | |
| 91 | 89 | Row row = rows.one(); |
| 92 | 90 | assertRow(row, object); |
| 93 | 91 | } |
| @@ -101,8 +99,8 @@ | ||
| 101 | 99 | .from("t1") |
| 102 | 100 | .where(eq("c1", bindMarker())) |
| 103 | 101 | .and(eq("c2", bindMarker())); |
| 104 | - session.execute(session.prepare(insertStmt).bind(notAJsonString, object)); | |
| 105 | - ResultSet rows = session.execute(session.prepare(selectStmt).bind(notAJsonString, object)); | |
| 102 | + session().execute(session().prepare(insertStmt).bind(notAJsonString, object)); | |
| 103 | + ResultSet rows = session().execute(session().prepare(selectStmt).bind(notAJsonString, object)); | |
| 106 | 104 | Row row = rows.one(); |
| 107 | 105 | assertRow(row, object); |
| 108 | 106 | } |
| @@ -117,29 +115,29 @@ | ||
| 117 | 115 | .from("t1") |
| 118 | 116 | .where(eq("c1", notAJsonString)) |
| 119 | 117 | .and(eq("c2", object)); |
| 120 | - session.execute(insertStmt); | |
| 121 | - ResultSet rows = session.execute(selectStmt); | |
| 118 | + session().execute(insertStmt); | |
| 119 | + ResultSet rows = session().execute(selectStmt); | |
| 122 | 120 | Row row = rows.one(); |
| 123 | 121 | assertRow(row, object); |
| 124 | 122 | } |
| 125 | 123 | |
| 126 | 124 | @Test(groups = "short", dataProvider = "Jsr353JsonCodecTest") |
| 127 | 125 | public void should_use_custom_codec_with_prepared_statements_1(JsonStructure object) throws IOException { |
| 128 | - session.execute(session.prepare(insertQuery).bind(notAJsonString, object)); | |
| 129 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 130 | - ResultSet rows = session.execute(ps.bind(notAJsonString, object)); | |
| 126 | + session().execute(session().prepare(insertQuery).bind(notAJsonString, object)); | |
| 127 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 128 | + ResultSet rows = session().execute(ps.bind(notAJsonString, object)); | |
| 131 | 129 | Row row = rows.one(); |
| 132 | 130 | assertRow(row, object); |
| 133 | 131 | } |
| 134 | 132 | |
| 135 | 133 | @Test(groups = "short", dataProvider = "Jsr353JsonCodecTest") |
| 136 | 134 | public void should_use_custom_codec_with_prepared_statements_2(JsonStructure object) throws IOException { |
| 137 | - session.execute(session.prepare(insertQuery).bind() | |
| 135 | + session().execute(session().prepare(insertQuery).bind() | |
| 138 | 136 | .setString(0, notAJsonString) |
| 139 | 137 | .set(1, object, JsonStructure.class) |
| 140 | 138 | ); |
| 141 | - PreparedStatement ps = session.prepare(selectQuery); | |
| 142 | - ResultSet rows = session.execute(ps.bind() | |
| 139 | + PreparedStatement ps = session().prepare(selectQuery); | |
| 140 | + ResultSet rows = session().execute(ps.bind() | |
| 143 | 141 | .setString(0, notAJsonString) |
| 144 | 142 | .set(1, object, JsonStructure.class) |
| 145 | 143 | ); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperAccessorParamsTest.java +11 −14
| @@ -19,19 +19,16 @@ | ||
| 19 | 19 | import com.datastax.driver.core.Row; |
| 20 | 20 | import com.datastax.driver.core.utils.CassandraVersion; |
| 21 | 21 | import com.datastax.driver.mapping.annotations.*; |
| 22 | -import com.google.common.collect.Lists; | |
| 23 | 22 | import org.testng.annotations.Test; |
| 24 | 23 | |
| 25 | -import java.util.Collection; | |
| 26 | - | |
| 27 | 24 | import static org.assertj.core.api.Assertions.assertThat; |
| 28 | 25 | |
| 29 | 26 | @SuppressWarnings("unused") |
| 30 | 27 | public class MapperAccessorParamsTest extends CCMTestsSupport { |
| 31 | 28 | |
| 32 | 29 | @Override |
| 33 | - public Collection<String> createTestFixtures() { | |
| 34 | - return Lists.newArrayList( | |
| 30 | + public void onTestContextInitialized() { | |
| 31 | + execute( | |
| 35 | 32 | "CREATE TABLE user ( key int primary key, gender int, home_phone text, work_phone text)", |
| 36 | 33 | "CREATE INDEX on user(gender)", |
| 37 | 34 | "CREATE TABLE user_str ( key int primary key, gender text)", |
| @@ -42,44 +39,44 @@ | ||
| 42 | 39 | @Test(groups = "short") |
| 43 | 40 | @CassandraVersion(major = 2.0, description = "Uses named parameters") |
| 44 | 41 | public void should_allow_less_parameters_than_bind_markers_if_there_are_repeated_names() { |
| 45 | - UserPhoneAccessor accessor = new MappingManager(session) | |
| 42 | + UserPhoneAccessor accessor = new MappingManager(session()) | |
| 46 | 43 | .createAccessor(UserPhoneAccessor.class); |
| 47 | 44 | |
| 48 | - session.execute("delete from user where key = 0"); | |
| 45 | + session().execute("delete from user where key = 0"); | |
| 49 | 46 | accessor.updatePhones_positional("1111", "2222", 0); |
| 50 | 47 | assertPhonesEqual(0, "1111", "2222"); |
| 51 | 48 | |
| 52 | - session.execute("delete from user where key = 0"); | |
| 49 | + session().execute("delete from user where key = 0"); | |
| 53 | 50 | accessor.updatePhones_named(0, "1111", "2222"); |
| 54 | 51 | assertPhonesEqual(0, "1111", "2222"); |
| 55 | 52 | |
| 56 | - session.execute("delete from user where key = 0"); | |
| 53 | + session().execute("delete from user where key = 0"); | |
| 57 | 54 | accessor.updatePhones_fallback("1111", "2222", 0); |
| 58 | 55 | assertPhonesEqual(0, "1111", "2222"); |
| 59 | 56 | |
| 60 | - session.execute("delete from user where key = 0"); | |
| 57 | + session().execute("delete from user where key = 0"); | |
| 61 | 58 | accessor.updateBothPhones(0, "1111"); |
| 62 | 59 | assertPhonesEqual(0, "1111", "1111"); |
| 63 | 60 | |
| 64 | - session.execute("delete from user where key = 0"); | |
| 61 | + session().execute("delete from user where key = 0"); | |
| 65 | 62 | accessor.updatePhones_fallback2("1111", "2222", 0); |
| 66 | 63 | assertPhonesEqual(0, "1111", "2222"); |
| 67 | 64 | } |
| 68 | 65 | |
| 69 | 66 | @Test(groups = "short", expectedExceptions = RuntimeException.class) |
| 70 | 67 | public void should_fail_if_not_enough_parameters() { |
| 71 | - new MappingManager(session) | |
| 68 | + new MappingManager(session()) | |
| 72 | 69 | .createAccessor(UserPhoneAccessor_NotEnoughParams.class); |
| 73 | 70 | } |
| 74 | 71 | |
| 75 | 72 | @Test(groups = "short", expectedExceptions = RuntimeException.class) |
| 76 | 73 | public void should_fail_if_too_many_parameters() { |
| 77 | - new MappingManager(session) | |
| 74 | + new MappingManager(session()) | |
| 78 | 75 | .createAccessor(UserPhoneAccessor_TooManyParams.class); |
| 79 | 76 | } |
| 80 | 77 | |
| 81 | 78 | private void assertPhonesEqual(int key, String home, String work) { |
| 82 | - Row row = session.execute("select * from user where key = " + key).one(); | |
| 79 | + Row row = session().execute("select * from user where key = " + key).one(); | |
| 83 | 80 | assertThat(row.getString("home_phone")).isEqualTo(home); |
| 84 | 81 | assertThat(row.getString("work_phone")).isEqualTo(work); |
| 85 | 82 | } |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperAccessorTest.java +10 −13
| @@ -22,23 +22,20 @@ | ||
| 22 | 22 | import com.datastax.driver.mapping.annotations.Accessor; |
| 23 | 23 | import com.datastax.driver.mapping.annotations.Param; |
| 24 | 24 | import com.datastax.driver.mapping.annotations.Query; |
| 25 | -import com.google.common.collect.Lists; | |
| 26 | 25 | import org.testng.annotations.Test; |
| 27 | 26 | |
| 28 | -import java.util.Collection; | |
| 29 | - | |
| 30 | 27 | import static org.assertj.core.api.Assertions.assertThat; |
| 31 | 28 | |
| 32 | 29 | public class MapperAccessorTest extends CCMTestsSupport { |
| 33 | 30 | |
| 34 | 31 | @Override |
| 35 | - public Collection<String> createTestFixtures() { | |
| 36 | - return Lists.newArrayList("CREATE TABLE foo (k int primary key, v text)"); | |
| 32 | + public void onTestContextInitialized() { | |
| 33 | + execute("CREATE TABLE foo (k int primary key, v text)"); | |
| 37 | 34 | } |
| 38 | 35 | |
| 39 | 36 | @Test(groups = "short") |
| 40 | 37 | public void should_implement_toString() { |
| 41 | - SystemAccessor accessor = new MappingManager(session) | |
| 38 | + SystemAccessor accessor = new MappingManager(session()) | |
| 42 | 39 | .createAccessor(SystemAccessor.class); |
| 43 | 40 | |
| 44 | 41 | assertThat(accessor.toString()) |
| @@ -47,7 +44,7 @@ | ||
| 47 | 44 | |
| 48 | 45 | @Test(groups = "short") |
| 49 | 46 | public void should_implement_equals_and_hashCode() { |
| 50 | - SystemAccessor accessor = new MappingManager(session) | |
| 47 | + SystemAccessor accessor = new MappingManager(session()) | |
| 51 | 48 | .createAccessor(SystemAccessor.class); |
| 52 | 49 | |
| 53 | 50 | assertThat(accessor).isNotEqualTo(new Object()); |
| @@ -57,32 +54,32 @@ | ||
| 57 | 54 | @Test(groups = "short") |
| 58 | 55 | @CassandraVersion(major = 2.0) |
| 59 | 56 | public void should_allow_null_argument_in_accessor_when_set_by_name() { |
| 60 | - FooAccessor accessor = new MappingManager(session) | |
| 57 | + FooAccessor accessor = new MappingManager(session()) | |
| 61 | 58 | .createAccessor(FooAccessor.class); |
| 62 | 59 | |
| 63 | 60 | accessor.insert(1, null); |
| 64 | - Row row = session.execute("select * from foo where k = 1").one(); | |
| 61 | + Row row = session().execute("select * from foo where k = 1").one(); | |
| 65 | 62 | |
| 66 | 63 | assertThat(row.getString("v")).isNull(); |
| 67 | 64 | } |
| 68 | 65 | |
| 69 | 66 | @Test(groups = "short") |
| 70 | 67 | public void should_allow_null_argument_in_accessor_when_set_by_index() { |
| 71 | - FooBindMarkerAccessor accessor = new MappingManager(session) | |
| 68 | + FooBindMarkerAccessor accessor = new MappingManager(session()) | |
| 72 | 69 | .createAccessor(FooBindMarkerAccessor.class); |
| 73 | 70 | |
| 74 | 71 | accessor.insert(1, null); |
| 75 | 72 | |
| 76 | - Row row = session.execute("select * from foo where k = 1").one(); | |
| 73 | + Row row = session().execute("select * from foo where k = 1").one(); | |
| 77 | 74 | |
| 78 | 75 | assertThat(row.getString("v")).isNull(); |
| 79 | 76 | } |
| 80 | 77 | |
| 81 | 78 | @Test(groups = "short") |
| 82 | 79 | public void should_allow_void_return_type_in_accessor() { |
| 83 | - VoidAccessor accessor = new MappingManager(session).createAccessor(VoidAccessor.class); | |
| 80 | + VoidAccessor accessor = new MappingManager(session()).createAccessor(VoidAccessor.class); | |
| 84 | 81 | accessor.insert(1, "bar"); |
| 85 | - Row row = session.execute("select * from foo where k = 1").one(); | |
| 82 | + Row row = session().execute("select * from foo where k = 1").one(); | |
| 86 | 83 | assertThat(row.getInt("k")).isEqualTo(1); |
| 87 | 84 | assertThat(row.getString("v")).isEqualTo("bar"); |
| 88 | 85 | } |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperCompositeKeyTest.java +3 −6
| @@ -21,17 +21,14 @@ | ||
| 21 | 21 | import com.datastax.driver.mapping.annotations.Table; |
| 22 | 22 | import org.testng.annotations.Test; |
| 23 | 23 | |
| 24 | -import java.util.Collection; | |
| 25 | -import java.util.Collections; | |
| 26 | - | |
| 27 | 24 | /** |
| 28 | 25 | * Tests for the mapper with composite partition keys and multiple clustering columns. |
| 29 | 26 | */ |
| 30 | 27 | public class MapperCompositeKeyTest extends CCMTestsSupport { |
| 31 | 28 | |
| 32 | 29 | @Override |
| 33 | - public Collection<String> createTestFixtures() { | |
| 34 | - return Collections.singletonList("CREATE TABLE test_table (pk1 int, pk2 int, cc1 int, cc2 int, PRIMARY KEY ((pk1, pk2), cc1, cc2))"); | |
| 30 | + public void onTestContextInitialized() { | |
| 31 | + execute("CREATE TABLE test_table (pk1 int, pk2 int, cc1 int, cc2 int, PRIMARY KEY ((pk1, pk2), cc1, cc2))"); | |
| 35 | 32 | } |
| 36 | 33 | |
| 37 | 34 | @SuppressWarnings("unused") |
| @@ -84,6 +81,6 @@ | ||
| 84 | 81 | |
| 85 | 82 | @Test(groups = "short") |
| 86 | 83 | public void testCreateMapper() throws Exception { |
| 87 | - new MappingManager(session).mapper(TestTable.class); | |
| 84 | + new MappingManager(session()).mapper(TestTable.class); | |
| 88 | 85 | } |
| 89 | 86 | } |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperComputedFieldsTest.java +6 −9
| @@ -20,13 +20,10 @@ | ||
| 20 | 20 | import com.datastax.driver.core.exceptions.InvalidQueryException; |
| 21 | 21 | import com.datastax.driver.core.utils.CassandraVersion; |
| 22 | 22 | import com.datastax.driver.mapping.annotations.*; |
| 23 | -import com.google.common.collect.Lists; | |
| 24 | 23 | import org.testng.SkipException; |
| 25 | 24 | import org.testng.annotations.BeforeMethod; |
| 26 | 25 | import org.testng.annotations.Test; |
| 27 | 26 | |
| 28 | -import java.util.Collection; | |
| 29 | - | |
| 30 | 27 | import static com.datastax.driver.core.Assertions.assertThat; |
| 31 | 28 | import static com.datastax.driver.core.ProtocolVersion.V1; |
| 32 | 29 | import static org.assertj.core.api.Assertions.fail; |
| @@ -39,8 +36,8 @@ | ||
| 39 | 36 | public class MapperComputedFieldsTest extends CCMTestsSupport { |
| 40 | 37 | |
| 41 | 38 | @Override |
| 42 | - public Collection<String> createTestFixtures() { | |
| 43 | - return Lists.newArrayList( | |
| 39 | + public void onTestContextInitialized() { | |
| 40 | + execute( | |
| 44 | 41 | "CREATE TABLE user (login text primary key, name text)", |
| 45 | 42 | "INSERT INTO user (login, name) VALUES ('testlogin', 'test name')"); |
| 46 | 43 | } |
| @@ -51,8 +48,8 @@ | ||
| 51 | 48 | |
| 52 | 49 | @BeforeMethod(groups = "short") |
| 53 | 50 | void setup() { |
| 54 | - mappingManager = new MappingManager(session); | |
| 55 | - protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 51 | + mappingManager = new MappingManager(session()); | |
| 52 | + protocolVersion = cluster().getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 56 | 53 | if (protocolVersion.compareTo(V1) > 0) |
| 57 | 54 | userMapper = mappingManager.mapper(User.class); |
| 58 | 55 | } |
| @@ -82,7 +79,7 @@ | ||
| 82 | 79 | assertThat(fetched.getTtl()).isNull(); // TTL should be null since it was not set. |
| 83 | 80 | |
| 84 | 81 | // Overwrite with TTL |
| 85 | - session.execute("insert into user (login, name) values ('testlogin2', 'blah') using TTL 600"); | |
| 82 | + session().execute("insert into user (login, name) values ('testlogin2', 'blah') using TTL 600"); | |
| 86 | 83 | fetched = userMapper.get("testlogin2"); |
| 87 | 84 | assertThat(fetched.getWriteTime()).isGreaterThanOrEqualTo(writeTime).isLessThan(writeTime + 30000000L); |
| 88 | 85 | assertThat(fetched.getTtl()).isBetween(570, 600); // TTL should be within 30 secs. |
| @@ -104,7 +101,7 @@ | ||
| 104 | 101 | public void should_map_aliased_resultset_to_objects() { |
| 105 | 102 | Statement getQuery = userMapper.getQuery("testlogin"); |
| 106 | 103 | getQuery.setConsistencyLevel(ConsistencyLevel.QUORUM); |
| 107 | - ResultSet rs = session.execute(getQuery); | |
| 104 | + ResultSet rs = session().execute(getQuery); | |
| 108 | 105 | |
| 109 | 106 | Result<User> result = userMapper.mapAliased(rs); |
| 110 | 107 | User user = result.one(); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperCustomCodecTest.java +18 −19
| @@ -22,7 +22,6 @@ | ||
| 22 | 22 | import com.google.common.base.Optional; |
| 23 | 23 | import com.google.common.base.Predicate; |
| 24 | 24 | import com.google.common.collect.ImmutableMap; |
| 25 | -import com.google.common.collect.Lists; | |
| 26 | 25 | import com.google.common.reflect.TypeParameter; |
| 27 | 26 | import com.google.common.reflect.TypeToken; |
| 28 | 27 | import org.testng.annotations.Test; |
| @@ -39,8 +38,8 @@ | ||
| 39 | 38 | public class MapperCustomCodecTest extends CCMTestsSupport { |
| 40 | 39 | |
| 41 | 40 | @Override |
| 42 | - public Collection<String> createTestFixtures() { | |
| 43 | - return Lists.newArrayList( | |
| 41 | + public void onTestContextInitialized() { | |
| 42 | + execute( | |
| 44 | 43 | // Columns mapped to custom types |
| 45 | 44 | "CREATE TABLE data1 (i int PRIMARY KEY, l bigint)", |
| 46 | 45 | "INSERT INTO data1 (i, l) VALUES (1, 11)", |
| @@ -65,7 +64,7 @@ | ||
| 65 | 64 | |
| 66 | 65 | @Test(groups = "short") |
| 67 | 66 | public void should_use_custom_codecs_with_basic_operations() { |
| 68 | - Mapper<Data1> mapper = new MappingManager(session).mapper(Data1.class); | |
| 67 | + Mapper<Data1> mapper = new MappingManager(session()).mapper(Data1.class); | |
| 69 | 68 | |
| 70 | 69 | // Get |
| 71 | 70 | Data1 data11 = mapper.get(new CustomInt(1)); |
| @@ -78,25 +77,25 @@ | ||
| 78 | 77 | data12.setL(new CustomLong(12)); |
| 79 | 78 | mapper.save(data12); |
| 80 | 79 | |
| 81 | - Row row = session.execute("select * from data1 where i = 2").one(); | |
| 80 | + Row row = session().execute("select * from data1 where i = 2").one(); | |
| 82 | 81 | assertThat(row.getInt(0)).isEqualTo(2); |
| 83 | 82 | assertThat(row.getLong(1)).isEqualTo(12); |
| 84 | 83 | |
| 85 | 84 | // Delete |
| 86 | 85 | mapper.delete(new CustomInt(2)); |
| 87 | - row = session.execute("select * from data1 where i = 2").one(); | |
| 86 | + row = session().execute("select * from data1 where i = 2").one(); | |
| 88 | 87 | assertThat(row).isNull(); |
| 89 | 88 | } |
| 90 | 89 | |
| 91 | 90 | @Test(groups = "short") |
| 92 | 91 | public void should_use_custom_codecs_with_accessors() { |
| 93 | - Data1Accessor accessor = new MappingManager(session).createAccessor(Data1Accessor.class); | |
| 92 | + Data1Accessor accessor = new MappingManager(session()).createAccessor(Data1Accessor.class); | |
| 94 | 93 | Data1 data1 = accessor.get(new CustomInt(1)); |
| 95 | 94 | assertThat(data1.getI()).isEqualTo(new CustomInt(1)); |
| 96 | 95 | assertThat(data1.getL()).isEqualTo(new CustomLong(11)); |
| 97 | 96 | |
| 98 | 97 | accessor.setL(1, new CustomLong(12)); |
| 99 | - Row row = session.execute("select l from data1 where i = 1").one(); | |
| 98 | + Row row = session().execute("select l from data1 where i = 1").one(); | |
| 100 | 99 | assertThat(row.getLong(0)).isEqualTo(12); |
| 101 | 100 | |
| 102 | 101 | accessor.setL(1, new CustomLong(11)); |
| @@ -104,7 +103,7 @@ | ||
| 104 | 103 | |
| 105 | 104 | @Test(groups = "short") |
| 106 | 105 | public void should_use_custom_codecs_in_UDTs() { |
| 107 | - Mapper<Data2> mapper = new MappingManager(session).mapper(Data2.class); | |
| 106 | + Mapper<Data2> mapper = new MappingManager(session()).mapper(Data2.class); | |
| 108 | 107 | |
| 109 | 108 | // Get |
| 110 | 109 | Data2 data21 = mapper.get(1); |
| @@ -117,7 +116,7 @@ | ||
| 117 | 116 | data22.setData(new Holder(2, 22)); |
| 118 | 117 | mapper.save(data22); |
| 119 | 118 | |
| 120 | - Row row = session.execute("select * from data2 where i = 2").one(); | |
| 119 | + Row row = session().execute("select * from data2 where i = 2").one(); | |
| 121 | 120 | assertThat(row.getUDTValue(1).getInt("i")).isEqualTo(2); |
| 122 | 121 | assertThat(row.getUDTValue(1).getLong("l")).isEqualTo(22); |
| 123 | 122 | |
| @@ -127,7 +126,7 @@ | ||
| 127 | 126 | |
| 128 | 127 | @Test(groups = "short") |
| 129 | 128 | public void should_use_custom_codecs_in_nested_structures() { |
| 130 | - Mapper<Data3> mapper = new MappingManager(session).mapper(Data3.class); | |
| 129 | + Mapper<Data3> mapper = new MappingManager(session()).mapper(Data3.class); | |
| 131 | 130 | |
| 132 | 131 | // Get |
| 133 | 132 | Data3 data31 = mapper.get(1); |
| @@ -140,7 +139,7 @@ | ||
| 140 | 139 | data32.setData(ImmutableMap.of(new CustomInt(2), new Holder(2, 22))); |
| 141 | 140 | mapper.save(data32); |
| 142 | 141 | |
| 143 | - Row row = session.execute("select * from data3 where i = 2").one(); | |
| 142 | + Row row = session().execute("select * from data3 where i = 2").one(); | |
| 144 | 143 | Map<Integer, UDTValue> data = row.getMap(1, Integer.class, UDTValue.class); |
| 145 | 144 | assertThat(data.containsKey(2)); |
| 146 | 145 | assertThat(data.get(2).getInt("i")).isEqualTo(2); |
| @@ -152,12 +151,12 @@ | ||
| 152 | 151 | |
| 153 | 152 | @Test(groups = "short", expectedExceptions = IllegalArgumentException.class) |
| 154 | 153 | public void should_fail_when_invalid_codec_with_no_default_ctor_provided() { |
| 155 | - new MappingManager(session).mapper(Data1InvalidCodecNoDefaultConstructor.class); | |
| 154 | + new MappingManager(session()).mapper(Data1InvalidCodecNoDefaultConstructor.class); | |
| 156 | 155 | } |
| 157 | 156 | |
| 158 | 157 | @Test(groups = "short", expectedExceptions = InvalidTypeException.class) |
| 159 | 158 | public void should_fail_when_invalid_codec_type_mapping() { |
| 160 | - Mapper<Data1InvalidCodecTypeMapping> mapper = new MappingManager(session).mapper(Data1InvalidCodecTypeMapping.class); | |
| 159 | + Mapper<Data1InvalidCodecTypeMapping> mapper = new MappingManager(session()).mapper(Data1InvalidCodecTypeMapping.class); | |
| 161 | 160 | |
| 162 | 161 | // Get should return an InvalidTypeException. |
| 163 | 162 | try { |
| @@ -176,12 +175,12 @@ | ||
| 176 | 175 | |
| 177 | 176 | @Test(groups = "short", expectedExceptions = IllegalArgumentException.class) |
| 178 | 177 | public void should_fail_when_invalid_codec_with_no_default_ctor_provided_in_accessor() { |
| 179 | - new MappingManager(session).createAccessor(Data1AccessorNoDefaultConstructor.class); | |
| 178 | + new MappingManager(session()).createAccessor(Data1AccessorNoDefaultConstructor.class); | |
| 180 | 179 | } |
| 181 | 180 | |
| 182 | 181 | @Test(groups = "short", expectedExceptions = InvalidTypeException.class) |
| 183 | 182 | public void should_fail_when_invalid_codec_type_mapping_in_accessor() { |
| 184 | - Data1AccessorInvalidCodecTypeMapping accessor = new MappingManager(session).createAccessor(Data1AccessorInvalidCodecTypeMapping.class); | |
| 183 | + Data1AccessorInvalidCodecTypeMapping accessor = new MappingManager(session()).createAccessor(Data1AccessorInvalidCodecTypeMapping.class); | |
| 185 | 184 | |
| 186 | 185 | // Get should return an InvalidTypeException. |
| 187 | 186 | try { |
| @@ -196,7 +195,7 @@ | ||
| 196 | 195 | |
| 197 | 196 | @Test(groups = "short") |
| 198 | 197 | public void should_be_able_to_use_parameterized_type() { |
| 199 | - Mapper<Data1ParameterizedType> mapper = new MappingManager(session).mapper(Data1ParameterizedType.class); | |
| 198 | + Mapper<Data1ParameterizedType> mapper = new MappingManager(session()).mapper(Data1ParameterizedType.class); | |
| 200 | 199 | |
| 201 | 200 | Data1ParameterizedType data1 = mapper.get(1); |
| 202 | 201 | assertThat(data1.getL()).isEqualTo(Optional.of(11L)); |
| @@ -212,7 +211,7 @@ | ||
| 212 | 211 | assertThat(empty1r.getL()).isEqualTo(Optional.<Long>absent()); |
| 213 | 212 | |
| 214 | 213 | // Value should come back absent with codec, otherwise null with getObject, 0 with getLong. |
| 215 | - Row row = session.execute("select l from data1 where i=1000").one(); | |
| 214 | + Row row = session().execute("select l from data1 where i=1000").one(); | |
| 216 | 215 | assertThat(row.getObject(0)).isEqualTo(null); // should map to long codec and return null. |
| 217 | 216 | assertThat(row.getLong(0)).isEqualTo(0L); // default boxed primitive value. |
| 218 | 217 | assertThat(row.get(0, new OptionalOfLong())).isEqualTo(Optional.<Long>absent()); |
| @@ -224,7 +223,7 @@ | ||
| 224 | 223 | mapper.save(present1); |
| 225 | 224 | |
| 226 | 225 | // Value should come back present with codec, otherwise 20L. |
| 227 | - row = session.execute("select l from data1 where i=1001").one(); | |
| 226 | + row = session().execute("select l from data1 where i=1001").one(); | |
| 228 | 227 | assertThat(row.getObject(0)).isEqualTo(20L); // should map to long codec. |
| 229 | 228 | assertThat(row.getLong(0)).isEqualTo(20L); |
| 230 | 229 | assertThat(row.get(0, new OptionalOfLong())).isEqualTo(Optional.of(20L)); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperDefaultKeyspaceTest.java +8 −10
| @@ -23,8 +23,6 @@ | ||
| 23 | 23 | import com.google.common.base.Objects; |
| 24 | 24 | import org.testng.annotations.Test; |
| 25 | 25 | |
| 26 | -import java.util.Arrays; | |
| 27 | -import java.util.Collection; | |
| 28 | 26 | import java.util.UUID; |
| 29 | 27 | |
| 30 | 28 | import static org.testng.Assert.assertEquals; |
| @@ -40,8 +38,8 @@ | ||
| 40 | 38 | private static final String KEYSPACE = "mapper_default_keyspace_test_ks"; |
| 41 | 39 | |
| 42 | 40 | @Override |
| 43 | - public Collection<String> createTestFixtures() { | |
| 44 | - return Arrays.asList( | |
| 41 | + public void onTestContextInitialized() { | |
| 42 | + execute( | |
| 45 | 43 | String.format("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }", KEYSPACE), |
| 46 | 44 | String.format("CREATE TYPE IF NOT EXISTS %s.group_name (name text)", KEYSPACE), |
| 47 | 45 | String.format("CREATE TABLE IF NOT EXISTS %s.groups (group_id uuid PRIMARY KEY, name text)", KEYSPACE), |
| @@ -51,9 +49,9 @@ | ||
| 51 | 49 | @Test(groups = "short") |
| 52 | 50 | public void testTableWithDefaultKeyspace() throws Exception { |
| 53 | 51 | // Ensure that the test session is logged into the keyspace. |
| 54 | - session.execute("USE " + KEYSPACE); | |
| 52 | + session().execute("USE " + KEYSPACE); | |
| 55 | 53 | |
| 56 | - MappingManager manager = new MappingManager(session); | |
| 54 | + MappingManager manager = new MappingManager(session()); | |
| 57 | 55 | Mapper<Group> m = manager.mapper(Group.class); |
| 58 | 56 | Group group = new Group("testGroup"); |
| 59 | 57 | UUID groupId = group.getGroupId(); |
| @@ -73,9 +71,9 @@ | ||
| 73 | 71 | @Test(groups = "short") |
| 74 | 72 | public void testUDTWithDefaultKeyspace() throws Exception { |
| 75 | 73 | // Ensure that the test session is logged into the keyspace. |
| 76 | - session.execute("USE " + KEYSPACE); | |
| 74 | + session().execute("USE " + KEYSPACE); | |
| 77 | 75 | |
| 78 | - MappingManager manager = new MappingManager(session); | |
| 76 | + MappingManager manager = new MappingManager(session()); | |
| 79 | 77 | Mapper<Group2> m = manager.mapper(Group2.class); |
| 80 | 78 | Group2 group = new Group2(new GroupName("testGroup")); |
| 81 | 79 | UUID groupId = group.getGroupId(); |
| @@ -96,7 +94,7 @@ | ||
| 96 | 94 | expectedExceptions = IllegalArgumentException.class, |
| 97 | 95 | expectedExceptionsMessageRegExp = "Error creating mapper for class Group, the @Table annotation declares no default keyspace, and the session is not currently logged to any keyspace") |
| 98 | 96 | public void should_throw_a_meaningful_error_message_when_no_default_table_keyspace_and_session_not_logged() { |
| 99 | - Session session2 = cluster.connect(); | |
| 97 | + Session session2 = cluster().connect(); | |
| 100 | 98 | MappingManager manager = new MappingManager(session2); |
| 101 | 99 | manager.mapper(Group.class); |
| 102 | 100 | } |
| @@ -105,7 +103,7 @@ | ||
| 105 | 103 | expectedExceptions = IllegalArgumentException.class, |
| 106 | 104 | expectedExceptionsMessageRegExp = "Error creating UDT codec for class GroupName, the @UDT annotation declares no default keyspace, and the session is not currently logged to any keyspace") |
| 107 | 105 | public void should_throw_a_meaningful_error_message_when_no_default_udt_keyspace_and_session_not_logged() { |
| 108 | - Session session2 = cluster.connect(); | |
| 106 | + Session session2 = cluster().connect(); | |
| 109 | 107 | MappingManager manager = new MappingManager(session2); |
| 110 | 108 | manager.udtCodec(GroupName.class); |
| 111 | 109 | } |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperMaterializedViewTest.java +6 −5
| @@ -24,19 +24,19 @@ | ||
| 24 | 24 | import org.testng.annotations.BeforeMethod; |
| 25 | 25 | import org.testng.annotations.Test; |
| 26 | 26 | |
| 27 | -import java.util.Collection; | |
| 28 | 27 | import java.util.Iterator; |
| 29 | 28 | |
| 30 | -import static com.google.common.collect.Lists.newArrayList; | |
| 31 | 29 | import static org.assertj.core.api.Assertions.assertThat; |
| 32 | 30 | |
| 31 | +@SuppressWarnings("unused") | |
| 33 | 32 | @CassandraVersion(major = 3.0) |
| 34 | 33 | public class MapperMaterializedViewTest extends CCMTestsSupport { |
| 35 | 34 | |
| 35 | + | |
| 36 | 36 | @Override |
| 37 | - public Collection<String> createTestFixtures() { | |
| 37 | + public void onTestContextInitialized() { | |
| 38 | 38 | // Example schema taken from: http://www.datastax.com/dev/blog/new-in-cassandra-3-0-materialized-views |
| 39 | - return newArrayList( | |
| 39 | + execute( | |
| 40 | 40 | "CREATE TABLE scores (user TEXT, game TEXT, year INT, month INT, day INT, score INT, PRIMARY KEY(user, game, year, month, day))", |
| 41 | 41 | "CREATE MATERIALIZED VIEW alltimehigh AS\n" |
| 42 | 42 | + " SELECT * FROM scores\n" |
| @@ -77,7 +77,7 @@ | ||
| 77 | 77 | |
| 78 | 78 | @BeforeMethod(groups = "short") |
| 79 | 79 | public void setUp() { |
| 80 | - accessor = new MappingManager(session).createAccessor(ScoreAccessor.class); | |
| 80 | + accessor = new MappingManager(session()).createAccessor(ScoreAccessor.class); | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
| @@ -243,6 +243,7 @@ | ||
| 243 | 243 | '}'; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | + @SuppressWarnings("SimplifiableIfStatement") | |
| 246 | 247 | @Override |
| 247 | 248 | public boolean equals(Object o) { |
| 248 | 249 | if (this == o) |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperNestedCollectionsTest.java +8 −5
| @@ -24,7 +24,10 @@ | ||
| 24 | 24 | import com.google.common.collect.Sets; |
| 25 | 25 | import org.testng.annotations.Test; |
| 26 | 26 | |
| 27 | -import java.util.*; | |
| 27 | +import java.util.ArrayList; | |
| 28 | +import java.util.List; | |
| 29 | +import java.util.Map; | |
| 30 | +import java.util.Set; | |
| 28 | 31 | |
| 29 | 32 | import static com.datastax.driver.core.Assertions.assertThat; |
| 30 | 33 | |
| @@ -33,8 +36,8 @@ | ||
| 33 | 36 | public class MapperNestedCollectionsTest extends CCMTestsSupport { |
| 34 | 37 | |
| 35 | 38 | @Override |
| 36 | - public Collection<String> createTestFixtures() { | |
| 37 | - return Lists.newArrayList( | |
| 39 | + public void onTestContextInitialized() { | |
| 40 | + execute( | |
| 38 | 41 | "CREATE TYPE testType(i int, ls list<frozen<set<int>>>)", |
| 39 | 42 | "CREATE TABLE testTable (k int primary key, " |
| 40 | 43 | + "m1 map<text, frozen<map<int, int>>>, " // nested collection |
| @@ -44,7 +47,7 @@ | ||
| 44 | 47 | |
| 45 | 48 | @Test(groups = "short") |
| 46 | 49 | public void should_map_fields_to_nested_collections() { |
| 47 | - Mapper<TestTable> mapper = new MappingManager(session).mapper(TestTable.class); | |
| 50 | + Mapper<TestTable> mapper = new MappingManager(session()).mapper(TestTable.class); | |
| 48 | 51 | |
| 49 | 52 | TestTable testTable = new TestTable(); |
| 50 | 53 | testTable.setK(1); |
| @@ -67,7 +70,7 @@ | ||
| 67 | 70 | |
| 68 | 71 | @Test(groups = "short") |
| 69 | 72 | public void should_map_accessor_params_to_nested_collections() { |
| 70 | - MappingManager manager = new MappingManager(session); | |
| 73 | + MappingManager manager = new MappingManager(session()); | |
| 71 | 74 | Mapper<TestTable> mapper = manager.mapper(TestTable.class); |
| 72 | 75 | TestAccessor accessor = manager.createAccessor(TestAccessor.class); |
| 73 | 76 |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperOptionTest.java +11 −13
| @@ -21,12 +21,10 @@ | ||
| 21 | 21 | import com.datastax.driver.core.utils.CassandraVersion; |
| 22 | 22 | import com.datastax.driver.mapping.annotations.PartitionKey; |
| 23 | 23 | import com.datastax.driver.mapping.annotations.Table; |
| 24 | -import com.google.common.collect.Lists; | |
| 25 | 24 | import org.testng.SkipException; |
| 26 | 25 | import org.testng.annotations.BeforeMethod; |
| 27 | 26 | import org.testng.annotations.Test; |
| 28 | 27 | |
| 29 | -import java.util.Collection; | |
| 30 | 28 | import java.util.concurrent.ExecutionException; |
| 31 | 29 | |
| 32 | 30 | import static com.datastax.driver.core.ConsistencyLevel.*; |
| @@ -42,14 +40,14 @@ | ||
| 42 | 40 | Mapper<User> mapper; |
| 43 | 41 | |
| 44 | 42 | @Override |
| 45 | - public Collection<String> createTestFixtures() { | |
| 46 | - return Lists.newArrayList("CREATE TABLE user (key int primary key, v text)"); | |
| 43 | + public void onTestContextInitialized() { | |
| 44 | + execute("CREATE TABLE user (key int primary key, v text)"); | |
| 47 | 45 | } |
| 48 | 46 | |
| 49 | 47 | @BeforeMethod(groups = "short") |
| 50 | 48 | public void setup() { |
| 51 | - mapper = new MappingManager(session).mapper(User.class); | |
| 52 | - protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 49 | + mapper = new MappingManager(session()).mapper(User.class); | |
| 50 | + protocolVersion = cluster().getConfiguration().getProtocolOptions().getProtocolVersion(); | |
| 53 | 51 | } |
| 54 | 52 | |
| 55 | 53 | @Test(groups = "short") |
| @@ -58,7 +56,7 @@ | ||
| 58 | 56 | Long tsValue = futureTimestamp(); |
| 59 | 57 | mapper.save(new User(42, "helloworld"), Option.timestamp(tsValue), Option.tracing(true)); |
| 60 | 58 | assertThat(mapper.get(42).getV()).isEqualTo("helloworld"); |
| 61 | - Long tsReturned = session.execute("SELECT writetime(v) FROM user WHERE key=" + 42).one().getLong(0); | |
| 59 | + Long tsReturned = session().execute("SELECT writetime(v) FROM user WHERE key=" + 42).one().getLong(0); | |
| 62 | 60 | assertThat(tsReturned).isEqualTo(tsValue); |
| 63 | 61 | } |
| 64 | 62 | |
| @@ -83,7 +81,7 @@ | ||
| 83 | 81 | assertThat(bs.isTracing()).isTrue(); |
| 84 | 82 | assertThat(bs.getConsistencyLevel()).isEqualTo(ALL); |
| 85 | 83 | |
| 86 | - ResultSet rs = session.execute(bs); | |
| 84 | + ResultSet rs = session().execute(bs); | |
| 87 | 85 | assertThat(rs.getExecutionInfo().getQueryTrace()).isNotNull(); |
| 88 | 86 | User us = mapper.mapAliased(rs).one(); |
| 89 | 87 | assertThat(us.getV()).isEqualTo("toget"); |
| @@ -97,7 +95,7 @@ | ||
| 97 | 95 | Long tsValue = futureTimestamp(); |
| 98 | 96 | mapper.save(new User(43, "helloworld"), Option.timestamp(tsValue)); |
| 99 | 97 | mapper.save(new User(44, "test")); |
| 100 | - Long tsReturned = session.execute("SELECT writetime(v) FROM user WHERE key=" + 44).one().getLong(0); | |
| 98 | + Long tsReturned = session().execute("SELECT writetime(v) FROM user WHERE key=" + 44).one().getLong(0); | |
| 101 | 99 | // Assuming we cannot go back in time (yet) and execute the write at ts=1 |
| 102 | 100 | assertThat(tsReturned).isNotEqualTo(tsValue); |
| 103 | 101 | } |
| @@ -165,7 +163,7 @@ | ||
| 165 | 163 | mapper.setDefaultSaveOptions(Option.timestamp(defaultTimestamp)); |
| 166 | 164 | |
| 167 | 165 | mapper.save(new User(42, "helloworld"), Option.timestamp(explicitTimestamp)); |
| 168 | - Long savedTimestamp = session.execute("SELECT writetime(v) FROM user WHERE key=" + 42).one().getLong(0); | |
| 166 | + Long savedTimestamp = session().execute("SELECT writetime(v) FROM user WHERE key=" + 42).one().getLong(0); | |
| 169 | 167 | assertThat(savedTimestamp).isEqualTo(explicitTimestamp); |
| 170 | 168 | } |
| 171 | 169 | |
| @@ -186,7 +184,7 @@ | ||
| 186 | 184 | assertThat(getWriteTime(user.getKey())).isEqualTo(timestamp); |
| 187 | 185 | mapper.delete(user.getKey()); |
| 188 | 186 | |
| 189 | - session.execute(mapper.saveQuery(user, Option.timestamp(timestamp))); | |
| 187 | + session().execute(mapper.saveQuery(user, Option.timestamp(timestamp))); | |
| 190 | 188 | assertThat(getWriteTime(user.getKey())).isEqualTo(timestamp); |
| 191 | 189 | mapper.delete(user.getKey()); |
| 192 | 190 | |
| @@ -201,13 +199,13 @@ | ||
| 201 | 199 | assertThat(getWriteTime(user.getKey())).isEqualTo(timestamp); |
| 202 | 200 | mapper.delete(user.getKey()); |
| 203 | 201 | |
| 204 | - session.execute(mapper.saveQuery(user)); | |
| 202 | + session().execute(mapper.saveQuery(user)); | |
| 205 | 203 | assertThat(getWriteTime(user.getKey())).isEqualTo(timestamp); |
| 206 | 204 | mapper.delete(user.getKey()); |
| 207 | 205 | } |
| 208 | 206 | |
| 209 | 207 | private Long getWriteTime(int key) { |
| 210 | - Row row = session.execute("SELECT writetime(v) FROM user WHERE key=" + key).one(); | |
| 208 | + Row row = session().execute("SELECT writetime(v) FROM user WHERE key=" + key).one(); | |
| 211 | 209 | return row.getLong(0); |
| 212 | 210 | } |
| 213 | 211 |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperPrimitiveTypes22Test.java +4 −5
| @@ -24,16 +24,15 @@ | ||
| 24 | 24 | import org.testng.annotations.Test; |
| 25 | 25 | |
| 26 | 26 | import java.nio.ByteBuffer; |
| 27 | -import java.util.Collection; | |
| 28 | -import java.util.Collections; | |
| 29 | 27 | |
| 30 | 28 | import static org.testng.Assert.assertEquals; |
| 31 | 29 | |
| 32 | 30 | @CassandraVersion(major = 2.2) |
| 33 | 31 | public class MapperPrimitiveTypes22Test extends CCMTestsSupport { |
| 34 | 32 | |
| 35 | - public Collection<String> createTestFixtures() { | |
| 36 | - return Collections.singletonList("CREATE TABLE primitiveTypes22 (" | |
| 33 | + @Override | |
| 34 | + public void onTestContextInitialized() { | |
| 35 | + execute("CREATE TABLE primitiveTypes22 (" | |
| 37 | 36 | + "byteBufferCol blob primary key," |
| 38 | 37 | + "localDateCol date," |
| 39 | 38 | + "timeCol time, timeWrapperCol time," |
| @@ -62,7 +61,7 @@ | ||
| 62 | 61 | primitiveTypes.setShortCol(shortCol); |
| 63 | 62 | primitiveTypes.setShortWrapperCol(shortWrapperCol); |
| 64 | 63 | |
| 65 | - Mapper<PrimitiveTypes22> mapper = new MappingManager(session).mapper(PrimitiveTypes22.class); | |
| 64 | + Mapper<PrimitiveTypes22> mapper = new MappingManager(session()).mapper(PrimitiveTypes22.class); | |
| 66 | 65 | mapper.save(primitiveTypes); |
| 67 | 66 | PrimitiveTypes22 primitiveTypes2 = mapper.get(byteBufferCol); |
| 68 | 67 |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperPrimitiveTypesTest.java +3 −5
| @@ -26,8 +26,6 @@ | ||
| 26 | 26 | import java.math.BigInteger; |
| 27 | 27 | import java.net.InetAddress; |
| 28 | 28 | import java.nio.ByteBuffer; |
| 29 | -import java.util.Collection; | |
| 30 | -import java.util.Collections; | |
| 31 | 29 | import java.util.Date; |
| 32 | 30 | import java.util.UUID; |
| 33 | 31 | |
| @@ -38,8 +36,8 @@ | ||
| 38 | 36 | */ |
| 39 | 37 | public class MapperPrimitiveTypesTest extends CCMTestsSupport { |
| 40 | 38 | |
| 41 | - public Collection<String> createTestFixtures() { | |
| 42 | - return Collections.singletonList("CREATE TABLE primitiveTypes (" | |
| 39 | + public void onTestContextInitialized() { | |
| 40 | + execute("CREATE TABLE primitiveTypes (" | |
| 43 | 41 | + "byteBufferCol blob primary key," |
| 44 | 42 | + "intCol int, intWrapperCol int," |
| 45 | 43 | + "longCol bigint, longWrapperCol bigint," |
| @@ -96,7 +94,7 @@ | ||
| 96 | 94 | primitiveTypes.setUuidCol(uuidCol); |
| 97 | 95 | primitiveTypes.setTimeUuidCol(timeUuidCol); |
| 98 | 96 | |
| 99 | - Mapper<PrimitiveTypes> mapper = new MappingManager(session).mapper(PrimitiveTypes.class); | |
| 97 | + Mapper<PrimitiveTypes> mapper = new MappingManager(session()).mapper(PrimitiveTypes.class); | |
| 100 | 98 | mapper.save(primitiveTypes); |
| 101 | 99 | PrimitiveTypes primitiveTypes2 = mapper.get(byteBufferCol); |
| 102 | 100 |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperSaveNullFieldsTest.java +4 −7
| @@ -20,12 +20,9 @@ | ||
| 20 | 20 | import com.datastax.driver.mapping.Mapper.Option; |
| 21 | 21 | import com.datastax.driver.mapping.annotations.PartitionKey; |
| 22 | 22 | import com.datastax.driver.mapping.annotations.Table; |
| 23 | -import com.google.common.collect.Lists; | |
| 24 | 23 | import org.testng.annotations.BeforeMethod; |
| 25 | 24 | import org.testng.annotations.Test; |
| 26 | 25 | |
| 27 | -import java.util.Collection; | |
| 28 | - | |
| 29 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| 30 | 27 | |
| 31 | 28 | @SuppressWarnings("unused") |
| @@ -34,13 +31,13 @@ | ||
| 34 | 31 | Mapper<User> mapper; |
| 35 | 32 | |
| 36 | 33 | @Override |
| 37 | - public Collection<String> createTestFixtures() { | |
| 38 | - return Lists.newArrayList("CREATE TABLE user (login text primary key, name text, phone text)"); | |
| 34 | + public void onTestContextInitialized() { | |
| 35 | + execute("CREATE TABLE user (login text primary key, name text, phone text)"); | |
| 39 | 36 | } |
| 40 | 37 | |
| 41 | 38 | @BeforeMethod(groups = "short") |
| 42 | 39 | public void setup() { |
| 43 | - mapper = new MappingManager(session).mapper(User.class); | |
| 40 | + mapper = new MappingManager(session()).mapper(User.class); | |
| 44 | 41 | } |
| 45 | 42 | |
| 46 | 43 | @Test(groups = "short") |
| @@ -74,7 +71,7 @@ | ||
| 74 | 71 | |
| 75 | 72 | private void should_save_null_fields(boolean nullName, boolean nullPhone, boolean saveExpected, Option... options) { |
| 76 | 73 | // Start with clean data |
| 77 | - session.execute("insert into user(login, name, phone) " | |
| 74 | + session().execute("insert into user(login, name, phone) " | |
| 78 | 75 | + "values ('test_login', 'previous_name', 'previous_phone')"); |
| 79 | 76 | |
| 80 | 77 | String newName = nullName ? null : "new_name"; |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperTest.java +13 −10
| @@ -24,7 +24,10 @@ | ||
| 24 | 24 | import org.testng.annotations.Test; |
| 25 | 25 | |
| 26 | 26 | import java.net.InetAddress; |
| 27 | -import java.util.*; | |
| 27 | +import java.util.Arrays; | |
| 28 | +import java.util.HashSet; | |
| 29 | +import java.util.Set; | |
| 30 | +import java.util.UUID; | |
| 28 | 31 | |
| 29 | 32 | import static org.assertj.core.api.Assertions.assertThat; |
| 30 | 33 | import static org.testng.Assert.assertEquals; |
| @@ -37,10 +40,10 @@ | ||
| 37 | 40 | public class MapperTest extends CCMTestsSupport { |
| 38 | 41 | |
| 39 | 42 | @Override |
| 40 | - public Collection<String> createTestFixtures() { | |
| 43 | + public void onTestContextInitialized() { | |
| 41 | 44 | // We'll allow to generate those create statement from the annotated entities later, but it's currently |
| 42 | 45 | // a TODO |
| 43 | - return Arrays.asList("CREATE TABLE users (user_id uuid PRIMARY KEY, name text, email text, year int, gender text)", | |
| 46 | + execute("CREATE TABLE users (user_id uuid PRIMARY KEY, name text, email text, year int, gender text)", | |
| 44 | 47 | "CREATE TABLE posts (user_id uuid, post_id timeuuid, title text, content text, device inet, tags set<text>, PRIMARY KEY(user_id, post_id))"); |
| 45 | 48 | } |
| 46 | 49 | |
| @@ -282,7 +285,7 @@ | ||
| 282 | 285 | // Very simple mapping a User, saving and getting it. Note that here we |
| 283 | 286 | // don't use the Accessor stuff since the queries we use are directly |
| 284 | 287 | // supported by the Mapper object. |
| 285 | - Mapper<User> m = new MappingManager(session).mapper(User.class); | |
| 288 | + Mapper<User> m = new MappingManager(session()).mapper(User.class); | |
| 286 | 289 | |
| 287 | 290 | User u1 = new User("Paul", "paul@yahoo.com"); |
| 288 | 291 | u1.setYear(2014); |
| @@ -298,7 +301,7 @@ | ||
| 298 | 301 | @Test(groups = "short") |
| 299 | 302 | @CassandraVersion(major = 2.0) |
| 300 | 303 | public void testDynamicEntity() throws Exception { |
| 301 | - MappingManager manager = new MappingManager(session); | |
| 304 | + MappingManager manager = new MappingManager(session()); | |
| 302 | 305 | |
| 303 | 306 | Mapper<Post> m = manager.mapper(Post.class); |
| 304 | 307 | |
| @@ -358,7 +361,7 @@ | ||
| 358 | 361 | |
| 359 | 362 | @Test(groups = "short") |
| 360 | 363 | public void should_map_objects_from_partial_queries() throws Exception { |
| 361 | - MappingManager manager = new MappingManager(session); | |
| 364 | + MappingManager manager = new MappingManager(session()); | |
| 362 | 365 | |
| 363 | 366 | Mapper<Post> m = manager.mapper(Post.class); |
| 364 | 367 | |
| @@ -376,7 +379,7 @@ | ||
| 376 | 379 | m.save(p3); |
| 377 | 380 | |
| 378 | 381 | // Retrieve posts with a projection query that only retrieves some of the fields |
| 379 | - ResultSet rs = session.execute("select user_id, post_id, title from posts where user_id = " + u1.getUserId()); | |
| 382 | + ResultSet rs = session().execute("select user_id, post_id, title from posts where user_id = " + u1.getUserId()); | |
| 380 | 383 | |
| 381 | 384 | Result<Post> result = m.map(rs); |
| 382 | 385 | for (Post post : result) { |
| @@ -389,13 +392,13 @@ | ||
| 389 | 392 | } |
| 390 | 393 | |
| 391 | 394 | // cleanup |
| 392 | - session.execute("delete from posts where user_id = " + u1.getUserId()); | |
| 395 | + session().execute("delete from posts where user_id = " + u1.getUserId()); | |
| 393 | 396 | } |
| 394 | 397 | |
| 395 | 398 | |
| 396 | 399 | @Test(groups = "short") |
| 397 | 400 | public void should_return_table_metadata() throws Exception { |
| 398 | - MappingManager manager = new MappingManager(session); | |
| 401 | + MappingManager manager = new MappingManager(session()); | |
| 399 | 402 | |
| 400 | 403 | Mapper<Post> m = manager.mapper(Post.class); |
| 401 | 404 | |
| @@ -406,7 +409,7 @@ | ||
| 406 | 409 | |
| 407 | 410 | @Test(groups = "short") |
| 408 | 411 | public void should_not_initialize_session_when_protocol_version_provided() { |
| 409 | - Session newSession = cluster.newSession(); | |
| 412 | + Session newSession = cluster().newSession(); | |
| 410 | 413 | |
| 411 | 414 | // Ensures that a Session is not initialized when a protocol version is provided. |
| 412 | 415 | MappingManager manager = new MappingManager(newSession, ProtocolVersion.V1); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperUDTCollectionsTest.java +7 −5
| @@ -23,7 +23,9 @@ | ||
| 23 | 23 | import org.testng.annotations.Test; |
| 24 | 24 | import org.testng.collections.Lists; |
| 25 | 25 | |
| 26 | -import java.util.*; | |
| 26 | +import java.util.List; | |
| 27 | +import java.util.Map; | |
| 28 | +import java.util.Set; | |
| 27 | 29 | |
| 28 | 30 | import static org.testng.Assert.assertEquals; |
| 29 | 31 | |
| @@ -34,8 +36,8 @@ | ||
| 34 | 36 | public class MapperUDTCollectionsTest extends CCMTestsSupport { |
| 35 | 37 | |
| 36 | 38 | @Override |
| 37 | - public Collection<String> createTestFixtures() { | |
| 38 | - return Arrays.asList("CREATE TYPE \"Sub\"(i int)", | |
| 39 | + public void onTestContextInitialized() { | |
| 40 | + execute("CREATE TYPE \"Sub\"(i int)", | |
| 39 | 41 | "CREATE TABLE collection_examples (id int PRIMARY KEY, " + |
| 40 | 42 | "l list<frozen<\"Sub\">>, " + |
| 41 | 43 | "s set<frozen<\"Sub\">>, " + |
| @@ -179,7 +181,7 @@ | ||
| 179 | 181 | |
| 180 | 182 | @Test(groups = "short") |
| 181 | 183 | public void testCollections() throws Exception { |
| 182 | - Mapper<CollectionExamples> m = new MappingManager(session).mapper(CollectionExamples.class); | |
| 184 | + Mapper<CollectionExamples> m = new MappingManager(session()).mapper(CollectionExamples.class); | |
| 183 | 185 | |
| 184 | 186 | CollectionExamples c = new CollectionExamples(1, 1); |
| 185 | 187 | m.save(c); |
| @@ -189,7 +191,7 @@ | ||
| 189 | 191 | |
| 190 | 192 | @Test(groups = "short") |
| 191 | 193 | public void testNullCollection() { |
| 192 | - Mapper<CollectionExamples> m = new MappingManager(session).mapper(CollectionExamples.class); | |
| 194 | + Mapper<CollectionExamples> m = new MappingManager(session()).mapper(CollectionExamples.class); | |
| 193 | 195 | |
| 194 | 196 | CollectionExamples c = new CollectionExamples(1, 1); |
| 195 | 197 | c.setL(null); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperUDTTest.java +9 −9
| @@ -35,14 +35,14 @@ | ||
| 35 | 35 | public class MapperUDTTest extends CCMTestsSupport { |
| 36 | 36 | |
| 37 | 37 | @Override |
| 38 | - public Collection<String> createTestFixtures() { | |
| 39 | - return Arrays.asList("CREATE TYPE address (street text, city text, \"ZIP_code\" int, phones set<text>)", | |
| 38 | + public void onTestContextInitialized() { | |
| 39 | + execute("CREATE TYPE address (street text, city text, \"ZIP_code\" int, phones set<text>)", | |
| 40 | 40 | "CREATE TABLE users (user_id uuid PRIMARY KEY, name text, mainaddress frozen<address>, other_addresses map<text,frozen<address>>)"); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | @BeforeMethod(groups = "short") |
| 44 | 44 | public void clean() { |
| 45 | - session.execute("TRUNCATE users"); | |
| 45 | + session().execute("TRUNCATE users"); | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | @Table(name = "users", |
| @@ -245,7 +245,7 @@ | ||
| 245 | 245 | |
| 246 | 246 | @Test(groups = "short") |
| 247 | 247 | public void testSimpleEntity() throws Exception { |
| 248 | - Mapper<User> m = new MappingManager(session).mapper(User.class); | |
| 248 | + Mapper<User> m = new MappingManager(session()).mapper(User.class); | |
| 249 | 249 | |
| 250 | 250 | User u1 = new User("Paul", new Address("12 4th Street", "Springfield", 12345, "12341343", "435423245")); |
| 251 | 251 | u1.addOtherAddress("work", new Address("5 Main Street", "Springfield", 12345, "23431342")); |
| @@ -256,7 +256,7 @@ | ||
| 256 | 256 | |
| 257 | 257 | @Test(groups = "short") |
| 258 | 258 | public void should_handle_null_UDT_value() throws Exception { |
| 259 | - Mapper<User> m = new MappingManager(session).mapper(User.class); | |
| 259 | + Mapper<User> m = new MappingManager(session()).mapper(User.class); | |
| 260 | 260 | |
| 261 | 261 | User u1 = new User("Paul", null); |
| 262 | 262 | m.save(u1); |
| @@ -266,9 +266,9 @@ | ||
| 266 | 266 | |
| 267 | 267 | @Test(groups = "short") |
| 268 | 268 | public void testAccessor() throws Exception { |
| 269 | - MappingManager manager = new MappingManager(session); | |
| 269 | + MappingManager manager = new MappingManager(session()); | |
| 270 | 270 | |
| 271 | - Mapper<User> m = new MappingManager(session).mapper(User.class); | |
| 271 | + Mapper<User> m = new MappingManager(session()).mapper(User.class); | |
| 272 | 272 | User u1 = new User("Paul", new Address("12 4th Street", "Springfield", 12345, "12341343", "435423245")); |
| 273 | 273 | m.save(u1); |
| 274 | 274 | |
| @@ -309,8 +309,8 @@ | ||
| 309 | 309 | public void should_be_able_to_use_udtCodec_standalone() { |
| 310 | 310 | // Create a separate Cluster/Session to start with a CodecRegistry from scratch (so not already registered). |
| 311 | 311 | Cluster cluster = register(Cluster.builder() |
| 312 | - .addContactPointsWithPorts(getInitialContactPoints()) | |
| 313 | - .withPort(ccm.getBinaryPort()) | |
| 312 | + .addContactPoints(getContactPoints()) | |
| 313 | + .withPort(ccm().getBinaryPort()) | |
| 314 | 314 | .build()); |
| 315 | 315 | CodecRegistry registry = cluster.getConfiguration().getCodecRegistry(); |
| 316 | 316 | Session session = cluster.connect(keyspace); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/SyntheticFieldsMapperTest.java +3 −5
| @@ -25,8 +25,6 @@ | ||
| 25 | 25 | import java.io.IOException; |
| 26 | 26 | import java.io.InputStream; |
| 27 | 27 | import java.lang.reflect.Constructor; |
| 28 | -import java.util.Collection; | |
| 29 | -import java.util.Collections; | |
| 30 | 28 | |
| 31 | 29 | import static org.testng.Assert.assertEquals; |
| 32 | 30 | |
| @@ -34,8 +32,8 @@ | ||
| 34 | 32 | public class SyntheticFieldsMapperTest extends CCMTestsSupport { |
| 35 | 33 | |
| 36 | 34 | @Override |
| 37 | - public Collection<String> createTestFixtures() { | |
| 38 | - return Collections.singletonList("CREATE TABLE synthetic_fields (id int PRIMARY KEY)"); | |
| 35 | + public void onTestContextInitialized() { | |
| 36 | + execute("CREATE TABLE synthetic_fields (id int PRIMARY KEY)"); | |
| 39 | 37 | } |
| 40 | 38 | |
| 41 | 39 | /** |
| @@ -61,7 +59,7 @@ | ||
| 61 | 59 | // Instead, it is a different Class (identity + ClassLoader), a modified version of ClassWithSyntheticField |
| 62 | 60 | // Nice ClassCastException will be thrown if we try to cast it to ClassWithSyntheticField |
| 63 | 61 | @SuppressWarnings("unchecked") |
| 64 | - Mapper<Object> m = (Mapper<Object>) new MappingManager(session).mapper(classWithSyntheticFields); | |
| 62 | + Mapper<Object> m = (Mapper<Object>) new MappingManager(session()).mapper(classWithSyntheticFields); | |
| 65 | 63 | m.save(instance); |
| 66 | 64 | |
| 67 | 65 | assertEquals(m.get(42), instance); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/UDTFieldMapperTest.java +19 −19
| @@ -34,11 +34,11 @@ | ||
| 34 | 34 | |
| 35 | 35 | @Test(groups = "short") |
| 36 | 36 | public void udt_and_tables_with_ks_created_in_another_session_should_be_mapped() { |
| 37 | - Cluster cluster = register(Cluster.builder() | |
| 38 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 39 | - .withPort(ccm.getBinaryPort()) | |
| 37 | + Cluster cluster1 = register(Cluster.builder() | |
| 38 | + .addContactPoints(getContactPoints().get(0)) | |
| 39 | + .withPort(ccm().getBinaryPort()) | |
| 40 | 40 | .build()); |
| 41 | - Session session1 = cluster.connect(); | |
| 41 | + Session session1 = cluster1.connect(); | |
| 42 | 42 | // Create type and table |
| 43 | 43 | session1.execute("create schema if not exists java_509 " + |
| 44 | 44 | "with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"); |
| @@ -48,14 +48,14 @@ | ||
| 48 | 48 | session1.execute("create table java_509.my_hash (" + |
| 49 | 49 | "key int primary key, " + |
| 50 | 50 | "properties map<text, frozen<java_509.my_tuple>>);"); |
| 51 | - cluster.close(); | |
| 51 | + cluster1.close(); | |
| 52 | 52 | |
| 53 | 53 | // Create entities with another connection |
| 54 | - cluster = register(Cluster.builder() | |
| 55 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 56 | - .withPort(ccm.getBinaryPort()) | |
| 54 | + Cluster cluster2 = register(Cluster.builder() | |
| 55 | + .addContactPoints(getContactPoints().get(0)) | |
| 56 | + .withPort(ccm().getBinaryPort()) | |
| 57 | 57 | .build()); |
| 58 | - Session session2 = cluster.newSession(); | |
| 58 | + Session session2 = cluster2.newSession(); | |
| 59 | 59 | Mapper<MyHashWithKeyspace> hashMapper = new MappingManager(session2).mapper(MyHashWithKeyspace.class); |
| 60 | 60 | hashMapper.save(new MyHashWithKeyspace( |
| 61 | 61 | 1, |
| @@ -76,11 +76,11 @@ | ||
| 76 | 76 | |
| 77 | 77 | @Test(groups = "short") |
| 78 | 78 | public void udt_and_tables_without_ks_created_in_another_session_should_be_mapped() { |
| 79 | - Cluster cluster = register(Cluster.builder() | |
| 80 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 81 | - .withPort(ccm.getBinaryPort()) | |
| 79 | + Cluster cluster1 = register(Cluster.builder() | |
| 80 | + .addContactPoints(getContactPoints().get(0)) | |
| 81 | + .withPort(ccm().getBinaryPort()) | |
| 82 | 82 | .build()); |
| 83 | - Session session1 = cluster.connect(); | |
| 83 | + Session session1 = cluster1.connect(); | |
| 84 | 84 | session1.execute("create schema if not exists java_509b " + |
| 85 | 85 | "with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"); |
| 86 | 86 | session1.execute("use java_509b"); |
| @@ -90,14 +90,14 @@ | ||
| 90 | 90 | session1.execute("create table my_hash (" + |
| 91 | 91 | "key int primary key, " + |
| 92 | 92 | "properties map<text, frozen<my_tuple>>);"); |
| 93 | - cluster.close(); | |
| 93 | + cluster1.close(); | |
| 94 | 94 | |
| 95 | 95 | // Create entities with another connection |
| 96 | - cluster = Cluster.builder() | |
| 97 | - .addContactPointsWithPorts(ccm.addressOfNode(1)) | |
| 98 | - .withPort(ccm.getBinaryPort()) | |
| 99 | - .build(); | |
| 100 | - Session session2 = cluster.newSession(); | |
| 96 | + Cluster cluster2 = register(Cluster.builder() | |
| 97 | + .addContactPoints(getContactPoints().get(0)) | |
| 98 | + .withPort(ccm().getBinaryPort()) | |
| 99 | + .build()); | |
| 100 | + Session session2 = cluster2.newSession(); | |
| 101 | 101 | |
| 102 | 102 | session2.execute("use java_509b"); |
| 103 | 103 | Mapper<MyHash> hashMapper = new MappingManager(session2).mapper(MyHash.class); |