Esempio n. 1
0
        protected override void InternalRun(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            const string insertNerdMovie = "INSERT INTO videos.NerdMovies (movie, director, main_actor, year)" +
                                           "VALUES ('Serenity', 'Joss Whedon', 'Nathan Fillion', 2005) " +
                                           "USING TTL 86400";

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

            const string selectNerdMovies = "select * from videos.NerdMovies";

            Console.WriteLine(selectNerdMovies);
            var taskSelectStartMovies = cmd.Execute <NerdMovie>(selectNerdMovies).AsFuture().ContinueWith(res => DisplayMovies(res.Result));

            taskSelectStartMovies.Wait();
            Console.WriteLine();

            const string selectAllFrom = "select * from videos.NerdMovies where director=? ALLOW FILTERING";

            Console.WriteLine(selectAllFrom);
            var preparedAllFrom = cmd.Prepare <NerdMovie>(selectAllFrom);
            var ds = new { Director = "Joss Whedon" };
            var taskSelectWhere =
                preparedAllFrom.Execute(ds).AsFuture().ContinueWith(res => DisplayMovies(res.Result));

            taskSelectWhere.Wait();
            Console.WriteLine();
        }
Esempio n. 2
0
        protected override void DropKeyspace(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            const string dropExcelsor = "drop keyspace videos";

            cmd.Execute(dropExcelsor).AsFuture().Wait();
        }
Esempio n. 3
0
        protected override void CreateKeyspace(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            const string createKeyspaceFoo = "CREATE KEYSPACE Foo WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";

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

            const string createBar = "CREATE TABLE Foo.Bar (id int, Baz blob, PRIMARY KEY (id))";

            cmd.Execute(createBar).AsFuture().Wait();
        }
Esempio n. 4
0
        protected override void InternalRun(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            const string cqlKeyspaces = "SELECT * from system.schema_columns";

            var req = from t in cmd.Execute <SchemaColumns>(cqlKeyspaces).AsFuture().Result
                      where t.KeyspaceName == "system"
                      select t;

            DisplayResult(req);
        }
Esempio n. 5
0
        public void KeyspaceCreated()
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            var res          = cmd.Execute <SchemaKeyspace>("SELECT * FROM system.schema_keyspaces").AsFuture().Result;
            var testKeyspace =
                res.FirstOrDefault(
                    x => x.KeyspaceName.Equals(DefaultKeyspaceTest.TestKeyspace, StringComparison.InvariantCultureIgnoreCase));

            Assert.IsNotNull(testKeyspace);
            Assert.IsFalse(testKeyspace.DurableWrites);
            Assert.IsTrue(testKeyspace.StrategyClass.Contains("SimpleStrategy"));
            Assert.IsTrue(testKeyspace.StrategyOptions.Contains("1"));
        }
        public void KeyspaceCreated()
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            var res          = cmd.Execute <SchemaKeyspace>("SELECT * FROM system_schema.keyspaces").AsFuture().Result;
            var testKeyspace =
                res.FirstOrDefault(
                    x => x.KeyspaceName.Equals(DefaultKeyspaceTest.TestKeyspace, StringComparison.InvariantCultureIgnoreCase));

            Assert.IsNotNull(testKeyspace);
            Assert.IsFalse(testKeyspace.DurableWrites);
            Assert.AreEqual("org.apache.cassandra.locator.SimpleStrategy", testKeyspace.Replication["class"]);
            Assert.AreEqual("1", testKeyspace.Replication["replication_factor"]);
        }
Esempio n. 7
0
        protected override void InternalRun(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            const string cqlKeyspaces = "SELECT * from system.schema_keyspaces";

            for (int i = 0; i < 10; ++i)
            {
                // timeout = 10 ms
                CancellationTokenSource cts = new CancellationTokenSource(10);
                var futRes = cmd.Execute <SchemaKeyspaces>(cqlKeyspaces).AsFuture(cts.Token).ContinueWith(DisplayKeyspace);
                futRes.Wait();
            }
        }
Esempio n. 8
0
        public void TearDown()
        {
            ICqlCommand cmd = cluster.CreateCommand().FromOrdinal().ToPoco().Build();

            try
            {
                cmd.Execute("drop keyspace " + TestKeyspace).AsFuture().Wait();
            }
            catch
            {
            }

            ClusterManager.Shutdown();
        }
Esempio n. 9
0
        public void CanOmitDefaultKeyspaceName()
        {
            ICqlCommand cmd = cluster.CreateOrdinalCommand();

            cmd.Execute("CREATE TABLE Test (cAscii ascii,cInt int,PRIMARY KEY (cInt))").AsFuture().Wait();
            cmd.Execute("INSERT INTO Test (cAscii,cInt) VALUES ('test',1)").AsFuture().Wait();
            var res = cmd.Execute <object[]>("SELECT cAscii FROM Test WHERE cInt = 1").AsFuture().Result.Single();

            Assert.AreEqual("test", res[0]);

            res =
                cmd.Execute <object[]>(string.Format("SELECT cAscii FROM {0}.Test WHERE cInt = 1", TestKeyspace)).
                AsFuture().Result.Single();
            Assert.AreEqual("test", res[0]);
        }
Esempio n. 10
0
        protected override void InternalRun(ICluster cluster)
        {
            const string cqlKeyspaces = "SELECT * from system_schema.keyspaces";

            ICqlCommand cmd = cluster.CreatePocoCommand();

            var allTasks = new List <Task>();

            for (int i = 0; i < 100; ++i)
            {
                var futRes = cmd.Execute <SchemaKeyspaces>(cqlKeyspaces).AsFuture().ContinueWith(t => DisplayKeyspace(t.Result));
                allTasks.Add(futRes);
            }

            Task.WaitAll(allTasks.ToArray());
        }
Esempio n. 11
0
        protected override void CreateKeyspace(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            const string createKeyspace = "CREATE KEYSPACE videos WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}";

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

            const string createNerdMovies = "CREATE TABLE videos.NerdMovies (movie text, " +
                                            "director text, " +
                                            "main_actor text, " +
                                            "year int, " +
                                            "PRIMARY KEY (movie, director))";

            cmd.Execute(createNerdMovies).AsFuture().Wait();
        }
Esempio n. 12
0
        protected override void InternalRun(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            const string cqlKeyspaces = "SELECT * from system_schema.keyspaces";

            var allResults = new List <Task <IList <SchemaKeyspaces> > >();

            for (int i = 0; i < 100; ++i)
            {
                var futRes = cmd.Execute <SchemaKeyspaces>(cqlKeyspaces).AsFuture();
                allResults.Add(futRes);
            }

            foreach (var result in allResults)
            {
                DisplayKeyspace(result);
            }
        }
Esempio n. 13
0
        public override Task <IRowSet> ExecuteAsync(ref CqlBatch batch)
        {
            if (batch.Commands == null || batch.Commands.Count <= 0)
            {
                throw new ArgumentException("CqlBatch has none commands");
            }

            BatchStatement bst = new BatchStatement();
            ICqlCommand    cmd = null;

            for (int i = 0; i < batch.Commands.Count; i++)
            {
                cmd = batch.Commands[i];
                if (cmd is CqlCommand)
                {
                    var ecmd = (CqlCommand)cmd;
                    switch (ecmd.Type)
                    {
                    case CqlCommandType.Insert:
                        bst.Add(new SimpleStatement(CqlCommandBuilder.BuildInsertEntityCommand(ecmd.Entity, ecmd.CheckExists)));
                        break;

                    case CqlCommandType.Update:
                        bst.Add(new SimpleStatement(CqlCommandBuilder.BuildUpdateEntityCommand(ecmd.Entity, ecmd.CheckExists)));
                        break;

                    case CqlCommandType.Delete:
                        bst.Add(new SimpleStatement(CqlCommandBuilder.BuildDeleteEntityCommand(ecmd.Entity, ecmd.CheckExists)));
                        break;

                    default:
                        throw new NotSupportedException("CassandraTableStore.Execut batch");
                    }
                }
                else
                {
                    throw new NotImplementedException("CassandraTableStore.Execut batch");
                }
            }

            return(ExecuteBatchAsync(bst));
        }
        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();
        }
Esempio n. 15
0
        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();
        }
Esempio n. 16
0
        protected override void InternalRun(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            const string insertBatch    = "INSERT INTO Foo.Bar (id, Baz) VALUES (?, ?)";
            var          preparedInsert = cmd.WithConsistencyLevel(ConsistencyLevel.ONE).Prepare(insertBatch);

            const int times = 10;

            var random = new Random();

            for (int i = 0; i < times; i++)
            {
                long running = Interlocked.Increment(ref _running);

                Console.WriteLine("Current {0} Running {1}", i, running);

                var data = new byte[30000];
                // var data = (float)random.NextDouble();
                preparedInsert.Execute(new { id = i, Baz = data }).AsFuture()
                .ContinueWith(_ => Interlocked.Decrement(ref _running));
            }

            while (Thread.VolatileRead(ref _running) > 0)
            {
                Console.WriteLine("Running {0}", _running);
                Thread.Sleep(1000);
            }

            var result = cmd.Execute <Foo>("select * from Foo.Bar where id = 50").AsFuture().Result;

            foreach (var res in result)
            {
                Console.WriteLine("{0} len={1}", res.Id, res.Baz.Length);
            }
        }
Esempio n. 17
0
 public PropertyBagCommand(ICqlCommand command)
 {
     _command = command;
 }
Esempio n. 18
0
        public void TestAllTypes()
        {
            ClusterManager.Shutdown();
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig();

            ClusterManager.Configure(cassandraSharpConfig);

            ClusterConfig clusterConfig = new ClusterConfig
            {
                Endpoints = new EndpointsConfig
                {
                    Servers = new[] { CQLBinaryProtocol.DefaultKeyspaceTest.CassandraServerIp }
                }
            };

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

                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,
                                                                            
                                                                            cDouble double,
                                                                            cFloat float,
                                                                            cInet inet,
                                                                            cInt int,
                                                                            cText text,
                                                                            cTimestamp timestamp,
                                                                            cTimeuuid timeuuid,
                                                                            cUuid uuid,
                                                                            cVarchar varchar,
                                                                           
                                                                            cList list<int>,
                                                                            cSet set<int>,
                                                                            cMap map<text, int>,
                                                                            cEnum int,
                                                                            
                                                                            cPoint blob,
                                                          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, cEnum, cPoint)
                                             values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                var          prepared    = cmd.Prepare(insertBatch);

                var allTypesInsert = new AllTypes
                {
                    CAscii     = new string('x', 8000),
                    CBigint    = 0x0102030405060708,
                    CBlob      = Enumerable.Repeat((byte)42, 33000).ToArray(),
                    CBoolean   = true,
                    CDouble    = 1234.5678,
                    CFloat     = 234.567f,
                    CInet      = new IPAddress(new byte[] { 0x01, 0x02, 0x03, 0x04 }),
                    CInt       = 42,
                    CText      = new string('x', 100000),
                    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 }, { new string('x', 65510), 3 }
                    },
                    CEnum  = TestEnum.ValueB,
                    CPoint = new Point {
                        X = 1, Y = 3
                    }
                };

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

                const string selectAll      = "select * 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);
                Assert.AreEqual(allTypesInsert.CEnum, allTypesSelect.CEnum);

                Assert.AreEqual(allTypesInsert.CPoint.X, allTypesSelect.CPoint.X);
                Assert.AreEqual(allTypesInsert.CPoint.Y, allTypesSelect.CPoint.Y);
            }

            ClusterManager.Shutdown();
        }
Esempio n. 19
0
        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 = cluster.CreatePocoCommand();

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

                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).AsFuture();
                resCount.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).AsFuture();
                resCount.Wait();
                Console.WriteLine();
                Console.WriteLine();

                using (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).AsFuture();
                resCount.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);
        }
Esempio n. 20
0
        protected override void DropKeyspace(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            cmd.Execute("drop keyspace Foo").AsFuture().Wait();
        }
Esempio n. 21
0
 public PropertyBagCommand(ICqlCommand command)
 {
     _command = command;
 }
Esempio n. 22
0
        private void BinaryProtocolRunWritePerformanceParallel(string transportType)
        {
            //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
                {
                    Type = transportType
                }
            };

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

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

                const string createFoo = "CREATE KEYSPACE Endurance 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 Endurance.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 Endurance.stresstest SET intid = ? WHERE strid = ?";
                Console.WriteLine("============================================================");
                Console.WriteLine(" Cassandra-Sharp Driver write performance test single thread ");
                Console.WriteLine("============================================================");
                var prepared = cmd.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 - pending requests {1}", i, Interlocked.CompareExchange(ref running, 0, 0));
                    }

                    Interlocked.Increment(ref running);
                    prepared.Execute(new { intid = i, strid = i.ToString("X") }).AsFuture().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("============================================================");

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

            ClusterManager.Shutdown();
        }
        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[] { "cassandra1" }
                },
            };

            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();
        }
Esempio n. 24
0
        public void ConnectionFailedTest()
        {
            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", CQLBinaryProtocol.DefaultKeyspaceTest.CassandraServerIp },
                    Strategy  = "RoundRobin",
                    Discovery = new DiscoveryConfig()
                    {
                        Type = "Null",
                    },
                },

                Transport = new TransportConfig
                {
                    Port           = 9042,
                    ReceiveTimeout = 10 * 1000,
                }
            };

            DisconnectingProxy proxy = new DisconnectingProxy(9042, 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();

                var prepared1 = cmd.Prepare("insert into data.test(time) values ('?');");
                var prepared2 = cmd.Prepare("insert into data.test(time) values ('?');");

                for (int i = 0; i < 100; ++i)
                {
                    int attempt = 0;
                    while (true)
                    {
                        var now = DateTime.Now;
                        Console.WriteLine("{0}.{1})", i, ++attempt);
                        try
                        {
                            prepared1.Execute(new { time = now }).AsFuture().Wait();
                            prepared2.Execute(new { time = now }).AsFuture().Wait();
                            break;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Failed with error {0}", ex.Message);
                            Thread.Sleep(1000);
                            if (attempt >= 3)
                            {
                                break;
                            }
                        }
                    }
                }

                ClusterManager.Shutdown();
            }

            proxy.Stop();
        }
Esempio n. 25
0
 private static void Worker(int taskId, ICqlCommand cmd)
 {
     for (int reqId = 0; reqId < 10000; ++reqId)
     {
         int attempt = 0;
         while (true)
         {
             try
             {
                 var now = DateTime.Now;
                 string insert = String.Format("insert into data.test(time) values ('{0}');", now);
                 cmd.Execute(insert).AsFuture().Wait();
                 Console.WriteLine("Task {0} RequestId {1} Try {2} ==> {3}", taskId, reqId, ++attempt, insert);
                 break;
             }
             catch (Exception ex)
             {
                 Console.WriteLine("FAILED Task {0} RequestId {1} Try {2} ==> {3}", taskId, reqId, ++attempt, ex.Message);
                 Thread.Sleep(5*1000);
             }
         }
     }
 }
Esempio n. 26
0
 public static IQuery <NonQuery> Execute(this ICqlCommand @this, string cql)
 {
     return(@this.Execute <NonQuery>(cql));
 }
Esempio n. 27
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[] { "cassandra1" },
                },
                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 < 100000; ++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);
                        }
                    }
                }

                Console.WriteLine("Stress test done");

                ClusterManager.Shutdown();
            }

            proxy.Stop();
        }
Esempio n. 28
0
 public static IPreparedQuery <NonQuery> Prepare(this ICqlCommand @this, string cql)
 {
     return(@this.Prepare <NonQuery>(cql));
 }