public void DirectChannel_Send_10_000_000_SingleHandler() { var services = new ServiceCollection(); var config = new ConfigurationBuilder().Build(); services.AddSingleton <IConfiguration>(config); services.AddSingleton <IApplicationContext, GenericApplicationContext>(); services.AddSingleton <IIntegrationServices, IntegrationServices>(); var provider = services.BuildServiceProvider(); var directChannel = new DirectChannel(provider.GetService <IApplicationContext>()); var handler = new CounterHandler(); directChannel.Subscribe(handler); var message = Message.Create("test"); directChannel.Send(message); for (var i = 0; i < 10_000_000; i++) { directChannel.Send(message); } if (handler.Count != 10_000_000 + 1) { throw new InvalidOperationException("Handler count invalid"); } }
public void FailoverNoLoadBalancing() { var channel = new DirectChannel(provider, null, "loadBalancerNoFailover", null); channel.Failover = true; handlerA.Setup((h) => h.HandleMessage(message)).Throws(new MessageRejectedException(message, null)); var dispatcher = channel.Dispatcher; dispatcher.AddHandler(handlerA.Object); dispatcher.AddHandler(handlerB.Object); try { channel.Send(message); } catch (Exception) { /* ignore */ } handlerA.Verify((h) => h.HandleMessage(message), Times.Exactly(1)); handlerB.Verify((h) => h.HandleMessage(message), Times.Exactly(1)); try { channel.Send(message); } catch (Exception) { /* ignore */ } handlerA.Verify((h) => h.HandleMessage(message), Times.Exactly(2)); handlerB.Verify((h) => h.HandleMessage(message), Times.Exactly(2)); }
public void TestSendOneHandler_10_000_000() { /* * INT-3308 - used to run 12 million/sec * 1. optimize for single handler 20 million/sec * 2. Don't iterate over empty datatypes 23 million/sec * 3. Don't iterate over empty interceptors 31 million/sec * 4. Move single handler optimization to dispatcher 34 million/sec * * 29 million per second with increment counter in the handler */ var channel = new DirectChannel(provider.GetService <IApplicationContext>()); var handler = new CounterHandler(); channel.Subscribe(handler); var message = Message.Create("test"); Assert.True(channel.Send(message)); for (var i = 0; i < 10000000; i++) { channel.Send(message); } Assert.Equal(10000001, handler.Count); }
public void TestSendOneHandler_10_000_000() { /* * INT-3308 - used to run 12 million/sec * 1. optimize for single handler 20 million/sec * 2. Don't iterate over empty datatypes 23 million/sec * 3. Don't iterate over empty interceptors 31 million/sec * 4. Move single handler optimization to dispatcher 34 million/sec * * 29 million per second with increment counter in the handler */ var services = new ServiceCollection(); services.AddSingleton <IIntegrationServices, IntegrationServices>(); var provider = services.BuildServiceProvider(); var channel = new DirectChannel(provider); var handler = new CounterHandler(); channel.Subscribe(handler); var message = new GenericMessage("test"); Assert.True(channel.Send(message)); for (var i = 0; i < 10000000; i++) { channel.Send(message); } Assert.Equal(10000001, handler.Count); }
public void NoFailoverNoLoadBalancing() { var channel = new DirectChannel(provider.GetService <IApplicationContext>(), null, "noLoadBalancerNoFailover", null); channel.Failover = false; handlerA.Setup((h) => h.HandleMessage(message)).Throws(new MessageRejectedException(message, null)); var dispatcher = channel.Dispatcher; dispatcher.AddHandler(handlerA.Object); dispatcher.AddHandler(handlerB.Object); try { channel.Send(message); } catch (Exception) { } try { channel.Send(message); } catch (Exception) { } handlerA.Verify((h) => h.HandleMessage(message), Times.Exactly(2)); handlerB.Verify((h) => h.HandleMessage(message), Times.Exactly(0)); }
public void DirectChannel_Send_10_000_000_TwoHandlers() { var services = new ServiceCollection(); services.AddSingleton <IIntegrationServices, IntegrationServices>(); var provider = services.BuildServiceProvider(); var channel = new DirectChannel(provider); var count1 = new CounterHandler(); var count2 = new CounterHandler(); channel.Subscribe(count1); channel.Subscribe(count2); var message = new GenericMessage("test"); for (var i = 0; i < 10_000_000; i++) { channel.Send(message); } if (count1.Count != 5000000) { throw new InvalidOperationException("Handler count1 invalid"); } if (count2.Count != 5000000) { throw new InvalidOperationException("Handler count2 invalid"); } }
public void TestSendTwoHandlers_10_000_000() { /* * INT-3308 - used to run 6.4 million/sec * 1. Skip empty iterators as above 7.2 million/sec * 2. optimize for single handler 6.7 million/sec (small overhead added) * 3. remove LB rwlock from UnicastingDispatcher 7.2 million/sec * 4. Move single handler optimization to dispatcher 7.3 million/sec */ var channel = new DirectChannel(provider.GetService <IApplicationContext>()); var count1 = new CounterHandler(); var count2 = new CounterHandler(); channel.Subscribe(count1); channel.Subscribe(count2); var message = Message.Create("test"); for (var i = 0; i < 10000000; i++) { channel.Send(message); } Assert.Equal(5000000, count1.Count); Assert.Equal(5000000, count2.Count); }
public void TestSendFourHandlers_10_000_000() { var services = new ServiceCollection(); services.AddSingleton <IIntegrationServices, IntegrationServices>(); var provider = services.BuildServiceProvider(); var channel = new DirectChannel(provider); var count1 = new CounterHandler(); var count2 = new CounterHandler(); var count3 = new CounterHandler(); var count4 = new CounterHandler(); channel.Subscribe(count1); channel.Subscribe(count2); channel.Subscribe(count3); channel.Subscribe(count4); var message = new GenericMessage("test"); for (var i = 0; i < 10000000; i++) { channel.Send(message); } Assert.Equal(10000000 / 4, count1.Count); Assert.Equal(10000000 / 4, count2.Count); Assert.Equal(10000000 / 4, count3.Count); Assert.Equal(10000000 / 4, count4.Count); }
public void TestSendTwoHandlers_10_000_000() { /* * INT-3308 - used to run 6.4 million/sec * 1. Skip empty iterators as above 7.2 million/sec * 2. optimize for single handler 6.7 million/sec (small overhead added) * 3. remove LB rwlock from UnicastingDispatcher 7.2 million/sec * 4. Move single handler optimization to dispatcher 7.3 million/sec */ var services = new ServiceCollection(); services.AddSingleton <IIntegrationServices, IntegrationServices>(); var provider = services.BuildServiceProvider(); var channel = new DirectChannel(provider); var count1 = new CounterHandler(); var count2 = new CounterHandler(); channel.Subscribe(count1); channel.Subscribe(count2); var message = new GenericMessage("test"); for (var i = 0; i < 10000000; i++) { channel.Send(message); } Assert.Equal(5000000, count1.Count); Assert.Equal(5000000, count2.Count); }
public void FailoverNoLoadBalancingConcurrent() { var channel = new DirectChannel(provider.GetService <IApplicationContext>(), null, "noLoadBalancerFailover", null); channel.Failover = true; handlerA.Setup((h) => h.HandleMessage(message)).Throws(new MessageRejectedException(message, null)); var dispatcher = channel.Dispatcher; dispatcher.AddHandler(handlerA.Object); dispatcher.AddHandler(handlerB.Object); dispatcher.AddHandler(handlerC.Object); var start1 = new CountdownEvent(1); var allDone1 = new CountdownEvent(TOTAL_EXECUTIONS); var message2 = message; var failed1 = 0; void MessageSenderTask() { try { start1.Wait(); } catch (Exception) { throw; } var sent = false; try { sent = channel.Send(message2); } catch (Exception e2) { exceptionRegistry.Object.Add(e2); } if (!sent) { failed1 = 1; } allDone1.Signal(); } for (var i = 0; i < TOTAL_EXECUTIONS; i++) { Task.Run(MessageSenderTask); } start1.Signal(); Assert.True(allDone1.Wait(10000)); Assert.Equal(0, failed1); handlerA.Verify((h) => h.HandleMessage(message2), Times.Exactly(TOTAL_EXECUTIONS)); handlerB.Verify((h) => h.HandleMessage(message2), Times.Exactly(TOTAL_EXECUTIONS)); handlerC.Verify((h) => h.HandleMessage(message2), Times.Never()); exceptionRegistry.Verify((list) => list.Add(It.IsAny <Exception>()), Times.Never()); }
public void NoFailoverNoLoadBalancingConcurrent() { var channel = new DirectChannel(provider, null, "noLoadBalancerNoFailover", null); channel.Failover = false; handlerA.Setup((h) => h.HandleMessage(message)).Throws(new MessageRejectedException(message, null)); var dispatcher = channel.Dispatcher; dispatcher.AddHandler(handlerA.Object); dispatcher.AddHandler(handlerB.Object); void MessageSenderTask() { try { start.Wait(); } catch (Exception) { throw; } var sent = false; try { sent = channel.Send(message); } catch (Exception e2) { exceptionRegistry.Object.Add(e2); } if (!sent) { failed = 1; } allDone.Signal(); } for (var i = 0; i < TOTAL_EXECUTIONS; i++) { Task.Run(MessageSenderTask); } start.Signal(); Assert.True(allDone.Wait(10000)); Assert.Equal(1, failed); handlerA.Verify((h) => h.HandleMessage(message), Times.Exactly(TOTAL_EXECUTIONS)); handlerB.Verify((h) => h.HandleMessage(message), Times.Exactly(0)); exceptionRegistry.Verify((list) => list.Add(It.IsAny <Exception>()), Times.Exactly(TOTAL_EXECUTIONS)); }
public void testSend() { DirectChannel channel = new DirectChannel(); ThreadNameExtractingTestTarget target = new ThreadNameExtractingTestTarget(); channel.Subscribe(target); StringMessage message = new StringMessage("test"); Assert.IsTrue(channel.Send(message)); Assert.That(target.ThreadName, Is.EqualTo(Thread.CurrentThread.Name)); }
public void TestSend() { var target = new ThreadNameExtractingTestTarget(); var channel = new DirectChannel(provider.GetService <IApplicationContext>()); channel.Subscribe(target); var message = Message.Create("test"); var currentId = Task.CurrentId; var curThreadId = Thread.CurrentThread.ManagedThreadId; Assert.True(channel.Send(message)); Assert.Equal(currentId, target.TaskId); Assert.Equal(curThreadId, target.ThreadId); }
public void DirectChannel_Send_10_000_000_SingleHandler() { var services = new ServiceCollection(); services.AddSingleton <IIntegrationServices, IntegrationServices>(); var provider = services.BuildServiceProvider(); var directChannel = new DirectChannel(provider); var handler = new CounterHandler(); directChannel.Subscribe(handler); var message = new GenericMessage("test"); directChannel.Send(message); for (var i = 0; i < 10_000_000; i++) { directChannel.Send(message); } if (handler.Count != 10_000_000 + 1) { throw new InvalidOperationException("Handler count invalid"); } }
public void TestCorrelationIdPassedIfAvailable() { object correlationId = "123-ABC"; IMessage message = MessageBuilder.WithPayload("test").SetCorrelationId(correlationId).Build(); DirectChannel inputChannel = new DirectChannel(); QueueChannel outputChannel = new QueueChannel(1); ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "UpperCase"); serviceActivator.OutputChannel = outputChannel; EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator); endpoint.Start(); Assert.IsTrue(inputChannel.Send(message)); IMessage reply = outputChannel.Receive(TimeSpan.Zero); Assert.That(reply.Headers.CorrelationId, Is.EqualTo(correlationId)); }
public void testSendInSeparateThread() { CountDownLatch latch = new CountDownLatch(1); DirectChannel channel = new DirectChannel(); ThreadNameExtractingTestTarget target = new ThreadNameExtractingTestTarget(latch); channel.Subscribe(target); StringMessage message = new StringMessage("test"); Thread t = new Thread(new ThreadStart(delegate { channel.Send(message); })); t.Name = "test-thread"; t.Start(); latch.Await(new TimeSpan(0, 0, 0, 0, 1000)); Assert.That(target.ThreadName, Is.EqualTo("test-thread")); }
public void TestSendInSeparateThread() { var latch = new CountdownEvent(1); var channel = new DirectChannel(provider.GetService <IApplicationContext>()); var target = new ThreadNameExtractingTestTarget(latch); channel.Subscribe(target); var message = Message.Create("test"); var thread = new Thread(() => channel.Send(message)); thread.Name = "test-thread"; thread.Start(); latch.Wait(1000); Assert.Equal("test-thread", target.ThreadName); }
public void TestCorrelationNotCopiedFromRequestMessgeIdIfAlreadySetByHandler() { IMessage message = new StringMessage("test"); DirectChannel inputChannel = new DirectChannel(); QueueChannel outputChannel = new QueueChannel(1); ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "CreateMessage"); serviceActivator.OutputChannel = outputChannel; EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator); endpoint.Start(); Assert.IsTrue(inputChannel.Send(message)); IMessage reply = outputChannel.Receive(TimeSpan.Zero); Assert.That(reply.Headers.CorrelationId, Is.EqualTo("456-XYZ")); }
public async Task TestCorrelationNotCopiedFromRequestMessgeIdIfAlreadySetByHandler() { IMessage message = Message.Create("test"); var inputChannel = new DirectChannel(provider.GetService <IApplicationContext>()); var outputChannel = new QueueChannel(provider.GetService <IApplicationContext>(), 1); var serviceActivator = new ServiceActivatingHandler(provider.GetService <IApplicationContext>(), new TestBeanCreateMessage()); serviceActivator.OutputChannel = outputChannel; var endpoint = new EventDrivenConsumerEndpoint(provider.GetService <IApplicationContext>(), inputChannel, serviceActivator); await endpoint.Start(); Assert.True(inputChannel.Send(message)); var reply = outputChannel.Receive(0); var accessor = new IntegrationMessageHeaderAccessor(reply); Assert.Equal("456-XYZ", accessor.GetCorrelationId()); }
public void TestCorrelationIdCopiedFromMessageCorrelationIdIfAvailable() { IMessage message = MessageBuilder.WithPayload("test").SetCorrelationId("correlationId").Build(); DirectChannel inputChannel = new DirectChannel(); QueueChannel outputChannel = new QueueChannel(1); ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "UpperCase"); serviceActivator.OutputChannel = outputChannel; EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator); endpoint.Start(); Assert.IsTrue(inputChannel.Send(message)); IMessage reply = outputChannel.Receive(TimeSpan.Zero); Assert.That(reply.Headers.CorrelationId, Is.EqualTo(message.Headers.CorrelationId)); Assert.IsTrue(message.Headers.CorrelationId.Equals(reply.Headers.CorrelationId)); }
public void TestCorrelationNotPassedFromRequestHeaderIfAlreadySetByHandler() { object correlationId = "123-ABC"; IMessage message = MessageBuilder.WithPayload("test").SetCorrelationId(correlationId).Build(); DirectChannel inputChannel = new DirectChannel(); QueueChannel outputChannel = new QueueChannel(1); ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "CreateMessage"); serviceActivator.OutputChannel = outputChannel; EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator); endpoint.Start(); Assert.IsTrue(inputChannel.Send(message)); IMessage reply = outputChannel.Receive(TimeSpan.Zero); Assert.That(reply.Headers.CorrelationId, Is.EqualTo("456-XYZ")); }
public void OneChannel() { var services = new ServiceCollection(); services.AddSingleton <IIntegrationServices, IntegrationServices>(); var provider = services.BuildServiceProvider(); var noSubscribersChannel = new DirectChannel(provider); try { noSubscribersChannel.Send(new GenericMessage <string>("Hello, world!")); throw new Exception("Exception expected"); } catch (MessagingException e) { Assert.Contains("Dispatcher has no subscribers", e.Message); } }
public async Task TestCorrelationIdPassedIfAvailable() { object correlationId = "123-ABC"; var message = Support.MessageBuilder.WithPayload("test").SetCorrelationId(correlationId).Build(); var inputChannel = new DirectChannel(provider); var outputChannel = new QueueChannel(provider, 1); var serviceActivator = new ServiceActivatingHandler(provider, new TestBeanUpperCase()); serviceActivator.OutputChannel = outputChannel; var endpoint = new EventDrivenConsumerEndpoint(provider, inputChannel, serviceActivator); await endpoint.Start(); Assert.True(inputChannel.Send(message)); var reply = outputChannel.Receive(0); var accessor = new IntegrationMessageHeaderAccessor(reply); Assert.Equal(correlationId, accessor.GetCorrelationId()); }
public void TestSend() { var services = new ServiceCollection(); services.AddSingleton <IIntegrationServices, IntegrationServices>(); var provider = services.BuildServiceProvider(); var target = new ThreadNameExtractingTestTarget(); var channel = new DirectChannel(provider); channel.Subscribe(target); var message = new GenericMessage("test"); var currentId = Task.CurrentId; var curThreadId = Thread.CurrentThread.ManagedThreadId; Assert.True(channel.Send(message)); Assert.Equal(currentId, target.TaskId); Assert.Equal(curThreadId, target.ThreadId); }
public async Task TestCorrelationNotPassedFromRequestHeaderIfAlreadySetByHandler() { object correlationId = "123-ABC"; var message = Support.IntegrationMessageBuilder.WithPayload("test").SetCorrelationId(correlationId).Build(); var inputChannel = new DirectChannel(provider.GetService <IApplicationContext>()); var outputChannel = new QueueChannel(provider.GetService <IApplicationContext>(), 1); var serviceActivator = new ServiceActivatingHandler(provider.GetService <IApplicationContext>(), new TestBeanCreateMessage()); serviceActivator.OutputChannel = outputChannel; var endpoint = new EventDrivenConsumerEndpoint(provider.GetService <IApplicationContext>(), inputChannel, serviceActivator); await endpoint.Start(); Assert.True(inputChannel.Send(message)); var reply = outputChannel.Receive(0); var accessor = new IntegrationMessageHeaderAccessor(reply); Assert.Equal("456-XYZ", accessor.GetCorrelationId()); }
public void DirectChannel_Send_10_000_000_FourHandlers() { var services = new ServiceCollection(); services.AddSingleton <IIntegrationServices, IntegrationServices>(); var provider = services.BuildServiceProvider(); var channel = new DirectChannel(provider.GetService <IApplicationContext>()); var count1 = new CounterHandler(); var count2 = new CounterHandler(); var count3 = new CounterHandler(); var count4 = new CounterHandler(); channel.Subscribe(count1); channel.Subscribe(count2); channel.Subscribe(count3); channel.Subscribe(count4); var message = Message.Create("test"); for (var i = 0; i < 10_000_000; i++) { channel.Send(message); } if (count1.Count != 10_000_000 / 4) { throw new InvalidOperationException("Handler count1 invalid"); } if (count2.Count != 10_000_000 / 4) { throw new InvalidOperationException("Handler count2 invalid"); } if (count3.Count != 10_000_000 / 4) { throw new InvalidOperationException("Handler count3 invalid"); } if (count4.Count != 10_000_000 / 4) { throw new InvalidOperationException("Handler count4 invalid"); } }
public void TestSendInSeparateThread() { var services = new ServiceCollection(); services.AddSingleton <IIntegrationServices, IntegrationServices>(); var provider = services.BuildServiceProvider(); var latch = new CountdownEvent(1); var channel = new DirectChannel(provider); var target = new ThreadNameExtractingTestTarget(latch); channel.Subscribe(target); var message = new GenericMessage("test"); var thread = new Thread(() => channel.Send(message)); thread.Name = "test-thread"; thread.Start(); latch.Wait(1000); Assert.Equal("test-thread", target.ThreadName); }
public void BridgedChannel() { var services = new ServiceCollection(); services.AddSingleton <IIntegrationServices, IntegrationServices>(); var provider = services.BuildServiceProvider(); var noSubscribersChannel = new DirectChannel(provider.GetService <IApplicationContext>()); var subscribedChannel = new DirectChannel(provider.GetService <IApplicationContext>()); var bridgeHandler = new BridgeHandler(provider.GetService <IApplicationContext>()); bridgeHandler.OutputChannel = noSubscribersChannel; subscribedChannel.Subscribe(bridgeHandler); try { subscribedChannel.Send(Message.Create("Hello, world!")); throw new Exception("Exception expected"); } catch (MessagingException e) { Assert.Contains("Dispatcher has no subscribers", e.Message); } }
public void TestSendFourHandlers_10_000_000() { var channel = new DirectChannel(provider.GetService <IApplicationContext>()); var count1 = new CounterHandler(); var count2 = new CounterHandler(); var count3 = new CounterHandler(); var count4 = new CounterHandler(); channel.Subscribe(count1); channel.Subscribe(count2); channel.Subscribe(count3); channel.Subscribe(count4); var message = Message.Create("test"); for (var i = 0; i < 10000000; i++) { channel.Send(message); } Assert.Equal(10000000 / 4, count1.Count); Assert.Equal(10000000 / 4, count2.Count); Assert.Equal(10000000 / 4, count3.Count); Assert.Equal(10000000 / 4, count4.Count); }
public void TestCorrelationNotCopiedFromRequestMessgeIdIfAlreadySetByHandler() { IMessage message = new StringMessage("test"); DirectChannel inputChannel = new DirectChannel(); QueueChannel outputChannel = new QueueChannel(1); ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "CreateMessage"); serviceActivator.OutputChannel = outputChannel; EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator); endpoint.Start(); Assert.IsTrue(inputChannel.Send(message)); IMessage reply = outputChannel.Receive(TimeSpan.Zero); Assert.That(reply.Headers.CorrelationId, Is.EqualTo("456-XYZ")); }