Esempio n. 1
0
        public void SpeculativeExecution_With_Multiple_Nodes_Pausing()
        {
            _testCluster = TestClusterManager.GetNonShareableTestCluster(3, 1, true, false);
            var session = GetSession(new ConstantSpeculativeExecutionPolicy(50L, 1));
            var timer   = new HashedWheelTimer(1000, 64);

            timer.NewTimeout(_ => Task.Factory.StartNew(() => _testCluster.PauseNode(2)), null, 2000);
            //2 secs after resume node2
            timer.NewTimeout(_ => Task.Factory.StartNew(() => _testCluster.ResumeNode(2)), null, 4000);
            timer.NewTimeout(_ => Task.Factory.StartNew(() => _testCluster.PauseNode(1)), null, 6000);
            //4 secs after resume node1
            timer.NewTimeout(_ => Task.Factory.StartNew(() => _testCluster.ResumeNode(1)), null, 10000);
            var finished = false;

            timer.NewTimeout(_ => Task.Factory.StartNew(() => finished = true), null, 12000);
            //64 constant concurrent requests
            var semaphore = new SemaphoreSlim(64);

            while (!finished)
            {
                TestHelper.ParallelInvoke(() =>
                {
                    semaphore.Wait();
                    session.Execute(new SimpleStatement(QueryLocal).SetIdempotence(true));
                    semaphore.Release();
                }, 512);
            }
            Thread.Sleep(1000);
            timer.Dispose();
        }
Esempio n. 2
0
        public void TryNextHostRetryPolicyTest()
        {
            ITestCluster testCluster   = TestClusterManager.GetNonShareableTestCluster(2);
            var          socketOptions = new SocketOptions().SetReadTimeoutMillis(2000);

            testCluster.Builder = Cluster.Builder()
                                  .WithRetryPolicy(new LoggingRetryPolicy(TryNextHostRetryPolicy.Instance))
                                  .AddContactPoint(testCluster.ClusterIpPrefix + "1")
                                  .AddContactPoint(testCluster.ClusterIpPrefix + "2")
                                  .WithSocketOptions(socketOptions);
            testCluster.InitClient();

            // Setup cluster
            PolicyTestTools policyTestTools = new PolicyTestTools();

            policyTestTools.CreateSchema(testCluster.Session, 2);
            policyTestTools.InitPreparedStatement(testCluster, 12);

            // Try with both hosts
            policyTestTools.Query(testCluster, 10);
            policyTestTools.AssertQueriedAtLeast(testCluster.ClusterIpPrefix + 1 + ":" + DefaultCassandraPort, 5);
            policyTestTools.AssertQueriedAtLeast(testCluster.ClusterIpPrefix + 2 + ":" + DefaultCassandraPort, 5);

            // Try with host 1
            policyTestTools.ResetCoordinators();
            testCluster.PauseNode(2);
            policyTestTools.Query(testCluster, 10);
            policyTestTools.AssertQueried(testCluster.ClusterIpPrefix + 1 + ":" + DefaultCassandraPort, 10);
            policyTestTools.AssertQueried(testCluster.ClusterIpPrefix + 2 + ":" + DefaultCassandraPort, 0);
            testCluster.ResumeNode(2);

            // Try with host 2
            policyTestTools.ResetCoordinators();
            testCluster.PauseNode(1);
            policyTestTools.Query(testCluster, 10);
            policyTestTools.AssertQueried(testCluster.ClusterIpPrefix + 1 + ":" + DefaultCassandraPort, 0);
            policyTestTools.AssertQueried(testCluster.ClusterIpPrefix + 2 + ":" + DefaultCassandraPort, 10);

            // Try with 0 hosts
            policyTestTools.ResetCoordinators();
            testCluster.PauseNode(2);
            Assert.Throws <NoHostAvailableException>(() => policyTestTools.Query(testCluster, 10));
            policyTestTools.AssertQueried(testCluster.ClusterIpPrefix + 1 + ":" + DefaultCassandraPort, 0);
            policyTestTools.AssertQueried(testCluster.ClusterIpPrefix + 2 + ":" + DefaultCassandraPort, 0);

            testCluster.ResumeNode(1);
            testCluster.ResumeNode(2);
        }
Esempio n. 3
0
        public void SpeculativeExecution_Pause_Using_All_Stream_Ids()
        {
            var maxProtocolVersion = Cluster.MaxProtocolVersion;

            _testCluster = TestClusterManager.GetNonShareableTestCluster(2, 1, true, false);
            Cluster.MaxProtocolVersion = 2;
            try
            {
                var       pooling        = PoolingOptions.Create();
                var       session        = GetSession(new ConstantSpeculativeExecutionPolicy(50L, 1), true, null, pooling);
                const int pauseThreshold = 140 * 2;
                var       tasks          = new List <Task <IPAddress> >();
                var       semaphore      = new SemaphoreSlim(150 * 2);
                for (var i = 0; i < 512; i++)
                {
                    //Pause after the stream ids are in use for the connections
                    if (i == pauseThreshold)
                    {
                        _testCluster.PauseNode(1);
                    }
                    semaphore.Wait();
                    tasks.Add(session
                              .ExecuteAsync(new SimpleStatement(QueryLocal).SetIdempotence(true))
                              .ContinueSync(rs =>
                    {
                        semaphore.Release();
                        return(rs.Info.QueriedHost.Address);
                    }));
                }
                Task.WaitAll(tasks.Select(t => (Task)t).ToArray());
                _testCluster.ResumeNode(1);
                //There shouldn't be any query using node1 as coordinator passed the threshold.
                Assert.AreEqual(0, tasks.Skip(pauseThreshold).Count(t => t.Result.Equals(_addressNode1)));
                Thread.Sleep(1000);
            }
            finally
            {
                Cluster.MaxProtocolVersion = maxProtocolVersion;
            }
        }
 public void SpeculativeExecution_Pause_Using_All_Stream_Ids()
 {
     var maxProtocolVersion = Cluster.MaxProtocolVersion;
     _testCluster = TestClusterManager.GetNonShareableTestCluster(2, 1, true, false);
     Cluster.MaxProtocolVersion = 2;
     try
     {
         var pooling = PoolingOptions.DefaultOptions(Version.Parse("2.0")).SetCoreConnectionsPerHost(HostDistance.Local, 1);
         var session = GetSession(new ConstantSpeculativeExecutionPolicy(50L, 1), true, null, pooling);
         const int pauseThreshold = 140 * 2;
         var tasks = new List<Task<IPAddress>>();
         var semaphore = new SemaphoreSlim(150 * 2);
         for (var i = 0; i < 512; i++)
         {
             //Pause after the stream ids are in use for the connections
             if (i == pauseThreshold)
             {
                 _testCluster.PauseNode(1);
             }
             semaphore.Wait();
             tasks.Add(session
                 .ExecuteAsync(new SimpleStatement(QueryLocal).SetIdempotence(true))
                 .Continue(t =>
                 {
                     semaphore.Release();
                     return t.Result.Info.QueriedHost.Address;
                 }));
         }
         Task.WaitAll(tasks.Select(t => (Task)t).ToArray());
         _testCluster.ResumeNode(1);
         //There shouldn't be any query using node1 as coordinator passed the threshold.
         Assert.AreEqual(0, tasks.Skip(pauseThreshold).Count(t => t.Result.Equals(_addressNode1)));
         Thread.Sleep(1000);
     }
     finally
     {
         Cluster.MaxProtocolVersion = maxProtocolVersion;
     }
 }
 public void SpeculativeExecution_With_Multiple_Nodes_Pausing()
 {
     _testCluster = TestClusterManager.GetNonShareableTestCluster(3, 1, true, false);
     var session = GetSession(new ConstantSpeculativeExecutionPolicy(50L, 1));
     var timer = new HashedWheelTimer(1000, 64);
     timer.NewTimeout(_ => Task.Factory.StartNew(() => _testCluster.PauseNode(2)), null, 2000);
     //2 secs after resume node2
     timer.NewTimeout(_ => Task.Factory.StartNew(() => _testCluster.ResumeNode(2)), null, 4000);
     timer.NewTimeout(_ => Task.Factory.StartNew(() => _testCluster.PauseNode(1)), null, 6000);
     //4 secs after resume node1
     timer.NewTimeout(_ => Task.Factory.StartNew(() => _testCluster.ResumeNode(1)), null, 10000);
     var finished = false;
     timer.NewTimeout(_ => Task.Factory.StartNew(() => finished = true), null, 12000);
     //64 constant concurrent requests
     var semaphore = new SemaphoreSlim(64);
     while (!finished)
     {
         TestHelper.ParallelInvoke(() =>
         {
             semaphore.Wait();
             session.Execute(new SimpleStatement(QueryLocal).SetIdempotence(true));
             semaphore.Release();
         }, 512);
     }
     Thread.Sleep(1000);
     timer.Dispose();
 }