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); }
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; }
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; }