kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | fa0faab5e1cbff01d9aca77407030563b67769c4a1fc72340965fb2422b0fcb0 |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-03-03 15:24 -08:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-03-03 15:24 -08:00 |
| Parents | 78fed81be230, b6bfa638a5f0 |
5 files changed
modified driver-core/CHANGELOG.rst +1 −0
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | - [improvement] Reduce level of logs on missing rpc_address (JAVA-568) |
| 10 | 10 | - [improvement] Expose node token and range information (JAVA-312) |
| 11 | 11 | - [bug] Fix guava dependency when using OSGI (JAVA-620) |
| 12 | +- [bug] Fix handling of DROP events when ks name is case-sensitive (JAVA-678) | |
| 12 | 13 | |
| 13 | 14 | Merged from 2.0.9_fixes branch: |
| 14 | 15 |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +1 −1
| @@ -2131,7 +2131,7 @@ | ||
| 2131 | 2131 | if (scc.table.isEmpty()) |
| 2132 | 2132 | manager.metadata.removeKeyspace(scc.keyspace); |
| 2133 | 2133 | else { |
| 2134 | - KeyspaceMetadata keyspace = manager.metadata.getKeyspace(scc.keyspace); | |
| 2134 | + KeyspaceMetadata keyspace = manager.metadata.getKeyspaceInternal(scc.keyspace); | |
| 2135 | 2135 | if (keyspace == null) |
| 2136 | 2136 | logger.warn("Received a DROPPED notification for {}.{}, but this keyspace is unknown in our metadata", |
| 2137 | 2137 | scc.keyspace, scc.table); |
modified driver-core/src/main/java/com/datastax/driver/core/DefaultResultSetFuture.java +1 −1
| @@ -84,7 +84,7 @@ | ||
| 84 | 84 | // session.poolsState.setKeyspace(null); |
| 85 | 85 | session.cluster.manager.metadata.removeKeyspace(scc.keyspace); |
| 86 | 86 | } else { |
| 87 | - KeyspaceMetadata keyspace = session.cluster.manager.metadata.getKeyspace(scc.keyspace); | |
| 87 | + KeyspaceMetadata keyspace = session.cluster.manager.metadata.getKeyspaceInternal(scc.keyspace); | |
| 88 | 88 | if (keyspace == null) |
| 89 | 89 | logger.warn("Received a DROPPED notification for {}.{}, but this keyspace is unknown in our metadata", |
| 90 | 90 | scc.keyspace, scc.columnFamily); |
modified driver-core/src/main/java/com/datastax/driver/core/Metadata.java +8 −0
| @@ -362,6 +362,14 @@ | ||
| 362 | 362 | return keyspaces.get(handleId(keyspace)); |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | + /** | |
| 366 | + * Used when the keyspace name is unquoted and in the exact case we store it in | |
| 367 | + * (typically when we got it from an internal call, not from the user). | |
| 368 | + */ | |
| 369 | + KeyspaceMetadata getKeyspaceInternal(String keyspace) { | |
| 370 | + return keyspaces.get(keyspace); | |
| 371 | + } | |
| 372 | + | |
| 365 | 373 | void removeKeyspace(String keyspace) { |
| 366 | 374 | keyspaces.remove(keyspace); |
| 367 | 375 | if (tokenMap != null) |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +53 −45
| @@ -4,12 +4,10 @@ | ||
| 4 | 4 | import java.util.List; |
| 5 | 5 | |
| 6 | 6 | import com.google.common.collect.Lists; |
| 7 | -import org.testng.annotations.AfterClass; | |
| 8 | -import org.testng.annotations.AfterMethod; | |
| 9 | -import org.testng.annotations.BeforeClass; | |
| 10 | -import org.testng.annotations.Test; | |
| 11 | - | |
| 12 | -import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 7 | +import com.google.common.util.concurrent.Futures; | |
| 8 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 9 | +import org.testng.annotations.*; | |
| 10 | + | |
| 13 | 11 | import com.datastax.driver.core.utils.Bytes; |
| 14 | 12 | |
| 15 | 13 | import static com.datastax.driver.core.Assertions.assertThat; |
| @@ -23,7 +21,12 @@ | ||
| 23 | 21 | |
| 24 | 22 | @Override |
| 25 | 23 | protected Collection<String> getTableDefinitions() { |
| 26 | - return Lists.newArrayList(); | |
| 24 | + return Lists.newArrayList("CREATE KEYSPACE \"CaseSensitive\" WITH REPLICATION = { 'class' : 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1' }"); | |
| 25 | + } | |
| 26 | + | |
| 27 | + @DataProvider(name = "existingKeyspaceName") | |
| 28 | + public static Object[][] existingKeyspaceName() { | |
| 29 | + return new Object[][]{ { "ks" }, { "\"CaseSensitive\"" } }; | |
| 27 | 30 | } |
| 28 | 31 | |
| 29 | 32 | @BeforeClass(groups = "short") |
| @@ -32,83 +35,88 @@ | ||
| 32 | 35 | metadatas = Lists.newArrayList(cluster.getMetadata(), cluster2.getMetadata()); |
| 33 | 36 | } |
| 34 | 37 | |
| 35 | - @Test(groups = "short") | |
| 36 | - public void should_notify_of_table_creation() { | |
| 37 | - session.execute("CREATE TABLE ks.table1(i int primary key)"); | |
| 38 | + @Test(groups = "short", dataProvider = "existingKeyspaceName") | |
| 39 | + public void should_notify_of_table_creation(String keyspace) { | |
| 40 | + session.execute(String.format("CREATE TABLE %s.table1(i int primary key)", keyspace)); | |
| 38 | 41 | |
| 39 | 42 | for (Metadata m : metadatas) |
| 40 | - assertThat(m.getKeyspace("ks").getTable("table1")) | |
| 43 | + assertThat(m.getKeyspace(keyspace).getTable("table1")) | |
| 41 | 44 | .isNotNull(); |
| 42 | 45 | } |
| 43 | 46 | |
| 44 | - @Test(groups = "short") | |
| 45 | - public void should_notify_of_table_update() { | |
| 46 | - session.execute("CREATE TABLE ks.table1(i int primary key)"); | |
| 47 | - session.execute("ALTER TABLE ks.table1 ADD j int"); | |
| 47 | + @Test(groups = "short", dataProvider = "existingKeyspaceName") | |
| 48 | + public void should_notify_of_table_update(String keyspace) { | |
| 49 | + session.execute(String.format("CREATE TABLE %s.table1(i int primary key)", keyspace)); | |
| 50 | + session.execute(String.format("ALTER TABLE %s.table1 ADD j int", keyspace)); | |
| 48 | 51 | |
| 49 | 52 | for (Metadata m : metadatas) |
| 50 | - assertThat(m.getKeyspace("ks").getTable("table1").getColumn("j")) | |
| 53 | + assertThat(m.getKeyspace(keyspace).getTable("table1").getColumn("j")) | |
| 51 | 54 | .isNotNull(); |
| 52 | 55 | } |
| 53 | 56 | |
| 54 | - @Test(groups = "short") | |
| 55 | - public void should_notify_of_table_drop() { | |
| 56 | - session.execute("CREATE TABLE ks.table1(i int primary key)"); | |
| 57 | - session.execute("DROP TABLE ks.table1"); | |
| 57 | + @Test(groups = "short", dataProvider = "existingKeyspaceName") | |
| 58 | + public void should_notify_of_table_drop(String keyspace) { | |
| 59 | + session.execute(String.format("CREATE TABLE %s.table1(i int primary key)", keyspace)); | |
| 60 | + session.execute(String.format("DROP TABLE %s.table1", keyspace)); | |
| 58 | 61 | |
| 59 | 62 | for (Metadata m : metadatas) |
| 60 | - assertThat(m.getKeyspace("ks").getTable("table1")) | |
| 63 | + assertThat(m.getKeyspace(keyspace).getTable("table1")) | |
| 61 | 64 | .isNull(); |
| 62 | 65 | } |
| 63 | 66 | |
| 64 | - @Test(groups = "short") | |
| 65 | - public void should_notify_of_keyspace_creation() { | |
| 66 | - session.execute("CREATE KEYSPACE ks2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); | |
| 67 | + @DataProvider(name = "newKeyspaceName") | |
| 68 | + public static Object[][] newKeyspaceName() { | |
| 69 | + return new Object[][]{ { "ks2" }, { "\"CaseSensitive2\"" } }; | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Test(groups = "short", dataProvider = "newKeyspaceName") | |
| 73 | + 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)); | |
| 67 | 75 | |
| 68 | 76 | for (Metadata m : metadatas) |
| 69 | - assertThat(m.getKeyspace("ks2")) | |
| 77 | + assertThat(m.getKeyspace(keyspace)) | |
| 70 | 78 | .isNotNull(); |
| 71 | 79 | } |
| 72 | 80 | |
| 73 | - @Test(groups = "short") | |
| 74 | - public void should_notify_of_keyspace_update() { | |
| 75 | - session.execute("CREATE KEYSPACE ks2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); | |
| 81 | + @Test(groups = "short", dataProvider = "newKeyspaceName") | |
| 82 | + 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)); | |
| 76 | 84 | for (Metadata m : metadatas) |
| 77 | - assertThat(m.getKeyspace("ks2").isDurableWrites()) | |
| 85 | + assertThat(m.getKeyspace(keyspace).isDurableWrites()) | |
| 78 | 86 | .isTrue(); |
| 79 | 87 | |
| 80 | - session.execute("ALTER KEYSPACE ks2 WITH durable_writes = false"); | |
| 88 | + session.execute(String.format("ALTER KEYSPACE %s WITH durable_writes = false", keyspace)); | |
| 81 | 89 | for (Metadata m : metadatas) |
| 82 | - assertThat(m.getKeyspace("ks2").isDurableWrites()) | |
| 90 | + assertThat(m.getKeyspace(keyspace).isDurableWrites()) | |
| 83 | 91 | .isFalse(); |
| 84 | 92 | } |
| 85 | 93 | |
| 86 | - @Test(groups = "short") | |
| 87 | - public void should_notify_of_keyspace_drop() { | |
| 88 | - session.execute("CREATE KEYSPACE ks2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); | |
| 94 | + @Test(groups = "short", dataProvider = "newKeyspaceName") | |
| 95 | + 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)); | |
| 89 | 97 | for (Metadata m : metadatas) |
| 90 | - assertThat(m.getReplicas("ks2", Bytes.fromHexString("0xCAFEBABE"))) | |
| 98 | + assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))) | |
| 91 | 99 | .isNotEmpty(); |
| 92 | 100 | |
| 93 | - session.execute("DROP KEYSPACE ks2"); | |
| 101 | + session.execute(String.format("DROP KEYSPACE %s", keyspace)); | |
| 94 | 102 | |
| 95 | 103 | for (Metadata m : metadatas) { |
| 96 | - assertThat(m.getKeyspace("ks2")) | |
| 104 | + assertThat(m.getKeyspace(keyspace)) | |
| 97 | 105 | .isNull(); |
| 98 | - assertThat(m.getReplicas("ks2", Bytes.fromHexString("0xCAFEBABE"))) | |
| 106 | + assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))) | |
| 99 | 107 | .isEmpty(); |
| 100 | 108 | } |
| 101 | 109 | } |
| 102 | 110 | |
| 103 | 111 | @AfterMethod(groups = "short") |
| 104 | 112 | public void cleanup() { |
| 105 | - try { | |
| 106 | - session.execute("DROP TABLE ks.table1"); | |
| 107 | - } catch(InvalidQueryException ex) {} | |
| 108 | - | |
| 109 | - try { | |
| 110 | - session.execute("DROP KEYSPACE ks2"); | |
| 111 | - } catch(InvalidQueryException ex) {} | |
| 113 | + ListenableFuture<List<ResultSet>> f = Futures.successfulAsList(Lists.newArrayList( | |
| 114 | + session.executeAsync("DROP TABLE ks.table1"), | |
| 115 | + session.executeAsync("DROP TABLE \"CaseSensitive\".table1"), | |
| 116 | + session.executeAsync("DROP KEYSPACE ks2"), | |
| 117 | + session.executeAsync("DROP KEYSPACE \"CaseSensitive2\"") | |
| 118 | + )); | |
| 119 | + Futures.getUnchecked(f); | |
| 112 | 120 | } |
| 113 | 121 | |
| 114 | 122 | @AfterClass(groups = "short") |