Beispiel #1
0
        private void InternalTestCaching(ColumnFamilyCaching?columnFamilyCaching)
        {
            var name = TestSchemaUtils.GetRandomColumnFamilyName();
            var originalColumnFamily = new ColumnFamily
            {
                Name = name,
                CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(sstableSizeInMb: 10),
                GCGraceSeconds     = 123,
                ReadRepairChance   = 0.3
            };

            if (columnFamilyCaching != null)
            {
                originalColumnFamily.Caching = columnFamilyCaching.Value;
            }
            keyspaceConnection.AddColumnFamily(originalColumnFamily);

            var columnFamily = keyspaceConnection.DescribeKeyspace().ColumnFamilies[name];

            if (columnFamilyCaching != null)
            {
                Assert.That(columnFamily.Caching, Is.EqualTo(columnFamilyCaching));
            }
            else
            {
                Assert.That(columnFamily.Caching, Is.EqualTo(ColumnFamilyCaching.KeysOnly));
            }
        }
        public void TestChangeCompactionProperties()
        {
            var scheme = new KeyspaceScheme
            {
                Name          = TestSchemaUtils.GetRandomKeyspaceName(),
                Configuration = new KeyspaceConfiguration
                {
                    ColumnFamilies = new[]
                    {
                        new ColumnFamily
                        {
                            Name = "CF1"
                        }
                    }
                }
            };

            ActualizeKeyspaces(scheme);
            Assert.That(cluster.UpdateColumnFamilyInvokeCount, Is.EqualTo(0));

            scheme.Configuration.ColumnFamilies[0].CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategy(4, 32);
            ActualizeKeyspaces(scheme);
            Assert.That(cluster.UpdateColumnFamilyInvokeCount, Is.EqualTo(0));

            scheme.Configuration.ColumnFamilies[0].CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategy(3, 32);
            ActualizeKeyspaces(scheme);
            Assert.That(cluster.UpdateColumnFamilyInvokeCount, Is.EqualTo(1));

            scheme.Configuration.ColumnFamilies[0].CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategy(3, 31);
            ActualizeKeyspaces(scheme);
            Assert.That(cluster.UpdateColumnFamilyInvokeCount, Is.EqualTo(2));

            ActualizeKeyspaces(scheme);
            Assert.That(cluster.UpdateColumnFamilyInvokeCount, Is.EqualTo(2));

            scheme.Configuration.ColumnFamilies[0].CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(10);
            ActualizeKeyspaces(scheme);
            Assert.That(cluster.UpdateColumnFamilyInvokeCount, Is.EqualTo(3));

            scheme.Configuration.ColumnFamilies[0].CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(11);
            ActualizeKeyspaces(scheme);
            Assert.That(cluster.UpdateColumnFamilyInvokeCount, Is.EqualTo(4));

            scheme.Configuration.ColumnFamilies[0].CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(11);
            ActualizeKeyspaces(scheme);
            Assert.That(cluster.UpdateColumnFamilyInvokeCount, Is.EqualTo(4));
        }
        public void TestUpdateColumnFamilyCaching()
        {
            var name = TestSchemaUtils.GetRandomColumnFamilyName();
            var originalColumnFamily = new ColumnFamily
            {
                Name = name,
                CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(sstableSizeInMb: 10),
                GCGraceSeconds     = 123,
                ReadRepairChance   = 0.3,
                Caching            = ColumnFamilyCaching.All
            };
            var keyspaceName    = TestSchemaUtils.GetRandomKeyspaceName();
            var keyspaceSchemes = new[]
            {
                new KeyspaceScheme
                {
                    Name          = keyspaceName,
                    Configuration = new KeyspaceConfiguration
                    {
                        ColumnFamilies = new[]
                        {
                            originalColumnFamily
                        }
                    }
                }
            };

            cluster.ActualizeKeyspaces(keyspaceSchemes);

            originalColumnFamily.Caching = ColumnFamilyCaching.None;
            cluster.ActualizeKeyspaces(keyspaceSchemes);
            Assert.That(cluster.RetrieveKeyspaceConnection(keyspaceName).DescribeKeyspace().ColumnFamilies[name].Caching, Is.EqualTo(ColumnFamilyCaching.None));

            originalColumnFamily.Caching = ColumnFamilyCaching.KeysOnly;
            cluster.ActualizeKeyspaces(keyspaceSchemes);
            Assert.That(cluster.RetrieveKeyspaceConnection(keyspaceName).DescribeKeyspace().ColumnFamilies[name].Caching, Is.EqualTo(ColumnFamilyCaching.KeysOnly));

            originalColumnFamily.Caching = ColumnFamilyCaching.RowsOnly;
            cluster.ActualizeKeyspaces(keyspaceSchemes);
            Assert.That(cluster.RetrieveKeyspaceConnection(keyspaceName).DescribeKeyspace().ColumnFamilies[name].Caching, Is.EqualTo(ColumnFamilyCaching.RowsOnly));

            originalColumnFamily.Caching = ColumnFamilyCaching.All;
            cluster.ActualizeKeyspaces(keyspaceSchemes);
            Assert.That(cluster.RetrieveKeyspaceConnection(keyspaceName).DescribeKeyspace().ColumnFamilies[name].Caching, Is.EqualTo(ColumnFamilyCaching.All));
        }
        public static void SetUp()
        {
            var templateDirectory = Path.Combine(FindCassandraTemplateDirectory(AppDomain.CurrentDomain.BaseDirectory), @"v3.11.x");
            var deployDirectory   = Path.Combine(Path.GetTempPath(), "deployed_cassandra_v3.11.x");

            cassandraNode = new LocalCassandraNode(templateDirectory, deployDirectory)
            {
                RpcPort    = 9360,
                CqlPort    = 9343,
                JmxPort    = 7399,
                GossipPort = 7400,
            };
            cassandraNode.Restart(timeout: TimeSpan.FromMinutes(1));

            cassandraCluster = new CassandraCluster(cassandraNode.CreateSettings(), Logger.Instance);
            var cassandraSchemaActualizer = new CassandraSchemaActualizer(cassandraCluster, null, Logger.Instance);

            cassandraSchemaActualizer.ActualizeKeyspaces(new[]
            {
                new KeyspaceSchema
                {
                    Name          = ksName,
                    Configuration = new KeyspaceConfiguration
                    {
                        ReplicationStrategy = SimpleReplicationStrategy.Create(replicationFactor: 1),
                        ColumnFamilies      = new[]
                        {
                            new ColumnFamily
                            {
                                Name = minTicksCfName,
                                CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(sstableSizeInMb: 160),
                                Caching            = ColumnFamilyCaching.All
                            },
                            new ColumnFamily
                            {
                                Name = maxTicksCfName,
                                CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(sstableSizeInMb: 160),
                                Caching            = ColumnFamilyCaching.KeysOnly
                            }
                        }
                    }
                },
            }, changeExistingKeyspaceMetadata: false);
        }
        public void TestCreateColumnFamily()
        {
            var name = TestSchemaUtils.GetRandomColumnFamilyName();
            var originalColumnFamily = new ColumnFamily
            {
                Name = name,
                CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(sstableSizeInMb: 10),
                GCGraceSeconds     = 123,
                ReadRepairChance   = 0.3
            };

            keyspaceConnection.AddColumnFamily(originalColumnFamily);

            var columnFamily = keyspaceConnection.DescribeKeyspace().ColumnFamilies[name];

            Assert.That(columnFamily.Name, Is.EqualTo(originalColumnFamily.Name));
            Assert.That(columnFamily.CompactionStrategy.CompactionStrategyType, Is.EqualTo(originalColumnFamily.CompactionStrategy.CompactionStrategyType));
            Assert.That(columnFamily.CompactionStrategy.CompactionStrategyOptions.SstableSizeInMb, Is.EqualTo(originalColumnFamily.CompactionStrategy.CompactionStrategyOptions.SstableSizeInMb));
            Assert.That(columnFamily.GCGraceSeconds, Is.EqualTo(originalColumnFamily.GCGraceSeconds));
            Assert.That(columnFamily.ReadRepairChance, Is.EqualTo(originalColumnFamily.ReadRepairChance));
        }
        public void TestUpdateColumnFamily()
        {
            var name = TestSchemaUtils.GetRandomColumnFamilyName();
            var originalColumnFamily = new ColumnFamily
            {
                Name = name,
                CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(sstableSizeInMb: 10),
                GCGraceSeconds     = 123,
                ReadRepairChance   = 0.3,
                Caching            = ColumnFamilyCaching.All
            };

            keyspaceConnection.AddColumnFamily(originalColumnFamily);

            originalColumnFamily.CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(sstableSizeInMb: 20);
            originalColumnFamily.GCGraceSeconds     = 321;
            originalColumnFamily.ReadRepairChance   = 0.9;
            originalColumnFamily.Caching            = ColumnFamilyCaching.None;
            keyspaceConnection.UpdateColumnFamily(originalColumnFamily);

            var columnFamily = keyspaceConnection.DescribeKeyspace().ColumnFamilies[name];

            Assert.That(columnFamily.Name, Is.EqualTo(originalColumnFamily.Name));
            Assert.That(columnFamily.CompactionStrategy.CompactionStrategyType, Is.EqualTo(originalColumnFamily.CompactionStrategy.CompactionStrategyType));
            Assert.That(columnFamily.CompactionStrategy.CompactionStrategyOptions.SstableSizeInMb, Is.EqualTo(originalColumnFamily.CompactionStrategy.CompactionStrategyOptions.SstableSizeInMb));
            Assert.That(columnFamily.GCGraceSeconds, Is.EqualTo(originalColumnFamily.GCGraceSeconds));
            Assert.That(columnFamily.ReadRepairChance, Is.EqualTo(originalColumnFamily.ReadRepairChance));

            originalColumnFamily.CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategy(minThreshold: 5, maxThreshold: 17);
            keyspaceConnection.UpdateColumnFamily(originalColumnFamily);

            columnFamily = keyspaceConnection.DescribeKeyspace().ColumnFamilies[name];
            Assert.That(columnFamily.Name, Is.EqualTo(originalColumnFamily.Name));
            Assert.That(columnFamily.CompactionStrategy.CompactionStrategyType, Is.EqualTo(originalColumnFamily.CompactionStrategy.CompactionStrategyType));
            Assert.That(columnFamily.CompactionStrategy.CompactionStrategyOptions.Enabled, Is.EqualTo(originalColumnFamily.CompactionStrategy.CompactionStrategyOptions.Enabled));
            Assert.That(columnFamily.CompactionStrategy.CompactionStrategyOptions.MinThreshold, Is.EqualTo(originalColumnFamily.CompactionStrategy.CompactionStrategyOptions.MinThreshold));
            Assert.That(columnFamily.CompactionStrategy.CompactionStrategyOptions.MaxThreshold, Is.EqualTo(originalColumnFamily.CompactionStrategy.CompactionStrategyOptions.MaxThreshold));
            Assert.That(columnFamily.GCGraceSeconds, Is.EqualTo(originalColumnFamily.GCGraceSeconds));
            Assert.That(columnFamily.ReadRepairChance, Is.EqualTo(originalColumnFamily.ReadRepairChance));
        }
 public void TestCompareColumnFamiliesByCompactionStrategy()
 {
     Assert.That(
         !comparer.NeedUpdateColumnFamily(
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(10)
     },
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(10)
     })
         );
     Assert.That(
         !comparer.NeedUpdateColumnFamily(
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.LeveledCompactionStrategyDisabled()
     },
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.LeveledCompactionStrategyDisabled()
     })
         );
     Assert.That(
         !comparer.NeedUpdateColumnFamily(
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategy(4, 32)
     },
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategy(4, 32)
     })
         );
     Assert.That(
         !comparer.NeedUpdateColumnFamily(
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategyDisabled()
     },
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategyDisabled()
     })
         );
     Assert.That(
         !comparer.NeedUpdateColumnFamily(
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategyDisabled()
     },
             new ColumnFamily {
         Name = "name", CompactionStrategy = new CompactionStrategy(CompactionStrategyType.SizeTiered, new CompactionStrategyOptions {
             Enabled = false, MinThreshold = 4, MaxThreshold = 32
         })
     })
         );
     Assert.That(
         comparer.NeedUpdateColumnFamily(
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategy(4, 32)
     },
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategyDisabled()
     })
         );
     Assert.That(
         comparer.NeedUpdateColumnFamily(
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategy(4, 32)
     },
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategy(16, 32)
     })
         );
     Assert.That(
         comparer.NeedUpdateColumnFamily(
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategy(4, 32)
     },
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategy(4, 16)
     })
         );
     Assert.That(
         comparer.NeedUpdateColumnFamily(
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(20)
     },
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(10)
     })
         );
     Assert.That(
         comparer.NeedUpdateColumnFamily(
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.LeveledCompactionStrategy(4)
     },
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategy(4, 4)
     })
         );
     Assert.That(
         comparer.NeedUpdateColumnFamily(
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.LeveledCompactionStrategyDisabled()
     },
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.SizeTieredCompactionStrategyDisabled()
     })
         );
     Assert.That(
         comparer.NeedUpdateColumnFamily(
             new ColumnFamily {
         Name = "name", CompactionStrategy = CompactionStrategy.LeveledCompactionStrategyDisabled()
     },
             new ColumnFamily {
         Name = "name", CompactionStrategy = null
     })
         );
 }