Elffuss BraidHub

kikocis/java-driver public

Refactor SchemaChangesTest to not use PerClassSingleNodeCluster.

(in preparation for JAVA-659)
Changeset6091a1724bd4f498ca70e30f7540190f0f15baeb969891db66fc19414fb32094
Authorolim7t <omichallat+github@gmail.com> · 2015-03-17 10:56 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2015-03-17 11:00 +01:00
Parents3b8b6fab7abf

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +38 −26
@@ -1,6 +1,5 @@
11 package com.datastax.driver.core;
22
3-import java.util.Collection;
43 import java.util.List;
54
65 import com.google.common.collect.Lists;
@@ -12,27 +11,46 @@
1211
1312 import static com.datastax.driver.core.Assertions.assertThat;
1413
15-public class SchemaChangesTest extends CCMBridge.PerClassSingleNodeCluster {
14+public class SchemaChangesTest {
15+ private static final String CREATE_KEYSPACE =
16+ "CREATE KEYSPACE %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor': '1' }";
1617
17- // Create a second cluster to check that other clients also get notified
18- Cluster cluster2;
19- // The metadatas of the two clusters should be kept in sync
20- List<Metadata> metadatas;
18+ CCMBridge ccm;
19+ Cluster cluster;
20+ Cluster cluster2; // a second cluster to check that other clients also get notified
2121
22- @Override
23- protected Collection<String> getTableDefinitions() {
24- return Lists.newArrayList("CREATE KEYSPACE \"CaseSensitive\" WITH REPLICATION = { 'class' : 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1' }");
25- }
22+ // The metadatas of the two clusters (we'll test that they're kept in sync)
23+ List<Metadata> metadatas;
2624
27- @DataProvider(name = "existingKeyspaceName")
28- public static Object[][] existingKeyspaceName() {
29- return new Object[][]{ { "ks" }, { "\"CaseSensitive\"" } };
30- }
25+ Session session;
3126
3227 @BeforeClass(groups = "short")
3328 public void setup() {
29+ ccm = CCMBridge.create("schemaChangesTest", 1);
30+
31+ cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build();
3432 cluster2 = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build();
33+
3534 metadatas = Lists.newArrayList(cluster.getMetadata(), cluster2.getMetadata());
35+
36+ session = cluster.connect();
37+ session.execute(String.format(CREATE_KEYSPACE, "lowercase"));
38+ session.execute(String.format(CREATE_KEYSPACE, "\"CaseSensitive\""));
39+ }
40+
41+ @AfterClass(groups = "short")
42+ public void teardown() {
43+ if (cluster != null)
44+ cluster.close();
45+ if (cluster2 != null)
46+ cluster2.close();
47+ if (ccm != null)
48+ ccm.remove();
49+ }
50+
51+ @DataProvider(name = "existingKeyspaceName")
52+ public static Object[][] existingKeyspaceName() {
53+ return new Object[][]{ { "lowercase" }, { "\"CaseSensitive\"" } };
3654 }
3755
3856 @Test(groups = "short", dataProvider = "existingKeyspaceName")
@@ -66,12 +84,12 @@
6684
6785 @DataProvider(name = "newKeyspaceName")
6886 public static Object[][] newKeyspaceName() {
69- return new Object[][]{ { "ks2" }, { "\"CaseSensitive2\"" } };
87+ return new Object[][]{ { "lowercase2" }, { "\"CaseSensitive2\"" } };
7088 }
7189
7290 @Test(groups = "short", dataProvider = "newKeyspaceName")
7391 public void should_notify_of_keyspace_creation(String keyspace) {
74- session.execute(String.format("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", keyspace));
92+ session.execute(String.format(CREATE_KEYSPACE, keyspace));
7593
7694 for (Metadata m : metadatas)
7795 assertThat(m.getKeyspace(keyspace))
@@ -80,7 +98,7 @@
8098
8199 @Test(groups = "short", dataProvider = "newKeyspaceName")
82100 public void should_notify_of_keyspace_update(String keyspace) {
83- session.execute(String.format("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", keyspace));
101+ session.execute(String.format(CREATE_KEYSPACE, keyspace));
84102 for (Metadata m : metadatas)
85103 assertThat(m.getKeyspace(keyspace).isDurableWrites())
86104 .isTrue();
@@ -93,7 +111,7 @@
93111
94112 @Test(groups = "short", dataProvider = "newKeyspaceName")
95113 public void should_notify_of_keyspace_drop(String keyspace) {
96- session.execute(String.format("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", keyspace));
114+ session.execute(String.format(CREATE_KEYSPACE, keyspace));
97115 for (Metadata m : metadatas)
98116 assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE")))
99117 .isNotEmpty();
@@ -111,17 +129,11 @@
111129 @AfterMethod(groups = "short")
112130 public void cleanup() {
113131 ListenableFuture<List<ResultSet>> f = Futures.successfulAsList(Lists.newArrayList(
114- session.executeAsync("DROP TABLE ks.table1"),
132+ session.executeAsync("DROP TABLE lowercase.table1"),
115133 session.executeAsync("DROP TABLE \"CaseSensitive\".table1"),
116- session.executeAsync("DROP KEYSPACE ks2"),
134+ session.executeAsync("DROP KEYSPACE lowercase2"),
117135 session.executeAsync("DROP KEYSPACE \"CaseSensitive2\"")
118136 ));
119137 Futures.getUnchecked(f);
120138 }
121-
122- @AfterClass(groups = "short")
123- public void teardown() {
124- if (cluster2 != null)
125- cluster2.close();
126- }
127139 }