kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 8dbbb33ac272748d29d6f901d8d9ec9b4b3ba9ee00e768d365ca19a999b83465 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-03-03 15:34 -08:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-03-03 15:34 -08:00 |
| Parents | 355ed2b1c974, fa0faab5e1cb |
5 files changed
modified driver-core/CHANGELOG.rst +1 −0
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | - [improvement] Reduce level of logs on missing rpc_address (JAVA-568) |
| 12 | 12 | - [improvement] Expose node token and range information (JAVA-312) |
| 13 | 13 | - [bug] Fix guava dependency when using OSGI (JAVA-620) |
| 14 | +- [bug] Fix handling of DROP events when ks name is case-sensitive (JAVA-678) | |
| 14 | 15 | - [bug] Prevent race between cancellation and query completion (JAVA-614) |
| 15 | 16 | - [bug] Prevent cancel and timeout from cancelling unrelated ResponseHandler if |
| 16 | 17 | streamId was already released and reused (JAVA-632). |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +2 −2
| @@ -2177,7 +2177,7 @@ | ||
| 2177 | 2177 | manager.metadata.removeKeyspace(scc.keyspace); |
| 2178 | 2178 | break; |
| 2179 | 2179 | case TABLE: |
| 2180 | - keyspace = manager.metadata.getKeyspace(scc.keyspace); | |
| 2180 | + keyspace = manager.metadata.getKeyspaceInternal(scc.keyspace); | |
| 2181 | 2181 | if (keyspace == null) |
| 2182 | 2182 | logger.warn("Received a DROPPED notification for table {}.{}, but this keyspace is unknown in our metadata", |
| 2183 | 2183 | scc.keyspace, scc.name); |
| @@ -2185,7 +2185,7 @@ | ||
| 2185 | 2185 | keyspace.removeTable(scc.name); |
| 2186 | 2186 | break; |
| 2187 | 2187 | case TYPE: |
| 2188 | - keyspace = manager.metadata.getKeyspace(scc.keyspace); | |
| 2188 | + keyspace = manager.metadata.getKeyspaceInternal(scc.keyspace); | |
| 2189 | 2189 | if (keyspace == null) |
| 2190 | 2190 | logger.warn("Received a DROPPED notification for UDT {}.{}, but this keyspace is unknown in our metadata", |
| 2191 | 2191 | scc.keyspace, scc.name); |
modified driver-core/src/main/java/com/datastax/driver/core/DefaultResultSetFuture.java +2 −2
| @@ -95,7 +95,7 @@ | ||
| 95 | 95 | session.cluster.manager.metadata.removeKeyspace(scc.keyspace); |
| 96 | 96 | break; |
| 97 | 97 | case TABLE: |
| 98 | - keyspace = session.cluster.manager.metadata.getKeyspace(scc.keyspace); | |
| 98 | + keyspace = session.cluster.manager.metadata.getKeyspaceInternal(scc.keyspace); | |
| 99 | 99 | if (keyspace == null) |
| 100 | 100 | logger.warn("Received a DROPPED notification for table {}.{}, but this keyspace is unknown in our metadata", |
| 101 | 101 | scc.keyspace, scc.name); |
| @@ -103,7 +103,7 @@ | ||
| 103 | 103 | keyspace.removeTable(scc.name); |
| 104 | 104 | break; |
| 105 | 105 | case TYPE: |
| 106 | - keyspace = session.cluster.manager.metadata.getKeyspace(scc.keyspace); | |
| 106 | + keyspace = session.cluster.manager.metadata.getKeyspaceInternal(scc.keyspace); | |
| 107 | 107 | if (keyspace == null) |
| 108 | 108 | logger.warn("Received a DROPPED notification for UDT {}.{}, but this keyspace is unknown in our metadata", |
| 109 | 109 | scc.keyspace, scc.name); |
modified driver-core/src/main/java/com/datastax/driver/core/Metadata.java +8 −0
| @@ -392,6 +392,14 @@ | ||
| 392 | 392 | return keyspaces.get(handleId(keyspace)); |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | + /** | |
| 396 | + * Used when the keyspace name is unquoted and in the exact case we store it in | |
| 397 | + * (typically when we got it from an internal call, not from the user). | |
| 398 | + */ | |
| 399 | + KeyspaceMetadata getKeyspaceInternal(String keyspace) { | |
| 400 | + return keyspaces.get(keyspace); | |
| 401 | + } | |
| 402 | + | |
| 395 | 403 | void removeKeyspace(String keyspace) { |
| 396 | 404 | keyspaces.remove(keyspace); |
| 397 | 405 | if (tokenMap != null) |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +73 −61
| @@ -4,13 +4,12 @@ | ||
| 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; |
| 12 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 14 | 13 | |
| 15 | 14 | import static com.datastax.driver.core.Assertions.assertThat; |
| 16 | 15 | |
| @@ -23,7 +22,12 @@ | ||
| 23 | 22 | |
| 24 | 23 | @Override |
| 25 | 24 | protected Collection<String> getTableDefinitions() { |
| 26 | - return Lists.newArrayList(); | |
| 25 | + return Lists.newArrayList("CREATE KEYSPACE \"CaseSensitive\" WITH REPLICATION = { 'class' : 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1' }"); | |
| 26 | + } | |
| 27 | + | |
| 28 | + @DataProvider(name = "existingKeyspaceName") | |
| 29 | + public static Object[][] existingKeyspaceName() { | |
| 30 | + return new Object[][]{ { "ks" }, { "\"CaseSensitive\"" } }; | |
| 27 | 31 | } |
| 28 | 32 | |
| 29 | 33 | @BeforeClass(groups = "short") |
| @@ -32,114 +36,122 @@ | ||
| 32 | 36 | metadatas = Lists.newArrayList(cluster.getMetadata(), cluster2.getMetadata()); |
| 33 | 37 | } |
| 34 | 38 | |
| 35 | - @Test(groups = "short") | |
| 36 | - public void should_notify_of_table_creation() { | |
| 37 | - session.execute("CREATE TABLE ks.table1(i int primary key)"); | |
| 39 | + @Test(groups = "short", dataProvider = "existingKeyspaceName") | |
| 40 | + public void should_notify_of_table_creation(String keyspace) { | |
| 41 | + session.execute(String.format("CREATE TABLE %s.table1(i int primary key)", keyspace)); | |
| 38 | 42 | |
| 39 | 43 | for (Metadata m : metadatas) |
| 40 | - assertThat(m.getKeyspace("ks").getTable("table1")) | |
| 44 | + assertThat(m.getKeyspace(keyspace).getTable("table1")) | |
| 41 | 45 | .isNotNull(); |
| 42 | 46 | } |
| 43 | 47 | |
| 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"); | |
| 48 | + @Test(groups = "short", dataProvider = "existingKeyspaceName") | |
| 49 | + public void should_notify_of_table_update(String keyspace) { | |
| 50 | + session.execute(String.format("CREATE TABLE %s.table1(i int primary key)", keyspace)); | |
| 51 | + session.execute(String.format("ALTER TABLE %s.table1 ADD j int", keyspace)); | |
| 48 | 52 | |
| 49 | 53 | for (Metadata m : metadatas) |
| 50 | - assertThat(m.getKeyspace("ks").getTable("table1").getColumn("j")) | |
| 54 | + assertThat(m.getKeyspace(keyspace).getTable("table1").getColumn("j")) | |
| 51 | 55 | .isNotNull(); |
| 52 | 56 | } |
| 53 | 57 | |
| 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"); | |
| 58 | + @Test(groups = "short", dataProvider = "existingKeyspaceName") | |
| 59 | + public void should_notify_of_table_drop(String keyspace) { | |
| 60 | + session.execute(String.format("CREATE TABLE %s.table1(i int primary key)", keyspace)); | |
| 61 | + session.execute(String.format("DROP TABLE %s.table1", keyspace)); | |
| 58 | 62 | |
| 59 | 63 | for (Metadata m : metadatas) |
| 60 | - assertThat(m.getKeyspace("ks").getTable("table1")) | |
| 64 | + assertThat(m.getKeyspace(keyspace).getTable("table1")) | |
| 61 | 65 | .isNull(); |
| 62 | 66 | } |
| 63 | 67 | |
| 64 | - @Test(groups = "short") | |
| 65 | - public void should_notify_of_udt_creation() { | |
| 66 | - session.execute("CREATE TYPE ks.type1(i int)"); | |
| 68 | + @Test(groups = "short", dataProvider = "existingKeyspaceName") | |
| 69 | + @CassandraVersion(major = 2.1) | |
| 70 | + public void should_notify_of_udt_creation(String keyspace) { | |
| 71 | + session.execute(String.format("CREATE TYPE %s.type1(i int)", keyspace)); | |
| 67 | 72 | |
| 68 | 73 | for (Metadata m : metadatas) |
| 69 | - assertThat(m.getKeyspace("ks").getUserType("type1")) | |
| 74 | + assertThat(m.getKeyspace(keyspace).getUserType("type1")) | |
| 70 | 75 | .isNotNull(); |
| 71 | 76 | } |
| 72 | 77 | |
| 73 | - @Test(groups = "short") | |
| 74 | - public void should_notify_of_udt_update() { | |
| 75 | - session.execute("CREATE TYPE ks.type1(i int)"); | |
| 76 | - session.execute("ALTER TYPE ks.type1 ADD j int"); | |
| 78 | + @Test(groups = "short", dataProvider = "existingKeyspaceName") | |
| 79 | + @CassandraVersion(major = 2.1) | |
| 80 | + public void should_notify_of_udt_update(String keyspace) { | |
| 81 | + session.execute(String.format("CREATE TYPE %s.type1(i int)", keyspace)); | |
| 82 | + session.execute(String.format("ALTER TYPE %s.type1 ADD j int", keyspace)); | |
| 77 | 83 | |
| 78 | 84 | for (Metadata m : metadatas) |
| 79 | - assertThat(m.getKeyspace("ks").getUserType("type1").getFieldType("j")) | |
| 85 | + assertThat(m.getKeyspace(keyspace).getUserType("type1").getFieldType("j")) | |
| 80 | 86 | .isNotNull(); |
| 81 | 87 | } |
| 82 | 88 | |
| 83 | - @Test(groups = "short") | |
| 84 | - public void should_notify_of_udt_drop() { | |
| 85 | - session.execute("CREATE TYPE ks.type1(i int)"); | |
| 86 | - session.execute("DROP TYPE ks.type1"); | |
| 89 | + @Test(groups = "short", dataProvider = "existingKeyspaceName") | |
| 90 | + @CassandraVersion(major = 2.1) | |
| 91 | + public void should_notify_of_udt_drop(String keyspace) { | |
| 92 | + session.execute(String.format("CREATE TYPE %s.type1(i int)", keyspace)); | |
| 93 | + session.execute(String.format("DROP TYPE %s.type1", keyspace)); | |
| 87 | 94 | |
| 88 | 95 | for (Metadata m : metadatas) |
| 89 | - assertThat(m.getKeyspace("ks").getUserType("type1")) | |
| 96 | + assertThat(m.getKeyspace(keyspace).getUserType("type1")) | |
| 90 | 97 | .isNull(); |
| 91 | 98 | } |
| 92 | 99 | |
| 93 | - @Test(groups = "short") | |
| 94 | - public void should_notify_of_keyspace_creation() { | |
| 95 | - session.execute("CREATE KEYSPACE ks2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); | |
| 100 | + @DataProvider(name = "newKeyspaceName") | |
| 101 | + public static Object[][] newKeyspaceName() { | |
| 102 | + return new Object[][]{ { "ks2" }, { "\"CaseSensitive2\"" } }; | |
| 103 | + } | |
| 104 | + | |
| 105 | + @Test(groups = "short", dataProvider = "newKeyspaceName") | |
| 106 | + public void should_notify_of_keyspace_creation(String keyspace) { | |
| 107 | + session.execute(String.format("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", keyspace)); | |
| 96 | 108 | |
| 97 | 109 | for (Metadata m : metadatas) |
| 98 | - assertThat(m.getKeyspace("ks2")) | |
| 110 | + assertThat(m.getKeyspace(keyspace)) | |
| 99 | 111 | .isNotNull(); |
| 100 | 112 | } |
| 101 | 113 | |
| 102 | - @Test(groups = "short") | |
| 103 | - public void should_notify_of_keyspace_update() { | |
| 104 | - session.execute("CREATE KEYSPACE ks2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); | |
| 114 | + @Test(groups = "short", dataProvider = "newKeyspaceName") | |
| 115 | + public void should_notify_of_keyspace_update(String keyspace) { | |
| 116 | + session.execute(String.format("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", keyspace)); | |
| 105 | 117 | for (Metadata m : metadatas) |
| 106 | - assertThat(m.getKeyspace("ks2").isDurableWrites()) | |
| 118 | + assertThat(m.getKeyspace(keyspace).isDurableWrites()) | |
| 107 | 119 | .isTrue(); |
| 108 | 120 | |
| 109 | - session.execute("ALTER KEYSPACE ks2 WITH durable_writes = false"); | |
| 121 | + session.execute(String.format("ALTER KEYSPACE %s WITH durable_writes = false", keyspace)); | |
| 110 | 122 | for (Metadata m : metadatas) |
| 111 | - assertThat(m.getKeyspace("ks2").isDurableWrites()) | |
| 123 | + assertThat(m.getKeyspace(keyspace).isDurableWrites()) | |
| 112 | 124 | .isFalse(); |
| 113 | 125 | } |
| 114 | 126 | |
| 115 | - @Test(groups = "short") | |
| 116 | - public void should_notify_of_keyspace_drop() { | |
| 117 | - session.execute("CREATE KEYSPACE ks2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); | |
| 127 | + @Test(groups = "short", dataProvider = "newKeyspaceName") | |
| 128 | + public void should_notify_of_keyspace_drop(String keyspace) { | |
| 129 | + session.execute(String.format("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", keyspace)); | |
| 118 | 130 | for (Metadata m : metadatas) |
| 119 | - assertThat(m.getReplicas("ks2", Bytes.fromHexString("0xCAFEBABE"))) | |
| 131 | + assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))) | |
| 120 | 132 | .isNotEmpty(); |
| 121 | 133 | |
| 122 | - session.execute("DROP KEYSPACE ks2"); | |
| 134 | + session.execute(String.format("DROP KEYSPACE %s", keyspace)); | |
| 123 | 135 | |
| 124 | 136 | for (Metadata m : metadatas) { |
| 125 | - assertThat(m.getKeyspace("ks2")) | |
| 137 | + assertThat(m.getKeyspace(keyspace)) | |
| 126 | 138 | .isNull(); |
| 127 | - assertThat(m.getReplicas("ks2", Bytes.fromHexString("0xCAFEBABE"))) | |
| 139 | + assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))) | |
| 128 | 140 | .isEmpty(); |
| 129 | 141 | } |
| 130 | 142 | } |
| 131 | 143 | |
| 132 | 144 | @AfterMethod(groups = "short") |
| 133 | 145 | public void cleanup() { |
| 134 | - try { | |
| 135 | - session.execute("DROP TABLE IF EXISTS ks.table1"); | |
| 136 | - } catch(InvalidQueryException ex) {} | |
| 137 | - try { | |
| 138 | - session.execute("DROP TYPE IF EXISTS ks.type1"); | |
| 139 | - } catch(InvalidQueryException ex) {} | |
| 140 | - try { | |
| 141 | - session.execute("DROP KEYSPACE IF EXISTS ks2"); | |
| 142 | - } catch(InvalidQueryException ex) {} | |
| 146 | + ListenableFuture<List<ResultSet>> f = Futures.successfulAsList(Lists.newArrayList( | |
| 147 | + session.executeAsync("DROP TABLE ks.table1"), | |
| 148 | + session.executeAsync("DROP TABLE \"CaseSensitive\".table1"), | |
| 149 | + session.executeAsync("DROP TYPE ks.type1"), | |
| 150 | + session.executeAsync("DROP TYPE \"CaseSensitive\".type1"), | |
| 151 | + session.executeAsync("DROP KEYSPACE ks2"), | |
| 152 | + session.executeAsync("DROP KEYSPACE \"CaseSensitive2\"") | |
| 153 | + )); | |
| 154 | + Futures.getUnchecked(f); | |
| 143 | 155 | } |
| 144 | 156 | |
| 145 | 157 | @AfterClass(groups = "short") |