示例#1
0
        when_send_queue_size_is_larger_than_threshold_should_close_connection()
        {
            var mre = new ManualResetEventSlim();

            var messageSize = _connectionPendingSendBytesThreshold;
            var evnt        = new EventRecord(0, 0, Guid.NewGuid(), Guid.NewGuid(), 0, 0, "testStream", 0, DateTime.Now,
                                              PrepareFlags.None, "eventType", new byte[messageSize], new byte[0]);
            var record  = ResolvedEvent.ForUnresolvedEvent(evnt, null);
            var message = new ClientMessage.ReadEventCompleted(Guid.NewGuid(), "testStream", ReadEventResult.Success,
                                                               record, StreamMetadata.Empty, false, "");

            var dummyConnection = new DummyTcpConnection();

            dummyConnection.SendQueueSize = ESConsts.MaxConnectionQueueSize + 1;

            var tcpConnectionManager = new TcpConnectionManager(
                Guid.NewGuid().ToString(), TcpServiceType.External, new ClientTcpDispatcher(2000),
                InMemoryBus.CreateTest(), dummyConnection, InMemoryBus.CreateTest(),
                new InternalAuthenticationProvider(InMemoryBus.CreateTest(),
                                                   new Core.Helpers.IODispatcher(InMemoryBus.CreateTest(), new NoopEnvelope()), null, 1, false),
                new AuthorizationGateway(new TestAuthorizationProvider()),
                TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), (man, err) => { mre.Set(); },
                ESConsts.UnrestrictedPendingSendBytes, ESConsts.MaxConnectionQueueSize);

            tcpConnectionManager.SendMessage(message);

            if (!mre.Wait(2000))
            {
                Assert.Fail("Timed out waiting for connection to close");
            }
        }
示例#2
0
        when_send_queue_size_is_smaller_than_threshold_should_not_close_connection()
        {
            var mre = new ManualResetEventSlim();

            var messageSize = _connectionPendingSendBytesThreshold;
            var evnt        = new EventRecord(0, 0, Guid.NewGuid(), Guid.NewGuid(), 0, 0, "testStream", 0, DateTime.Now,
                                              PrepareFlags.None, "eventType", new byte[messageSize], new byte[0]);
            var record  = ResolvedEvent.ForUnresolvedEvent(evnt, null);
            var message = new ClientMessage.ReadEventCompleted(Guid.NewGuid(), "testStream", ReadEventResult.Success,
                                                               record, StreamMetadata.Empty, false, "");

            var dummyConnection = new DummyTcpConnection();

            dummyConnection.SendQueueSize = ESConsts.MaxConnectionQueueSize - 1;

            var tcpConnectionManager = new TcpConnectionManager(
                Guid.NewGuid().ToString(), TcpServiceType.External, new ClientTcpDispatcher(2000),
                InMemoryBus.CreateTest(), dummyConnection, InMemoryBus.CreateTest(),
                new InternalAuthenticationProvider(InMemoryBus.CreateTest(),
                                                   new Core.Helpers.IODispatcher(InMemoryBus.CreateTest(), new NoopEnvelope()), null, 1, false),
                new AuthorizationGateway(new TestAuthorizationProvider()),
                TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), (man, err) => { mre.Set(); },
                ESConsts.UnrestrictedPendingSendBytes, ESConsts.MaxConnectionQueueSize);

            tcpConnectionManager.SendMessage(message);

            var data            = dummyConnection.ReceivedData.Last();
            var receivedPackage = TcpPackage.FromArraySegment(data);

            Assert.AreEqual(receivedPackage.Command, TcpCommand.ReadEventCompleted,
                            "Expected ReadEventCompleted but got {0}", receivedPackage.Command);
        }