public void IsAddressedTo_WhenNotificationWasNotAddressed_Throws(
     INotificationListener listener,
     EventStreamUpdated notification,
     EventStreamReaderId consumerId)
 {
     Assert.Throws <InvalidOperationException>(() => notification.IsAddressedTo(listener));
 }
 public void RedeliverTo_WhenNotificationWasNotDelivered_DoesNotTouchDecreasesDeliveryCount(
     INotificationListener listener,
     EventStreamUpdated notification,
     EventStreamReaderId consumerId)
 {
     Assert.Equal(0, notification.RedeliverTo(listener).DeliveryCount);
 }
 public async Task CreateSubscriptionConsumerAsync_WhenSubscriptionWasNotStarted_Throws(
     [Frozen] EventStreamReaderId consumerId,
     NotificationListenerSubscription subscription,
     string streamName)
 {
     await Assert.ThrowsAsync <InvalidOperationException>(
         () => subscription.CreateSubscriptionConsumerAsync(streamName));
 }
        public void SendTo_ChangesNotificationId(
            INotificationListener listener,
            EventStreamUpdated notification,
            EventStreamReaderId consumerId)
        {
            var addressedNotification = notification.SendTo(listener);

            Assert.NotEqual(notification.NotificationId, addressedNotification.NotificationId);
        }
        public void SendTo_WhenMessagHasBeenAddressedToTheSameConsumer_ReturnsItself(
            INotificationListener listener,
            EventStreamUpdated notification,
            EventStreamReaderId consumerId)
        {
            var addressedNotification = notification.SendTo(listener);

            Assert.Same(addressedNotification, addressedNotification.SendTo(listener));
        }
 public void IsAddressedTo_WhenRecipientSpecifiedDirectly_ReturnsTrue(
     INotificationListener listener,
     EventStreamUpdated notification,
     EventStreamReaderId consumerId)
 {
     Assert.True(notification
                 .SendTo(listener)
                 .IsAddressedTo(listener));
 }
        public void RedeliverTo_DecreasesDeliveryCount(
            INotificationListener listener,
            EventStreamUpdated notification,
            EventStreamReaderId consumerId)
        {
            SaveAndRestore(notification);

            Assert.Equal(0, notification.RedeliverTo(listener).DeliveryCount);
        }
Beispiel #8
0
        public ConsumerDescription(StreamVersion streamVersion, string consumerName, EventStreamReaderId consumerId)
        {
            Require.NotNull(streamVersion, nameof(streamVersion));
            Require.NotEmpty(consumerName, nameof(consumerName));
            Require.NotNull(consumerId, nameof(consumerId));

            StreamVersion = streamVersion;
            ConsumerName  = consumerName;
            ConsumerId    = consumerId;
        }
        public StreamReaderDescription(string streamName, EventStreamReaderId streamReaderId, StreamVersion streamVersion)
        {
            Require.NotEmpty(streamName, nameof(streamName));
            Require.NotNull(streamReaderId, nameof(streamReaderId));
            Require.NotNull(streamVersion, nameof(streamVersion));

            StreamName     = streamName;
            StreamReaderId = streamReaderId;
            StreamVersion  = streamVersion;
        }
        public void SendTo_WhenMessagHasBeenAddressedToTheSameConsumer_SavesId(
            INotificationListener listener,
            EventStreamUpdated notification,
            EventStreamReaderId consumerId)
        {
            var addressedNotification = notification.SendTo(listener);

            Assert.Equal(
                addressedNotification.NotificationId,
                addressedNotification.SendTo(listener).NotificationId);
        }
Beispiel #11
0
        private async Task <EventStreamReaderId> QueryConsumerId(string consumerName)
        {
            var query = m_consumerMetadataTable.PrepareEntityPointQuery(
                partitionKey: Constants.StorageEntities.MetadataTable.EVENT_STREAM_CONSUMERS_IDS_PK,
                rowKey: consumerName);

            var result = await query.ExecuteAsync();

            return(EventStreamReaderId.Parse(
                       (string)result[Constants.StorageEntities.MetadataTableProperties.EVENT_STREAM_READER_ID]));
        }
Beispiel #12
0
        public IEventStreamConsumingSession CreateSession(EventStreamReaderId readerId, string streamName)
        {
            Require.NotNull(readerId, "readerId");
            Require.NotEmpty(streamName, "streamName");

            return(new EventStreamConsumingSession(
                       streamName,
                       readerId,
                       TimeSpan.FromMinutes(Constants.Settings.SESSION_LOCK_TIMEOUT_MINUTES),
                       m_sessionsBlob));
        }
 public void AddressedNotification_WhenRecipientIsDifferent_ReturnsFalse(
     ListenerType1 listener1,
     ListenerType2 listener2,
     EventStreamUpdated notification,
     EventStreamReaderId originalConsumer,
     EventStreamReaderId sendedConsumer)
 {
     Assert.False(notification
                  .SendTo(listener1)
                  .IsAddressedTo(listener2));
 }
Beispiel #14
0
        public async Task InserStreamReaderPropertiesAsync(string streamName, EventStreamReaderId readerId, StreamVersion version)
        {
            var operation = m_table.PrepareBatchOperation();

            operation.Insert(
                streamName,
                "RDR|" + readerId,
                EventJournalTableRowPropertyNames.Version,
                (int)version);

            await operation.ExecuteAsync();
        }
        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 void CreateSubscriptionConsumerAsync_WhenSubscriptionWasStarted_UseConnection(
            [Frozen] EventStreamReaderId consumerId,
            Mock <IEventStoreConnection> connectionMock,
            NotificationListenerSubscription subscription,
            string streamName)
        {
            subscription.Start(connectionMock.Object);

            subscription.CreateSubscriptionConsumerAsync(streamName);

            connectionMock.Verify(self => self.CreateStreamConsumerAsync(
                                      It.IsAny <Action <IEventStreamConsumerConfiguration> >()));
        }
        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);
        }
Beispiel #18
0
        public async Task <Option <string> > TryGetNameAsync(EventStreamReaderId eventStreamReaderId)
        {
            Require.NotNull(eventStreamReaderId, nameof(eventStreamReaderId));

            var query = m_consumerMetadataTable.PrepareEntityPointQuery(
                Constants.StorageEntities.MetadataTable.EVENT_STREAM_CONSUMERS_IDS_PK,
                eventStreamReaderId.ToString());

            var result = await query.ExecuteAsync();

            return(result
                   .MayBe()
                   .Select(row => row[Constants.StorageEntities.MetadataTableProperties.EVENT_STREAM_CONSUMER_NAME].ToString()));
        }
        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());
        }
Beispiel #20
0
        public EventStreamConsumingSession(
            string streamName,
            EventStreamReaderId consumerId,
            TimeSpan leaseTimeout,
            ICloudBlobContainer blobContainer)
        {
            Require.NotEmpty(streamName, "streamName");
            Require.NotNull(consumerId, "consumerId");
            Require.NotNull(blobContainer, "blobContainer");

            m_streamName    = streamName;
            m_consumerId    = consumerId;
            m_leaseTimeout  = leaseTimeout;
            m_blobContainer = blobContainer;
        }
        public PersistentEventStreamReaderFactory(
            EventStreamReaderId readerId,
            IEventJournal journal,
            IEventStoreConnectionState connectionState,
            IEventMutationPipeline mutationPipeline,
            EventStreamConsumerConfiguration configuration)
        {
            Require.NotNull(readerId, "readerId");
            Require.NotNull(journal, "journal");
            Require.NotNull(connectionState, "connectionState");
            Require.NotNull(mutationPipeline, "mutationPipeline");
            Require.NotNull(configuration, "configuration");

            m_readerId         = readerId;
            m_journal          = journal;
            m_connectionState  = connectionState;
            m_mutationPipeline = mutationPipeline;
            m_configuration    = configuration;
        }
Beispiel #22
0
        public async Task <EventStreamReaderId> RegisterAsync(string consumerName)
        {
            Require.NotEmpty(consumerName, "consumerName");

            EventStreamReaderId consumerId;

            if (m_cache.TryGetValue(consumerName, out consumerId))
            {
                return(consumerId);
            }

            var alreadyInserted = false;

            try
            {
                consumerId = EventStreamReaderId.Create();
                await InsertConsumerId(consumerName, consumerId);
            }
            catch (BatchOperationException exception)
            {
                if (exception.HttpStatusCode != HttpStatusCode.Conflict)
                {
                    throw;
                }

                alreadyInserted = true;
            }

            if (alreadyInserted)
            {
                consumerId = await QueryConsumerId(consumerName);
            }

            m_cache.TryAdd(consumerName, consumerId);

            return(consumerId);
        }
Beispiel #23
0
        private async Task InsertConsumerId(string consumerName, EventStreamReaderId consumerId)
        {
            var operation = m_consumerMetadataTable.PrepareBatchOperation();

            operation.Insert(
                partitionKey: Constants.StorageEntities.MetadataTable.EVENT_STREAM_CONSUMERS_IDS_PK,
                rowKey: consumerName,
                properties: new Dictionary <string, object>
            {
                { Constants.StorageEntities.MetadataTableProperties.EVENT_STREAM_READER_ID, consumerId.ToString() }
            });

            operation.Insert(
                partitionKey: Constants.StorageEntities.MetadataTable.EVENT_STREAM_CONSUMERS_IDS_PK,
                rowKey: consumerId.ToString(),
                properties: new Dictionary <string, object>
            {
                {
                    Constants.StorageEntities.MetadataTableProperties.EVENT_STREAM_CONSUMER_NAME, consumerName
                }
            });

            await operation.ExecuteAsync();
        }
Beispiel #24
0
 public Task <IDictionary <string, object> > ReadStreamReaderPropertiesAsync(string streamName, EventStreamReaderId readerId)
 {
     return(ReadReferenceRowHeadAsync(streamName, "RDR|" + readerId));
 }