Пример #1
0
        public void MarkHostDown_PartialPoolConnection()
        {
            //start scassandra
            _scassandraManager = new SCassandraManager();
            _scassandraManager.Start();
            _scassandraManager.SetupInitialConf().Wait();
            const int connectionLength = 4;
            var       builder          = Cluster.Builder()
                                         .AddContactPoint("127.0.0.1")
                                         .WithPort(_scassandraManager.BinaryPort)
                                         .WithPoolingOptions(new PoolingOptions()
                                                             .SetCoreConnectionsPerHost(HostDistance.Local, connectionLength)
                                                             .SetMaxConnectionsPerHost(HostDistance.Local, connectionLength)
                                                             .SetHeartBeatInterval(2000))
                                         .WithReconnectionPolicy(new ConstantReconnectionPolicy(long.MaxValue));

            using (var cluster = builder.Build())
            {
                var session  = (Session)cluster.Connect();
                var allHosts = cluster.AllHosts();

                TestHelper.WaitUntil(() =>
                                     allHosts.Sum(h => session
                                                  .GetOrCreateConnectionPool(h, HostDistance.Local)
                                                  .OpenConnections
                                                  ) == allHosts.Count * connectionLength);
                var h1    = allHosts.FirstOrDefault();
                var pool  = session.GetOrCreateConnectionPool(h1, HostDistance.Local);
                var ports = _scassandraManager.GetListOfConnectedPorts().Result;
                // 4 pool connections + the control connection
                Assert.AreEqual(5, ports.Length);
                _scassandraManager.DisableConnectionListener().Wait();
                // Remove the first connections
                for (var i = 0; i < 3; i++)
                {
                    // Closure
                    var index = i;
                    var expectedOpenConnections = 5 - index;
                    WaitSimulatorConnections(_scassandraManager, expectedOpenConnections);
                    ports = _scassandraManager.GetListOfConnectedPorts().Result;
                    Assert.AreEqual(expectedOpenConnections, ports.Length, "Cassandra simulator contains unexpected number of connected clients");
                    _scassandraManager.DropConnection(ports.Last()).Wait();
                    // Host pool could have between pool.OpenConnections - i and pool.OpenConnections - i - 1
                    TestHelper.WaitUntil(() => pool.OpenConnections >= 4 - index - 1 && pool.OpenConnections <= 4 - index);
                    Assert.LessOrEqual(pool.OpenConnections, 4 - index);
                    Assert.GreaterOrEqual(pool.OpenConnections, 4 - index - 1);
                    Assert.IsTrue(h1.IsUp);
                }
                WaitSimulatorConnections(_scassandraManager, 2);
                ports = _scassandraManager.GetListOfConnectedPorts().Result;
                Assert.AreEqual(2, ports.Length);
                _scassandraManager.DropConnection(ports[1]).Wait();
                _scassandraManager.DropConnection(ports[0]).Wait();
                TestHelper.WaitUntil(() => pool.OpenConnections == 0 && !h1.IsUp);
                Assert.IsFalse(h1.IsUp);
            }
        }
Пример #2
0
 /// <summary>
 /// Waits for the simulator to have the expected number of connections
 /// </summary>
 private static void WaitSimulatorConnections(SCassandraManager scassandra, int expected)
 {
     TestHelper.WaitUntil(() => scassandra.GetListOfConnectedPorts().Result.Length == expected);
 }