public async Task SendAsyncShouldTimeoutMultipleMessagesAtATime() { using (var server = new FakeTcpServer(_log, 8999)) using (var socket = new KafkaTcpSocket(_log, _kafkaEndpoint, _maxRetry)) using (var conn = new KafkaConnection(socket, TimeSpan.FromMilliseconds(100), log: _log)) { server.HasClientConnected.Wait(TimeSpan.FromSeconds(3)); Assert.That(server.ConnectionEventcount, Is.EqualTo(1)); var tasks = new[] { conn.SendAsync(new MetadataRequest()), conn.SendAsync(new MetadataRequest()), conn.SendAsync(new MetadataRequest()) }; Task.WhenAll(tasks); await TaskTest.WaitFor(() => tasks.All(t => t.IsFaulted)); foreach (var task in tasks) { Assert.That(task.IsFaulted, Is.True, "Task should have faulted."); Assert.That(task.Exception.InnerException, Is.TypeOf <ResponseTimeoutException>(), "Task fault should be of type ResponseTimeoutException."); } } }
public void SendAsyncShouldTimeoutMultipleMessagesAtATime() { using (var server = new FakeTcpServer(8999)) using (var socket = new KafkaTcpSocket(_log, _kafkaEndpoint)) using (var conn = new KafkaConnection(socket, TimeSpan.FromMilliseconds(100), log: _log)) { TaskTest.WaitFor(() => server.ConnectionEventcount > 0); Assert.That(server.ConnectionEventcount, Is.EqualTo(1)); var tasks = new[] { conn.SendAsync(new MetadataRequest()), conn.SendAsync(new MetadataRequest()), conn.SendAsync(new MetadataRequest()) }; Task.WhenAll(tasks); TaskTest.WaitFor(() => tasks.Any(t => t.IsFaulted)); foreach (var task in tasks) { Assert.That(task.IsFaulted, Is.True); Assert.That(task.Exception.InnerException, Is.TypeOf <ResponseTimeoutException>()); } } }
public async void SendAsyncShouldNotAllowResponseToTimeoutWhileAwaitingKafkaToEstableConnection() { using (var socket = new KafkaTcpSocket(_log, _kafkaEndpoint)) using (var conn = new KafkaConnection(socket, TimeSpan.FromMilliseconds(1000000), log: _log)) { Console.WriteLine("SendAsync blocked by reconnection attempts..."); var taskResult = conn.SendAsync(new MetadataRequest()); taskResult.ContinueWith(t => taskResult = t).Wait(TimeSpan.FromSeconds(1)); Console.WriteLine("Task result should be WaitingForActivation..."); Assert.That(taskResult.IsFaulted, Is.False); Assert.That(taskResult.Status, Is.EqualTo(TaskStatus.WaitingForActivation)); Console.WriteLine("Starting server to establish connection..."); using (var server = new FakeTcpServer(8999)) { server.OnClientConnected += () => Console.WriteLine("Client connected..."); server.OnBytesReceived += (b) => { server.SendDataAsync(MessageHelper.CreateMetadataResponse(1, "Test")); }; await taskResult; Assert.That(taskResult.IsFaulted, Is.False); Assert.That(taskResult.IsCanceled, Is.False); Assert.That(taskResult.Status, Is.EqualTo(TaskStatus.RanToCompletion)); } } }
public void ShouldDisposeWithoutExceptionEvenWhileCallingSendAsync() { using (var socket = new KafkaTcpSocket(_log, _kafkaEndpoint)) using (var conn = new KafkaConnection(socket, log: _log)) { var task = conn.SendAsync(new MetadataRequest()); task.Wait(TimeSpan.FromMilliseconds(1000)); Assert.That(task.IsCompleted, Is.False, "The send task should still be pending."); } }
public void ShouldDisposeWithoutExceptionEvenWhileCallingSendAsync() { using (var socket = new KafkaTcpSocket(_log, _kafkaEndpoint)) using (var conn = new KafkaConnection(socket, log: _log)) { var task = conn.SendAsync(new MetadataRequest()); task.Wait(TimeSpan.FromMilliseconds(1000)); Assert.That(task.IsCompleted, Is.False, "The send task should still be pending."); } }
public void SendAsyncShouldTimeoutByThrowingResponseTimeoutExceptionWhenTcpConnectionIsNotAvailable() { using (var socket = new KafkaTcpSocket(_log, _kafkaEndpoint)) using (var conn = new KafkaConnection(socket, TimeSpan.FromMilliseconds(100), log: _log)) { var taskResult = conn.SendAsync(new MetadataRequest()); taskResult.ContinueWith(t => taskResult = t).Wait(TimeSpan.FromSeconds(1)); Assert.That(taskResult.IsFaulted, Is.True); Assert.That(taskResult.Exception.InnerException, Is.TypeOf <ResponseTimeoutException>()); } }
public void SendAsyncShouldTimeoutByThrowingResponseTimeoutException() { using (var server = new FakeTcpServer(8999)) using (var socket = new KafkaTcpSocket(_log, _kafkaEndpoint)) using (var conn = new KafkaConnection(socket, TimeSpan.FromMilliseconds(100), log: _log)) { TaskTest.WaitFor(() => server.ConnectionEventcount > 0); Assert.That(server.ConnectionEventcount, Is.EqualTo(1)); var taskResult = conn.SendAsync(new MetadataRequest()); taskResult.ContinueWith(t => taskResult = t).Wait(TimeSpan.FromSeconds(1)); Assert.That(taskResult.IsFaulted, Is.True); Assert.That(taskResult.Exception.InnerException, Is.TypeOf <ResponseTimeoutException>()); } }
public async Task SendAsyncShouldTimeoutWhenSendAsyncTakesTooLong() { using (var server = new FakeTcpServer(_log, 8999)) using (var socket = new KafkaTcpSocket(_log, _kafkaEndpoint, _maxRetry)) using (var conn = new KafkaConnection(socket, TimeSpan.FromMilliseconds(1), log: _log)) { await TaskTest.WaitFor(() => server.ConnectionEventcount > 0); Assert.That(server.ConnectionEventcount, Is.EqualTo(1)); var taskResult = conn.SendAsync(new MetadataRequest()); taskResult.ContinueWith(t => taskResult = t).Wait(TimeSpan.FromMilliseconds(100)); Assert.That(taskResult.IsFaulted, Is.True, "Task should have reported an exception."); Assert.That(taskResult.Exception.InnerException, Is.TypeOf <ResponseTimeoutException>()); } }
public void EnsureGzipCompressedMessageCanSend() { //ensure topic exists _kafkaConnection.SendAsync(new MetadataRequest { Topics = new List <string>(new[] { IntegrationConfig.IntegrationCompressionTopic }) }).Wait(); var conn = _router.SelectBrokerRoute(IntegrationConfig.IntegrationCompressionTopic, 0); var request = new ProduceRequest { Acks = 1, TimeoutMS = 1000, Payload = new List <Payload> { new Payload { Codec = MessageCodec.CodecGzip, Topic = IntegrationConfig.IntegrationCompressionTopic, Partition = 0, Messages = new List <Message> { new Message { Value = "0", Key = "1" }, new Message { Value = "1", Key = "1" }, new Message { Value = "2", Key = "1" } } } } }; var response = conn.Connection.SendAsync(request).Result; Assert.That(response.First().Error, Is.EqualTo(0)); }
public void EnsureTwoRequestsCanCallOneAfterAnother() { var result1 = _conn.SendAsync(new MetadataRequest()).Result; var result2 = _conn.SendAsync(new MetadataRequest()).Result; Assert.That(result1.Count, Is.EqualTo(1)); Assert.That(result2.Count, Is.EqualTo(1)); }
public void SendAsyncShouldTimeoutMultipleMessagesAtATime() { using (var server = new FakeTcpServer(8999)) using (var socket = new KafkaTcpSocket(_log, _kafkaEndpoint)) using (var conn = new KafkaConnection(socket, TimeSpan.FromMilliseconds(100), log: _log)) { server.HasClientConnected.Wait(TimeSpan.FromSeconds(3)); Assert.That(server.ConnectionEventcount, Is.EqualTo(1)); var tasks = new[] { conn.SendAsync(new MetadataRequest()), conn.SendAsync(new MetadataRequest()), conn.SendAsync(new MetadataRequest()) }; Task.WhenAll(tasks); TaskTest.WaitFor(() => tasks.Any(t => t.IsFaulted)); foreach (var task in tasks) { Assert.That(task.IsFaulted, Is.True, "Task should have faulted."); Assert.That(task.Exception.InnerException, Is.TypeOf<ResponseTimeoutException>(), "Task fault should be of type ResponseTimeoutException."); } } }
public async void SendAsyncShouldNotAllowResponseToTimeoutWhileAwaitingKafkaToEstableConnection() { using (var socket = new KafkaTcpSocket(_log, _kafkaEndpoint)) using (var conn = new KafkaConnection(socket, TimeSpan.FromMilliseconds(1000000), log: _log)) { Console.WriteLine("SendAsync blocked by reconnection attempts..."); var taskResult = conn.SendAsync(new MetadataRequest()); taskResult.ContinueWith(t => taskResult = t).Wait(TimeSpan.FromSeconds(1)); Console.WriteLine("Task result should be WaitingForActivation..."); Assert.That(taskResult.IsFaulted, Is.False); Assert.That(taskResult.Status, Is.EqualTo(TaskStatus.WaitingForActivation)); Console.WriteLine("Starting server to establish connection..."); using (var server = new FakeTcpServer(8999)) { server.OnClientConnected += () => Console.WriteLine("Client connected..."); server.OnBytesReceived += (b) => { server.SendDataAsync(MessageHelper.CreateMetadataResponse(1, "Test")); }; await taskResult; Assert.That(taskResult.IsFaulted, Is.False); Assert.That(taskResult.IsCanceled, Is.False); Assert.That(taskResult.Status, Is.EqualTo(TaskStatus.RanToCompletion)); } } }
public void SendAsyncShouldTimeoutWhenSendAsyncTakesTooLong() { using (var server = new FakeTcpServer(8999)) using (var socket = new KafkaTcpSocket(_log, _kafkaEndpoint)) using (var conn = new KafkaConnection(socket, TimeSpan.FromMilliseconds(1), log: _log)) { TaskTest.WaitFor(() => server.ConnectionEventcount > 0); Assert.That(server.ConnectionEventcount, Is.EqualTo(1)); var taskResult = conn.SendAsync(new MetadataRequest()); taskResult.ContinueWith(t => taskResult = t).Wait(TimeSpan.FromMilliseconds(100)); Assert.That(taskResult.IsFaulted, Is.True, "Task should have reported an exception."); Assert.That(taskResult.Exception.InnerException, Is.TypeOf<ResponseTimeoutException>()); } }