Ejemplo n.º 1
0
        virtual public void Connect(Session owner, bool moveNext, out int streamId)
        {
            if (_hostsIter == null)
            {
                _hostsIter = owner.Policies.LoadBalancingPolicy.NewQueryPlan(Statement).GetEnumerator();
                if (!_hostsIter.MoveNext())
                {
                    var ex = new NoHostAvailableException(new Dictionary <IPAddress, List <Exception> >());
                    _logger.Error(ex);
                    throw ex;
                }
            }
            else
            {
                if (moveNext)
                {
                    if (!_hostsIter.MoveNext())
                    {
                        var ex = new NoHostAvailableException(InnerExceptions);
                        _logger.Error(ex);
                        throw ex;
                    }
                }
            }

            Connection = owner.Connect(_hostsIter, TriedHosts, InnerExceptions, out streamId);
        }
Ejemplo n.º 2
0
        public void NoHostAvailableException_Message_Includes_First_Host()
        {
            var ex = new NoHostAvailableException(new Dictionary <IPEndPoint, Exception>
            {
                { new IPEndPoint(IPAddress.Parse("10.10.0.1"), 9042), new AuthenticationException("Bad credentials") }
            });

            Assert.AreEqual(
                "All hosts tried for query failed (tried 10.10.0.1:9042: AuthenticationException 'Bad credentials')",
                ex.Message);
        }
Ejemplo n.º 3
0
 public void SetNoMoreHosts(NoHostAvailableException ex, IRequestExecution execution)
 {
     //An execution ended with a NoHostAvailableException (retrying or starting).
     //If there is a running execution, do not yield it to the user
     _running.Remove(execution);
     if (_running.Count > 0)
     {
         RequestHandler.Logger.Info("Could not obtain an available host for speculative execution");
         return;
     }
     SetCompleted(ex);
 }
Ejemplo n.º 4
0
        public void NoHostAvailableException_Message_Can_Contain_Host_Without_Info()
        {
            var ex = new NoHostAvailableException(new Dictionary <IPEndPoint, Exception>
            {
                { new IPEndPoint(IPAddress.Parse("10.10.0.1"), 9042), null },
                { new IPEndPoint(IPAddress.Parse("10.10.0.2"), 9042), new AuthenticationException("No credentials") }
            });

            Assert.AreEqual(
                "All hosts tried for query failed (tried 10.10.0.1:9042; 10.10.0.2:9042: AuthenticationException " +
                "'No credentials')",
                ex.Message);
        }
Ejemplo n.º 5
0
        public void NoHostAvailableException_Message_Includes_Message_To_See_Errors_Property()
        {
            var ex = new NoHostAvailableException(new Dictionary <IPEndPoint, Exception>
            {
                { new IPEndPoint(IPAddress.Parse("10.10.0.1"), 9042), new AuthenticationException("Bad credentials") },
                { new IPEndPoint(IPAddress.Parse("10.10.0.2"), 9042), new AuthenticationException("No credentials") },
                { new IPEndPoint(IPAddress.Parse("10.10.0.3"), 9042), new AuthenticationException("No credentials") }
            });

            Assert.AreEqual(
                "All hosts tried for query failed (tried 10.10.0.1:9042: AuthenticationException 'Bad credentials';" +
                " 10.10.0.2:9042: AuthenticationException 'No credentials'; ...), see Errors property for more info",
                ex.Message);
        }
Ejemplo n.º 6
0
        private void AssertIsSslError(NoHostAvailableException ex)
        {
#if NET452
            if (TestHelper.IsMono)
            {
                var ex2 = ex.InnerException;
                Assert.IsTrue(ex2 is WebException, ex2.ToString());
                Assert.IsTrue(ex2.Message.Contains("Authentication failed"), ex2.Message);
                Assert.IsTrue(ex2.Message.Contains("SecureChannelFailure"), ex2.Message);
            }
            else
            {
                var ex2 = ex.InnerException;
                Assert.IsTrue(ex2 is WebException, ex2.ToString());
                Assert.IsTrue(ex2.Message.Contains("Could not create SSL/TLS secure channel."), ex2.Message);
            }
#else
            var ex2 = ex.InnerException;
            Assert.IsTrue(ex2 is HttpRequestException, ex2.ToString());

            // SocketsHttpHandler
            Assert.IsTrue(ex2.Message.Contains("The SSL connection could not be established"), ex2.Message);
#endif
        }
Ejemplo n.º 7
0
        private void AssertCaMismatchSslError(NoHostAvailableException ex)
        {
#if NETCOREAPP2_1
            var ex2 = ex.InnerException;
            Assert.IsTrue(ex2 is HttpRequestException, ex2.ToString());
            var ex3 = ex2.InnerException;
            Assert.IsTrue(ex2 is HttpRequestException, ex2.ToString());
            Assert.IsTrue(ex2.Message.Contains("The SSL connection could not be established"), ex2.Message);
#elif NET452
            if (TestHelper.IsMono)
            {
                var ex2 = ex.InnerException;
                Assert.IsTrue(ex2 is WebException, ex2.ToString());
                Assert.IsTrue(ex2.Message.Contains("Authentication failed"), ex2.Message);
                Assert.IsTrue(ex2.Message.Contains("TrustFailure"), ex2.Message);
            }
            else
            {
                var ex2 = ex.InnerException;
                Assert.IsTrue(ex2 is WebException, ex2.ToString());
                Assert.IsTrue(ex2.Message.Contains("Could not establish trust relationship for the SSL/TLS secure channel"), ex2.Message);
            }
#endif
        }
Ejemplo n.º 8
0
        public void NoHostAvailableException_Message_Includes_No_Host_Tried()
        {
            var ex = new NoHostAvailableException(new Dictionary <IPEndPoint, Exception>());

            Assert.AreEqual("No host is available to be queried (no host tried)", ex.Message);
        }