Elffuss BraidHub

kikocis/java-driver public

Fix handling of DROP events when ks name is case-sensitive (JAVA-678).
Changesetb6bfa638a5f08c6624148f5637d4d09a1a07a0449513b0457abd830a4e76cd0d
Authorolim7t <omichallat+github@gmail.com> · 2015-03-02 13:07 -08:00
Committerolim7t <omichallat+github@gmail.com> · 2015-03-03 15:18 -08:00
Parents78fed81be230

Browse the files at this changeset

5 files changed

modified driver-core/CHANGELOG.rst +1 −0
@@ -9,6 +9,7 @@
99 - [improvement] Reduce level of logs on missing rpc_address (JAVA-568)
1010 - [improvement] Expose node token and range information (JAVA-312)
1111 - [bug] Fix guava dependency when using OSGI (JAVA-620)
12+- [bug] Fix handling of DROP events when ks name is case-sensitive (JAVA-678)
1213
1314 Merged from 2.0.9_fixes branch:
1415
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +1 −1
@@ -2131,7 +2131,7 @@
21312131 if (scc.table.isEmpty())
21322132 manager.metadata.removeKeyspace(scc.keyspace);
21332133 else {
2134- KeyspaceMetadata keyspace = manager.metadata.getKeyspace(scc.keyspace);
2134+ KeyspaceMetadata keyspace = manager.metadata.getKeyspaceInternal(scc.keyspace);
21352135 if (keyspace == null)
21362136 logger.warn("Received a DROPPED notification for {}.{}, but this keyspace is unknown in our metadata",
21372137 scc.keyspace, scc.table);
modified driver-core/src/main/java/com/datastax/driver/core/DefaultResultSetFuture.java +1 −1
@@ -84,7 +84,7 @@
8484 // session.poolsState.setKeyspace(null);
8585 session.cluster.manager.metadata.removeKeyspace(scc.keyspace);
8686 } else {
87- KeyspaceMetadata keyspace = session.cluster.manager.metadata.getKeyspace(scc.keyspace);
87+ KeyspaceMetadata keyspace = session.cluster.manager.metadata.getKeyspaceInternal(scc.keyspace);
8888 if (keyspace == null)
8989 logger.warn("Received a DROPPED notification for {}.{}, but this keyspace is unknown in our metadata",
9090 scc.keyspace, scc.columnFamily);
modified driver-core/src/main/java/com/datastax/driver/core/Metadata.java +8 −0
@@ -362,6 +362,14 @@
362362 return keyspaces.get(handleId(keyspace));
363363 }
364364
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+
365373 void removeKeyspace(String keyspace) {
366374 keyspaces.remove(keyspace);
367375 if (tokenMap != null)
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +53 −45
@@ -4,12 +4,10 @@
44 import java.util.List;
55
66 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+
1311 import com.datastax.driver.core.utils.Bytes;
1412
1513 import static com.datastax.driver.core.Assertions.assertThat;
@@ -23,7 +21,12 @@
2321
2422 @Override
2523 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\"" } };
2730 }
2831
2932 @BeforeClass(groups = "short")
@@ -32,83 +35,88 @@
3235 metadatas = Lists.newArrayList(cluster.getMetadata(), cluster2.getMetadata());
3336 }
3437
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));
3841
3942 for (Metadata m : metadatas)
40- assertThat(m.getKeyspace("ks").getTable("table1"))
43+ assertThat(m.getKeyspace(keyspace).getTable("table1"))
4144 .isNotNull();
4245 }
4346
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));
4851
4952 for (Metadata m : metadatas)
50- assertThat(m.getKeyspace("ks").getTable("table1").getColumn("j"))
53+ assertThat(m.getKeyspace(keyspace).getTable("table1").getColumn("j"))
5154 .isNotNull();
5255 }
5356
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));
5861
5962 for (Metadata m : metadatas)
60- assertThat(m.getKeyspace("ks").getTable("table1"))
63+ assertThat(m.getKeyspace(keyspace).getTable("table1"))
6164 .isNull();
6265 }
6366
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));
6775
6876 for (Metadata m : metadatas)
69- assertThat(m.getKeyspace("ks2"))
77+ assertThat(m.getKeyspace(keyspace))
7078 .isNotNull();
7179 }
7280
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));
7684 for (Metadata m : metadatas)
77- assertThat(m.getKeyspace("ks2").isDurableWrites())
85+ assertThat(m.getKeyspace(keyspace).isDurableWrites())
7886 .isTrue();
7987
80- session.execute("ALTER KEYSPACE ks2 WITH durable_writes = false");
88+ session.execute(String.format("ALTER KEYSPACE %s WITH durable_writes = false", keyspace));
8189 for (Metadata m : metadatas)
82- assertThat(m.getKeyspace("ks2").isDurableWrites())
90+ assertThat(m.getKeyspace(keyspace).isDurableWrites())
8391 .isFalse();
8492 }
8593
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));
8997 for (Metadata m : metadatas)
90- assertThat(m.getReplicas("ks2", Bytes.fromHexString("0xCAFEBABE")))
98+ assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE")))
9199 .isNotEmpty();
92100
93- session.execute("DROP KEYSPACE ks2");
101+ session.execute(String.format("DROP KEYSPACE %s", keyspace));
94102
95103 for (Metadata m : metadatas) {
96- assertThat(m.getKeyspace("ks2"))
104+ assertThat(m.getKeyspace(keyspace))
97105 .isNull();
98- assertThat(m.getReplicas("ks2", Bytes.fromHexString("0xCAFEBABE")))
106+ assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE")))
99107 .isEmpty();
100108 }
101109 }
102110
103111 @AfterMethod(groups = "short")
104112 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);
112120 }
113121
114122 @AfterClass(groups = "short")