cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [36/50] cassandra git commit: Add tests for MVs when a column in the base table is renamed with ALTER TABLE
Date Tue, 05 Sep 2017 06:05:50 GMT
Add tests for MVs when a column in the base table is renamed with ALTER TABLE

patch by Andres de la Peña; reviewed by Zhao Yang for CASSANDRA-12952


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/d9c8cebc
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/d9c8cebc
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/d9c8cebc

Branch: refs/heads/master
Commit: d9c8cebc2d7907d04efb1ce81bda9e2fa2780530
Parents: b724df8
Author: Andrés de la Peña <a.penya.garcia@gmail.com>
Authored: Fri Jul 28 11:56:38 2017 +0100
Committer: Andrés de la Peña <a.penya.garcia@gmail.com>
Committed: Fri Jul 28 11:56:38 2017 +0100

----------------------------------------------------------------------
 byteman/merge_schema_failure_3x.btm | 12 ++++++
 byteman/merge_schema_failure_4x.btm | 12 ++++++
 materialized_views_test.py          | 73 +++++++++++++++++++++++++++++++-
 3 files changed, 95 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/d9c8cebc/byteman/merge_schema_failure_3x.btm
----------------------------------------------------------------------
diff --git a/byteman/merge_schema_failure_3x.btm b/byteman/merge_schema_failure_3x.btm
new file mode 100644
index 0000000..d4c9b36
--- /dev/null
+++ b/byteman/merge_schema_failure_3x.btm
@@ -0,0 +1,12 @@
+#
+# Inject node failure on merge schema exit.
+#
+RULE inject node failure on merge schema exit
+CLASS org.apache.cassandra.schema.SchemaKeyspace
+METHOD mergeSchema
+AT EXIT
+# set flag to only run this rule once.
+IF TRUE
+DO
+   System.exit(0)
+ENDRULE

http://git-wip-us.apache.org/repos/asf/cassandra/blob/d9c8cebc/byteman/merge_schema_failure_4x.btm
----------------------------------------------------------------------
diff --git a/byteman/merge_schema_failure_4x.btm b/byteman/merge_schema_failure_4x.btm
new file mode 100644
index 0000000..bee5c3c
--- /dev/null
+++ b/byteman/merge_schema_failure_4x.btm
@@ -0,0 +1,12 @@
+#
+# Inject node failure on merge schema exit.
+#
+RULE inject node failure on merge schema exit
+CLASS org.apache.cassandra.schema.Schema
+METHOD merge
+AT EXIT
+# set flag to only run this rule once.
+IF TRUE
+DO
+   System.exit(0)
+ENDRULE

http://git-wip-us.apache.org/repos/asf/cassandra/blob/d9c8cebc/materialized_views_test.py
----------------------------------------------------------------------
diff --git a/materialized_views_test.py b/materialized_views_test.py
index 0c9cdcb..306d719 100644
--- a/materialized_views_test.py
+++ b/materialized_views_test.py
@@ -8,6 +8,7 @@ from multiprocessing import Process, Queue
 from unittest import skip, skipIf
 
 from cassandra import ConsistencyLevel
+from cassandra.cluster import NoHostAvailable
 from cassandra.concurrent import execute_concurrent_with_args
 from cassandra.cluster import Cluster
 from cassandra.query import SimpleStatement
@@ -40,9 +41,9 @@ class TestMaterializedViews(Tester):
     @since 3.0
     """
 
-    def prepare(self, user_table=False, rf=1, options=None, nodes=3, **kwargs):
+    def prepare(self, user_table=False, rf=1, options=None, nodes=3, install_byteman=False,
**kwargs):
         cluster = self.cluster
-        cluster.populate([nodes, 0])
+        cluster.populate([nodes, 0], install_byteman=install_byteman)
         if options:
             cluster.set_configuration_options(values=options)
         cluster.start()
@@ -773,6 +774,74 @@ class TestMaterializedViews(Tester):
             ['TX', 'user1']
         )
 
+    def rename_column_test(self):
+        """
+        Test that a materialized view created with a 'SELECT *' works as expected when renaming
a column
+        @expected_result The column is also renamed in the view.
+        """
+
+        session = self.prepare(user_table=True)
+
+        self._insert_data(session)
+
+        assert_one(
+            session,
+            "SELECT * FROM users_by_state WHERE state = 'TX' AND username = 'user1'",
+            ['TX', 'user1', 1968, 'f', 'ch@ngem3a', None]
+        )
+
+        session.execute("ALTER TABLE users RENAME username TO user")
+
+        results = list(session.execute("SELECT * FROM users_by_state WHERE state = 'TX' AND
user = 'user1'"))
+        self.assertEqual(len(results), 1)
+        self.assertTrue(hasattr(results[0], 'user'), 'Column "user" not found')
+        assert_one(
+            session,
+            "SELECT state, user, birth_year, gender FROM users_by_state WHERE state = 'TX'
AND user = 'user1'",
+            ['TX', 'user1', 1968, 'f']
+        )
+
+    def rename_column_atomicity_test(self):
+        """
+        Test that column renaming is atomically done between a table and its materialized
views
+        @jira_ticket CASSANDRA-12952
+        """
+
+        session = self.prepare(nodes=1, user_table=True, install_byteman=True)
+        node = self.cluster.nodelist()[0]
+
+        self._insert_data(session)
+
+        assert_one(
+            session,
+            "SELECT * FROM users_by_state WHERE state = 'TX' AND username = 'user1'",
+            ['TX', 'user1', 1968, 'f', 'ch@ngem3a', None]
+        )
+
+        # Rename a column with an injected byteman rule to kill the node after the first
schema update
+        self.allow_log_errors = True
+        script_version = '4x' if self.cluster.version() >= '4' else '3x'
+        node.byteman_submit(['./byteman/merge_schema_failure_{}.btm'.format(script_version)])
+        with self.assertRaises(NoHostAvailable):
+            session.execute("ALTER TABLE users RENAME username TO user")
+
+        debug('Restarting node')
+        node.stop()
+        node.start(wait_for_binary_proto=True)
+        session = self.patient_cql_connection(node, consistency_level=ConsistencyLevel.ONE)
+
+        # Both the table and its view should have the new schema after restart
+        assert_one(
+            session,
+            "SELECT * FROM ks.users WHERE state = 'TX' AND user = 'user1' ALLOW FILTERING",
+            ['user1', 1968, 'f', 'ch@ngem3a', None, 'TX']
+        )
+        assert_one(
+            session,
+            "SELECT * FROM ks.users_by_state WHERE state = 'TX' AND user = 'user1'",
+            ['TX', 'user1', 1968, 'f', 'ch@ngem3a', None]
+        )
+
     def lwt_test(self):
         """Test that lightweight transaction behave properly with a materialized view"""
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message