Exemple #1
0
        public async Task Cluster_Should_StopSendingPeersV2Requests_When_InvalidQueryIsThrown()
        {
            var oldLevel = Diagnostics.CassandraTraceSwitch.Level;
            var listener = new TestTraceListener();

            Trace.Listeners.Add(listener);
            Diagnostics.CassandraTraceSwitch.Level = TraceLevel.Verbose;

            try
            {
                TestCluster.PrimeFluent(
                    p => p.WhenQuery("SELECT * FROM system.peers_v2")
                    .ThenServerError(ServerError.Invalid, "error"));

                SetupNewSession(b => b.WithPoolingOptions(new PoolingOptions().SetHeartBeatInterval(3000)));

                var peersV2Queries = TestCluster.GetQueries("SELECT * FROM system.peers_v2");
                var peersQueries   = TestCluster.GetQueries("SELECT * FROM system.peers");

                await TestCluster.GetNode(Session.Cluster.Metadata.ControlConnection.Host.Address).Stop().ConfigureAwait(false);

                // wait until control connection reconnection is done
                TestHelper.RetryAssert(
                    () =>
                {
                    Assert.AreEqual(1, Session.Cluster.AllHosts().Count(h => !h.IsUp));
                    Assert.IsTrue(Session.Cluster.Metadata.ControlConnection.Host.IsUp);
                },
                    200,
                    100);

                await TestCluster.GetNode(Session.Cluster.Metadata.ControlConnection.Host.Address).Stop().ConfigureAwait(false);

                // wait until control connection reconnection is done
                TestHelper.RetryAssert(
                    () =>
                {
                    Assert.AreEqual(2, Session.Cluster.AllHosts().Count(h => !h.IsUp));
                    Assert.IsTrue(Session.Cluster.Metadata.ControlConnection.Host.IsUp);
                },
                    200,
                    100);

                var afterPeersV2Queries = TestCluster.GetQueries("SELECT * FROM system.peers_v2");
                var afterPeersQueries   = TestCluster.GetQueries("SELECT * FROM system.peers");

                Assert.AreEqual(peersV2Queries.Count, afterPeersV2Queries.Count);
                Assert.AreEqual(peersQueries.Count + 2, afterPeersQueries.Count);
            }
            catch (Exception ex)
            {
                Trace.Flush();
                Assert.Fail(ex.ToString() + Environment.NewLine + string.Join(Environment.NewLine, listener.Queue.ToList()));
            }
            finally
            {
                Trace.Listeners.Remove(listener);
                Diagnostics.CassandraTraceSwitch.Level = oldLevel;
            }
        }
        public async Task Cluster_Should_StopSendingPeersV2Requests_When_InvalidQueryIsThrown()
        {
            TestCluster.PrimeFluent(
                p => p.WhenQuery("SELECT * FROM system.peers_v2")
                .ThenServerError(ServerError.Invalid, "error"));

            SetupNewSession();

            var peersV2Queries = TestCluster.GetQueries("SELECT * FROM system.peers_v2");
            var peersQueries   = TestCluster.GetQueries("SELECT * FROM system.peers");

            await TestCluster.GetNode(Session.Cluster.Metadata.ControlConnection.Host.Address).Stop().ConfigureAwait(false);

            // wait until control connection reconnection is done
            TestHelper.RetryAssert(
                () =>
            {
                Assert.AreEqual(1, Session.Cluster.AllHosts().Count(h => !h.IsUp));
                Assert.IsTrue(Session.Cluster.Metadata.ControlConnection.Host.IsUp);
            },
                100,
                50);

            await TestCluster.GetNode(Session.Cluster.Metadata.ControlConnection.Host.Address).Stop().ConfigureAwait(false);

            // wait until control connection reconnection is done
            TestHelper.RetryAssert(
                () =>
            {
                Assert.AreEqual(2, Session.Cluster.AllHosts().Count(h => !h.IsUp));
                Assert.IsTrue(Session.Cluster.Metadata.ControlConnection.Host.IsUp);
            },
                100,
                50);

            var afterPeersV2Queries = TestCluster.GetQueries("SELECT * FROM system.peers_v2");
            var afterPeersQueries   = TestCluster.GetQueries("SELECT * FROM system.peers");

            Assert.AreEqual(peersV2Queries.Count, afterPeersV2Queries.Count);
            Assert.AreEqual(peersQueries.Count + 2, afterPeersQueries.Count);
        }
Exemple #3
0
        public void TestCounters()
        {
            var tableName = TestUtils.GetUniqueTableName();

            var tweet_id = Guid.NewGuid();

            var tasks = Enumerable.Range(0, 100).Select(i => Task.Factory.StartNew(
                                                            () =>
            {
                QueryTools.ExecuteSyncNonQuery(Session,
                                               string.Format(@"UPDATE {0} SET incdec = incdec {2}  WHERE tweet_id = {1};", tableName,
                                                             tweet_id, (i % 2 == 0 ? "-" : "+") + i));
            },
                                                            TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler));

            Task.WaitAll(tasks.ToArray());

            var logs = TestCluster.GetQueries(null, QueryType.Query).Where(l => l.Query.StartsWith("UPDATE")).ToList();

            Assert.AreEqual(100, logs.Count);
            foreach (var i in Enumerable.Range(0, 100))
            {
                var query = string.Format(@"UPDATE {0} SET incdec = incdec {2}  WHERE tweet_id = {1};", tableName,
                                          tweet_id, (i % 2 == 0 ? "-" : "+") + i);
                VerifyStatement(logs, query, 1);
            }

            TestCluster.PrimeFluent(
                b => b.WhenQuery($"SELECT * FROM {tableName};", when => when.WithConsistency(ConsistencyLevel.LocalOne))
                .ThenRowsSuccess(new[] { "tweet_id", "incdec" }, r => r.WithRow(tweet_id, (Int64)50)));

            QueryTools.ExecuteSyncQuery(Session, $"SELECT * FROM {tableName};",
                                        Session.Cluster.Configuration.QueryOptions.GetConsistencyLevel(),
                                        new List <object[]> {
                new object[2] {
                    tweet_id, (Int64)50
                }
            });
        }