Exemplo n.º 1
0
        public void GetMaterializedView_Should_Refresh_View_Metadata_Via_Events()
        {
            var queries = new[]
            {
                "CREATE KEYSPACE ks_view_meta3 WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3}",
                "CREATE TABLE ks_view_meta3.scores (user TEXT, game TEXT, year INT, month INT, day INT, score INT, PRIMARY KEY (user, game, year, month, day))",
                "CREATE MATERIALIZED VIEW ks_view_meta3.monthlyhigh AS SELECT user FROM scores WHERE game IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL AND day IS NOT NULL PRIMARY KEY ((game, year, month), score, user, day) WITH CLUSTERING ORDER BY (score DESC) AND compaction = { 'class' : 'SizeTieredCompactionStrategy' }"
            };
            var testCluster = TestClusterManager.GetNonShareableTestCluster(1, DefaultMaxClusterCreateRetries, true, false);
            using (var cluster = Cluster.Builder().AddContactPoint(testCluster.InitialContactPoint).Build())
            {
                var session = cluster.Connect();
                foreach (var q in queries)
                {
                    session.Execute(q);
                }
                var view = cluster.Metadata.GetMaterializedView("ks_view_meta3", "monthlyhigh");
                Assert.NotNull(view);
                StringAssert.Contains("SizeTieredCompactionStrategy", view.Options.CompactionOptions["class"]);

                const string alterQuery = "ALTER MATERIALIZED VIEW ks_view_meta3.monthlyhigh WITH compaction = { 'class' : 'LeveledCompactionStrategy' }";
                session.Execute(alterQuery);
                //Wait for event
                Thread.Sleep(5000);
                view = cluster.Metadata.GetMaterializedView("ks_view_meta3", "monthlyhigh");
                StringAssert.Contains("LeveledCompactionStrategy", view.Options.CompactionOptions["class"]);

                const string dropQuery = "DROP MATERIALIZED VIEW ks_view_meta3.monthlyhigh";
                session.Execute(dropQuery);
                //Wait for event
                Thread.Sleep(5000);
                Assert.Null(cluster.Metadata.GetMaterializedView("ks_view_meta3", "monthlyhigh"));
            }
        }
Exemplo n.º 2
0
        public void MaterializedView_Should_Retrieve_View_Metadata_Quoted_Identifiers()
        {
            var queries = new[]
            {
                "CREATE KEYSPACE ks_view_meta2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3}",
                @"CREATE TABLE ks_view_meta2.t1 (""theKey"" INT, ""the;Clustering"" INT, ""the Value"" INT, PRIMARY KEY (""theKey"", ""the;Clustering""))",
                @"CREATE MATERIALIZED VIEW ks_view_meta2.mv1 AS SELECT ""theKey"", ""the;Clustering"", ""the Value"" FROM t1 WHERE ""theKey"" IS NOT NULL AND ""the;Clustering"" IS NOT NULL AND ""the Value"" IS NOT NULL PRIMARY KEY (""theKey"", ""the;Clustering"")"
            };
            var testCluster = TestClusterManager.GetNonShareableTestCluster(1, DefaultMaxClusterCreateRetries, true, false);
            using (var cluster = Cluster.Builder().AddContactPoint(testCluster.InitialContactPoint).Build())
            {
                var session = cluster.Connect();
                foreach (var q in queries)
                {
                    session.Execute(q);
                }

                var ks = cluster.Metadata.GetKeyspace("ks_view_meta2");
                Assert.NotNull(ks);
                var view = ks.GetMaterializedViewMetadata("mv1");
                Assert.NotNull(view);
                Assert.NotNull(view.Options);

                Assert.AreEqual("mv1", view.Name);
                Assert.AreEqual(@"""theKey"" IS NOT NULL AND ""the;Clustering"" IS NOT NULL AND ""the Value"" IS NOT NULL", view.WhereClause);
                Assert.AreEqual(3, view.TableColumns.Length);

                Assert.AreEqual(new[] { "ks_view_meta2", "ks_view_meta2", "ks_view_meta2" }, view.TableColumns.Select(c => c.Keyspace));
                Assert.AreEqual(new[] { "mv1", "mv1", "mv1" }, view.TableColumns.Select(c => c.Table));

                Assert.AreEqual(new[] { "the Value", "the;Clustering", "theKey" }, view.TableColumns.Select(c => c.Name));
                Assert.AreEqual(new[] { ColumnTypeCode.Int, ColumnTypeCode.Int, ColumnTypeCode.Int }, view.TableColumns.Select(c => c.TypeCode));
                Assert.AreEqual(new[] { "theKey" }, view.PartitionKeys.Select(c => c.Name));
                Assert.AreEqual(new[] { "the;Clustering" }, view.ClusteringKeys.Select(c => c.Item1.Name));
                Assert.AreEqual(new[] { SortOrder.Ascending }, view.ClusteringKeys.Select(c => c.Item2));
            }
        }
Exemplo n.º 3
0
 public void SchemaAgreementRaceTest()
 {
     var testCluster = TestClusterManager.GetNonShareableTestCluster(3, DefaultMaxClusterCreateRetries, true, false);
     var queries = new[]
     {
         "CREATE KEYSPACE ks1 WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};",
         "CREATE TABLE ks1.tbl1 (id uuid PRIMARY KEY, value text)",
         "SELECT * FROM ks1.tbl1",
         "SELECT * FROM ks1.tbl1 where id = d54cb06d-d168-45a0-b1b2-9f5c75435d3d",
         "CREATE KEYSPACE ks2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};",
         "CREATE TABLE ks2.tbl2 (id uuid PRIMARY KEY, value text)",
         "SELECT * FROM ks2.tbl2",
         "SELECT * FROM ks2.tbl2",
         "CREATE TABLE ks2.tbl3 (id uuid PRIMARY KEY, value text)",
         "SELECT * FROM ks2.tbl3",
         "SELECT * FROM ks2.tbl3",
         "CREATE TABLE ks2.tbl4 (id uuid PRIMARY KEY, value text)",
         "SELECT * FROM ks2.tbl4",
         "SELECT * FROM ks2.tbl4",
         "SELECT * FROM ks2.tbl4"
     };
     using (var cluster = Cluster.Builder().AddContactPoint(testCluster.InitialContactPoint).Build())
     {
         var session = cluster.Connect();
         //warm up the pool
         TestHelper.Invoke(() => session.Execute("SELECT key from system.local"), 10);
         foreach (var q in queries)
         {
             Assert.DoesNotThrow(() => session.Execute(q));
         }
         CollectionAssert.Contains(cluster.Metadata.GetTables("ks2"), "tbl4");
         CollectionAssert.Contains(cluster.Metadata.GetTables("ks1"), "tbl1");
     }
 }
Exemplo n.º 4
0
        public void GetMaterializedView_Should_Retrieve_View_Metadata()
        {
            var queries = new[]
            {
                "CREATE KEYSPACE ks_view_meta WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3}",
                "CREATE TABLE ks_view_meta.scores (user TEXT, game TEXT, year INT, month INT, day INT, score INT, PRIMARY KEY (user, game, year, month, day))",
                "CREATE MATERIALIZED VIEW ks_view_meta.dailyhigh AS SELECT user FROM scores WHERE game IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND day IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL PRIMARY KEY ((game, year, month, day), score, user) WITH CLUSTERING ORDER BY (score DESC)"
            };
            var testCluster = TestClusterManager.GetNonShareableTestCluster(1, DefaultMaxClusterCreateRetries, true, false);
            using (var cluster = Cluster.Builder().AddContactPoint(testCluster.InitialContactPoint).Build())
            {
                var session = cluster.Connect();
                foreach (var q in queries)
                {
                    session.Execute(q);
                }
                
                var ks = cluster.Metadata.GetKeyspace("ks_view_meta");
                Assert.NotNull(ks);
                var view = ks.GetMaterializedViewMetadata("dailyhigh");
                Assert.NotNull(view);
                Assert.NotNull(view.Options);
                //Value is cached
                var view2 = cluster.Metadata.GetMaterializedView("ks_view_meta", "dailyhigh");
                Assert.AreSame(view, view2);

                Assert.AreEqual("dailyhigh", view.Name);
                Assert.AreEqual(
                    "game IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND day IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL",
                    view.WhereClause);
                Assert.AreEqual(6, view.TableColumns.Length);

                Assert.AreEqual(new[] { "ks_view_meta", "ks_view_meta", "ks_view_meta", "ks_view_meta", "ks_view_meta", "ks_view_meta" }, 
                    view.TableColumns.Select(c => c.Keyspace));
                Assert.AreEqual(new[] { "dailyhigh", "dailyhigh", "dailyhigh", "dailyhigh", "dailyhigh", "dailyhigh" },
                    view.TableColumns.Select(c => c.Table));

                Assert.AreEqual(new[] { "day", "game", "month", "score", "user", "year" }, view.TableColumns.Select(c => c.Name));
                Assert.AreEqual(new[] { ColumnTypeCode.Int, ColumnTypeCode.Varchar, ColumnTypeCode.Int, ColumnTypeCode.Int, ColumnTypeCode.Varchar, 
                    ColumnTypeCode.Int }, view.TableColumns.Select(c => c.TypeCode));
                Assert.AreEqual(new[] { "game", "year", "month", "day" }, view.PartitionKeys.Select(c => c.Name));
                Assert.AreEqual(new[] { "score", "user" }, view.ClusteringKeys.Select(c => c.Item1.Name));
                Assert.AreEqual(new[] { SortOrder.Descending, SortOrder.Ascending }, view.ClusteringKeys.Select(c => c.Item2));
            }
        }
Exemplo n.º 5
0
        public void MaterializedView_Base_Table_Column_Alteration()
        {
            var queries = new[]
            {
                "CREATE KEYSPACE ks_view_meta5 WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3}",
                "CREATE TABLE ks_view_meta5.scores (user TEXT, game TEXT, year INT, month INT, day INT, score INT, PRIMARY KEY (user, game, year, month, day))",
                "CREATE MATERIALIZED VIEW ks_view_meta5.dailyhigh AS SELECT user FROM scores WHERE game IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND day IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL PRIMARY KEY ((game, year, month, day), score, user) WITH CLUSTERING ORDER BY (score DESC)"
            };
            var testCluster = TestClusterManager.GetNonShareableTestCluster(1, DefaultMaxClusterCreateRetries, true, false);
            using (var cluster = Cluster.Builder().AddContactPoint(testCluster.InitialContactPoint).Build())
            {
                var session = cluster.Connect();
                foreach (var q in queries)
                {
                    session.Execute(q);
                }

                var ks = cluster.Metadata.GetKeyspace("ks_view_meta5");
                Assert.NotNull(ks);
                var dailyView = ks.GetMaterializedViewMetadata("dailyhigh");
                Assert.NotNull(dailyView);
                Assert.NotNull(dailyView.Options);
                var scoreMeta = dailyView.ColumnsByName["score"];
                Assert.NotNull(scoreMeta);
                Assert.AreEqual(ColumnTypeCode.Int, scoreMeta.TypeCode);

                session.Execute("ALTER TABLE ks_view_meta5.scores ALTER score TYPE blob");
                //Wait for event
                Thread.Sleep(5000);
                Assert.AreEqual(ColumnTypeCode.Blob, cluster.Metadata.GetKeyspace("ks_view_meta5").GetTableMetadata("scores").ColumnsByName["score"].TypeCode);

                dailyView = cluster.Metadata.GetMaterializedView("ks_view_meta5", "dailyhigh");
                scoreMeta = dailyView.ColumnsByName["score"];
                Assert.AreEqual(ColumnTypeCode.Blob, scoreMeta.TypeCode);
            }
        }