Elffuss BraidHub

kikocis/java-driver public

JAVA-911: Process materialized views events.
Changeseta607de2d38d9ad0d49f01b7207d5f431759a06e636a289cab0dcd05eb54f289d
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-09-17 15:45 +02:00
CommitterAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-09-17 18:49 +02:00
Parents8e3e8fb031fa

Browse the files at this changeset

3 files changed

modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +4 −0
@@ -2195,7 +2195,11 @@
21952195 } else {
21962196 switch (scc.targetType) {
21972197 case TABLE:
2198+ // we can't tell whether it's a table or a view,
2199+ // but since two objects cannot have the same name,
2200+ // try removing both
21982201 keyspace.removeTable(scc.targetName);
2202+ keyspace.removeMaterializedView(scc.targetName);
21992203 break;
22002204 case TYPE:
22012205 keyspace.removeUserType(scc.targetName);
modified driver-core/src/main/java/com/datastax/driver/core/DefaultResultSetFuture.java +4 −0
@@ -88,7 +88,11 @@
8888 } else {
8989 switch (scc.targetType) {
9090 case TABLE:
91+ // we can't tell whether it's a table or a view,
92+ // but since two objects cannot have the same name,
93+ // try removing both
9194 keyspace.removeTable(scc.targetName);
95+ keyspace.removeMaterializedView(scc.targetName);
9296 break;
9397 case TYPE:
9498 keyspace.removeUserType(scc.targetName);
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +38 −0
@@ -219,6 +219,42 @@
219219 .isNull();
220220 }
221221
222+ @Test(groups = "short", dataProvider = "existingKeyspaceName")
223+ @CassandraVersion(major = 3.0)
224+ public void should_notify_of_view_creation(String keyspace) {
225+ session.execute(String.format("CREATE TABLE %s.table1 (pk int PRIMARY KEY, c int)", keyspace));
226+ session.execute(String.format("CREATE MATERIALIZED VIEW %s.mv1 AS SELECT c FROM %s.table1 WHERE c IS NOT NULL PRIMARY KEY (pk, c)", keyspace, keyspace));
227+
228+ for (Metadata m : metadatas)
229+ assertThat(m.getKeyspace(keyspace).getMaterializedView("mv1")).isNotNull();
230+ }
231+
232+ @Test(groups = "short", dataProvider = "existingKeyspaceName")
233+ @CassandraVersion(major = 3.0)
234+ public void should_notify_of_view_update(String keyspace) {
235+ session.execute(String.format("CREATE TABLE %s.table1 (pk int PRIMARY KEY, c int)", keyspace));
236+ session.execute(String.format("CREATE MATERIALIZED VIEW %s.mv1 AS SELECT c FROM %s.table1 WHERE c IS NOT NULL PRIMARY KEY (pk, c) WITH compaction = { 'class' : 'SizeTieredCompactionStrategy' }", keyspace, keyspace));
237+
238+ for (Metadata m : metadatas)
239+ assertThat(m.getKeyspace(keyspace).getMaterializedView("mv1").getOptions().getCompaction().get("class")).contains("SizeTieredCompactionStrategy");
240+
241+ session.execute(String.format("ALTER MATERIALIZED VIEW %s.mv1 WITH compaction = { 'class' : 'LeveledCompactionStrategy' }", keyspace));
242+
243+ for (Metadata m : metadatas)
244+ assertThat(m.getKeyspace(keyspace).getMaterializedView("mv1").getOptions().getCompaction().get("class")).contains("LeveledCompactionStrategy");
245+ }
246+
247+ @Test(groups = "short", dataProvider = "existingKeyspaceName")
248+ @CassandraVersion(major = 3.0)
249+ public void should_notify_of_view_drop(String keyspace) {
250+ session.execute(String.format("CREATE TABLE %s.table1 (pk int PRIMARY KEY, c int)", keyspace));
251+ session.execute(String.format("CREATE MATERIALIZED VIEW %s.mv1 AS SELECT c FROM %s.table1 WHERE c IS NOT NULL PRIMARY KEY (pk, c)", keyspace, keyspace));
252+ session.execute(String.format("DROP MATERIALIZED VIEW %s.mv1", keyspace));
253+
254+ for (Metadata m : metadatas)
255+ assertThat(m.getKeyspace(keyspace).getMaterializedView("mv1")).isNull();
256+ }
257+
222258 @DataProvider(name = "newKeyspaceName")
223259 public static Object[][] newKeyspaceName() {
224260 return new Object[][]{ { "lowercase2" }, { "\"CaseSensitive2\"" } };
@@ -276,6 +312,8 @@
276312 session.executeAsync("DROP FUNCTION \"CaseSensitive\".plus"),
277313 session.executeAsync("DROP AGGREGATE lowercase.sum"),
278314 session.executeAsync("DROP AGGREGATE \"CaseSensitive\".sum"),
315+ session.executeAsync("DROP MATERIALIZED VIEW lowercase.mv1"),
316+ session.executeAsync("DROP MATERIALIZED VIEW \"CaseSensitive\".mv1"),
279317 session.executeAsync("DROP KEYSPACE lowercase2"),
280318 session.executeAsync("DROP KEYSPACE \"CaseSensitive2\"")
281319 ));