void can_ignore_messages_not_subscribed() { _t1.Start(); // The task publishes a CountedTestMessage, a TestMessage and a CountedEvent each time thru the loop, so expect 3 per iteration Assert.IsOrBecomesTrue(() => BusMessages.Count == FirstTaskMax * 3, TimeoutInMs, $"Expected {FirstTaskMax * 3} Messages, found {BusMessages.Count}"); // the task only publishes one Event (CountedEvent), so expect 1 per iteration Assert.IsOrBecomesTrue(() => BusEvents.Count == FirstTaskMax, TimeoutInMs, $"Expected {FirstTaskMax} Messages, found {BusEvents.Count}"); // _messageSubscriber subscribes to CountedTestMessage, but not TestMessage, so expect 1 per iteration Assert.IsOrBecomesTrue( // ReSharper disable once AccessToDisposedClosure () => Interlocked.Read(ref _messageSubscriber.MessagesHandled) == FirstTaskMax, 2000, $"Expected {FirstTaskMax} Messages, found {_messageSubscriber.MessagesHandled}"); Assert.Equal(BusMessages.Count, FirstTaskMax * 3); Assert.True(_messageSubscriber.MessagesInOrder(), "Messages are not in order"); Assert.True(_messageSubscriber.EventsInOrder(), "Events are not in order"); _messageSubscriber.Dispose(); TestQueue.Clear(); _t2.Start(); // publish more messages - no subscriber is available //Messages and events are published. Don't know how to prove no one handles them. Assert.IsOrBecomesTrue(() => BusMessages.Count == FirstTaskMax * 3, TimeoutInMs, $"Expected {FirstTaskMax * 3} Messages, found {BusMessages.Count}"); }
public void grand_child_invokes_all_handlers_thrice() { using (var sub = new TestInheritedMessageSubscriber(Bus, false)) { var subscriber = sub; TestQueue.Clear(); Bus.Publish(new GrandChildTestDomainEvent(TestCorrelationId, ChildMsgId)); BusMessages .AssertNext <GrandChildTestDomainEvent>(TestCorrelationId) .AssertEmpty(); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscriber.TestDomainEventHandleCount) == 0, 2000, $"Expected 0 Test Domain Event Handled, found {subscriber.TestDomainEventHandleCount}"); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscriber.GrandChildTestDomainEventHandleCount) == 3, 3000, $"Expected 3 GrandChildTestDomainEvent handled , found {subscriber.ChildTestDomainEventHandleCount}"); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscriber.ChildTestDomainEventHandleCount) == 3, 3000, $"Expected 3 ChildTestDomainEvent handled , found {subscriber.ChildTestDomainEventHandleCount}"); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscriber.ParentTestDomainEventHandleCount) == 3, 3000, $"Expected 3 Parent Test Domain Event handled, found {subscriber.ParentTestDomainEventHandleCount}"); } }
public void child_invokes_parent_and_child_handlers_once() { using (var sub = new TestInheritedMessageSubscriber(Bus)) { var subscription = sub; TestQueue.Clear(); Bus.Publish(new ChildTestDomainEvent(TestCorrelationId, ChildMsgId)); BusMessages .AssertNext <ChildTestDomainEvent>(TestCorrelationId) .AssertEmpty(); Assert.IsOrBecomesTrue(() => subscription.Starving, 3000); Assert.IsOrBecomesTrue(() => subscription.TestDomainEventHandleCount == 0, 1000, $"Expected 0 Test Domain Event Handled, found {subscription.TestDomainEventHandleCount}"); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscription.GrandChildTestDomainEventHandleCount) == 0, 1000, $"Expected 0 GrandChildTestDomainEvent handled , found {subscription.ChildTestDomainEventHandleCount}"); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscription.ChildTestDomainEventHandleCount) == 1, 1000, $"Expected 1 ChildTestDomainEvent handled , found {subscription.ChildTestDomainEventHandleCount}"); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscription.ParentTestDomainEventHandleCount) == 1, 1000, $"Expected 1 Parent Test Domain Event handled, found {subscription.ParentTestDomainEventHandleCount}"); } }
public void TestClear() { PopulateTestQueue(); Assert.Equal(SampleSize, TestQueue.Count); TestQueue.Clear(); Assert.Empty(TestQueue); }
protected virtual void CreateTestStorageEntities() { TestQueue = QueueClient.GetQueueReference(string.Format("test-input-{0}", _testId)); TestQueue.CreateIfNotExists(); TestQueue.Clear(); TestInputContainer = BlobClient.GetContainerReference(string.Format("test-input-{0}", _testId)); TestInputContainer.CreateIfNotExists(); TestOutputContainer = BlobClient.GetContainerReference(string.Format("test-output-{0}", _testId)); TestOutputContainer.CreateIfNotExists(); TestTable = TableClient.GetTableReference("test"); TestTable.CreateIfNotExists(); DeleteEntities(TestTable, "AAA"); DeleteEntities(TestTable, "BBB"); var batch = new TableBatchOperation(); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "001", Region = "West", Name = "Test Entity 1", Status = 0 }); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "002", Region = "East", Name = "Test Entity 2", Status = 1 }); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "003", Region = "West", Name = "Test Entity 3", Status = 1 }); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "004", Region = "West", Name = "Test Entity 4", Status = 1 }); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "005", Region = "East", Name = "Test Entity 5", Status = 0 }); TestTable.ExecuteBatch(batch); batch = new TableBatchOperation(); batch.Insert(new TestEntity { PartitionKey = "BBB", RowKey = "001", Region = "South", Name = "Test Entity 1", Status = 0 }); batch.Insert(new TestEntity { PartitionKey = "BBB", RowKey = "002", Region = "West", Name = "Test Entity 2", Status = 1 }); batch.Insert(new TestEntity { PartitionKey = "BBB", RowKey = "003", Region = "West", Name = "Test Entity 3", Status = 0 }); TestTable.ExecuteBatch(batch); string serviceBusQueueName = string.Format("test-input-{0}", _testId); string connectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.ServiceBus); var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); namespaceManager.DeleteQueue(serviceBusQueueName); namespaceManager.CreateQueue(serviceBusQueueName); ServiceBusQueueClient = Microsoft.ServiceBus.Messaging.QueueClient.CreateFromConnectionString(connectionString, serviceBusQueueName); }
private void CreateTestStorageEntities() { TestQueue = _queueClient.GetQueueReference("test-input"); TestQueue.CreateIfNotExists(); TestQueue.Clear(); TestContainer = _blobClient.GetContainerReference("test-output"); TestContainer.CreateIfNotExists(); }
void can_unsubscribe_messages_by_disposing() { _t1.Start(); Assert.IsOrBecomesTrue( // ReSharper disable once AccessToDisposedClosure () => Interlocked.Read(ref _messageSubscriber.MessagesHandled) == FirstTaskMax, 2000, $"Expected {FirstTaskMax} Messages, found {_messageSubscriber.MessagesHandled}"); Assert.Equal(BusMessages.Count, FirstTaskMax); Assert.True(_messageSubscriber.MessagesInOrder(), "Messages are not in order"); _messageSubscriber.Dispose(); TestQueue.Clear(); var newSubscriber = new CountedMessageSubscriber(Bus); _t2.Start(); Assert.IsOrBecomesTrue(() => BusMessages.Count == SecondTaskMax, null, $"Expected {FirstTaskMax} Messages, found {BusMessages.Count}"); Assert.IsOrBecomesTrue( // ReSharper disable once AccessToDisposedClosure () => Interlocked.Read(ref newSubscriber.MessagesHandled) == SecondTaskMax, SecondTaskMax, $"Expected {SecondTaskMax} Messages, found {newSubscriber.MessagesHandled}"); // disposed first subscriber has unsubscribed from messages, and doesn't handle second task messages. Assert.Equal(_messageSubscriber.MessagesHandled, FirstTaskMax); TestQueue.Clear(); var thirdSubscriber = new CountedMessageSubscriber(Bus); _t3.Start(); Assert.IsOrBecomesTrue(() => BusMessages.Count == ThirdTaskMax, null, $"Expected {ThirdTaskMax} Messages, found {BusMessages.Count}"); Assert.IsOrBecomesTrue( // ReSharper disable once AccessToDisposedClosure () => Interlocked.Read(ref newSubscriber.MessagesHandled) == (SecondTaskMax + ThirdTaskMax), ThirdTaskMax, $"Expected {(SecondTaskMax + ThirdTaskMax)} Messages, found {newSubscriber.MessagesHandled}"); Assert.IsOrBecomesTrue( // ReSharper disable once AccessToDisposedClosure () => Interlocked.Read(ref thirdSubscriber.MessagesHandled) == ThirdTaskMax, null, $"Expected {ThirdTaskMax} Messages, found {newSubscriber.MessagesHandled}"); Assert.Equal(newSubscriber.MessagesHandled, (SecondTaskMax + ThirdTaskMax)); Assert.Equal(thirdSubscriber.MessagesHandled, ThirdTaskMax); }
private void CreateTestStorageEntities() { string connectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.Storage); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); TestQueue = queueClient.GetQueueReference("test-input"); TestQueue.CreateIfNotExists(); TestQueue.Clear(); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); TestContainer = blobClient.GetContainerReference("test-output"); TestContainer.CreateIfNotExists(); }
public void grand_child_invokes_all_handlers_four_times() { //n.b. the number of duplications matched the number of times we have subscribed to the hierarchy //see the next test where we do not subscribe to Message // the subscription to Test Event does not matter because it tis outside the heirarchy using (var sub = new TestInheritedMessageSubscriber(Bus, false)) { var subscriber = sub; subscriber.Subscribe <Message>(subscriber); TestQueue.Clear(); Bus.Publish(new GrandChildTestDomainEvent(TestCorrelationId, ChildMsgId)); BusMessages .AssertNext <GrandChildTestDomainEvent>(TestCorrelationId) .AssertEmpty(); Assert.IsOrBecomesTrue(() => subscriber.Starving, 3000); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscriber.TestDomainEventHandleCount) == 0, 1000, $"Expected 0 Test Domain Event Handled, found {subscriber.TestDomainEventHandleCount}"); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscriber.GrandChildTestDomainEventHandleCount) == 4, 3000, $"Expected 4 GrandChildTestDomainEvent handled , found {subscriber.ChildTestDomainEventHandleCount}"); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscriber.ChildTestDomainEventHandleCount) == 4, 3000, $"Expected 4 ChildTestDomainEvent handled , found {subscriber.ChildTestDomainEventHandleCount}"); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscriber.ParentTestDomainEventHandleCount) == 4, 3000, $"Expected 4 Parent Test Domain Event handled, found {subscriber.ParentTestDomainEventHandleCount}"); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscriber.MessageHandleCount) == 4, 3000, $"Expected 4 Message Test Domain Event handled, found {subscriber.MessageHandleCount}"); } }
public void can_clear_all_messages() { var msg1 = new TestMessage(); var msg2 = new TestMessage(); var msg3 = new TestMessage(); var msgs = new Queue <Message>(); msgs.Enqueue(msg1); msgs.Enqueue(msg2); msgs.Enqueue(msg3); _bus.Publish(msg1); _bus.Publish(msg2); _bus.Publish(msg3); _queue.Clear(); Assert.Equal(0, _queue.Messages.Count); Assert.Empty(_queue.Messages); }
public void can_handle_all_messages() { TestQueue.Clear(); var cmdHandler = new TestCommandSubscriber(Bus); // this is just an example command - choice to fire this one was random var cmd = new TestCommands.TestCommand2( Guid.NewGuid(), null); Bus.Fire(cmd, "exception message", TimeSpan.FromSeconds(5)); Assert.IsOrBecomesTrue( () => BusMessages.Count == 3, 1000, $"Expected 3 bus messages for TestCommand2, found {BusMessages.Count}"); Message deQdMsg; if (BusMessages.TryDequeue(out deQdMsg)) { Assert.IsAssignableFrom <Message>(deQdMsg); } if (BusMessages.TryDequeue(out deQdMsg)) { Assert.IsAssignableFrom <Message>(deQdMsg); } if (BusMessages.TryDequeue(out deQdMsg)) { Assert.IsAssignableFrom <Message>(deQdMsg); } }
protected virtual void CreateTestStorageEntities() { TestQueue = QueueClient.GetQueueReference(string.Format("test-input-{0}", FixtureId)); TestQueue.CreateIfNotExists(); TestQueue.Clear(); // This queue name should really be suffixed by -fsharp, -csharp, -node etc. MobileTablesQueue = QueueClient.GetQueueReference("mobiletables-input"); MobileTablesQueue.CreateIfNotExists(); // do not clear this queue since it is currently shared between fixtures TestInputContainer = BlobClient.GetContainerReference(string.Format("test-input-{0}", FixtureId)); TestInputContainer.CreateIfNotExists(); // Processing a large number of blobs on startup can take a while, // so let's start with an empty container. TestHelpers.ClearContainer(TestInputContainer); TestOutputContainer = BlobClient.GetContainerReference(string.Format("test-output-{0}", FixtureId)); TestOutputContainer.CreateIfNotExists(); TestHelpers.ClearContainer(TestOutputContainer); TestTable = TableClient.GetTableReference("test"); TestTable.CreateIfNotExists(); DeleteEntities(TestTable, "AAA"); DeleteEntities(TestTable, "BBB"); var batch = new TableBatchOperation(); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "001", Region = "West", Name = "Test Entity 1", Status = 0 }); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "002", Region = "East", Name = "Test Entity 2", Status = 1 }); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "003", Region = "West", Name = "Test Entity 3", Status = 1 }); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "004", Region = "West", Name = "Test Entity 4", Status = 1 }); batch.Insert(new TestEntity { PartitionKey = "AAA", RowKey = "005", Region = "East", Name = "Test Entity 5", Status = 0 }); TestTable.ExecuteBatch(batch); batch = new TableBatchOperation(); batch.Insert(new TestEntity { PartitionKey = "BBB", RowKey = "001", Region = "South", Name = "Test Entity 1", Status = 0 }); batch.Insert(new TestEntity { PartitionKey = "BBB", RowKey = "002", Region = "West", Name = "Test Entity 2", Status = 1 }); batch.Insert(new TestEntity { PartitionKey = "BBB", RowKey = "003", Region = "West", Name = "Test Entity 3", Status = 0 }); TestTable.ExecuteBatch(batch); string serviceBusQueueName = string.Format("test-input-{0}", FixtureId); string connectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.ServiceBus); var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); namespaceManager.DeleteQueue(serviceBusQueueName); namespaceManager.CreateQueue(serviceBusQueueName); ServiceBusQueueClient = Microsoft.ServiceBus.Messaging.QueueClient.CreateFromConnectionString(connectionString, serviceBusQueueName); }
public virtual void ClearQueues() { RepositoryQueue.Clear(); TestQueue.Clear(); }