kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 6091a1724bd4f498ca70e30f7540190f0f15baeb969891db66fc19414fb32094 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-03-17 10:56 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-03-17 11:00 +01:00 |
| Parents | 3b8b6fab7abf |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +38 −26
| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | package com.datastax.driver.core; |
| 2 | 2 | |
| 3 | -import java.util.Collection; | |
| 4 | 3 | import java.util.List; |
| 5 | 4 | |
| 6 | 5 | import com.google.common.collect.Lists; |
| @@ -12,27 +11,46 @@ | ||
| 12 | 11 | |
| 13 | 12 | import static com.datastax.driver.core.Assertions.assertThat; |
| 14 | 13 | |
| 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' }"; | |
| 16 | 17 | |
| 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 | |
| 21 | 21 | |
| 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; | |
| 26 | 24 | |
| 27 | - @DataProvider(name = "existingKeyspaceName") | |
| 28 | - public static Object[][] existingKeyspaceName() { | |
| 29 | - return new Object[][]{ { "ks" }, { "\"CaseSensitive\"" } }; | |
| 30 | - } | |
| 25 | + Session session; | |
| 31 | 26 | |
| 32 | 27 | @BeforeClass(groups = "short") |
| 33 | 28 | public void setup() { |
| 29 | + ccm = CCMBridge.create("schemaChangesTest", 1); | |
| 30 | + | |
| 31 | + cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build(); | |
| 34 | 32 | cluster2 = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build(); |
| 33 | + | |
| 35 | 34 | 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\"" } }; | |
| 36 | 54 | } |
| 37 | 55 | |
| 38 | 56 | @Test(groups = "short", dataProvider = "existingKeyspaceName") |
| @@ -66,12 +84,12 @@ | ||
| 66 | 84 | |
| 67 | 85 | @DataProvider(name = "newKeyspaceName") |
| 68 | 86 | public static Object[][] newKeyspaceName() { |
| 69 | - return new Object[][]{ { "ks2" }, { "\"CaseSensitive2\"" } }; | |
| 87 | + return new Object[][]{ { "lowercase2" }, { "\"CaseSensitive2\"" } }; | |
| 70 | 88 | } |
| 71 | 89 | |
| 72 | 90 | @Test(groups = "short", dataProvider = "newKeyspaceName") |
| 73 | 91 | 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)); | |
| 75 | 93 | |
| 76 | 94 | for (Metadata m : metadatas) |
| 77 | 95 | assertThat(m.getKeyspace(keyspace)) |
| @@ -80,7 +98,7 @@ | ||
| 80 | 98 | |
| 81 | 99 | @Test(groups = "short", dataProvider = "newKeyspaceName") |
| 82 | 100 | 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)); | |
| 84 | 102 | for (Metadata m : metadatas) |
| 85 | 103 | assertThat(m.getKeyspace(keyspace).isDurableWrites()) |
| 86 | 104 | .isTrue(); |
| @@ -93,7 +111,7 @@ | ||
| 93 | 111 | |
| 94 | 112 | @Test(groups = "short", dataProvider = "newKeyspaceName") |
| 95 | 113 | 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)); | |
| 97 | 115 | for (Metadata m : metadatas) |
| 98 | 116 | assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))) |
| 99 | 117 | .isNotEmpty(); |
| @@ -111,17 +129,11 @@ | ||
| 111 | 129 | @AfterMethod(groups = "short") |
| 112 | 130 | public void cleanup() { |
| 113 | 131 | ListenableFuture<List<ResultSet>> f = Futures.successfulAsList(Lists.newArrayList( |
| 114 | - session.executeAsync("DROP TABLE ks.table1"), | |
| 132 | + session.executeAsync("DROP TABLE lowercase.table1"), | |
| 115 | 133 | session.executeAsync("DROP TABLE \"CaseSensitive\".table1"), |
| 116 | - session.executeAsync("DROP KEYSPACE ks2"), | |
| 134 | + session.executeAsync("DROP KEYSPACE lowercase2"), | |
| 117 | 135 | session.executeAsync("DROP KEYSPACE \"CaseSensitive2\"") |
| 118 | 136 | )); |
| 119 | 137 | Futures.getUnchecked(f); |
| 120 | 138 | } |
| 121 | - | |
| 122 | - @AfterClass(groups = "short") | |
| 123 | - public void teardown() { | |
| 124 | - if (cluster2 != null) | |
| 125 | - cluster2.close(); | |
| 126 | - } | |
| 127 | 139 | } |