public void IsAddressedTo_WhenNotificationWasNotAddressed_Throws( INotificationListener listener, EventStreamUpdated notification, EventStreamReaderId consumerId) { Assert.Throws <InvalidOperationException>(() => notification.IsAddressedTo(listener)); }
public void OnSubscriptionStarted_WhenSubscriptionWasStarted_Throws( StreamConsumingNotificationListenerStub listener, EventStreamUpdated notification, INotificationListenerSubscription subscription) { Assert.Throws <InvalidOperationException>(() => listener.OnSubscriptionStarted(subscription)); }
private async Task <bool> ReceiveAndProcessEventsAsync(EventStreamUpdated notification, IEventStreamConsumer consumer) { var retryProcessing = true; var commitProcessing = false; var receivingResult = await consumer.ReceiveEventsAsync(); if (receivingResult == ReceivingResultCode.EventsReceived) { var processingResult = await TryProcessEventFromConsumerAsync(consumer, notification.ToVersion); retryProcessing = !processingResult.IsSuccessful; commitProcessing = processingResult.ShouldCommitProcessing; } else if (receivingResult == ReceivingResultCode.EmptyStream) { retryProcessing = false; } if (commitProcessing) { await consumer.CommitProcessedStreamVersionAsync(); } if (retryProcessing) { ListenerLogger.Warning( "Processing notification ({NotificationId}, {NotificationType}) was unsuccessful {Code}. Going to try later.", notification.NotificationId, notification.NotificationType, receivingResult); } return(retryProcessing); }
public void RedeliverTo_WhenNotificationWasNotDelivered_DoesNotTouchDecreasesDeliveryCount( INotificationListener listener, EventStreamUpdated notification, EventStreamReaderId consumerId) { Assert.Equal(0, notification.RedeliverTo(listener).DeliveryCount); }
public async Task OnEventStreamUpdated_WhenListenerProcessingCompleted_ClosesConsumer( [Frozen] Mock <IEventStreamConsumer> consumerMock, StreamConsumingNotificationListenerStub listener, EventStreamUpdated notification) { await listener.On(notification); consumerMock.Verify(self => self.CloseAsync()); }
public async Task OnEventStreamUpdated_WhenListenerProcessingCompleted_DoesNotDefereNotification( [Frozen] Mock <INotificationListenerSubscription> subscriptionMock, StreamConsumingNotificationListenerStub listener, EventStreamUpdated notification) { await listener.On(notification); subscriptionMock.Verify(self => self.RetryNotificationProcessingAsync(notification), Times.Never()); }
public async Task OnEventStreamUpdated_WhenListenerProcessingCompleted_CommitsConsumedStreamVersion( [Frozen] Mock <IEventStreamConsumer> consumerMock, StreamConsumingNotificationListenerStub listener, EventStreamUpdated notification) { await listener.On(notification); consumerMock.Verify(self => self.CommitProcessedStreamVersionAsync(false)); }
public void IsAddressedTo_WhenRecipientSpecifiedDirectly_ReturnsTrue( INotificationListener listener, EventStreamUpdated notification, EventStreamReaderId consumerId) { Assert.True(notification .SendTo(listener) .IsAddressedTo(listener)); }
public async Task nEventStreamUpdated_WhenSubscriptionWasStopped_Throws( StreamConsumingNotificationListenerStub listener, EventStreamUpdated notification, INotificationListenerSubscription subscription) { listener.OnSubscriptionStopped(); await Assert.ThrowsAsync <InvalidOperationException>(() => listener.On(notification)); }
public void RedeliverTo_DecreasesDeliveryCount( INotificationListener listener, EventStreamUpdated notification, EventStreamReaderId consumerId) { SaveAndRestore(notification); Assert.Equal(0, notification.RedeliverTo(listener).DeliveryCount); }
public void SendTo_WhenMessagHasBeenAddressedToTheSameConsumer_ReturnsItself( INotificationListener listener, EventStreamUpdated notification, EventStreamReaderId consumerId) { var addressedNotification = notification.SendTo(listener); Assert.Same(addressedNotification, addressedNotification.SendTo(listener)); }
public async Task OnEventStreamUpdated_WhenProcessingFailed_DefersNotification( [Frozen] Mock <INotificationListenerSubscription> subscriptionMock, EventConsumingNotificationListenerStub listener, EventStreamUpdated notification) { await listener.On(notification); subscriptionMock.Verify(self => self.RetryNotificationProcessingAsync(notification), Times.Once()); }
public void SendTo_ChangesNotificationId( INotificationListener listener, EventStreamUpdated notification, EventStreamReaderId consumerId) { var addressedNotification = notification.SendTo(listener); Assert.NotEqual(notification.NotificationId, addressedNotification.NotificationId); }
public async Task NotifyAsync_SendsNotificationBytesToChannel( [Frozen] Mock <INotificationFormatter> formatterMock, [Frozen] Mock <INotificationsChannel> channelMock, NotificationHub hub, EventStreamUpdated notification) { await hub.NotifyAsync(notification); channelMock.Verify(self => self.SendAsync(notification), Times.Once()); }
public async Task HandleNotificationAsync_WhenSubscriptionDidNotStart_NotPropagatesNotificationToTheListener( [Frozen] Mock <INotificationListener> listenerMock, NotificationListenerSubscription subscription, EventStreamUpdated notification) { await subscription.HandleNotificationAsync(notification); listenerMock.Verify( self => self.On(notification), Times.Never()); }
public void AddressedNotification_WhenRecipientIsDifferent_ReturnsFalse( ListenerType1 listener1, ListenerType2 listener2, EventStreamUpdated notification, EventStreamReaderId originalConsumer, EventStreamReaderId sendedConsumer) { Assert.False(notification .SendTo(listener1) .IsAddressedTo(listener2)); }
public void SendTo_WhenMessagHasBeenAddressedToTheSameConsumer_SavesId( INotificationListener listener, EventStreamUpdated notification, EventStreamReaderId consumerId) { var addressedNotification = notification.SendTo(listener); Assert.Equal( addressedNotification.NotificationId, addressedNotification.SendTo(listener).NotificationId); }
public async Task OnEventStreamUpdated_CreatesUpdatedStreamConsumer( [Frozen] Mock <INotificationListenerSubscription> subscriptionMock, StreamConsumingNotificationListenerStub listener, EventStreamUpdated notification) { await listener.On(notification); subscriptionMock.Verify( self => self.CreateSubscriptionConsumerAsync(notification.StreamName), Times.Once()); }
public void RestoreFrom_IncreasesDeliveryCount( EventStreamUpdated notification, EventStreamReaderId consumerId) { Assert.Equal(0, notification.DeliveryCount); SaveAndRestore(notification); Assert.Equal(1, notification.DeliveryCount); SaveAndRestore(notification); Assert.Equal(2, notification.DeliveryCount); }
public async Task OnEventStreamUpdated_WhenConsumerReceiveOperationFailed_ClosesConsumer( [Frozen] Mock <IEventStreamConsumer> consumerMock, StreamConsumingNotificationListenerStub listener, EventStreamUpdated notification) { consumerMock .Setup(self => self.ReceiveEventsAsync()) .Returns(ReceivingResultCode.PromotionFailed.YieldTask()); await listener.On(notification); consumerMock.Verify(self => self.CloseAsync(), Times.Once()); }
public void SendTo_PreservesNotificationPropertiesValues( INotificationListener listener, EventStreamUpdated notification, EventStreamReaderId consumerId) { var addressedNotification = (EventStreamUpdated)notification.SendTo(listener); Assert.Equal(notification.StreamName, addressedNotification.StreamName); Assert.Equal(notification.FromVersion, addressedNotification.FromVersion); Assert.Equal(notification.ToVersion, addressedNotification.ToVersion); Assert.Equal(notification.NotificationType, addressedNotification.NotificationType); Assert.Equal(notification.DeliveryCount, addressedNotification.DeliveryCount); }
public async Task HandleNotificationAsync_WhenSubscriptionStarted_PropagatesNotificationToTheListener( [Frozen] Mock <INotificationListener> listenerMock, IEventStoreConnection connection, NotificationListenerSubscription subscription, EventStreamUpdated notification) { subscription.Start(connection); await subscription.HandleNotificationAsync(notification); listenerMock.Verify( self => self.On(notification), Times.Once()); }
public async Task OnEventStreamUpdated_WhenListenerProcessingFailed_DefersNotificationProcessing( [Frozen] Mock <INotificationListenerSubscription> subscriptionMock, [Frozen] Mock <IEventStreamConsumer> consumerMock, StreamConsumingNotificationListenerStub listener, EventStreamUpdated notification) { listener.ProcessingCompleted = false; await listener.On(notification); subscriptionMock.Verify( self => self.RetryNotificationProcessingAsync(notification), Times.Once()); }
public async Task HandleNotificationAsync_WhenNotificationNotAddressedToConsumer_PropagatesNotificationToTheListener( [Frozen] Mock <INotificationListener> listenerMock, IEventStoreConnection connection, NotificationListenerSubscription subscription, EventStreamUpdated notification, EventStreamReaderId consumerId) { subscription.Start(connection); await subscription.HandleNotificationAsync(notification.SendTo(listenerMock.Object)); listenerMock.Verify( self => self.On(notification), Times.Never()); }
public async Task OnEventStreamUpdated_WhenConsumerReceiveOperationFailed_DefersNotificationProcessing( [Frozen] Mock <INotificationListenerSubscription> subscriptionMock, [Frozen] Mock <IEventStreamConsumer> consumerMock, StreamConsumingNotificationListenerStub listener, EventStreamUpdated notification) { consumerMock .Setup(self => self.ReceiveEventsAsync()) .Returns(ReceivingResultCode.PromotionFailed.YieldTask()); await listener.On(notification); subscriptionMock.Verify( self => self.RetryNotificationProcessingAsync(notification), Times.Once()); }
public async Task On(EventStreamUpdated notification) { Require.NotNull(notification, "notification"); AssertSubscriptionWasBound(); m_processingCountdown.AddCount(); var retryProcessing = false; try { var consumer = await m_subscription.CreateSubscriptionConsumerAsync(notification.StreamName); retryProcessing = await ReceiveAndProcessEventsAsync(notification, consumer); await consumer.CloseAsync(); } catch (Exception exception) { ListenerLogger.Error( exception, "Processing notification ({NotificationId}, {NotificationType}) from {Stream} failed.", notification.NotificationId, notification.NotificationType, notification.StreamName); retryProcessing = true; } finally { m_processingCountdown.Signal(); } if (retryProcessing) { await m_subscription.RetryNotificationProcessingAsync(notification); } }
public Task On(EventStreamUpdated notification) { Notifications.Add(notification); return(TaskDone.Done); }
public Task On(EventStreamUpdated notification) { throw new NotImplementedException(); }