Example #1
0
        public void SetupTest()
        {
            _session = TestClusterManager.GetTestCluster(1).Session;
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            // Create necessary tables
            MappingConfiguration config1 = new MappingConfiguration();

            config1.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(EntityWithTimeUuid),
                                                                       () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(EntityWithTimeUuid)));
            _tableEntityWithTimeUuid = new Table <EntityWithTimeUuid>(_session, config1);
            _tableEntityWithTimeUuid.Create();

            MappingConfiguration config2 = new MappingConfiguration();

            config2.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(EntityWithNullableTimeUuid),
                                                                       () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(EntityWithNullableTimeUuid)));
            _tableEntityWithNullableTimeUuid = new Table <EntityWithNullableTimeUuid>(_session, config2);
            _tableEntityWithNullableTimeUuid.Create();

            _expectedTimeUuidObjectList = EntityWithTimeUuid.GetDefaultObjectList();
            for (int i = 0; i < _expectedTimeUuidObjectList.Count; i++)
            {
                _expectedTimeUuidObjectList[i].StringType = i.ToString();
            }
        }
Example #2
0
        public void SetupTest()
        {
            _session = TestClusterManager.GetTestCluster(1).Session;
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            // Create necessary tables
            MappingConfiguration config1 = new MappingConfiguration();

            config1.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(EntityWithTimeUuid),
                                                                       () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(EntityWithTimeUuid)));
            _tableEntityWithTimeUuid = new Table <EntityWithTimeUuid>(_session, config1);
            _tableEntityWithTimeUuid.Create();

            MappingConfiguration config2 = new MappingConfiguration();

            config2.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(EntityWithNullableTimeUuid),
                                                                       () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(EntityWithNullableTimeUuid)));
            _tableEntityWithNullableTimeUuid = new Table <EntityWithNullableTimeUuid>(_session, config2);
            _tableEntityWithNullableTimeUuid.Create();

            _expectedTimeUuidObjectList         = EntityWithTimeUuid.GetDefaultObjectList();
            _expectedNullableTimeUuidObjectList = EntityWithNullableTimeUuid.GetDefaultObjectList();

            _dateBefore = DateTimeOffset.Parse("2014-2-1");
            _dateAfter  = DateTimeOffset.Parse("2014-4-1");
        }
Example #3
0
        public void TokenAware_TargetWrongPartition_HopsOccur()
        {
            // Setup
            PolicyTestTools policyTestTools = new PolicyTestTools();
            ITestCluster    testCluster     = TestClusterManager.GetTestCluster(3);

            testCluster.Builder = Cluster.Builder().WithLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
            testCluster.InitClient();

            var session = testCluster.Session;

            policyTestTools.TableName = TestUtils.GetUniqueTableName();
            policyTestTools.CreateSchema(session, 1);
            var traces = new List <QueryTrace>();

            for (var i = 1; i < 10; i++)
            {
                //The partition key is wrongly calculated
                var statement = new SimpleStatement(String.Format("INSERT INTO " + policyTestTools.TableName + " (k, i) VALUES ({0}, {0})", i))
                                .SetRoutingKey(new RoutingKey()
                {
                    RawRoutingKey = new byte[] { 0, 0, 0, 0 }
                })
                                .EnableTracing();
                var rs = session.Execute(statement);
                traces.Add(rs.Info.QueryTrace);
            }
            //Check that there were hops
            var hopsPerQuery = traces.Select(t => t.Events.Any(e => e.Source.ToString() == t.Coordinator.ToString()));

            Assert.True(hopsPerQuery.Any(v => v));
        }
        public override void OneTimeSetUp()
        {
            base.OneTimeSetUp();
            _session = TestClusterManager.GetTestCluster(1).Session;
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            // drop table if exists, re-create
            MappingConfiguration movieMappingConfig = new MappingConfiguration();

            //Using attributes is deprecated
            #pragma warning disable 612
            movieMappingConfig.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(Movie),
                                                                                  () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(Movie)));
            _movieTable = new Table <Movie>(_session, movieMappingConfig);
            #pragma warning restore 612
            _movieTable.Create();


            //Insert some data
            foreach (var movie in _movieList)
            {
                _movieTable.Insert(movie).Execute();
            }
        }
        public void FunctionFailureExceptionTest()
        {
            if (TestClusterManager.CassandraVersion < Version.Parse("2.2"))
            {
                Assert.Ignore("Function failure error were introduced in Cassandra 2.2");
            }
            var testCluster = TestClusterManager.GetTestCluster(1, 0, false, DefaultMaxClusterCreateRetries, false, false);

            testCluster.UpdateConfig("enable_user_defined_functions: true");
            testCluster.Start(1);
            var builder = Cluster
                          .Builder()
                          .AddContactPoint(testCluster.InitialContactPoint);

            using (var cluster = builder.Build())
            {
                var session = cluster.Connect();
                session.Execute(String.Format(TestUtils.CreateKeyspaceSimpleFormat, "ks_func", 1));
                session.Execute("CREATE TABLE ks_func.tbl1 (id int PRIMARY KEY, v1 int, v2 int)");
                session.Execute("INSERT INTO ks_func.tbl1 (id, v1, v2) VALUES (1, 1, 0)");
                session.Execute("CREATE FUNCTION ks_func.div(a int, b int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return a / b;'");

                Assert.Throws <FunctionFailureException>(() =>
                                                         session.Execute("SELECT ks_func.div(v1,v2) FROM ks_func.tbl1 where id = 1"));
            }
        }
Example #6
0
        public void SetupTest()
        {
            _session = TestClusterManager.GetTestCluster(1).Session;
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            // drop table if exists, re-create
            MappingConfiguration movieMappingConfig = new MappingConfiguration();

            movieMappingConfig.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(Movie),
                                                                                  () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(Movie)));
            _movieTable = new Table <Movie>(_session, movieMappingConfig);
            _movieTable.Create();

            //Insert some data
            foreach (var movie in _movieList)
            {
                _movieTable.Insert(movie).Execute();
            }

            // Wait for data to be query-able
            DateTime futureDateTime = DateTime.Now.AddSeconds(2); // it should not take very long for these records to become available for querying!

            while (DateTime.Now < futureDateTime && _movieTable.Count().Execute() < _movieList.Count)
            {
                Thread.Sleep(200);
            }
            Assert.AreEqual(_movieList.Count(), _movieTable.Count().Execute(), "Setup failure: Expected number of records are not query-able");
        }
        public void SetupFixture()
        {
            ITestCluster testCluster = TestClusterManager.GetTestCluster(1, DefaultMaxClusterCreateRetries, true, false);

            _contactPoint = testCluster.InitialContactPoint;
            _contactPoint = DefaultInitialContactPoint;
        }
Example #8
0
        public void TokenAware_TargetPartition_NoHops()
        {
            // Setup
            PolicyTestTools policyTestTools = new PolicyTestTools();
            ITestCluster    testCluster     = TestClusterManager.GetTestCluster(3);

            testCluster.Builder = Cluster.Builder().WithLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
            testCluster.InitClient();

            // Test
            policyTestTools.TableName = TestUtils.GetUniqueTableName();
            policyTestTools.CreateSchema(testCluster.Session, 1);
            var traces = new List <QueryTrace>();

            for (var i = -10; i < 10; i++)
            {
                var partitionKey = BitConverter.GetBytes(i).Reverse().ToArray();
                var statement    = new SimpleStatement(String.Format("INSERT INTO " + policyTestTools.TableName + " (k, i) VALUES ({0}, {0})", i))
                                   .SetRoutingKey(new RoutingKey()
                {
                    RawRoutingKey = partitionKey
                })
                                   .EnableTracing();
                var rs = testCluster.Session.Execute(statement);
                traces.Add(rs.Info.QueryTrace);
            }
            //Check that there weren't any hops
            foreach (var t in traces)
            {
                //The coordinator must be the only one executing the query
                Assert.True(t.Events.All(e => e.Source.ToString() == t.Coordinator.ToString()), "There were trace events from another host for coordinator " + t.Coordinator);
            }
        }
Example #9
0
 public void TestFixtureSetup()
 {
     if (CassandraVersion < Version.Parse("2.2"))
     {
         return;
     }
     _testCluster = TestClusterManager.GetTestCluster(1, 0, false, DefaultMaxClusterCreateRetries, false, false);
     _testCluster.UpdateConfig("enable_user_defined_functions: true");
     _testCluster.Start(1);
     using (var cluster = Cluster.Builder().AddContactPoint(_testCluster.InitialContactPoint).Build())
     {
         var session = cluster.Connect();
         var queries = new[]
         {
             "CREATE KEYSPACE  ks_udf WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}",
             "CREATE FUNCTION  ks_udf.return_one() RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return 1;'",
             "CREATE FUNCTION  ks_udf.plus(s int, v int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return s+v;'",
             "CREATE FUNCTION  ks_udf.plus(s bigint, v bigint) RETURNS NULL ON NULL INPUT RETURNS bigint LANGUAGE java AS 'return s+v;'",
             "CREATE AGGREGATE ks_udf.sum(int) SFUNC plus STYPE int INITCOND 1",
             "CREATE AGGREGATE ks_udf.sum(bigint) SFUNC plus STYPE bigint INITCOND 2"
         };
         foreach (var q in queries)
         {
             session.Execute(q);
         }
     }
 }
Example #10
0
 public void SetupTest()
 {
     _session      = TestClusterManager.GetTestCluster(1).Session;
     _uniqueKsName = TestUtils.GetUniqueKeyspaceName();
     _session.CreateKeyspace(_uniqueKsName);
     _session.ChangeKeyspace(_uniqueKsName);
 }
Example #11
0
        public void TokenAware_Prepared_Composite_NoHops()
        {
            // Setup
            PolicyTestTools policyTestTools = new PolicyTestTools();
            ITestCluster    testCluster     = TestClusterManager.GetTestCluster(3);

            testCluster.Builder = Cluster.Builder().WithLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
            testCluster.InitClient();

            // Test
            var session = testCluster.Session;

            policyTestTools.CreateSchema(session);
            policyTestTools.TableName = TestUtils.GetUniqueTableName();
            session.Execute(String.Format("CREATE TABLE {0} (k1 text, k2 int, i int, PRIMARY KEY ((k1, k2)))", policyTestTools.TableName));
            Thread.Sleep(1000);
            var ps     = session.Prepare(String.Format("INSERT INTO {0} (k1, k2, i) VALUES (?, ?, ?)", policyTestTools.TableName));
            var traces = new List <QueryTrace>();

            for (var i = 0; i < 10; i++)
            {
                var statement = ps.Bind(i.ToString(), i, i).EnableTracing();
                //Routing key is calculated by the driver
                Assert.NotNull(statement.RoutingKey);
                var rs = session.Execute(statement);
                traces.Add(rs.Info.QueryTrace);
            }
            //Check that there weren't any hops
            foreach (var t in traces)
            {
                //The coordinator must be the only one executing the query
                Assert.True(t.Events.All(e => e.Source.ToString() == t.Coordinator.ToString()), "There were trace events from another host for coordinator " + t.Coordinator);
            }
        }
Example #12
0
        public void SetupTest()
        {
            _session = TestClusterManager.GetTestCluster(1).Session;
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            _entityList = AllDataTypesEntity.SetupDefaultTable(_session);
        }
Example #13
0
 public void SetupTest()
 {
     _session      = TestClusterManager.GetTestCluster(1).Session;
     _uniqueKsName = TestUtils.GetUniqueKeyspaceName();
     _session.CreateKeyspace(_uniqueKsName);
     TestUtils.WaitForSchemaAgreement(_session.Cluster);
     _session.ChangeKeyspace(_uniqueKsName);
 }
Example #14
0
 protected virtual void TestFixtureSetUp()
 {
     TestCluster = TestClusterManager.GetTestCluster(AmountOfNodes, DefaultMaxClusterCreateRetries, true, false);
     Cluster     = Cluster.Builder().AddContactPoint(TestCluster.InitialContactPoint).Build();
     Session     = (Session)Cluster.Connect();
     Session.CreateKeyspace(KeyspaceName, null, false);
     Session.ChangeKeyspace(KeyspaceName);
 }
Example #15
0
        public void SetupTest()
        {
            _session = TestClusterManager.GetTestCluster(1).Session;
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            _entityList = AllDataTypesEntity.SetupDefaultTable(_session);
            _table      = new Table <AllDataTypesEntity>(_session, new MappingConfiguration());
        }
Example #16
0
        public void TestFixtureSetUp()
        {
            var testCluster = TestClusterManager.GetTestCluster(1);

            _cluster      = Cluster.Builder().AddContactPoint(testCluster.InitialContactPoint).Build();
            _session      = _cluster.Connect();
            _uniqueKsName = TestUtils.GetUniqueKeyspaceName();
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);
        }
        public void SetupFixture()
        {
            Diagnostics.CassandraTraceSwitch.Level = TraceLevel.Info;
            //Using a mirroring handler, the server will reply providing the same payload that was sent
            var jvmArgs     = new[] { "-Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler" };
            var testCluster = TestClusterManager.GetTestCluster(1, 0, false, DefaultMaxClusterCreateRetries, true, true, 0, jvmArgs);

            Session = testCluster.Session;
            Session.Execute(String.Format(TestUtils.CreateKeyspaceSimpleFormat, Keyspace, 1));
            Session.Execute(String.Format(TestUtils.CreateTableSimpleFormat, Table));
        }
Example #18
0
        public void TestFixtureSetUp()
        {
            var testCluster = TestClusterManager.GetTestCluster(1, DefaultMaxClusterCreateRetries, true, false);

            _cluster = Cluster.Builder().AddContactPoint(testCluster.InitialContactPoint).Build();
            _session = _cluster.Connect();
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            _movieTable = new Table <Movie>(_session, new MappingConfiguration());
            _movieTable.Create();
        }
Example #19
0
        public void Setup()
        {
            _testCluster = TestClusterManager.GetTestCluster(1);
            _session     = _testCluster.Session;

            _session.Execute(String.Format(TestUtils.CreateKeyspaceSimpleFormat, _uniqueKeyspaceName, 1));
            _session.ChangeKeyspace(_uniqueKeyspaceName);
            _session.Execute("CREATE TYPE song (id uuid, title text, artist text)");
            _session.Execute("CREATE TABLE albums (id uuid primary key, name text, songs list<frozen<song>>, publishingdate timestamp)");
            _session.Execute(
                new SimpleStatement(
                    "INSERT INTO albums (id, name, songs) VALUES (?, 'Legend', [{id: uuid(), title: 'Africa Unite', artist: 'Bob Marley'}])",
                    _sampleId));
            _session.UserDefinedTypes.Define(UdtMap.For <Song>());
        }
        public void Memory_Consumption_After_Cluster_Dispose()
        {
            var testCluster = TestClusterManager.GetTestCluster(2, DefaultMaxClusterCreateRetries, true, false);

            //Only warning as tracing through console slows it down.
            Diagnostics.CassandraTraceSwitch.Level = TraceLevel.Warning;
            var  start = GC.GetTotalMemory(false);
            long diff  = 0;

            Trace.TraceInformation("--Initial memory: {0}", start / 1024);
            Action multipleConnect = () =>
            {
                var cluster = Cluster.Builder().AddContactPoint(testCluster.InitialContactPoint).Build();
                for (var i = 0; i < 200; i++)
                {
                    var session = cluster.Connect();
                    TestHelper.ParallelInvoke(() => session.Execute("select * from system.local"), 20);
                }
                Trace.TraceInformation("--Before disposing: {0}", GC.GetTotalMemory(false) / 1024);
                cluster.Dispose();
                Trace.TraceInformation("--After disposing: {0}", GC.GetTotalMemory(false) / 1024);
            };

            multipleConnect();
            var handle = new AutoResetEvent(false);

            //Collect all generations
            GC.Collect();
            //Wait 5 seconds for all the connections resources to be freed
            Timer timer = null;

            timer = new Timer(s =>
            {
                GC.Collect();
                handle.Set();
                diff = GC.GetTotalMemory(false) - start;
                Trace.TraceInformation("--End, diff memory: {0}", diff / 1024);
                var t = timer;
                if (t != null)
                {
                    t.Dispose();
                }
            }, null, 5000, Timeout.Infinite);
            handle.WaitOne();
            //the end memory usage can not be greater than double the start memory
            //If there is a memory leak, it should be an order of magnitude greater...
            Assert.Less(diff, start / 2);
        }
        public void RoundRobin_DcAware_BuildClusterWithNonExistentDc()
        {
            ITestCluster testCluster = TestClusterManager.GetTestCluster(1);

            testCluster.Builder = Cluster.Builder().WithLoadBalancingPolicy(new DCAwareRoundRobinPolicy("dc2"));
            try
            {
                testCluster.InitClient();
                Assert.Fail("Expected exception was not thrown!");
            }
            catch (ArgumentException e)
            {
                string expectedErrMsg = "Datacenter dc2 does not match any of the nodes, available datacenters: datacenter1.";
                Assert.IsTrue(e.Message.Contains(expectedErrMsg));
            }
        }
Example #22
0
        public void Connect_With_Ssl_Test()
        {
            //use ssl
            var testCluster = TestClusterManager.GetTestCluster(1, 0, false, 1, true, false, 0, null, true);

            using (var cluster = Cluster.Builder()
                                 .AddContactPoint(testCluster.InitialContactPoint)
                                 .WithSSL(new SSLOptions().SetRemoteCertValidationCallback((a, b, c, d) => true))
                                 .Build())
            {
                Assert.DoesNotThrow(() =>
                {
                    var session = cluster.Connect();
                    TestHelper.Invoke(() => session.Execute("select * from system.local"), 10);
                });
            }
        }
Example #23
0
        public void SetupFixture()
        {
            if (TestClusterManager.CheckCassandraVersion(false, Version.Parse("2.2.0"), Comparison.LessThan))
            {
                Assert.Ignore("Requires Cassandra version >= 2.2");
                return;
            }

            Diagnostics.CassandraTraceSwitch.Level = TraceLevel.Info;
            //Using a mirroring handler, the server will reply providing the same payload that was sent
            var jvmArgs     = new [] { "-Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler" };
            var testCluster = TestClusterManager.GetTestCluster(1, 0, false, DefaultMaxClusterCreateRetries, true, true, 0, jvmArgs);

            Session = testCluster.Session;
            Session.Execute(string.Format(TestUtils.CreateKeyspaceSimpleFormat, Keyspace, 1));
            Session.Execute(string.Format(TestUtils.CreateTableSimpleFormat, Table));
        }
        public void SetupTest()
        {
            _session = TestClusterManager.GetTestCluster(1).Session;
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            // drop table if exists, re-create
            var table = _session.GetTable <Movie>();

            table.Create();

            //Insert some data
            foreach (var movie in _movieList)
            {
                table.Insert(movie).Execute();
            }
        }
Example #25
0
        public void TestFixtureSetup()
        {
            if (TestClusterManager.CheckCassandraVersion(false, Version.Parse("2.2"), Comparison.LessThan))
            {
                return;
            }
            _testCluster = TestClusterManager.GetTestCluster(1, 0, false, DefaultMaxClusterCreateRetries, false, false);
            _testCluster.UpdateConfig("enable_user_defined_functions: true");
            _testCluster.Start(1);
            using (var cluster = ClusterBuilder().AddContactPoint(_testCluster.InitialContactPoint).Build())
            {
                var session = cluster.Connect();
                var queries = new List <string>
                {
                    "CREATE KEYSPACE  ks_udf WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}",
                    "CREATE FUNCTION  ks_udf.return_one() RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return 1;'",
                    "CREATE FUNCTION  ks_udf.plus(s int, v int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return s+v;'",
                    "CREATE FUNCTION  ks_udf.plus(s bigint, v bigint) RETURNS NULL ON NULL INPUT RETURNS bigint LANGUAGE java AS 'return s+v;'",
                    "CREATE AGGREGATE ks_udf.sum(int) SFUNC plus STYPE int INITCOND 1",
                    "CREATE AGGREGATE ks_udf.sum(bigint) SFUNC plus STYPE bigint INITCOND 2"
                };

                if (TestClusterManager.CheckDseVersion(new Version(6, 0), Comparison.GreaterThanOrEqualsTo))
                {
                    queries.Add("CREATE FUNCTION ks_udf.deterministic(dividend int, divisor int) " +
                                "CALLED ON NULL INPUT RETURNS int DETERMINISTIC LANGUAGE java AS " +
                                "'return dividend / divisor;'");
                    queries.Add("CREATE FUNCTION ks_udf.monotonic(dividend int, divisor int) " +
                                "CALLED ON NULL INPUT RETURNS int MONOTONIC LANGUAGE java AS " +
                                "'return dividend / divisor;'");
                    queries.Add("CREATE FUNCTION ks_udf.md(dividend int, divisor int) " +
                                "CALLED ON NULL INPUT RETURNS int DETERMINISTIC MONOTONIC LANGUAGE java AS " +
                                "'return dividend / divisor;'");
                    queries.Add("CREATE FUNCTION ks_udf.monotonic_on(dividend int, divisor int) " +
                                "CALLED ON NULL INPUT RETURNS int MONOTONIC ON dividend LANGUAGE java AS " +
                                "'return dividend / divisor;'");
                    queries.Add("CREATE AGGREGATE ks_udf.deta(int) SFUNC plus STYPE int INITCOND 0 DETERMINISTIC;");
                }

                foreach (var q in queries)
                {
                    session.Execute(q);
                }
            }
        }
Example #26
0
        public void SetupTest()
        {
            _session = TestClusterManager.GetTestCluster(1).Session;
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            // drop table if exists, re-create
            _movieMappingConfig = new MappingConfiguration();
            _movieMappingConfig.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(Movie),
                                                                                   () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(Movie)));
            _movieTable = new Table <Movie>(_session, _movieMappingConfig);
            _movieTable.Create();

            //Insert some data
            foreach (var movie in _movieList)
            {
                _movieTable.Insert(movie).Execute();
            }
        }
Example #27
0
        private ITestCluster SetupSessionAndCluster(int nodes, Dictionary <string, string> replication = null)
        {
            ITestCluster testCluster = TestClusterManager.GetTestCluster(nodes);

            _session = testCluster.Session;
            _ksName  = TestUtils.GetUniqueKeyspaceName();
            _session.CreateKeyspace(_ksName, replication);
            TestUtils.WaitForSchemaAgreement(_session.Cluster);
            _session.ChangeKeyspace(_ksName);
            _table = new Table <ManyDataTypesEntity>(_session, new MappingConfiguration());
            _table.Create();
            _defaultPocoList   = ManyDataTypesEntity.GetDefaultAllDataTypesList();
            _preparedStatement = _session.Prepare(_preparedInsertStatementAsString);
            foreach (var manyDataTypesEntity in _defaultPocoList)
            {
                _session.Execute(GetBoundInsertStatementBasedOnEntity(manyDataTypesEntity));
            }

            return(testCluster);
        }
Example #28
0
        public void SetupTest()
        {
            _session = TestClusterManager.GetTestCluster(1).Session;
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            // drop table if exists, re-create
            var config        = new Map <Movie>().PartitionKey(c => c.MovieMaker);
            var mappingConfig = new MappingConfiguration().Define(config);

            _mapper     = new Mapper(_session, mappingConfig);
            _movieTable = new Table <Movie>(_session, mappingConfig);
            _movieTable.Create();

            //Insert some data
            foreach (var movie in _movieList)
            {
                _movieTable.Insert(movie).Execute();
            }
        }
Example #29
0
        public void TestFixtureSetUp()
        {
            _session = TestClusterManager.GetTestCluster(1).Session;
            _session.CreateKeyspace(_keyspace);
            var table = GetTable();

            table.Create();
            var tasks = new List <Task>();

            for (var i = 0; i < TotalRows; i++)
            {
                tasks.Add(table.Insert(new Song
                {
                    Id          = Guid.NewGuid(),
                    Artist      = "Artist " + i,
                    Title       = "Title " + i,
                    ReleaseDate = DateTimeOffset.Now
                }).ExecuteAsync());
            }
            Assert.True(Task.WaitAll(tasks.ToArray(), 10000));
        }
Example #30
0
        public void TokenAware_Composite_NoHops()
        {
            // Setup
            PolicyTestTools policyTestTools = new PolicyTestTools();
            ITestCluster    testCluster     = TestClusterManager.GetTestCluster(3);

            testCluster.Builder = Cluster.Builder().WithLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
            testCluster.InitClient();

            // Test
            var session = testCluster.Session;

            policyTestTools.CreateSchema(session);
            policyTestTools.TableName = TestUtils.GetUniqueTableName();
            session.Execute(String.Format("CREATE TABLE {0} (k1 text, k2 int, i int, PRIMARY KEY ((k1, k2)))", policyTestTools.TableName));
            var traces = new List <QueryTrace>();

            for (var i = 0; i < 10; i++)
            {
                var statement = new SimpleStatement(String.Format("INSERT INTO " + policyTestTools.TableName + " (k1, k2, i) VALUES ('{0}', {0}, {0})", i))
                                .SetRoutingKey(
                    new RoutingKey()
                {
                    RawRoutingKey = Encoding.UTF8.GetBytes(i.ToString())
                },
                    new RoutingKey()
                {
                    RawRoutingKey = BitConverter.GetBytes(i).Reverse().ToArray()
                })
                                .EnableTracing();
                var rs = session.Execute(statement);
                traces.Add(rs.Info.QueryTrace);
            }
            //Check that there weren't any hops
            foreach (var t in traces)
            {
                //The coordinator must be the only one executing the query
                Assert.True(t.Events.All(e => e.Source.ToString() == t.Coordinator.ToString()), "There were trace events from another host for coordinator " + t.Coordinator);
            }
        }