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 = new PocoCommand(cluster);

                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 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 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 = 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("============================================================");

                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}},
                    };

                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);
            }

            ClusterManager.Shutdown();
        }
        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);
            ICqlCommand cmd = new PocoCommand(cluster);

            const string dropKeySpace = "drop keyspace Tests";
            try
            {
                cmd.Execute(dropKeySpace).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).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).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("============================================================");

            var prepared = cmd.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);
        }