Exemplo n.º 1
0
        public void Session_Execute_Throws_TimeoutException_When_QueryAbortTimeout_Elapsed()
        {
            var dummyCluster = Cluster.Builder().AddContactPoint("0.0.0.0").Build();

            Assert.AreNotEqual(dummyCluster.Configuration.ClientOptions.QueryAbortTimeout, Timeout.Infinite);
            try
            {
                using (var localCluster = Cluster.Builder()
                                          .AddContactPoint(TestCluster.InitialContactPoint)
                                          //Disable socket read timeout
                                          .WithSocketOptions(new SocketOptions().SetReadTimeoutMillis(0))
                                          //Set abort timeout at a low value
                                          .WithQueryTimeout(1500)
                                          .Build())
                {
                    var localSession = localCluster.Connect("system");
                    localSession.Execute("SELECT * FROM local");
                    TestCluster.PauseNode(1);
                    TestCluster.PauseNode(2);
                    Assert.Throws <TimeoutException>(() => localSession.Execute("SELECT * FROM local"));
                }
            }
            finally
            {
                TestCluster.ResumeNode(1);
                TestCluster.ResumeNode(2);
            }
        }
        public void SpeculativeExecution_Should_Execute_On_Next_Node()
        {
            var session = GetSession(new ConstantSpeculativeExecutionPolicy(50L, 1));

            TestCluster.PauseNode(2);
            Trace.TraceInformation("Node 2 paused");
            TestHelper.ParallelInvoke(() =>
            {
                var rs = session.Execute(new SimpleStatement(QueryLocal).SetIdempotence(true));
                Assert.AreNotEqual(_addressNode2, rs.Info.QueriedHost.Address);
            }, 10);
            TestCluster.ResumeNode(2);
        }
Exemplo n.º 3
0
        public void SpeculativeExecution_Should_Not_Execute_On_Next_Node_When_Not_Idempotent()
        {
            var lbp     = new OrderedLoadBalancingPolicy(2, 1, 3);
            var session = GetSession(new ConstantSpeculativeExecutionPolicy(50L, 1), true, lbp);

            TestCluster.PauseNode(2);
            var t = session.ExecuteAsync(new SimpleStatement(QueryLocal).SetIdempotence(false));

            Thread.Sleep(200);
            Assert.AreEqual(TaskStatus.WaitingForActivation, t.Status);
            TestCluster.ResumeNode(2);
            Thread.Sleep(200);
            Assert.AreEqual(TaskStatus.RanToCompletion, t.Status);
        }
        public async Task SpeculativeExecution_Should_Not_Execute_On_Next_Node_When_Not_Idempotent()
        {
            var lbp     = new OrderedLoadBalancingPolicy(2, 1);
            var session = GetSession(new ConstantSpeculativeExecutionPolicy(50L, 1), true, lbp);

            TestCluster.PauseNode(2);
            var t = session.ExecuteAsync(new SimpleStatement(QueryLocal).SetIdempotence(false));
            await Task.Delay(200).ConfigureAwait(false);

            Assert.AreEqual(TaskStatus.WaitingForActivation, t.Status);

            TestCluster.ResumeNode(2);
            var rs = await t.ConfigureAwait(false);

            // Used the first host in the query plan
            Assert.AreEqual(2, TestHelper.GetLastAddressByte(rs.Info.QueriedHost));
        }
Exemplo n.º 5
0
        public async Task Should_CheckSchemaAgreementReturnTrueAndSchemaInAgreementReturnTrue_When_AllNodesUp()
        {
            if (_paused)
            {
                TestCluster.ResumeNode(2);
            }

            //// this test can't be done with simulacron because there's no support for schema_changed responses
            var tableName = TestUtils.GetUniqueTableName().ToLower();

            var cql = new SimpleStatement(
                $"CREATE TABLE {tableName} (id int PRIMARY KEY, description text)");
            var rowSet = await _session.ExecuteAsync(cql).ConfigureAwait(false);

            Assert.IsTrue(rowSet.Info.IsSchemaInAgreement);
            Assert.IsTrue(await _cluster.Metadata.CheckSchemaAgreementAsync().ConfigureAwait(false));
        }
Exemplo n.º 6
0
        public async Task Should_CheckSchemaAgreementReturnTrueAndSchemaInAgreementReturnTrue_When_AllNodesUp()
        {
            var listener = new TestTraceListener();
            var level    = Diagnostics.CassandraTraceSwitch.Level;

            Diagnostics.CassandraTraceSwitch.Level = TraceLevel.Verbose;
            Trace.Listeners.Add(listener);
            try
            {
                if (_paused)
                {
                    TestCluster.ResumeNode(2);
                }

                //// this test can't be done with simulacron because there's no support for schema_changed responses
                var tableName = TestUtils.GetUniqueTableName().ToLower();

                var cql = new SimpleStatement(
                    $"CREATE TABLE {tableName} (id int PRIMARY KEY, description text)");
                var rowSet = await _session.ExecuteAsync(cql).ConfigureAwait(false);

                Assert.IsTrue(rowSet.Info.IsSchemaInAgreement, "is in agreement");
                await TestHelper.RetryAssertAsync(
                    async() =>
                {
                    Assert.IsTrue(await _cluster.Metadata.CheckSchemaAgreementAsync().ConfigureAwait(false), "check");
                },
                    100,
                    50).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Trace.Flush();
                Assert.Fail("Exception: " + ex.ToString() + Environment.NewLine + string.Join(Environment.NewLine, listener.Queue.ToArray()));
            }
            finally
            {
                Trace.Listeners.Remove(listener);
                Diagnostics.CassandraTraceSwitch.Level = level;
            }
        }
 public void TearDown()
 {
     TestCluster.ResumeNode(2);
     TestUtils.WaitForSchemaAgreement(_cluster, false, true, MaxTestSchemaAgreementRetries);
 }
 public void TestTearDown()
 {
     //Resume both nodes before each test
     TestCluster.ResumeNode(1);
     TestCluster.ResumeNode(2);
 }