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"); } }
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); }
when_limit_pending_and_sending_message_larger_than_pending_bytes_threshold_but_no_bytes_pending_should_not_close_connection() { var messageSize = _connectionPendingSendBytesThreshold + 1000; 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.PendingSendBytes = 0; var tcpConnectionManager = new TcpConnectionManager( Guid.NewGuid().ToString(), TcpServiceType.External, new ClientTcpDispatcher(), InMemoryBus.CreateTest(), dummyConnection, InMemoryBus.CreateTest(), new InternalAuthenticationProvider( new Core.Helpers.IODispatcher(InMemoryBus.CreateTest(), new NoopEnvelope()), null, 1, false), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), (man, err) => { }, _connectionPendingSendBytesThreshold, _connectionQueueSizeThreshold); 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); }
public void Handle(ClientMessage.ReadEvent message) { _correlations.Add(message.CorrelationId, message.Envelope); //TODO: null envelope? _connection.SendMessage(message); }