예제 #1
0
        private ICluster CreateClusterAndWaitUntilConnectException(Action <Builder> b, out Exception ex)
        {
            Exception tempEx  = null;
            ICluster  cluster = null;

            TestHelper.RetryAssert(
                () =>
            {
                var builder = Cluster.Builder().AddContactPoints(TestCluster.ContactPoints);
                b(builder);
                cluster = builder.Build();
                try
                {
                    tempEx = Assert.Catch <Exception>(() => cluster.Connect());
                }
                catch (Exception)
                {
                    cluster.Dispose();
                    SetupNewTestCluster();
                    Interlocked.MemoryBarrier();
                    TestCluster.DisableConnectionListener(type: "reject_startup");
                    throw;
                }
            }, 500, 20);

            Interlocked.MemoryBarrier();
            ex = tempEx;
            return(cluster);
        }
예제 #2
0
        public void RepeatedClusterConnectCallsAfterTimeoutErrorThrowCachedInitErrorException()
        {
            TestCluster.DisableConnectionListener(type: "reject_startup");
            var timeoutMessage = "Cluster initialization was aborted after timing out. This mechanism is put in place to" +
                                 " avoid blocking the calling thread forever. This usually caused by a networking issue" +
                                 " between the client driver instance and the cluster. You can increase this timeout via " +
                                 "the SocketOptions.ConnectTimeoutMillis config setting. This can also be related to deadlocks " +
                                 "caused by mixing synchronous and asynchronous code.";
            var cachedError = "An error occured during the initialization of the cluster instance. Further initialization attempts " +
                              "for this cluster instance will never succeed and will return this exception instead. The InnerException property holds " +
                              "a reference to the exception that originally caused the initialization error.";

            using (var cluster = CreateClusterAndWaitUntilConnectException(
                       b => b
                       .WithSocketOptions(
                           new SocketOptions()
                           .SetConnectTimeoutMillis(500)
                           .SetMetadataAbortTimeout(500)),
                       out var ex))
            {
                Assert.AreEqual(typeof(TimeoutException), ex.GetType());
                Assert.AreEqual(timeoutMessage, ex.Message);
                var ex2 = Assert.Throws <InitFatalErrorException>(() => cluster.Connect("sample_ks"));
                Assert.AreEqual(cachedError, ex2.Message);
                Assert.AreEqual(typeof(TimeoutException), ex2.InnerException.GetType());
                Assert.AreEqual(timeoutMessage, ex2.InnerException.Message);
            }
        }
예제 #3
0
 public void RepeatedClusterConnectCallsAfterNoHostErrorDontThrowCachedInitErrorException()
 {
     TestCluster.DisableConnectionListener(type: "reject_startup");
     using (var cluster = CreateClusterAndWaitUntilConnectException(
                b => b.WithSocketOptions(new SocketOptions().SetConnectTimeoutMillis(1).SetReadTimeoutMillis(1)),
                out _))
     {
         var ex  = Assert.Throws <NoHostAvailableException>(() => cluster.Connect());
         var ex2 = Assert.Throws <NoHostAvailableException>(() => cluster.Connect("sample_ks"));
         Assert.AreNotSame(ex, ex2);
     }
 }
예제 #4
0
 public void RepeatedClusterConnectCallsAfterTimeoutErrorEventuallyThrowNoHostException()
 {
     TestCluster.DisableConnectionListener(type: "reject_startup");
     using (var cluster = CreateClusterAndWaitUntilConnectException(
                b => b
                .WithSocketOptions(
                    new SocketOptions()
                    .SetConnectTimeoutMillis(500)
                    .SetMetadataAbortTimeout(500)),
                out var ex))
     {
         Assert.AreEqual(typeof(TimeoutException), ex.GetType());
         TestHelper.RetryAssert(
             () =>
         {
             var ex2 = Assert.Throws <InitFatalErrorException>(() => cluster.Connect("sample_ks"));
             Assert.AreEqual(typeof(NoHostAvailableException), ex2.InnerException.GetType());
         },
             1000,
             30);
     }
 }