Ejemplo n.º 1
0
        public void SecureClientClearsPoolWhenAllConnectionsCorrupt()
        {
            var pool = new ConnectionPool<ServiceEndPoint, IConnection>();
            var stream = Substitute.For<IMessageExchangeStream>();
            stream.When(x => x.IdentifyAsClient()).Do(x => { throw new ConnectionInitializationFailedException(""); });
            for (int i = 0; i < SecureClient.RetryCountLimit; i++)
            {
                var connection = Substitute.For<IConnection>();
                connection.Protocol.Returns(new MessageExchangeProtocol(stream));
                pool.Return(endpoint, connection);
            }

            var request = new RequestMessage
            {
                Destination = endpoint,
                ServiceName = "IEchoService",
                MethodName = "SayHello",
                Params = new object[] { "Fred" }
            };

            var secureClient = new SecureClient(endpoint, Certificates.Octopus, log, pool);
            ResponseMessage response = null;
            secureClient.ExecuteTransaction((mep) => response = mep.ExchangeAsClient(request));

            // The pool should be cleared after the second failure
            stream.Received(2).IdentifyAsClient();
            // And a new valid connection should then be made
            Assert.AreEqual("Fred...", response.Result);
        }
Ejemplo n.º 2
0
 public PollingClient(Uri subscription, SecureClient secureClient, Func <RequestMessage, ResponseMessage> handleIncomingRequest)
 {
     this.subscription          = subscription;
     this.secureClient          = secureClient;
     this.handleIncomingRequest = handleIncomingRequest;
     thread              = new Thread(ExecutePollingLoop);
     thread.Name         = "Polling client for " + secureClient.ServiceEndpoint + " for subscription " + subscription;
     thread.IsBackground = true;
 }
Ejemplo n.º 3
0
 public PollingClient(Uri subscription, SecureClient secureClient, Func<RequestMessage, ResponseMessage> handleIncomingRequest)
 {
     this.subscription = subscription;
     this.secureClient = secureClient;
     this.handleIncomingRequest = handleIncomingRequest;
     thread = new Thread(ExecutePollingLoop);
     thread.Name = "Polling client for " + secureClient.ServiceEndpoint + " for subscription " + subscription;
     thread.IsBackground = true;
 }