示例#1
0
        public void Should_publish_request_with_address()
        {
            // Arrange
            var routeFinder = Substitute.For<IRpcRouteFinder>();
            routeFinder.RequestQueue.Returns("RequestQueue");
            InternalDependencies.RpcQueueHelper = Substitute.For<IRpcQueueHelper>();
            var client = new BurrowRpcClientCoordinator<ISomeService>(null, routeFinder);

            var res = new RpcRequest
            {
                MethodName = "TryParse",
                Id = Guid.NewGuid(),
                UtcExpiryTime = DateTime.UtcNow.AddSeconds(20),
            };

            tunnel.When(x => x.Publish(Arg.Any<RpcRequest>(), Arg.Any<string>()))
                  .Do(callInfo =>
                    {
                        var waithHandler = client.GetCachedWaitHandlers()[res.Id];
                        waithHandler.WaitHandle.Set();
                        waithHandler.Response = new RpcResponse { ChangedParams = new Dictionary<string, object> { { "result", "1000" } } };
                    });
            // Action
            client.Send(res);

            // Assert
            tunnel.Received(1).Publish(Arg.Any<RpcRequest>(), "RequestQueue");
        }
示例#2
0
        public void Should_publish_request_with_address()
        {
            // Arrange
            var routeFinder = Substitute.For <IRpcRouteFinder>();

            routeFinder.RequestQueue.Returns("RequestQueue");
            InternalDependencies.RpcQueueHelper = Substitute.For <IRpcQueueHelper>();
            var client = new BurrowRpcClientCoordinator <ISomeService>(null, routeFinder);

            var res = new RpcRequest
            {
                MethodName    = "TryParse",
                Id            = Guid.NewGuid(),
                UtcExpiryTime = DateTime.UtcNow.AddSeconds(20),
            };

            tunnel.When(x => x.Publish(Arg.Any <RpcRequest>(), Arg.Any <string>()))
            .Do(callInfo =>
            {
                var waithHandler = client.GetCachedWaitHandlers()[res.Id];
                waithHandler.WaitHandle.Set();
                waithHandler.Response = new RpcResponse {
                    ChangedParams = new Dictionary <string, object> {
                        { "result", "1000" }
                    }
                };
            });
            // Action
            client.Send(res);

            // Assert
            tunnel.Received(1).Publish(Arg.Any <RpcRequest>(), "RequestQueue");
        }
示例#3
0
        public void Should_throw_exeception_if_timeout()
        {
            // Arrange
            var routeFinder = Substitute.For<IRpcRouteFinder>();
            routeFinder.UniqueResponseQueue.Returns("ISomeService.ResponseQueue");
            InternalDependencies.RpcQueueHelper = Substitute.For<IRpcQueueHelper>();
            var client = new BurrowRpcClientCoordinator<ISomeService>(null, routeFinder);

            var res = new RpcRequest
            {
                UtcExpiryTime = DateTime.UtcNow.AddSeconds(1)
            };

            // Action
            client.Send(res);
        }
示例#4
0
        public void Should_throw_exeception_if_timeout()
        {
            // Arrange
            var routeFinder = Substitute.For <IRpcRouteFinder>();

            routeFinder.UniqueResponseQueue.Returns("ISomeService.ResponseQueue");
            InternalDependencies.RpcQueueHelper = Substitute.For <IRpcQueueHelper>();
            var client = new BurrowRpcClientCoordinator <ISomeService>(null, routeFinder);

            var res = new RpcRequest
            {
                UtcExpiryTime = DateTime.UtcNow.AddSeconds(1)
            };

            // Action
            client.Send(res);
        }
示例#5
0
        public void Should_return_and_log_warn_msg_if_the_waitHandlers_does_not_contain_requestId()
        {
            // Arrange
            InternalDependencies.RpcQueueHelper = Substitute.For <IRpcQueueHelper>();
            var client = new BurrowRpcClientCoordinator <ISomeService>(null, Substitute.For <IRpcRouteFinder>());

            var res = new RpcResponse
            {
                RequestId = Guid.NewGuid()
            };

            // Action
            client.ReceiveResponse(res);

            // Assert
            Global.DefaultWatcher.Received(1).WarnFormat(Arg.Any <string>(), Arg.Any <object[]>());
        }
        public void Should_return_and_log_warn_msg_if_the_waitHandlers_does_not_contain_requestId()
        {
            // Arrange
            InternalDependencies.RpcQueueHelper = Substitute.For<IRpcQueueHelper>();
            var client = new BurrowRpcClientCoordinator<ISomeService>(null, Substitute.For<IRpcRouteFinder>());

            var res = new RpcResponse
            {
                RequestId = Guid.NewGuid()
            };

            // Action
            client.ReceiveResponse(res);

            // Assert
            Global.DefaultWatcher.Received(1).WarnFormat(Arg.Any<string>(), Arg.Any<object[]>());
        }
示例#7
0
        public void Should_publish_request_without_address()
        {
            // Arrange
            InternalDependencies.RpcQueueHelper = Substitute.For <IRpcQueueHelper>();
            var client = new BurrowRpcClientCoordinator <ISomeService>(null, Substitute.For <IRpcRouteFinder>());

            var res = new RpcRequest
            {
                ResponseAddress = "abc"
            };

            // Action
            client.SendAsync(res);

            // Assert
            tunnel.Received(1).Publish(Arg.Any <RpcRequest>(), Arg.Any <string>());
            Assert.IsNull(res.ResponseAddress);
        }
示例#8
0
        public void Should_publish_request_without_address()
        {
            // Arrange
            InternalDependencies.RpcQueueHelper = Substitute.For<IRpcQueueHelper>();
            var client = new BurrowRpcClientCoordinator<ISomeService>(null, Substitute.For<IRpcRouteFinder>());

            var res = new RpcRequest
            {
                ResponseAddress = "abc"
                
            };

            // Action
            client.SendAsync(res);

            // Assert
            tunnel.Received(1).Publish(Arg.Any<RpcRequest>(), Arg.Any<string>());
            Assert.IsNull(res.ResponseAddress);
            

        }
        public void Should_set_respones_value_to_wait_handler_and_set_the_wait_handler()
        {
            // Arrange
            InternalDependencies.RpcQueueHelper = Substitute.For<IRpcQueueHelper>();
            var client = new BurrowRpcClientCoordinator<ISomeService>(null, Substitute.For<IRpcRouteFinder>());

            var res = new RpcResponse
            {
                RequestId = Guid.NewGuid()
            };
            var handlers = client.GetCachedWaitHandlers();
            var wait = new RpcWaitHandler();
            handlers.TryAdd(res.RequestId, wait);

            // Action
            Task.Factory.StartNew(() => client.ReceiveResponse(res));

            // Assert
            wait.WaitHandle.WaitOne();
            Assert.AreEqual(res, wait.Response);
        }
示例#10
0
        public void Should_set_respones_value_to_wait_handler_and_set_the_wait_handler()
        {
            // Arrange
            InternalDependencies.RpcQueueHelper = Substitute.For <IRpcQueueHelper>();
            var client = new BurrowRpcClientCoordinator <ISomeService>(null, Substitute.For <IRpcRouteFinder>());

            var res = new RpcResponse
            {
                RequestId = Guid.NewGuid()
            };
            var handlers = client.GetCachedWaitHandlers();
            var wait     = new RpcWaitHandler();

            handlers.TryAdd(res.RequestId, wait);

            // Action
            Task.Factory.StartNew(() => client.ReceiveResponse(res));

            // Assert
            wait.WaitHandle.WaitOne();
            Assert.AreEqual(res, wait.Response);
        }