Elffuss BraidHub

kikocis/java-driver public

Merge branch '2.0' into 2.1
Changeset8dbbb33ac272748d29d6f901d8d9ec9b4b3ba9ee00e768d365ca19a999b83465
Authorolim7t <omichallat+github@gmail.com> · 2015-03-03 15:34 -08:00
Committerolim7t <omichallat+github@gmail.com> · 2015-03-03 15:34 -08:00
Parents355ed2b1c974, fa0faab5e1cb

Browse the files at this changeset

5 files changed

modified driver-core/CHANGELOG.rst +1 −0
@@ -11,6 +11,7 @@
1111 - [improvement] Reduce level of logs on missing rpc_address (JAVA-568)
1212 - [improvement] Expose node token and range information (JAVA-312)
1313 - [bug] Fix guava dependency when using OSGI (JAVA-620)
14+- [bug] Fix handling of DROP events when ks name is case-sensitive (JAVA-678)
1415 - [bug] Prevent race between cancellation and query completion (JAVA-614)
1516 - [bug] Prevent cancel and timeout from cancelling unrelated ResponseHandler if
1617 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 @@
21772177 manager.metadata.removeKeyspace(scc.keyspace);
21782178 break;
21792179 case TABLE:
2180- keyspace = manager.metadata.getKeyspace(scc.keyspace);
2180+ keyspace = manager.metadata.getKeyspaceInternal(scc.keyspace);
21812181 if (keyspace == null)
21822182 logger.warn("Received a DROPPED notification for table {}.{}, but this keyspace is unknown in our metadata",
21832183 scc.keyspace, scc.name);
@@ -2185,7 +2185,7 @@
21852185 keyspace.removeTable(scc.name);
21862186 break;
21872187 case TYPE:
2188- keyspace = manager.metadata.getKeyspace(scc.keyspace);
2188+ keyspace = manager.metadata.getKeyspaceInternal(scc.keyspace);
21892189 if (keyspace == null)
21902190 logger.warn("Received a DROPPED notification for UDT {}.{}, but this keyspace is unknown in our metadata",
21912191 scc.keyspace, scc.name);
modified driver-core/src/main/java/com/datastax/driver/core/DefaultResultSetFuture.java +2 −2
@@ -95,7 +95,7 @@
9595 session.cluster.manager.metadata.removeKeyspace(scc.keyspace);
9696 break;
9797 case TABLE:
98- keyspace = session.cluster.manager.metadata.getKeyspace(scc.keyspace);
98+ keyspace = session.cluster.manager.metadata.getKeyspaceInternal(scc.keyspace);
9999 if (keyspace == null)
100100 logger.warn("Received a DROPPED notification for table {}.{}, but this keyspace is unknown in our metadata",
101101 scc.keyspace, scc.name);
@@ -103,7 +103,7 @@
103103 keyspace.removeTable(scc.name);
104104 break;
105105 case TYPE:
106- keyspace = session.cluster.manager.metadata.getKeyspace(scc.keyspace);
106+ keyspace = session.cluster.manager.metadata.getKeyspaceInternal(scc.keyspace);
107107 if (keyspace == null)
108108 logger.warn("Received a DROPPED notification for UDT {}.{}, but this keyspace is unknown in our metadata",
109109 scc.keyspace, scc.name);
modified driver-core/src/main/java/com/datastax/driver/core/Metadata.java +8 −0
@@ -392,6 +392,14 @@
392392 return keyspaces.get(handleId(keyspace));
393393 }
394394
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+
395403 void removeKeyspace(String keyspace) {
396404 keyspaces.remove(keyspace);
397405 if (tokenMap != null)
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +73 −61
@@ -4,13 +4,12 @@
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;
12+import com.datastax.driver.core.utils.CassandraVersion;
1413
1514 import static com.datastax.driver.core.Assertions.assertThat;
1615
@@ -23,7 +22,12 @@
2322
2423 @Override
2524 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\"" } };
2731 }
2832
2933 @BeforeClass(groups = "short")
@@ -32,114 +36,122 @@
3236 metadatas = Lists.newArrayList(cluster.getMetadata(), cluster2.getMetadata());
3337 }
3438
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));
3842
3943 for (Metadata m : metadatas)
40- assertThat(m.getKeyspace("ks").getTable("table1"))
44+ assertThat(m.getKeyspace(keyspace).getTable("table1"))
4145 .isNotNull();
4246 }
4347
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));
4852
4953 for (Metadata m : metadatas)
50- assertThat(m.getKeyspace("ks").getTable("table1").getColumn("j"))
54+ assertThat(m.getKeyspace(keyspace).getTable("table1").getColumn("j"))
5155 .isNotNull();
5256 }
5357
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));
5862
5963 for (Metadata m : metadatas)
60- assertThat(m.getKeyspace("ks").getTable("table1"))
64+ assertThat(m.getKeyspace(keyspace).getTable("table1"))
6165 .isNull();
6266 }
6367
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));
6772
6873 for (Metadata m : metadatas)
69- assertThat(m.getKeyspace("ks").getUserType("type1"))
74+ assertThat(m.getKeyspace(keyspace).getUserType("type1"))
7075 .isNotNull();
7176 }
7277
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));
7783
7884 for (Metadata m : metadatas)
79- assertThat(m.getKeyspace("ks").getUserType("type1").getFieldType("j"))
85+ assertThat(m.getKeyspace(keyspace).getUserType("type1").getFieldType("j"))
8086 .isNotNull();
8187 }
8288
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));
8794
8895 for (Metadata m : metadatas)
89- assertThat(m.getKeyspace("ks").getUserType("type1"))
96+ assertThat(m.getKeyspace(keyspace).getUserType("type1"))
9097 .isNull();
9198 }
9299
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));
96108
97109 for (Metadata m : metadatas)
98- assertThat(m.getKeyspace("ks2"))
110+ assertThat(m.getKeyspace(keyspace))
99111 .isNotNull();
100112 }
101113
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));
105117 for (Metadata m : metadatas)
106- assertThat(m.getKeyspace("ks2").isDurableWrites())
118+ assertThat(m.getKeyspace(keyspace).isDurableWrites())
107119 .isTrue();
108120
109- session.execute("ALTER KEYSPACE ks2 WITH durable_writes = false");
121+ session.execute(String.format("ALTER KEYSPACE %s WITH durable_writes = false", keyspace));
110122 for (Metadata m : metadatas)
111- assertThat(m.getKeyspace("ks2").isDurableWrites())
123+ assertThat(m.getKeyspace(keyspace).isDurableWrites())
112124 .isFalse();
113125 }
114126
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));
118130 for (Metadata m : metadatas)
119- assertThat(m.getReplicas("ks2", Bytes.fromHexString("0xCAFEBABE")))
131+ assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE")))
120132 .isNotEmpty();
121133
122- session.execute("DROP KEYSPACE ks2");
134+ session.execute(String.format("DROP KEYSPACE %s", keyspace));
123135
124136 for (Metadata m : metadatas) {
125- assertThat(m.getKeyspace("ks2"))
137+ assertThat(m.getKeyspace(keyspace))
126138 .isNull();
127- assertThat(m.getReplicas("ks2", Bytes.fromHexString("0xCAFEBABE")))
139+ assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE")))
128140 .isEmpty();
129141 }
130142 }
131143
132144 @AfterMethod(groups = "short")
133145 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);
143155 }
144156
145157 @AfterClass(groups = "short")