Example #1
0
            public static Session Connect(string keyspace = null)
            {
                int tryNo = 0;

RETRY:
                try
                {
                    Session = Cluster.Connect();
                    if (keyspace != null)
                    {
                        Session.CreateKeyspaceIfNotExists(keyspace);
                        Session.ChangeKeyspace(keyspace);
                    }
                    return(Session);
                }
                catch (NoHostAvailableException e)
                {
                    if (tryNo < 10)
                    {
                        Console.WriteLine("CannotConnect to CCM node - give another try");
                        tryNo++;
                        Thread.Sleep(1000);
                        goto RETRY;
                    }
                    foreach (var entry in e.Errors)
                    {
                        Trace.TraceError("Error connecting to " + entry.Key + ": " + entry.Value);
                    }
                    throw new InvalidOperationException(null, e);
                }
            }
        public void checkKSMetadata()
        {
            CCMCluster = CCMBridge.CCMCluster.Create(2, Cluster.Builder());
            try
            {
                Session = CCMCluster.Session;
                Cluster = CCMCluster.Cluster;
                Session.CreateKeyspaceIfNotExists(Keyspace);
                Session.ChangeKeyspace(Keyspace);

                string keyspacename = "keyspace" + Guid.NewGuid().ToString("N").ToLower();
                bool durableWrites = false;
                string strgyClass = "SimpleStrategy";
                short rplctnFactor = 1;
                Session.Cluster.WaitForSchemaAgreement(
                    Session.Execute(
            string.Format(@"CREATE KEYSPACE {0}
             WITH replication = {{ 'class' : '{1}', 'replication_factor' : {2} }}
             AND durable_writes={3};"
            , keyspacename, strgyClass, rplctnFactor.ToString(), durableWrites.ToString())).QueriedHost
                );
                Session.ChangeKeyspace(keyspacename);

                for (int i = 0; i < 10; i++)
                    checkPureMetadata("table" + Guid.NewGuid().ToString("N"), keyspacename);

                KeyspaceMetadata ksmd = Cluster.Metadata.GetKeyspace(keyspacename);
                Assert.True(ksmd.DurableWrites == durableWrites);
                Assert.True(ksmd.Replication.Where(opt => opt.Key == "replication_factor").First().Value == rplctnFactor);
                Assert.True(ksmd.StrategyClass == strgyClass);

            }
            finally
            {
                CCMCluster.Discard();
            }
        }
Example #3
0
 public void SetFixture()
 {
     Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
     CCMBridge.ReusableCCMCluster.Setup(2);
     CCMBridge.ReusableCCMCluster.Build(Cluster.Builder());
     Session = CCMBridge.ReusableCCMCluster.Connect("tester");
     Session.CreateKeyspaceIfNotExists(KeyspaceName);
     Session.ChangeKeyspace(KeyspaceName);
 }
        public void checkMetadata(string TableName = null, string KeyspaceName = null, TableOptions tableOptions = null)
        {
            CCMCluster = CCMBridge.CCMCluster.Create(2, Cluster.Builder());
            try
            {
                Session = CCMCluster.Session;
                Cluster = CCMCluster.Cluster;
                Session.CreateKeyspaceIfNotExists(Keyspace);
                Session.ChangeKeyspace(Keyspace);

                checkPureMetadata(TableName, KeyspaceName, tableOptions);
            }
            finally
            {
                CCMCluster.Discard();
            }
        }
        public void CreateKeyspaceWithPropertiesTest(string strategy_class)
        {
            CCMCluster = CCMBridge.CCMCluster.Create(2, Cluster.Builder());
            try
            {
                Session = CCMCluster.Session;
                Cluster = CCMCluster.Cluster;

                Randomm rndm = new Randomm(DateTime.Now.Millisecond);
                bool durable_writes = rndm.NextBoolean();

                int? replication_factor = null;
                int? data_centers_count = null;
                Dictionary<string, int> datacenters_replication_factors = null;

                if (strategy_class == ReplicationStrategies.SimpleStrategy)
                {
                    replication_factor = rndm.Next(1, 21);
                    Session.CreateKeyspaceIfNotExists(Keyspace,ReplicationStrategies.CreateSimpleStrategyReplicationProperty((int)replication_factor), durable_writes);
                    Session.ChangeKeyspace(Keyspace);
                }
                else
                    if (strategy_class == ReplicationStrategies.NetworkTopologyStrategy)
                    {
                        data_centers_count = rndm.Next(1, 11);
                        datacenters_replication_factors = new Dictionary<string, int>((int)data_centers_count);
                        for (int i = 0; i < data_centers_count; i++)
                            datacenters_replication_factors.Add("dc" + i.ToString(), rndm.Next(1, 21));
                        Session.CreateKeyspaceIfNotExists(Keyspace, ReplicationStrategies.CreateNetworkTopologyStrategyReplicationProperty(datacenters_replication_factors), durable_writes);
                    }

                KeyspaceMetadata ksmd = Cluster.Metadata.GetKeyspace(Keyspace);
                Assert.Equal(strategy_class, ksmd.StrategyClass);
                Assert.Equal(durable_writes, ksmd.DurableWrites);
                if (replication_factor != null)
                    Assert.Equal(replication_factor, ksmd.Replication["replication_factor"]);
                if (datacenters_replication_factors != null)
                    Assert.True(datacenters_replication_factors.SequenceEqual(ksmd.Replication));
            }
            finally
            {
                CCMCluster.Discard();
            }
        }
Example #6
0
 public static Session Connect(string keyspace = null)
 {
     int tryNo = 0;
     RETRY:
     try
     {
         Session = Cluster.Connect();
         if (keyspace != null)
         {
             Session.CreateKeyspaceIfNotExists(keyspace);
             Session.ChangeKeyspace(keyspace);
         }
         return Session;
     }
     catch (NoHostAvailableException e)
     {
         if (tryNo < 10)
         {
             Console.WriteLine("CannotConnect to CCM node - give another try");
             tryNo++;
             Thread.Sleep(1000);
             goto RETRY;
         }
         foreach (var entry in e.Errors)
             Trace.TraceError("Error connecting to " + entry.Key + ": " + entry.Value);
         throw new InvalidOperationException(null, e);
     }
 }
Example #7
0
 public void SetFixture()
 {
     Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
     CCMCluster = CCMBridge.CCMCluster.Create(2, Cluster.Builder());
     Session = CCMCluster.Session;
     Cluster = CCMCluster.Cluster;
     Session.CreateKeyspaceIfNotExists(Keyspace);
     Session.ChangeKeyspace(Keyspace);
 }