コード例 #1
0
        public void RecoveryTest()
        {
            CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig
            {
                Logger = new LoggerConfig {
                    Type = typeof(ResilienceLogger).AssemblyQualifiedName
                },
                Recovery = new RecoveryConfig {
                    Interval = 2
                }
            };

            ClusterManager.Configure(cassandraSharpConfig);

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

            DisconnectingProxy proxy = new DisconnectingProxy(666, 9042);

            proxy.Start();

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

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

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

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

                proxy.EnableKiller();

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

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

                ClusterManager.Shutdown();
            }

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

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

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

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

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

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

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

                proxy.EnableKiller();

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

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

                ClusterManager.Shutdown();
            }

            proxy.Stop();
        }
コード例 #3
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();
        }