public void SetUp()
        {
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();
            ClusterManager.Configure(cassandraSharpConfig);

            var config = new ClusterConfig
            {
                Endpoints = new EndpointsConfig { Servers = new[] { "localhost" } },
                DefaultKeyspace =
                    new KeyspaceConfig
                    {
                        Name = TestKeyspace,
                        DurableWrites = false,
                        Replication = new ReplicationConfig
                        {
                            Options = new Dictionary<string, string>
                                            {
                                                { "class", "SimpleStrategy" },
                                                { "replication_factor", "1" },
                                            }
                        }
                    }
            };

            cluster = ClusterManager.GetCluster(config);
        }
示例#2
0
        public void RecoveryTest()
        {
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig
                {
                        Recovery = "Simple",
                        //Logger = typeof(ResilienceLogger).AssemblyQualifiedName,
                };
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {"localhost"},
                            },
                };

            using (ICluster cluster = ClusterManager.GetCluster(clusterConfig))
            {
                ICqlCommand cmd = new PocoCommand(cluster);

                const string dropFoo = "drop keyspace data";
                try
                {
                    cmd.Execute(dropFoo).Wait();
                }
                catch
                {
                }

                const string createFoo = "CREATE KEYSPACE data WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
                cmd.Execute(createFoo).Wait();

                const string createBar = "CREATE TABLE data.test (time text PRIMARY KEY)";
                cmd.Execute(createBar).Wait();

                for (int i = 0; i < 30; ++i)
                {
                    while (true)
                    {
                        Thread.Sleep(1000);
                        var now = DateTime.Now;
                        string insert = String.Format("insert into data.test(time) values ('{0}');", now);
                        Console.WriteLine("{0}) {1}", i, insert);

                        try
                        {
                            cmd.Execute(insert).Wait();
                            break;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }

                ClusterManager.Shutdown();
            }
        }
        public static void Configure(CassandraSharpConfig config)
        {
            config.CheckArgumentNotNull("config");

            if (null != _config)
            {
                throw new InvalidOperationException("ClusterManager is already initialized");
            }

            _logger = Logger.Factory.Create(config.Logger);
            _recoveryService = Recovery.Factory.Create(config.Recovery, _logger);
            _config = config;
        }
示例#4
0
        private static void Run(IStatementReader statementReader)
        {
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();
            cassandraSharpConfig.Logger = typeof(ConsoleDebugLogger).AssemblyQualifiedName;
            cassandraSharpConfig.Instrumentation = typeof(ConsoleInstrumentation).AssemblyQualifiedName;
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Transport = new TransportConfig
                            {
                                    User = _cliArgs.User,
                                    Password = _cliArgs.Password
                            },
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {_cliArgs.Hostname},
                                    Discovery = "Null",
                            }
                };

            using (ICluster cluster = ClusterManager.GetCluster(clusterConfig))
            {
                CommandContext.Cluster = cluster;

                if (_cliArgs.CheckConnection)
                {
                    Console.WriteLine("Connecting to {0}:{1}...", _cliArgs.Hostname, _cliArgs.Port);
                    const string checkStatement = "select cluster_name, data_center, rack, release_version from system.local";
                    new Exec {Statement = checkStatement}.Execute();
                    if (CommandContext.LastCommandFailed)
                    {
                        return;
                    }
                }

                if (! _cliArgs.NoHelp)
                {
                    new Exec {Statement = "!help"}.Execute();
                }

                foreach (string statement in statementReader.Read())
                {
                    new Exec {Statement = statement}.Execute();
                    if (CommandContext.Exit)
                    {
                        return;
                    }
                }
            }
        }
        public override void Open(string hostname)
        {
            //run Write Performance Test using cassandra-sharp driver
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();
            cassandraSharpConfig.Instrumentation = new InstrumentationConfig();
            cassandraSharpConfig.Instrumentation.Type = typeof(PerformanceInstrumentation).AssemblyQualifiedName;
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {hostname}
                            },
                };

            _cluster = ClusterManager.GetCluster(clusterConfig);

            _cmd = _cluster.CreateOrdinalCommand();
        }
示例#6
0
        public void TestNull()
        {
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {"localhost"}
                            }
                };

            using (ICluster cluster = ClusterManager.GetCluster(clusterConfig))
            {
                var cmd = cluster.CreatePropertyBagCommand();

                const string dropFoo = "drop keyspace Tests";

                try
                {
                    cmd.Execute(dropFoo).AsFuture().Wait();
                }
                catch
                {
                }

                const string createFoo = "CREATE KEYSPACE Tests WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
                Console.WriteLine("============================================================");
                Console.WriteLine(createFoo);
                Console.WriteLine("============================================================");

                cmd.Execute(createFoo).AsFuture().Wait();
                Console.WriteLine();
                Console.WriteLine();

                const string createBar = @"CREATE TABLE Tests.AllTypes (a int, b int, primary key (a))";
                Console.WriteLine("============================================================");
                Console.WriteLine(createBar);
                Console.WriteLine("============================================================");
                cmd.Execute(createBar).AsFuture().Wait();
                Console.WriteLine();
                Console.WriteLine();

                //const string useBar = @"use Tests";
                //Console.WriteLine("============================================================");
                //Console.WriteLine(useBar);
                //Console.WriteLine("============================================================");
                //cmd.Execute(useBar).AsFuture().Wait();
                //Console.WriteLine();
                //Console.WriteLine();

                const string insertBatch = @"insert into Tests.AllTypes (a, b) values (?, ?)";
                var prepared = cmd.Prepare(insertBatch);

                PropertyBag insertBag = new PropertyBag();
                insertBag["a"] = 1;
                insertBag["b"] = null;

                prepared.Execute(insertBag).AsFuture().Wait();

                const string selectAll = "select * from Tests.AllTypes";
                var res = cmd.Execute(selectAll).AsFuture();
                Assert.IsTrue(1 == res.Result.Count);
                PropertyBag selectBag = res.Result.Single();
                Assert.IsTrue(selectBag.Keys.Contains("a"));
                Assert.IsTrue(1 == (int) selectBag["a"]);
                Assert.IsTrue(null == selectBag["b"]);
            }
        }
示例#7
0
        public void RecoveryTest()
        {
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig
                {
                        Recovery = new RecoveryConfig {Type = "Default", Interval = 2},
                        Logger = new LoggerConfig {Type = typeof(ResilienceLogger).AssemblyQualifiedName},
                };
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {"localhost"},
                            },
                        Transport = new TransportConfig
                            {
                                    Port = 666,
                                    Type = "ShortRunning",
                                    ReceiveTimeout = 10000,
                                    SendTimeout = 10000,
                            }
                };

            DisconnectingProxy proxy = new DisconnectingProxy(666, 9042, 0.05, 0.0);
            proxy.Start();

            using (ICluster cluster = ClusterManager.GetCluster(clusterConfig))
            {
                ICqlCommand cmd = cluster.CreatePocoCommand();

                const string dropFoo = "drop keyspace data";
                try
                {
                    cmd.Execute(dropFoo).AsFuture().Wait();
                }
                catch
                {
                }

                const string createFoo = "CREATE KEYSPACE data WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
                cmd.Execute(createFoo).AsFuture().Wait();

                const string createBar = "CREATE TABLE data.test (time text PRIMARY KEY)";
                cmd.Execute(createBar).AsFuture().Wait();

                proxy.EnableKiller();

                List<Task> tasks = new List<Task>();
                for (int taskId = 0; taskId < 5; ++taskId)
                {
                    int tmpTaskId = taskId;
                    Task task = Task.Factory.StartNew(() => Worker(tmpTaskId, cmd), TaskCreationOptions.LongRunning);
                    tasks.Add(task);
                }

                foreach (Task task in tasks)
                {
                    task.Wait();
                }

                ClusterManager.Shutdown();
            }

            proxy.Stop();
        }
        public void TestAllTypes()
        {
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {"localhost"}
                            }
                };

            using (ICluster cluster = ClusterManager.GetCluster(clusterConfig))
            {
                const string createFoo = "CREATE KEYSPACE Tests WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
                Console.WriteLine("============================================================");
                Console.WriteLine(createFoo);
                Console.WriteLine("============================================================");

                var resCount = cluster.ExecuteNonQuery(createFoo);
                resCount.Wait();
                Console.WriteLine();
                Console.WriteLine();

                // http://www.datastax.com/docs/1.1/references/cql/cql_data_types
                const string createBar = @"CREATE TABLE Tests.AllTypes (cAscii ascii,
                                                                            cBigint bigint,
                                                                            cBlob blob,
                                                                            cBoolean boolean,
                                                                            cDecimal decimal,
                                                                            cDouble double,
                                                                            cFloat float,
                                                                            cInet inet,
                                                                            cInt int,
                                                                            cText text,
                                                                            cTimestamp timestamp,
                                                                            cTimeuuid timeuuid,
                                                                            cUuid uuid,
                                                                            cVarchar varchar,
                                                                            cVarint varint,
                                                          PRIMARY KEY (cInt))";
                Console.WriteLine("============================================================");
                Console.WriteLine(createBar);
                Console.WriteLine("============================================================");
                resCount = cluster.ExecuteNonQuery(createBar);
                resCount.Wait();
                Console.WriteLine();
                Console.WriteLine();

                const string insertBatch = @"insert into Tests.AllTypes (cAscii, cBigint, cBlob, cBoolean, cDouble, cFloat,
                                                                         cInet, cInt, cText, cTimestamp, cTimeuuid, cUuid, cVarchar)
                                             values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                var prepared = cluster.Prepare(insertBatch);

                var allTypesInsert = new AllTypes
                    {
                            CAscii = "ascii",
                            CBigint = 0x0102030405060708,
                            CBlob = new byte[] {0x1, 0x02, 0x03, 0x04, 0x05},
                            CBoolean = true,
                            CDouble = 1234.5678,
                            CFloat = 234.567f,
                            CInet = new IPAddress(new byte[] {0x01, 0x02, 0x03, 0x04}),
                            CInt = 42,
                            CText = "text",
                            CTimestamp = new DateTime(2013, 1, 16, 14, 20, 0),
                            CTimeuuid = TimedUuid.GenerateTimeBasedGuid(DateTime.Now),
                            CUuid = Guid.NewGuid(),
                            CVarchar = "varchar"
                    };

                prepared.ExecuteNonQuery(allTypesInsert).Wait();

                const string selectAll = "select * from Tests.AllTypes";
                AllTypes allTypesSelect = cluster.Execute<AllTypes>(selectAll).Result.Single();

                const string dropFoo = "drop keyspace Tests";
                resCount = cluster.ExecuteNonQuery(dropFoo);
                resCount.Wait();

                Assert.AreEqual(allTypesInsert.CAscii, allTypesSelect.CAscii);
                Assert.AreEqual(allTypesInsert.CBigint, allTypesSelect.CBigint);
                Assert.AreEqual(allTypesInsert.CBlob, allTypesSelect.CBlob);
                Assert.AreEqual(allTypesInsert.CBoolean, allTypesSelect.CBoolean);
                Assert.AreEqual(allTypesInsert.CDouble, allTypesSelect.CDouble);
                Assert.AreEqual(allTypesInsert.CFloat, allTypesSelect.CFloat);
                Assert.AreEqual(allTypesInsert.CInet, allTypesSelect.CInet);
                Assert.AreEqual(allTypesInsert.CInt, allTypesSelect.CInt);
                Assert.AreEqual(allTypesInsert.CText, allTypesSelect.CText);
                Assert.AreEqual(allTypesInsert.CTimestamp, allTypesSelect.CTimestamp);
                Assert.AreEqual(allTypesInsert.CTimeuuid, allTypesSelect.CTimeuuid);
                Assert.AreEqual(allTypesInsert.CUuid, allTypesSelect.CUuid);
                Assert.AreEqual(allTypesInsert.CVarchar, allTypesSelect.CVarchar);
            }

            ClusterManager.Shutdown();
        }
示例#9
0
        public static void Configure()
        {
            CassandraSharpConfig cassandraSharpConfig = (CassandraSharpConfig)ConfigurationManager.GetSection("CassandraSharp");

            ClusterManager.Configure(cassandraSharpConfig);
        }
示例#10
0
        public void RecoveryTest()
        {
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig
                {
                        Logger = new LoggerConfig {Type = typeof(ResilienceLogger).AssemblyQualifiedName},
                        Recovery = new RecoveryConfig {Interval = 2}
                };
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {"localhost"},
                            },
                        Transport = new TransportConfig
                            {
                                    Port = 666,
                                    ReceiveTimeout = 10*1000,
                            }
                };

            DisconnectingProxy proxy = new DisconnectingProxy(666, 9042);
            proxy.Start();

            using (ICluster cluster = ClusterManager.GetCluster(clusterConfig))
            {
                ICqlCommand cmd = cluster.CreatePocoCommand();

                const string dropFoo = "drop keyspace data";
                try
                {
                    cmd.Execute(dropFoo).AsFuture().Wait();
                }
                catch
                {
                }

                const string createFoo = "CREATE KEYSPACE data WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
                cmd.Execute(createFoo).AsFuture().Wait();

                const string createBar = "CREATE TABLE data.test (time text PRIMARY KEY)";
                cmd.Execute(createBar).AsFuture().Wait();

                proxy.EnableKiller();

                for (int i = 0; i < 10000; ++i)
                {
                    int attempt = 0;
                    while (true)
                    {
                        var now = DateTime.Now;
                        string insert = String.Format("insert into data.test(time) values ('{0}');", now);
                        Console.WriteLine("{0}.{1}) {2}", i, ++attempt, insert);

                        try
                        {
                            cmd.Execute(insert).AsFuture().Wait();
                            break;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Failed with error {0}", ex.Message);
                            Thread.Sleep(1000);
                        }
                    }
                }

                ClusterManager.Shutdown();
            }

            proxy.Stop();
        }
        public void Configure(CassandraSharpConfig config)
        {
            config.CheckArgumentNotNull("config");

            lock (_lock)
            {
                if (null != _config)
                {
                    throw new InvalidOperationException("ClusterManager is already initialized");
                }

                _logger = ServiceActivator<Logger.Factory>.Create<ILogger>(config.Logger.Type, config.Logger);
                _recoveryService = ServiceActivator<Recovery.Factory>.Create<IRecoveryService>(config.Recovery.Type, config.Recovery, _logger);
                _instrumentation = ServiceActivator<Instrumentation.Factory>.Create<IInstrumentation>(config.Instrumentation.Type, config.Instrumentation);
                _config = config;
            }
        }
        public void BinaryProtocolRunWritePerformanceSingleThread()
        {
            PerformanceInstrumentation.RootFolder = "";

            //run Write Performance Test using cassandra-sharp driver
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();
            cassandraSharpConfig.Instrumentation = new InstrumentationConfig();
            cassandraSharpConfig.Instrumentation.Type = typeof(PerformanceInstrumentation).AssemblyQualifiedName;
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {"localhost"}
                            },
                };

            using (ICluster cluster = ClusterManager.GetCluster(clusterConfig))
            {
                ICqlCommand cmd = new PocoCommand(cluster);

                const string dropFoo = "drop keyspace Tests";
                try
                {
                    cmd.Execute(dropFoo).AsFuture().Wait();
                }
                catch
                {
                }

                const string createFoo = "CREATE KEYSPACE Tests WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
                Console.WriteLine("============================================================");
                Console.WriteLine(createFoo);
                Console.WriteLine("============================================================");

                var resCount = cmd.Execute(createFoo);
                resCount.AsFuture().Wait();
                Console.WriteLine();
                Console.WriteLine();

                const string createBar = "CREATE TABLE Tests.stresstest (strid varchar,intid int,PRIMARY KEY (strid))";
                Console.WriteLine("============================================================");
                Console.WriteLine(createBar);
                Console.WriteLine("============================================================");
                resCount = cmd.Execute(createBar);
                resCount.AsFuture().Wait();
                Console.WriteLine();
                Console.WriteLine();

                const string insertPerf = "UPDATE Tests.stresstest SET intid = ? WHERE strid = ?";
                Console.WriteLine("============================================================");
                Console.WriteLine(" Cassandra-Sharp Driver write performance test single thread ");
                Console.WriteLine("============================================================");
                var prepared = cmd.Prepare(insertPerf);
                int n = 0;
                while (n < NUM_ROUND)
                {
                    var timer = new Stopwatch();
                    timer.Start();

                    for (int i = 0; i < NUM_WRITES_PER_ROUND; i++)
                    {
                        prepared.Execute(new {intid = i, strid = i.ToString("X")}).AsFuture().Wait();
                    }

                    timer.Stop();
                    double rate = (1000.0*NUM_WRITES_PER_ROUND)/timer.ElapsedMilliseconds;
                    Console.WriteLine("[Cassandra-Sharp] Time : " + timer.ElapsedMilliseconds + " (rate: " + rate + " qps)");
                    n++;
                }

                Console.WriteLine("============================================================");
                Console.WriteLine(dropFoo);
                Console.WriteLine("============================================================");

                resCount = cmd.Execute(dropFoo);
                resCount.AsFuture().Wait();
            }

            Thread.Sleep(10*1000);

            ClusterManager.Shutdown();
        }
        public void BinaryProtocolRunWritePerformanceSingleThread()
        {
            //run Write Performance Test using cassandra-sharp driver
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {"localhost"}
                            },
                        Transport = new TransportConfig
                            {
                                    Tracing = true,
                            }
                };

            using (ICluster cluster = ClusterManager.GetCluster(clusterConfig))
            {
                const string createFoo = "CREATE KEYSPACE Tests WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
                Console.WriteLine("============================================================");
                Console.WriteLine(createFoo);
                Console.WriteLine("============================================================");

                var resCount = cluster.ExecuteNonQuery(createFoo);
                resCount.Wait();
                Console.WriteLine();
                Console.WriteLine();

                const string createBar = "CREATE TABLE Tests.stresstest (strid varchar,intid int,PRIMARY KEY (strid))";
                Console.WriteLine("============================================================");
                Console.WriteLine(createBar);
                Console.WriteLine("============================================================");
                resCount = cluster.ExecuteNonQuery(createBar);
                resCount.Wait();
                Console.WriteLine();
                Console.WriteLine();

                const string insertPerf = "UPDATE Tests.stresstest SET intid = ? WHERE strid = ?";
                Console.WriteLine("============================================================");
                Console.WriteLine(" Cassandra-Sharp Driver write performance test single thread ");
                Console.WriteLine("============================================================");
                var prepared = cluster.Prepare(insertPerf);
                int n = 0;
                while (n < NUM_ROUND)
                {
                    var timer = new Stopwatch();
                    timer.Start();

                    for (int i = 0; i < NUM_WRITES_PER_ROUND; i++)
                    {
                        prepared.ExecuteNonQuery(new {intid = i, strid = i.ToString("X")}).Wait();
                    }

                    timer.Stop();
                    double rate = NUM_WRITES_PER_ROUND/(timer.ElapsedMilliseconds/1000d);
                    Console.WriteLine("[Cassandra-Sharp] Time : " + timer.ElapsedMilliseconds + " (rate: " + rate + " qps)");
                    n++;
                }

                const string dropFoo = "drop keyspace Tests";
                Console.WriteLine("============================================================");
                Console.WriteLine(dropFoo);
                Console.WriteLine("============================================================");

                resCount = cluster.ExecuteNonQuery(dropFoo);
                resCount.Wait();
            }
        }
示例#14
0
 public static void Configure(CassandraSharpConfig config)
 {
     EnlightenmentMgr.ClusterManager().Configure(config);
 }
        public void StreamStarvationMultiThread()
        {
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig
                {
                        Logger = new LoggerConfig {Type = typeof(ConsoleDebugLogger).AssemblyQualifiedName}
                };
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {"localhost"}
                            },
                };

            ICluster cluster = ClusterManager.GetCluster(clusterConfig);
            ICqlCommand cmd = cluster.CreatePocoCommand();

            const string dropKeySpace = "drop keyspace Tests";
            try
            {
                cmd.Execute(dropKeySpace).AsFuture().Wait();
            }
            catch
            {
            }

            const string createKeySpace = "CREATE KEYSPACE Tests WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
            Console.WriteLine("============================================================");
            Console.WriteLine(createKeySpace);
            Console.WriteLine("============================================================");

            cmd.Execute(createKeySpace).AsFuture().Wait();
            Console.WriteLine();
            Console.WriteLine();

            const string createFoo = "CREATE TABLE Tests.foo (strid varchar,bar varchar,intid int,PRIMARY KEY (strid))";
            Console.WriteLine("============================================================");
            Console.WriteLine(createFoo);
            Console.WriteLine("============================================================");
            cmd.Execute(createFoo).AsFuture().Wait();
            Console.WriteLine();
            Console.WriteLine();

            const string insertPerf = "UPDATE Tests.foo SET bar = ?, intid = ? WHERE strid = ?";
            Console.WriteLine("============================================================");
            Console.WriteLine(" Cassandra-Sharp Driver reproducing stream starvation ");
            Console.WriteLine("============================================================");

            using (var prepared = cmd.WithConsistencyLevel(ConsistencyLevel.ONE).Prepare(insertPerf))
            {
                Thread[] failsThreads = new Thread[NUM_THREADS];

                for (int i = 0; i < NUM_THREADS; i++)
                {
                    failsThreads[i] = new Thread(() => FailingThread(prepared));
                    failsThreads[i].Start();
                    //Thread.Sleep(5000);
                }

                foreach (Thread thread in failsThreads)
                {
                    thread.Join();
                }
            }

            ClusterManager.Shutdown();
        }
        public void PacketSizeTest()
        {
            long time1423;
            long time1424;

            //run Write Performance Test using cassandra-sharp driver
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {"localhost"}
                            },
                };

            using (ICluster cluster = ClusterManager.GetCluster(clusterConfig))
            {
                ICqlCommand cmd = new PocoCommand(cluster);

                const string dropFoo = "drop keyspace Tests";
                try
                {
                    cmd.Execute(dropFoo).AsFuture().Wait();
                }
                catch
                {
                }

                const string createFoo = "CREATE KEYSPACE Tests WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
                Console.WriteLine("============================================================");
                Console.WriteLine(createFoo);
                Console.WriteLine("============================================================");

                var resCount = cmd.Execute(createFoo);
                resCount.AsFuture().Wait();
                Console.WriteLine();
                Console.WriteLine();

                const string createBar = "CREATE TABLE Tests.tbl ( x varchar primary key, y varchar )";
                Console.WriteLine("============================================================");
                Console.WriteLine(createBar);
                Console.WriteLine("============================================================");
                resCount = cmd.Execute(createBar);
                resCount.AsFuture().Wait();
                Console.WriteLine();
                Console.WriteLine();

                var preparedQuery = cmd.Prepare("insert into Tests.tbl (x, y) values (?, ?)");

                time1423 = InsertData(new string('x', 1423), preparedQuery);
                Console.WriteLine();

                time1424 = InsertData(new string('x', 1424), preparedQuery);
                Console.WriteLine();

                Console.WriteLine("============================================================");
                Console.WriteLine(dropFoo);
                Console.WriteLine("============================================================");

                resCount = cmd.Execute(dropFoo);
                resCount.AsFuture().Wait();
            }

            ClusterManager.Shutdown();

            long delta = Math.Abs(time1424 - time1423);
            long min = Math.Max(time1423, time1424);
            double percent = delta/(double) min;
            Assert.IsTrue(percent < 1.0);
        }
        public static void Shutdown()
        {
            if (null != _recoveryService)
            {
                _recoveryService.SafeDispose();
                _recoveryService = null;
            }

            _config = null;
        }
        public void StreamStarvationMultiThread()
        {
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();
            //a dirty hack to push the logger to Config.
            cassandraSharpConfig.Logger = typeof(ConsoleDebugLogger).AssemblyQualifiedName;
            ClusterManager.Configure(cassandraSharpConfig);
            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {"localhost"}
                            },
                };

            ICluster cluster = ClusterManager.GetCluster(clusterConfig);
            const string dropKeySpace = "drop keyspace Tests";
            try
            {
                cluster.ExecuteNonQuery(dropKeySpace).Wait();
            }
            catch
            {
            }

            const string createKeySpace = "CREATE KEYSPACE Tests WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
            Console.WriteLine("============================================================");
            Console.WriteLine(createKeySpace);
            Console.WriteLine("============================================================");

            var resCount = cluster.ExecuteNonQuery(createKeySpace);
            resCount.Wait();
            Console.WriteLine();
            Console.WriteLine();

            const string createFoo = "CREATE TABLE Tests.foo (strid varchar,bar varchar,intid int,PRIMARY KEY (strid))";
            Console.WriteLine("============================================================");
            Console.WriteLine(createFoo);
            Console.WriteLine("============================================================");
            resCount = cluster.ExecuteNonQuery(createFoo);
            resCount.Wait();
            Console.WriteLine();
            Console.WriteLine();

            const string insertPerf = "UPDATE Tests.foo SET bar = ?, intid = ? WHERE strid = ?";
            Console.WriteLine("============================================================");
            Console.WriteLine(" Cassandra-Sharp Driver reproducing stream starvation ");
            Console.WriteLine("============================================================");

            IPreparedQuery prepared = cluster.Prepare(insertPerf);

            Thread[] failsThreads = new Thread[NUM_THREADS];

            for (int i = 0; i < NUM_THREADS; i++)
            {
                failsThreads[i] = new Thread(() => FailingThread(prepared));
                failsThreads[i].Start();
                //Thread.Sleep(5000);
            }

            foreach (Thread thread in failsThreads)
            {
                thread.Join();
            }
        }
        public void Shutdown()
        {
            lock (_lock)
            {
                _recoveryService.SafeDispose();
                _recoveryService = null;

                _instrumentation.SafeDispose();
                _instrumentation = null;

                _logger.SafeDispose();
                _logger = null;

                _config = null;
            }
        }
示例#20
0
        public void TestAllTypes()
        {
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {"localhost"}
                            }
                };

            using (ICluster cluster = ClusterManager.GetCluster(clusterConfig))
            {
                ICqlCommand cmd = cluster.CreateCommand().FromOrdinal().ToPoco().Build();

                const string dropFoo = "drop keyspace Tests";

                try
                {
                    cmd.Execute(dropFoo).AsFuture().Wait();
                }
                catch
                {
                }

                const string createFoo = "CREATE KEYSPACE Tests WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
                Console.WriteLine("============================================================");
                Console.WriteLine(createFoo);
                Console.WriteLine("============================================================");

                cmd.Execute(createFoo).AsFuture().Wait();
                Console.WriteLine();
                Console.WriteLine();

                // http://www.datastax.com/docs/1.1/references/cql/cql_data_types
                const string createBar = @"CREATE TABLE Tests.AllTypes (cAscii ascii, 
                                                                            cBigint bigint,
                                                                            cBlob blob,
                                                                            cBoolean boolean,
                                                                            cDecimal decimal,
                                                                            cDouble double,
                                                                            cFloat float,
                                                                            cInet inet,
                                                                            cInt int,
                                                                            cText text,
                                                                            cTimestamp timestamp,
                                                                            cTimeuuid timeuuid,
                                                                            cUuid uuid,
                                                                            cVarchar varchar,
                                                                            cVarint varint,
                                                                            cList list<int>,
                                                                            cSet set<int>,
                                                                            cMap map<text, int>,
                                                          PRIMARY KEY (cInt))";
                Console.WriteLine("============================================================");
                Console.WriteLine(createBar);
                Console.WriteLine("============================================================");
                cmd.Execute(createBar).AsFuture().Wait();
                Console.WriteLine();
                Console.WriteLine();

                const string insertBatch = @"insert into Tests.AllTypes (cAscii, cBigint, cBlob, cBoolean, cDouble, cFloat,
                                                                         cInet, cInt, cText, cTimestamp, cTimeuuid, cUuid, cVarchar, cList, cSet, cMap)
                                             values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                var prepared = cmd.Prepare(insertBatch);

                var allTypesInsert = new AllTypes
                    {
                            CAscii = new string('x', 8000),
                            CBigint = 0x0102030405060708,
                            CBlob = Enumerable.Repeat((byte) 42, 7142).ToArray(),
                            CBoolean = true,
                            CDouble = 1234.5678,
                            CFloat = 234.567f,
                            CInet = new IPAddress(new byte[] {0x01, 0x02, 0x03, 0x04}),
                            CInt = 42,
                            CText = new string('x', 3000),
                            CTimestamp = new DateTime(2013, 1, 16, 14, 20, 0),
                            CTimeuuid = TimedUuid.GenerateTimeBasedGuid(DateTime.Now),
                            CUuid = Guid.NewGuid(),
                            CVarchar = new string('x', 5000),
                            CList = new List<int> {1, 2, 3},
                            CSet = new HashSet<int> {1, 2, 3},
                            CMap = new Dictionary<string, int> {{"one", 1}, {"two", 2}, {"three", 3}},
                    };

                var param = new object[]
                    {
                            allTypesInsert.CAscii,
                            allTypesInsert.CBigint,
                            allTypesInsert.CBlob,
                            allTypesInsert.CBoolean,
                            allTypesInsert.CDouble,
                            allTypesInsert.CFloat,
                            allTypesInsert.CInet,
                            allTypesInsert.CInt,
                            allTypesInsert.CText,
                            allTypesInsert.CTimestamp,
                            allTypesInsert.CTimeuuid,
                            allTypesInsert.CUuid,
                            allTypesInsert.CVarchar,
                            allTypesInsert.CList,
                            allTypesInsert.CSet,
                            allTypesInsert.CMap,
                    };

                prepared.Execute(param).AsFuture().Wait();

                const string selectAll =
                        "select cAscii, cBigint, cBlob, cBoolean, cDouble, cFloat, cInet, cInt, cText, cTimestamp, cTimeuuid, cUuid, cVarchar, cList, cSet, cMap from Tests.AllTypes";
                AllTypes allTypesSelect = cmd.Execute<AllTypes>(selectAll).AsFuture().Result.Single();

                cmd.Execute(dropFoo).AsFuture().Wait();

                Assert.AreEqual(allTypesInsert.CAscii, allTypesSelect.CAscii);
                Assert.AreEqual(allTypesInsert.CBigint, allTypesSelect.CBigint);
                Assert.AreEqual(allTypesInsert.CBlob, allTypesSelect.CBlob);
                Assert.AreEqual(allTypesInsert.CBoolean, allTypesSelect.CBoolean);
                Assert.AreEqual(allTypesInsert.CDouble, allTypesSelect.CDouble);
                Assert.AreEqual(allTypesInsert.CFloat, allTypesSelect.CFloat);
                Assert.AreEqual(allTypesInsert.CInet, allTypesSelect.CInet);
                Assert.AreEqual(allTypesInsert.CInt, allTypesSelect.CInt);
                Assert.AreEqual(allTypesInsert.CText, allTypesSelect.CText);
                Assert.AreEqual(allTypesInsert.CTimestamp, allTypesSelect.CTimestamp);
                Assert.AreEqual(allTypesInsert.CTimeuuid, allTypesSelect.CTimeuuid);
                Assert.AreEqual(allTypesInsert.CUuid, allTypesSelect.CUuid);
                Assert.AreEqual(allTypesInsert.CVarchar, allTypesSelect.CVarchar);
                Assert.AreEqual(allTypesInsert.CList, allTypesSelect.CList);
                Assert.AreEqual(allTypesInsert.CSet, allTypesSelect.CSet);
                Assert.AreEqual(allTypesInsert.CMap, allTypesSelect.CMap);
            }

            ClusterManager.Shutdown();
        }
        private void BinaryProtocolRunWritePerformanceParallel(bool streaming)
        {
            //run Write Performance Test using cassandra-sharp driver
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {"localhost"}
                            },
                        Transport = new TransportConfig
                            {
                                    Streaming = streaming
                            }
                };

            using (ICluster cluster = ClusterManager.GetCluster(clusterConfig))
            {
                const string dropFoo = "drop keyspace Endurance";
                try
                {
                    cluster.ExecuteNonQuery(dropFoo).Wait();
                }
                catch
                {
                }

                const string createFoo = "CREATE KEYSPACE Endurance WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";
                Console.WriteLine("============================================================");
                Console.WriteLine(createFoo);
                Console.WriteLine("============================================================");

                var resCount = cluster.ExecuteNonQuery(createFoo);
                resCount.Wait();
                Console.WriteLine();
                Console.WriteLine();

                const string createBar = "CREATE TABLE Endurance.stresstest (strid varchar,intid int,PRIMARY KEY (strid))";
                Console.WriteLine("============================================================");
                Console.WriteLine(createBar);
                Console.WriteLine("============================================================");
                resCount = cluster.ExecuteNonQuery(createBar);
                resCount.Wait();
                Console.WriteLine();
                Console.WriteLine();

                const string insertPerf = "UPDATE Endurance.stresstest SET intid = ? WHERE strid = ?";
                Console.WriteLine("============================================================");
                Console.WriteLine(" Cassandra-Sharp Driver write performance test single thread ");
                Console.WriteLine("============================================================");
                var prepared = cluster.Prepare(insertPerf);

                var timer = Stopwatch.StartNew();

                int running = 0;
                for (int i = 0; i < 100000; i++)
                {
                    if (0 == i%1000)
                    {
                        Console.WriteLine("Sent {0} requests so far - pending requests {1}", i, Interlocked.CompareExchange(ref running, 0, 0));
                    }

                    Interlocked.Increment(ref running);
                    prepared.ExecuteNonQuery(new {intid = i, strid = i.ToString("X")}).ContinueWith(_ => Interlocked.Decrement(ref running));
                }

                while (0 != Interlocked.CompareExchange(ref running, 0, 0))
                {
                    Console.WriteLine("{0} requests still running", running);
                    Thread.Sleep(1*1000);
                }
                timer.Stop();
                Console.WriteLine("Endurance ran in {0} ms", timer.ElapsedMilliseconds);

                Console.WriteLine("============================================================");
                Console.WriteLine(dropFoo);
                Console.WriteLine("============================================================");

                cluster.ExecuteNonQuery(dropFoo).Wait();
            }

            ClusterManager.Shutdown();
        }
示例#22
0
        private static void Run(string hostname, IStatementReader statementReader)
        {
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();
            cassandraSharpConfig.Logger = typeof(ConsoleDebugLogger).AssemblyQualifiedName;
            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
                {
                        Transport = new TransportConfig
                            {
                                    User = _cliArgs.User,
                                    Password = _cliArgs.Password,
                            },
                        Endpoints = new EndpointsConfig
                            {
                                    Servers = new[] {hostname},
                            }
                };

            using (ICluster cluster = ClusterManager.GetCluster(clusterConfig))
            {
                CommandContext.Cluster = cluster;

                if (_cliArgs.CheckConnection)
                {
                    Console.WriteLine("Connecting to {0}:", hostname);
                    const string checkStatement = "select cluster_name, data_center, rack, release_version from system.local";
                    if (!ExecuteCommand(checkStatement))
                    {
                        return;
                    }
                }

                if (_cliArgs.Banner)
                {
                    ExecuteCommand("!help");
                }

                foreach (string statement in statementReader.Read())
                {
                    ExecuteCommand(statement);

                    if (CommandContext.Exit)
                    {
                        return;
                    }
                }
            }
        }