Exemplo n.º 1
0
        public void WideBatchRows()
        {
            string uniqueTableName = "wide_batch_rows" + Randomm.RandomAlphaNum(16);

            TestWideBatchRows(_session, uniqueTableName);
        }
Exemplo n.º 2
0
        public void KeyspacesMetadataAvailableAtStartup(bool metadataSync)
        {
            var cluster = GetNewCluster(builder => builder.WithMetadataSyncOptions(new MetadataSyncOptions().SetMetadataSyncEnabled(metadataSync)));

            // Basic status check
            Assert.Greater(cluster.Metadata.GetKeyspaces().Count, 0);
            Assert.NotNull(cluster.Metadata.GetKeyspace("system"));
            Assert.AreEqual("system", cluster.Metadata.GetKeyspace("system").Name);

            Assert.NotNull(cluster.Metadata.GetKeyspace("system").AsCqlQuery());

            //Not existent tables return null
            Assert.Null(cluster.Metadata.GetKeyspace("nonExistentKeyspace_" + Randomm.RandomAlphaNum(12)));
            Assert.Null(cluster.Metadata.GetTable("nonExistentKeyspace_" + Randomm.RandomAlphaNum(12), "nonExistentTable_" + Randomm.RandomAlphaNum(12)));
            Assert.Null(cluster.Metadata.GetTable("system", "nonExistentTable_" + Randomm.RandomAlphaNum(12)));

            //Case sensitive
            Assert.Null(cluster.Metadata.GetKeyspace("SYSTEM"));
        }
Exemplo n.º 3
0
 private static string GetUniqueTableName()
 {
     return("LgDataTsts_" + Randomm.RandomAlphaNum(16));
 }
Exemplo n.º 4
0
        public void MassiveAsyncTest()
        {
            Cluster  localCluster = _builder.Build();
            ISession localSession = localCluster.Connect();
            string   keyspaceName = "kp_mat_" + Randomm.RandomAlphaNum(8);

            localSession.Execute(
                string.Format(@"CREATE KEYSPACE {0} 
                    WITH replication = {{ 'class' : 'SimpleStrategy', 'replication_factor' : 2 }};"
                              , keyspaceName));
            localSession.ChangeKeyspace(keyspaceName);

            string tableName = "table" + Randomm.RandomAlphaNum(8);

            localSession.Execute(string.Format(@"CREATE TABLE {0}(
                    tweet_id uuid,
                    author text,
                    body text,
                    isok boolean,
                    PRIMARY KEY(tweet_id))", tableName));

            int RowsNo = 100;
            var ar     = new bool[RowsNo];
            var thr    = new Thread(() =>
            {
                for (int i = 0; i < RowsNo; i++)
                {
                    int tmpi = i;
                    localSession.BeginExecute(string.Format(@"INSERT INTO {0} (
                             tweet_id,
                             author,
                             isok,
                             body)
                            VALUES ({1},'test{2}',{3},'body{2}');", tableName, Guid.NewGuid(), i, i % 2 == 0 ? "false" : "true")
                                              , ConsistencyLevel.One, _ =>
                    {
                        ar[tmpi] = true;
                        Interlocked.MemoryBarrier();
                    }, null);
                }
            });

            thr.Start();

            var done = new HashSet <int>();

            while (done.Count < RowsNo)
            {
                for (int i = 0; i < RowsNo; i++)
                {
                    Interlocked.MemoryBarrier();
                    if (!done.Contains(i) && ar[i])
                    {
                        done.Add(i);
                    }
                }
            }

            thr.Join();

            Trace.TraceInformation("Inserted... now we are checking the count");

            var ret = localSession.Execute(string.Format(@"SELECT * from {0} LIMIT {1};", tableName, RowsNo + 100), ConsistencyLevel.Quorum);

            Assert.AreEqual(RowsNo, ret.GetRows().ToList().Count);
            localSession.Dispose();
        }
Exemplo n.º 5
0
        public void ParallelInsertTest()
        {
            Cluster  localCluster = _builder.Build();
            ISession localSession = localCluster.Connect();
            string   keyspaceName = "kp_pi1_" + Randomm.RandomAlphaNum(10);

            localSession.Execute(string.Format(@"CREATE KEYSPACE {0} WITH replication = {{ 'class' : 'SimpleStrategy', 'replication_factor' : 2 }};", keyspaceName));

            TestUtils.WaitForSchemaAgreement(localCluster);
            localSession.ChangeKeyspace(keyspaceName);

            for (int KK = 0; KK < 1; KK++)
            {
                string tableName = "table" + Guid.NewGuid().ToString("N").ToLower();
                try
                {
                    localSession.Execute(string.Format(@"
                        CREATE TABLE {0}(
                        tweet_id uuid,
                        author text,
                        body text,
                        isok boolean,
                        PRIMARY KEY(tweet_id))", tableName));

                    TestUtils.WaitForSchemaAgreement(localCluster);
                }
                catch (AlreadyExistsException)
                {
                }

                int RowsNo   = 1000;
                var ar       = new IAsyncResult[RowsNo];
                var threads  = new List <Thread>();
                var monit    = new object();
                int readyCnt = 0;
                Trace.TraceInformation("Preparing...");

                for (int idx = 0; idx < RowsNo; idx++)
                {
                    int i = idx;
                    threads.Add(new Thread(() =>
                    {
                        try
                        {
                            lock (monit)
                            {
                                readyCnt++;
                                Monitor.Wait(monit);
                            }

                            ar[i] = localSession.BeginExecute(string.Format(@"
                                INSERT INTO {0} (tweet_id, author, isok, body) 
                                VALUES ({1},'test{2}',{3},'body{2}');",
                                                                            tableName, Guid.NewGuid(), i, i % 2 == 0 ? "false" : "true"), ConsistencyLevel.One, null, null);
                            Interlocked.MemoryBarrier();
                        }
                        catch
                        {
                        }
                    }));
                }

                for (int idx = 0; idx < RowsNo; idx++)
                {
                    threads[idx].Start();
                }

                lock (monit)
                {
                    while (true)
                    {
                        if (readyCnt < RowsNo)
                        {
                            Monitor.Exit(monit);
                            Thread.Sleep(100);
                            Monitor.Enter(monit);
                        }
                        else
                        {
                            Monitor.PulseAll(monit);
                            break;
                        }
                    }
                }

                Trace.TraceInformation("Start!");

                var done = new HashSet <int>();
                while (done.Count < RowsNo)
                {
                    for (int i = 0; i < RowsNo; i++)
                    {
                        Interlocked.MemoryBarrier();
                        if (!done.Contains(i) && ar[i] != null)
                        {
                            if (ar[i].AsyncWaitHandle.WaitOne(10))
                            {
                                try
                                {
                                    localSession.EndExecute(ar[i]);
                                }
                                catch (Exception ex)
                                {
                                    Trace.TraceError("There was an exception while trying to end the async Execution: " + Environment.NewLine + ex);
                                }
                                done.Add(i);
                            }
                        }
                    }
                }

                Trace.TraceInformation("Inserted... now we are checking the count");

                var ret = localSession.Execute(string.Format(@"SELECT * from {0} LIMIT {1};", tableName, RowsNo + 100), ConsistencyLevel.Quorum);
                Assert.AreEqual(RowsNo, ret.GetRows().ToList().Count);


                for (int idx = 0; idx < RowsNo; idx++)
                {
                    threads[idx].Join();
                }
            }
        }
Exemplo n.º 6
0
        public void KeyspacesMetadataAvailableAtStartup()
        {
            ITestCluster testCluster = TestClusterManager.GetNonShareableTestCluster(DefaultNodeCount);
            var          cluster     = testCluster.Cluster;

            // Basic status check
            Assert.Greater(cluster.Metadata.GetKeyspaces().Count, 0);
            Assert.NotNull(cluster.Metadata.GetKeyspace("system"));
            Assert.AreEqual("system", cluster.Metadata.GetKeyspace("system").Name);

            //Not existent tables return null
            Assert.Null(cluster.Metadata.GetKeyspace("nonExistentKeyspace_" + Randomm.RandomAlphaNum(12)));
            Assert.Null(cluster.Metadata.GetTable("nonExistentKeyspace_" + Randomm.RandomAlphaNum(12), "nonExistentTable_" + Randomm.RandomAlphaNum(12)));
            Assert.Null(cluster.Metadata.GetTable("system", "nonExistentTable_" + Randomm.RandomAlphaNum(12)));

            //Case sensitive
            Assert.Null(cluster.Metadata.GetKeyspace("SYSTEM"));
        }
Exemplo n.º 7
0
        public void WideTable()
        {
            string uniqueTableName = "wide_table" + Randomm.RandomAlphaNum(16);

            TestWideTable(_session, uniqueTableName);
        }
Exemplo n.º 8
0
        public void LargeText()
        {
            string uniqueTableName = "large_text_" + Randomm.RandomAlphaNum(16);

            TestLargeText(_session, uniqueTableName);
        }
Exemplo n.º 9
0
        public void WideByteRows()
        {
            string uniqueTableName = "wide_byte_rows" + Randomm.RandomAlphaNum(16);

            TestByteRows(_session, uniqueTableName);
        }
Exemplo n.º 10
0
        public void Parallel_Insert_And_Select_Sync()
        {
            var          originalTraceLevel = Diagnostics.CassandraTraceSwitch.Level;
            ITestCluster testCluster        = TestClusterManager.GetTestCluster(3);

            Diagnostics.CassandraTraceSwitch.Level = TraceLevel.Warning;
            testCluster.Builder = Cluster.Builder().WithRetryPolicy(DowngradingConsistencyRetryPolicy.Instance);
            testCluster.InitClient();

            ISession session      = testCluster.Session;
            string   uniqueKsName = "keyspace_" + Randomm.RandomAlphaNum(10);

            session.Execute(@"CREATE KEYSPACE " + uniqueKsName +
                            " WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};");
            TestUtils.WaitForSchemaAgreement(testCluster.Cluster);
            session.ChangeKeyspace(uniqueKsName);

            string tableName = "table_" + Guid.NewGuid().ToString("N").ToLower();

            session.Execute(String.Format(TestUtils.CREATE_TABLE_TIME_SERIES, tableName));
            TestUtils.WaitForSchemaAgreement(testCluster.Cluster);

            var insertQuery         = String.Format("INSERT INTO {0} (id, event_time, text_sample) VALUES (?, ?, ?)", tableName);
            var insertQueryPrepared = session.Prepare(insertQuery);
            var selectQuery         = String.Format("SELECT * FROM {0} LIMIT 10000", tableName);

            const int rowsPerId            = 1000;
            object    insertQueryStatement = new SimpleStatement(insertQuery);

            if (CassandraVersion.Major < 2)
            {
                //Use prepared statements all the way as it is not possible to bind on a simple statement with C* 1.2
                insertQueryStatement = session.Prepare(insertQuery);
            }
            var actionInsert         = GetInsertAction(session, insertQueryStatement, ConsistencyLevel.Quorum, rowsPerId);
            var actionInsertPrepared = GetInsertAction(session, insertQueryPrepared, ConsistencyLevel.Quorum, rowsPerId);
            var actionSelect         = GetSelectAction(session, selectQuery, ConsistencyLevel.Quorum, 10);

            //Execute insert sync to have some records
            actionInsert();
            //Execute select sync to assert that everything is going OK
            actionSelect();


            var actions = new List <Action>();

            for (var i = 0; i < 10; i++)
            {
                //Add 10 actions to execute
                actions.AddRange(new[] { actionInsert, actionSelect, actionInsertPrepared });
                actions.AddRange(new[] { actionSelect, actionInsert, actionInsertPrepared, actionInsert });
                actions.AddRange(new[] { actionInsertPrepared, actionInsertPrepared, actionSelect });
            }
            //Execute in parallel the 100 actions
            var parallelOptions = new ParallelOptions();

            parallelOptions.TaskScheduler          = new ThreadPerTaskScheduler();
            parallelOptions.MaxDegreeOfParallelism = 300;
            Parallel.Invoke(parallelOptions, actions.ToArray());
            Parallel.Invoke(actions.ToArray());
            Diagnostics.CassandraTraceSwitch.Level = originalTraceLevel;
        }