Example #1
0
        public static TracingSession QueryTracingInfo(this ICluster @this, Guid tracingId)
        {
            var cmd = @this.CreatePocoCommand();

            // query events and session
            string queryEvents = "select * from system_traces.events where session_id = " + tracingId;
            var    obsEvents   = cmd.WithConsistencyLevel(ConsistencyLevel.ONE)
                                 .Execute <TracingEvent>(queryEvents)
                                 .AsFuture();

            string querySession = "select * from system_traces.sessions where session_id = " + tracingId;
            var    obsSession   = cmd.WithConsistencyLevel(ConsistencyLevel.ONE)
                                  .Execute <TracingSession>(querySession)
                                  .AsFuture();

            Task.WaitAll(obsEvents, obsSession);

            // format the events
            var tracingEvents = obsEvents.Result.ToList();

            tracingEvents.Sort(CompareTracingEvent);
            TracingEvent[] events = tracingEvents.ToArray();
            foreach (var evt in events)
            {
                string[] tmp = evt.Thread.Split(':');
                evt.Stage  = tmp[0];
                evt.Thread = tmp[1];
            }

            // build the result
            TracingSession tracingSession = obsSession.Result.Single();

            tracingSession.TracingEvents = events;
            return(tracingSession);
        }
Example #2
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();
        }
Example #3
0
        protected override void DropKeyspace(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            const string dropExcelsor = "drop keyspace videos";
            cmd.Execute(dropExcelsor).AsFuture().Wait();
        }
        protected override void InternalRun(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            const string insertBatch = "INSERT INTO Foo.Bar (id, Baz) VALUES (?, ?)";
            var preparedInsert = cmd.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}, ConsistencyLevel.ONE).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);
            }
        }
Example #5
0
        public static async Task QueryKeyspaces()
        {
            // This is configurable in your cassandra-env.sh file, but the default is 7199.
            // Ports 57311 and 57312 are randomly assigned ports used for RMI communication.
            // These ports change each time Cassandra starts up, but need to be open in the firewall,
            // along with 8080 / 7199(depending on version), to allow for remote JMX acces


            // XmlConfigurator.Configure();
            // using (ICluster cluster = ClusterManager.GetCluster("TestCassandra"))
            //using (ICluster cluster = GetCluster(7199, new string[] { "127.0.0.1" }))
            //using (ICluster cluster = GetCluster(9042, new string[] { "127.0.0.1" }))
            using (ICluster cluster = GetCluster(9042, new string[] { "localhost" }))
            {
                var          cmd          = cluster.CreatePocoCommand();
                const string cqlKeyspaces = "SELECT * from system_schema.keyspaces";

                // async operation with streaming
                cmd.WithConsistencyLevel(ConsistencyLevel.ONE)
                .Execute <SchemaKeyspaces>(cqlKeyspaces)
                .Subscribe(DisplayKeyspace);

                // future
                System.Collections.Generic.IList <SchemaKeyspaces> kss = await cmd.Execute <SchemaKeyspaces>(cqlKeyspaces).AsFuture();

                foreach (SchemaKeyspaces ks in kss)
                {
                    DisplayKeyspace(ks);
                }
            }

            ClusterManager.Shutdown();
        }
Example #6
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();
        }
Example #7
0
        protected override void DropKeyspace(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            const string dropExcelsor = "drop keyspace videos";

            cmd.Execute(dropExcelsor).AsFuture().Wait();
        }
        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();
        }
Example #9
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);
        }
Example #10
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);
        }
Example #11
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();
        }
Example #12
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();
            }
        }
Example #13
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();
        }
Example #14
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());
        }
Example #15
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());
        }
Example #16
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();
        }
Example #17
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);
            }
        }
Example #18
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);
            }
        }
        protected override void InternalRun(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

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

            Random rnd = new Random();
            for (int i = 0; i < 10; ++i)
            {
                DateTime dtStart = DateTime.Now;
                DateTime dtStop = dtStart.AddSeconds(2); // 2 second max
                int wait = rnd.Next(4*1000);
                var futRes = cmd.Execute<SchemaKeyspaces>(cqlKeyspaces).AsFuture()
                                .ContinueWith(t =>
                                    {
                                        // simulate an eventually long operation
                                        Thread.Sleep(wait);
                                        return t;
                                    }).Unwrap().ContinueWith(t => DisplayKeyspace(t.Result, dtStop));
                futRes.Wait();
            }
        }
Example #20
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);
            }
        }
Example #21
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();
        }
Example #22
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();
        }
Example #23
0
        protected override void DropKeyspace(ICluster cluster)
        {
            ICqlCommand cmd = cluster.CreatePocoCommand();

            cmd.Execute("drop keyspace Foo").AsFuture().Wait();
        }
Example #24
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();
        }
        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();
        }
Example #26
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);
        }
        public override void ActivateOptions()
        {
            _cluster = ClusterManager.GetCluster(ClusterName);

            string insertCQL =
                    string.Format(
                            "insert into {0}.{1} " +
                            "(id," +
                            "app_name," +
                            "app_start_time," +
                            "class_name," +
                            "file_name," +
                            "host_ip," +
                            "host_name," +
                            "level," +
                            "line_number," +
                            "log_timestamp," +
                            "logger_name," +
                            "message," +
                            "method_name," +
                            "thread_name," +
                            "throwable_str_rep) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
                            Keyspace, ColumnFamily);

            _insert = _cluster.CreatePocoCommand()
                              .WithConsistencyLevel(ConsistencyLevel)
                              .Prepare(insertCQL);
        }
 protected override void DropKeyspace(ICluster cluster)
 {
     ICqlCommand cmd = cluster.CreatePocoCommand();
     cmd.Execute("drop keyspace Foo").AsFuture().Wait();
 }
Example #29
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();
        }