public void AskToIntegrateFailsIfUnableToLock() { var project = new ProjectStub(); var queue = new TestQueue(); var context = new IntegrationContext(project); queue.Lock(); Assert.Throws<Exception>(() => queue.AskToIntegrate(context)); }
public void CompletingAnIntegrationFailsIfUnableToLock() { var project = new ProjectStub(); var queue = new TestQueue(); var context = new IntegrationContext(project); queue.AskToIntegrate(context); queue.Lock(); Assert.Throws<Exception>(context.Complete); }
public void TestArrayResize() { const int initCapacity = DataStructures.Queue <int?> .InitCapacity; Assert.Equal(initCapacity, TestQueue.Capacity); TestQueue.Enqueue(1); TestQueue.Enqueue(2); TestQueue.Enqueue(3); TestQueue.Enqueue(4); Assert.Equal(initCapacity, TestQueue.Capacity); TestQueue.Enqueue(5); Assert.Equal(initCapacity * 2, TestQueue.Capacity); }
public void can_wait_for_a_specific_message() { using (var tq = new TestQueue(_dispatcher)) { var evt = new TestEvent(); var evt2 = new TestEvent(); _dispatcher.Publish(evt); _dispatcher.Publish(evt2); tq.WaitForMsgId(evt2.MsgId, TimeSpan.FromMilliseconds(200)); tq.AssertNext <TestEvent>(evt.CorrelationId) .AssertNext <TestEvent>(evt2.CorrelationId) .AssertEmpty(); } }
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 TestEnqueue() { PopulateTestQueue(); Assert.Equal(SampleSize, TestQueue.Count); int currentValue = 2; do { Assert.Equal(currentValue, TestQueue.Dequeue()); currentValue++; } while (TestQueue.Count > 0); TestQueue.Enqueue(null); Assert.Null(TestQueue.Dequeue()); }
public void can_wait_for_multiple_messages_of_a_type() { using (var tq = new TestQueue(_dispatcher)) { var evt = new TestEvent(); var evt2 = new TestEvent(); _dispatcher.Publish(evt); _dispatcher.Publish(evt2); tq.WaitForMultiple <TestEvent>(2, TimeSpan.FromMilliseconds(100)); Assert.Throws <TimeoutException>(() => tq.WaitForMultiple <TestEvent>(3, TimeSpan.FromMilliseconds(100))); tq.AssertNext <TestEvent>(evt.CorrelationId) .AssertNext <TestEvent>(evt2.CorrelationId) .AssertEmpty(); } }
public void will_not_cross_cancel() { TestQueue.WaitFor <TestTokenCancellableCmd>(TimeSpan.FromSeconds(2)); TokenSource1.Cancel(); Handler.ParkedMessages[Cmd1.MsgId].Set(); TestQueue.WaitFor <Canceled>(TimeSpan.FromSeconds(2)); Handler.ParkedMessages[Cmd2.MsgId].Set(); TestQueue.WaitFor <Success>(TimeSpan.FromSeconds(3)); TestQueue.Commands .AssertNext <TestTokenCancellableCmd>(_ => true) .AssertNext <TestTokenCancellableCmd>(_ => true) .AssertEmpty(); TestQueue.Responses .AssertNext <Canceled>(msg => msg.SourceCommand.MsgId == Cmd1.MsgId) .AssertNext <Success>(msg => msg.SourceCommand.MsgId == Cmd2.MsgId) .AssertEmpty(); }
public void can_wait_for_a_specific_message_twice() { using (var tq = new TestQueue(_dispatcher)) { var evt = new TestEvent(); Task.Delay(50) .ContinueWith(_ => _dispatcher.Publish(evt)); Parallel.Invoke( () => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(200)), () => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(200)) ); tq.AssertNext <TestEvent>(evt.CorrelationId) .AssertEmpty(); } }
public void slow_commands_should_throw_timeout() { Assert.Throws <CommandTimedOutException>( () => Bus.Fire(new TestCommands.TimeoutTestCommand(Guid.NewGuid(), null)) ); Assert.IsOrBecomesTrue(() => Interlocked.Read(ref gotCmd1) == 1, msg: "Expected Cmd1 handled"); TestQueue.WaitFor <TestCommands.TimeoutTestCommand>(TimeSpan.FromMilliseconds(2000)); TestQueue.WaitFor <Canceled>(TimeSpan.FromMilliseconds(2000)); TestQueue.Commands .AssertNext <TestCommands.TimeoutTestCommand>(_ => true) .AssertEmpty(); TestQueue.Responses .AssertNext <Canceled>(msg => msg.Exception is CommandCanceledException) .AssertEmpty(); }
public void TestDequeue() { PopulateTestQueue(); Assert.Equal(SampleSize, TestQueue.Count); int currentValue = 2; int queueCount = SampleSize; do { Assert.Equal(currentValue, TestQueue.Dequeue()); currentValue++; queueCount--; Assert.Equal(queueCount, TestQueue.Count); } while (TestQueue.Count > 0); Assert.Empty(TestQueue); }
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 TestCopyTo() { PopulateTestQueue(); int?[] copyArray = new int?[SampleSize + 1]; TestQueue.CopyTo(copyArray, 1); for (int i = 1; i < copyArray.Length; i++) { Assert.Equal(TestQueue.Dequeue(), copyArray[i]); } PopulateTestQueue(); int?[] smallList = new int?[TestQueue.Count / 2]; int?[] largeList = new int?[TestQueue.Count * 2]; Assert.Throws <IndexOutOfRangeException>(() => TestQueue.CopyTo(largeList, -1)); Assert.Throws <ArgumentOutOfRangeException>(() => TestQueue.CopyTo(smallList, 0)); Assert.Throws <ArgumentOutOfRangeException>(() => TestQueue.CopyTo(largeList, largeList.Length - 2)); }
public async Task Refresh_Works_NoEvent(FFXIVRole role) { var queue = new TestQueue(); var enqueuedSlot = new QueueSlot(UserId, "", new List <ulong>()) { QueueTime = DateTime.UtcNow.AddHours(-4).AddMinutes(-45), }; queue.AddSlot(enqueuedSlot, role); await Task.Delay(1000); var now = DateTime.UtcNow; queue.Refresh(UserId); var dequeuedSlot = queue.GetAllSlots().First(); Assert.AreEqual(now.Hour, dequeuedSlot.QueueTime.Hour); Assert.AreEqual(now.Minute, dequeuedSlot.QueueTime.Minute); }
public void can_get_all_messages_from_queue() { using (var tq = new TestQueue(_dispatcher)) { var evt = new TestEvent(); var cmd = new TestCommands.Command1(); _dispatcher.Publish(evt); _dispatcher.Send(cmd); tq.WaitFor <CommandResponse>(TimeSpan.FromMilliseconds(100)); tq.WaitFor <Success>(TimeSpan.FromMilliseconds(100)); Assert.Throws <TimeoutException>(() => tq.WaitFor <Fail>(TimeSpan.FromMilliseconds(10))); tq.AssertNext <TestEvent>(evt.CorrelationId) .AssertNext <AckCommand>(cmd.CorrelationId) .AssertNext <Success>(cmd.CorrelationId) .AssertNext <TestCommands.Command1>(cmd.CorrelationId) .AssertEmpty(); } }
public void commands_are_not_logged() { TestQueue.WaitFor <TestCommands.TestCommand3>(TimeSpan.FromSeconds(5)); // Wait for last command to be queued // // Wait for last event to be queued Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _multiFireCount > 0, 1000, $"Commands logged to ES when logging should be disabled - {_multiFireCount}")); Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _testCommandCount == 1, 1000, $"Last command logged to ES when logging should be disabled")); Assert.False(_multiFireCount == _maxCountedCommands, $"Command count {_multiFireCount} doesn't match expected index {_maxCountedCommands}"); Assert.False(_testCommandCount == 1, $"Last event count {_testCommandCount} doesn't match expected value {1}"); }
public static void ExampleTestQueue() { ITestProvider testProvider = new TestProvider(); testProvider.Model = "7482-5194-2849-1943-2448"; testProvider.Method = "com.example.test.Demo.typeString"; TestQueue queue = testProvider.QueueNWise(); Console.WriteLine(queue); // DEBUG Thread.Sleep(2000); // DEBUG Console.WriteLine(queue); // DEBUG foreach (TestCaseData element in queue) { Console.WriteLine("HANDLER: [{0}]", string.Join(", ", element.Arguments)); } Console.WriteLine(queue); // DEBUG }
public void events_are_not_logged() { // wait for all events to be queued TestQueue.WaitFor <TestDomainEvent>(TimeSpan.FromSeconds(5)); //// Need the "is or becomes" here because if the handler (see below) is executed, it takes time. // see the enabled test Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _countedEventCount > 0, 1000, $"Found {_countedEventCount} CountedEvents on log")); Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _testDomainEventCount > 0, 1000, $"Found {_testDomainEventCount} TestDomainEvents on log")); // counters are never incremented because they are not logged, therefore not "heard" by the repo listener Assert.False(_countedEventCount == _maxCountedEvents, $"{_countedEventCount} CountedEvents found on Log"); Assert.True(_testDomainEventCount == 0, $"Last event count {_testDomainEventCount} is not 0"); }
public async Task QueueOnExitCalledEvenIfNextErrors() { var flag = false; var testQueue = new TestQueue( onTryEnter: (_) => true, onExit: () => { flag = true; }); var middleware = TestUtils.CreateTestMiddleware( queue: testQueue, next: httpContext => { throw new DivideByZeroException(); }); Assert.Equal(0, testQueue.QueuedRequests); await Assert.ThrowsAsync <DivideByZeroException>(() => middleware.Invoke(new DefaultHttpContext())).DefaultTimeout(); Assert.Equal(0, testQueue.QueuedRequests); Assert.True(flag); }
public void can_wait_for_multiple_messages_not_yet_recieved() { using (var tq = new TestQueue(_dispatcher)) { var evt = new TestEvent(); var evt2 = new TestEvent(); Task.Delay(50) .ContinueWith(_ => { _dispatcher.Publish(evt); _dispatcher.Publish(evt2); }); tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(200)); tq.WaitForMsgId(evt2.MsgId, TimeSpan.FromMilliseconds(200)); tq.AssertNext <TestEvent>(evt.CorrelationId) .AssertNext <TestEvent>(evt2.CorrelationId) .AssertEmpty(); } }
public void can_subscribe_to_all() { foreach (var repo in _repos) { var r = repo as MockEventStoreRepository; if (r == null) { continue; } var q = new TestQueue(); r.Subscribe(q); var id = Guid.NewGuid(); var tAgg = new TestAggregate(id); tAgg.RaiseBy(1); tAgg.RaiseBy(1); tAgg.RaiseBy(1); repo.Save(tAgg, Guid.NewGuid(), h => { }); Assert.Equal(4, q.Messages.Count); } }
public async Task DequeueThings(CancellationToken cancel) { Debug.WriteLine("DEQUEUE cancel? " + cancel.IsCancellationRequested); while (cancel.IsCancellationRequested == false) { string thingy = ""; if (TestQueue.TryPeekAwait(out thingy)) { await Task.Delay(50); TestQueue.TryDequeue(out thingy); OutputText = "dequeued: " + thingy + " queue count: " + TestQueue.Count(); Debug.WriteLine("dequeued: " + thingy); } if (TestQueue.Count() == 0) { Debug.WriteLine("cancel"); source2.Cancel(); } } }
public void EventCountersTrackQueuedRequests() { var blocker = new TaskCompletionSource <bool>(); var testQueue = new TestQueue( onTryEnter: async(_) => { return(await blocker.Task); }); var middleware = TestUtils.CreateTestMiddleware(testQueue); Assert.Equal(0, testQueue.QueuedRequests); var task1 = middleware.Invoke(new DefaultHttpContext()); Assert.False(task1.IsCompleted); Assert.Equal(1, testQueue.QueuedRequests); blocker.SetResult(true); Assert.Equal(0, testQueue.QueuedRequests); }
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); } }
public void Enqueue_IsThreadSafe() { var rand = new Random(1234); var queue = new TestQueue(); var threads = new List <Thread>(); for (ulong i = 0; i < 1000; i++) { var curI = i; var nextRole = rand.Next(0, 3) switch { 0 => FFXIVRole.DPS, 1 => FFXIVRole.Healer, 2 => FFXIVRole.Tank, _ => throw new NotImplementedException(), }; var thread = new Thread(() => { Thread.Sleep(rand.Next(0, 1001)); queue.Enqueue(curI, nextRole, ""); }); thread.Start(); threads.Add(thread); } foreach (var thread in threads) { thread.Join(); } var slots = queue.GetAllSlots().ToList(); slots.Sort((a, b) => (int)a.Id - (int)b.Id); for (ulong i = 0; i < 1000; i++) { Assert.That(slots[(int)i].Id == i); } }
public void mixed_messages_are_not_logged() { // all events published, commands fired TestQueue.WaitFor <TestCommands.TestCommand3>(TimeSpan.FromSeconds(5)); // Wait for last CountedEvent to be "heard" from logger/repo - times out because events not logged Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _countedEventCount > 0, 1000, $"Found {_countedEventCount} CountedEvents on log")); Assert.True(_countedEventCount == 0, $"{_countedEventCount} CountedEvents found on Log"); // Wait for last command to be queued - times out because events not logged Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _multiFireCount > 0, 9000, $"Found {_multiFireCount} TestCommand2s on log - expected 0")); Assert.True(_multiFireCount == 0, $"Command count {_multiFireCount} expected 0"); // Wait for last TestDomainEvent to be "heard" from logger/repo - times out because events not logged Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _testDomainEventCount > 0, 1000, $"Found {_testDomainEventCount} TestDomainEvents on log, expected 0")); Assert.True(_testDomainEventCount == 0, $"Last event count {_testDomainEventCount} doesn't match expected value {1}"); Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _testCommandCount == 1, 1000, $"Found {_testCommandCount} TestCommand3s on log - expected 0")); Assert.True(_testCommandCount == 0, $"Last event count {_testCommandCount} is not 0"); }
public IAsyncResult BeginOpenLink(AmqpLink link, TimeSpan timeout, AsyncCallback callback, object state) { if (link.IsReceiver && link.Settings.Target is Coordinator) { this.txnManager.AddCoordinator((ReceivingAmqpLink)link); } else { Address address = link.IsReceiver ? ((Target)link.Settings.Target).Address : ((Source)link.Settings.Source).Address; if (address == null) { throw new AmqpException(AmqpErrorCode.InvalidField, "Address not set"); } string node = address.ToString(); TestQueue queue; lock (this.queues) { if (!this.queues.TryGetValue(node, out queue)) { if (!this.implicitQueue) { throw new AmqpException(AmqpErrorCode.NotFound, string.Format("Node '{0}' not found", address)); } queue = new TestQueue(this); this.queues.Add(node, queue); } } queue.CreateClient(link); } return(new CompletedAsyncResult(callback, state)); }
public void ExpireEvent_Works_Event() { var rand = new Random(1234); var queue = new TestQueue(); for (ulong i = 0; i < 1000; i++) { var nextRole = rand.Next(0, 3) switch { 0 => FFXIVRole.DPS, 1 => FFXIVRole.Healer, 2 => FFXIVRole.Tank, _ => throw new NotImplementedException(), }; queue.Enqueue(i, nextRole, EventId); } queue.ExpireEvent(EventId); var slots = queue.GetAllSlots(); Assert.That(!slots.Any()); }
public void QueryTimeout_NoIncludeEvents_Works() { var rand = new Random(1234); var queue = new TestQueue(); var counts = new Dictionary <FFXIVRole, int> { { FFXIVRole.DPS, 0 }, { FFXIVRole.Healer, 0 }, { FFXIVRole.Tank, 0 }, }; for (ulong i = 0; i < 1000; i++) { var nextRole = rand.Next(0, 3) switch { 0 => FFXIVRole.DPS, 1 => FFXIVRole.Healer, 2 => FFXIVRole.Tank, _ => throw new NotImplementedException(), }; counts[nextRole]++; queue.AddSlot(new QueueSlot(i, EventId) { QueueTime = DateTime.UtcNow.AddHours(-5), }, nextRole); } var roles = new[] { FFXIVRole.DPS, FFXIVRole.Healer, FFXIVRole.Tank }; var timeouts = new Dictionary <FFXIVRole, IEnumerable <ulong> >(); foreach (var role in roles) { timeouts[role] = queue.TryQueryTimeout(role, 4 * Time.Hour); } Assert.That(timeouts[FFXIVRole.DPS].Concat(timeouts[FFXIVRole.Healer]).Concat(timeouts[FFXIVRole.Tank]).Count() == 1000); Assert.That(!queue.GetAllSlots().Any()); }
public void RunNextTest(string directory) { CurrentTest = TestQueue.Dequeue(); NetworkStream stream = clientSocket.GetStream(); Console.WriteLine("Running " + CurrentTest.TestName + " ..."); SocketUtil.SendMessage(stream, "start;" + CurrentTest.TestName); SQLResponse response = RunQuerySync(CurrentTest.Query); if (response == null) { Console.WriteLine("Test " + CurrentTest.TestName + " failed :("); SocketUtil.SendMessage(stream, "reset;failed"); } else { Console.WriteLine("Test " + CurrentTest.TestName + " Passed! Execution Time: " + response.ExecutionTime + " ms"); SocketUtil.SendMessage(stream, "reset"); string jsonData = GetOrderedResult(stream); HandleResult(directory, jsonData, response); } }
public void parent_invokes_only_parent_handler_once() { using (var sub = new TestInheritedMessageSubscriber(Bus)) { var subscriber = sub; TestQueue.Clear(); Bus.Publish(new ParentTestDomainEvent(TestCorrelationId, ChildMsgId)); BusMessages .AssertNext <ParentTestDomainEvent>(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) == 0, 1000, $"Expected 0 GrandChildTestDomainEvent handled , found {subscriber.ChildTestDomainEventHandleCount}"); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscriber.ChildTestDomainEventHandleCount) == 0, 1000, $"Expected 0 ChildTestDomainEvent handled , found {subscriber.ChildTestDomainEventHandleCount}"); Assert.IsOrBecomesTrue( () => Interlocked.Read(ref subscriber.ParentTestDomainEventHandleCount) == 1, 1000, $"Expected 1 Parent Test Domain Event handled, found {subscriber.ParentTestDomainEventHandleCount}"); } }
bool IContainer.AttachLink(ListenerConnection connection, ListenerSession session, Link link, Attach attach) { Source source = attach.Source as Source; Target target = attach.Target as Target; bool dynamic = false; string address = null; if (attach.Role) { address = source.Address; dynamic = source.Dynamic; } else { if (target != null) { address = target.Address; dynamic = target.Dynamic; } else if (attach.Target is Coordinator) { this.txnManager.AddCoordinator((ListenerLink)link); return(true); } } if (dynamic) { address = string.Format("$dynamic.{0}", Interlocked.Increment(ref this.dynamidId)); if (attach.Role) { source.Dynamic = false; source.Address = address; } else { target.Address = address; target.Dynamic = false; } } TestQueue queue; lock (this.queues) { if (!this.queues.TryGetValue(address, out queue)) { if (dynamic || (this.implicitQueue && !link.Name.StartsWith("$explicit:"))) { queue = new TestQueue(this); this.queues.Add(address, queue); connection.Closed += (o, e) => this.RemoveQueue(address); } else { throw new AmqpException(ErrorCode.NotFound, string.Format("Node '{0}' not found", address)); } } } if (attach.Role) { queue.CreateConsumer((ListenerLink)link); } else { queue.CreatePublisher((ListenerLink)link); } return(true); }
public void GetPendingRequestsFailsIfUnableToLock() { var queue = new TestQueue(); queue.Lock(); Assert.Throws<Exception>(() => queue.GetPendingRequests()); }
public Consumer(TestQueue queue, ListenerLink link, int id) { this.queue = queue; this.link = link; this.id = id; link.Closed += this.OnLinkClosed; link.InitializeSender(onCredit, onDispose, this); }
public Publisher(TestQueue queue, ListenerLink link, int id) { this.queue = queue; this.link = link; this.id = id; link.Closed += this.OnLinkClosed; link.InitializeReceiver(200, onMessage, this); }
bool IContainer.AttachLink(ListenerConnection connection, ListenerSession session, Link link, Attach attach) { Source source = attach.Source as Source; Target target = attach.Target as Target; bool dynamic = false; string address = null; if (attach.Role) { address = source.Address; dynamic = source.Dynamic; } else { if (target != null) { address = target.Address; dynamic = target.Dynamic; } else if (attach.Target is Coordinator) { this.txnManager.AddCoordinator((ListenerLink)link); return true; } } if (dynamic) { address = string.Format("$dynamic.{0}", Interlocked.Increment(ref this.dynamidId)); if (attach.Role) { source.Dynamic = false; source.Address = address; } else { target.Address = address; target.Dynamic = false; } } TestQueue queue; lock (this.queues) { if (!this.queues.TryGetValue(address, out queue)) { if (dynamic || this.implicitQueue) { queue = new TestQueue(this); this.queues.Add(address, queue); connection.Closed += (o, e) => this.RemoveQueue(address); } else { throw new AmqpException(ErrorCode.NotFound, string.Format("Node '{0}' not found", address)); } } } if (attach.Role) { queue.CreateConsumer((ListenerLink)link); } else { queue.CreatePublisher((ListenerLink)link); } return true; }
public IAsyncResult BeginOpenLink(AmqpLink link, TimeSpan timeout, AsyncCallback callback, object state) { if (link.IsReceiver && link.Settings.Target is Coordinator) { this.txnManager.AddCoordinator((ReceivingAmqpLink)link); } else { string address = link.IsReceiver ? ((Target)link.Settings.Target).Address.ToString() : ((Source)link.Settings.Source).Address.ToString(); TestQueue queue; if (!this.queues.TryGetValue(address, out queue)) { if (!this.implicitQueue) { throw new AmqpException(AmqpErrorCode.NotFound, string.Format("Node '{0}' not found", address)); } queue = new TestQueue(this); this.queues.Add(address, queue); link.Closed += (s, e) => this.queues.Remove(address); } queue.CreateClient(link); } return new CompletedAsyncResult(callback, state); }
public Publisher(TestQueue queue, ReceivingAmqpLink link, int id) { this.queue = queue; this.link = link; this.id = id; this.link.RegisterMessageListener(this.OnMessage); this.link.Closed += new EventHandler(link_Closed); }
public Consumer(TestQueue queue, SendingAmqpLink link, int id) { this.queue = queue; this.link = link; this.id = id; this.link.Closed += new EventHandler(link_Closed); this.link.RegisterCreditListener(this.OnCredit); this.link.RegisterDispositionListener(this.OnDispose); }