public void OnMessage_NotSupported() { IDeliveryQueue queue = Substitute.For <IDeliveryQueue>(); var endpoint = new OutgoingLinkEndpoint(queue); Should.Throw <NotSupportedException>(() => endpoint.OnMessage(null)); }
public async Task OnFlow_SendsMessageToReceiverLink() { var message = new Message("x") { Properties = new Properties { CorrelationId = "abc123" } }; IDeliveryQueue fakeDeliveryQueue = Substitute.For <IDeliveryQueue>(); fakeDeliveryQueue .Dequeue(Arg.Any <CancellationToken>()) .Returns(message); var endpoint = new OutgoingLinkEndpoint(fakeDeliveryQueue); ReceiverLink receiver = await TestAmqpHost.OpenAndLinkReceiverAsync(endpoint); try { receiver.SetCredit(1, CreditMode.Manual); Message receivedMessage = await receiver.ReceiveAsync(); receivedMessage.Properties.CorrelationId .ShouldBe(message.Properties.CorrelationId); } finally { await receiver.Session.Connection.CloseAsync(); } }
private void AttachOutgoingLink(AttachContext attachContext, Source source) { IEntity entity = _entityLookup.Find(source.Address); if (entity == null) { attachContext.Complete(new Error(ErrorCode.NotFound) { Description = "Entity not found." }); _logger.LogError($"Could not attach outgoing link to non-existing entity '{source.Address}'."); return; } DeliveryQueue queue = entity.DeliveryQueue; if (queue == null) { attachContext.Complete(new Error(ErrorCode.NotFound) { Description = "Queue not found." }); _logger.LogError($"Could not attach outgoing link to non-existing queue '{source.Address}'."); return; } var outgoingLinkEndpoint = new OutgoingLinkEndpoint(queue); attachContext.Complete(outgoingLinkEndpoint, 0); _logger.LogDebug($"Attached outgoing link to queue '{source.Address}'."); }
public void OnFlow_CancelsPreviousTask_WhenCalledMultipleTimes() { ListenerLink link = Construct.Uninitialized <ListenerLink>(); FlowContext flowContext = Construct.ForPrivate <FlowContext>(link, 1, new Fields()); IDeliveryQueue queue = Substitute.For <IDeliveryQueue>(); var endpoint = new OutgoingLinkEndpoint(queue); endpoint.OnFlow(flowContext); Should.NotThrow(() => endpoint.OnFlow(flowContext)); }
public void OnLinkClosed_CancelsSendingMessages() { var backingQueue = new BlockingCollection <Message>(new ConcurrentQueue <Message>()); ListenerLink link = Construct.Uninitialized <ListenerLink>(); FlowContext flowContext = Construct.ForPrivate <FlowContext>(link, 1, new Fields()); IDeliveryQueue queue = Substitute.For <IDeliveryQueue>(); queue.Dequeue(Arg.Any <CancellationToken>()) .Returns(ci => backingQueue.Take(ci.Arg <CancellationToken>())); var endpoint = new OutgoingLinkEndpoint(queue); endpoint.OnFlow(flowContext); endpoint.OnLinkClosed(null, null); backingQueue.Add(new Message()); Thread.Sleep(10); backingQueue.Count.ShouldBe(1); }
public void OnDisposition_CallsIDeliveryQueueProcess() { var message = new Message(); message.InitializePrivateProperty("Delivery"); IDeliveryQueue queue = Substitute.For <IDeliveryQueue>(); DispositionContext dispositionContext = Construct.ForPrivate <DispositionContext>( Construct.Uninitialized <ListenerLink>(), message, new Accepted(), true ); var endpoint = new OutgoingLinkEndpoint(queue); endpoint.OnDisposition(dispositionContext); queue.Received(1).Process(dispositionContext); dispositionContext.State.ShouldBe(ContextState.Completed); }
public async Task OnFlow_StartsSendingMessagesAsynchronously() { var backingQueue = new BlockingCollection <Message>(new ConcurrentQueue <Message>()); ListenerLink link = Construct.Uninitialized <ListenerLink>(); FlowContext flowContext = Construct.ForPrivate <FlowContext>(link, 1, new Fields()); IDeliveryQueue queue = Substitute.For <IDeliveryQueue>(); queue.Dequeue(Arg.Any <CancellationToken>()) .Returns(ci => backingQueue.Take(ci.Arg <CancellationToken>())); var endpoint = new OutgoingLinkEndpoint(queue); endpoint.OnFlow(flowContext); backingQueue.Add(new Message()); await Task.Delay(500); queue.Received(1).Dequeue(Arg.Any <CancellationToken>()); backingQueue.ShouldBeEmpty(); }