예제 #1
0
        public async Task SubscriptionWorker_ConnectionDroppedAndIsRestablished()
        {
            CancellationToken cancellationToken = CancellationToken.None;

            SubscriptionWorker sw = SubscriptionWorker.CreateConcurrentSubscriptionWorker(this.EventStoreConnectionString,
                                                                                          this.domainEventHandlerResolver.Object,
                                                                                          this.SubscriptionRepository,
                                                                                          200,
                                                                                          1).UseInMemory();

            await sw.StartAsync(cancellationToken);

            //Give our service time to run
            await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);

            sw.IsRunning.ShouldBeTrue();

            var connected     = sw.GetPersistentSubscription();
            var originalCount = connected.Count;

            //Drop the connection
            connected[0].SubscriptionDropped("Test");

            var stillConnected = sw.GetPersistentSubscription();

            stillConnected.Count().ShouldBe(originalCount - 1); //One less than original

            //Wait for n seconds on reconnect
            await Task.Delay(TimeSpan.FromSeconds(2), cancellationToken);

            stillConnected = sw.GetPersistentSubscription();
            stillConnected.Count().ShouldBe(originalCount); //One less than original
        }
예제 #2
0
        public async Task SubscriptionWorker_CanBeStartedAndStopped()
        {
            CancellationToken  cancellationToken = CancellationToken.None;
            SubscriptionWorker sw = SubscriptionWorker.CreateConcurrentSubscriptionWorker(this.EventStoreConnectionString,
                                                                                          this.domainEventHandlerResolver.Object,
                                                                                          this.SubscriptionRepository).UseInMemory();

            await sw.StartAsync(cancellationToken);

            //Give our service time to run
            await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);

            sw.IsRunning.ShouldBeTrue();

            await sw.StopAsync(cancellationToken);

            sw.IsRunning.ShouldBe(false);

            var stillConnected = sw.GetPersistentSubscription().Count;

            stillConnected.ShouldBe(0);
        }
예제 #3
0
        public async Task SubscriptionWorker_CanBeCreatedAndReceiveEvents()
        {
            CancellationToken      cancellationToken = CancellationToken.None;
            TestDomainEventHandler eventHandler1     = new();
            Int32 inflight         = 200;
            Int32 pollingInSeconds = 60;

            this.domainEventHandlerResolver.Setup(d => d.GetDomainEventHandlers(It.IsAny <IDomainEvent>())).Returns(new List <IDomainEventHandler>()
            {
                eventHandler1
            });

            SubscriptionWorker sw = SubscriptionWorker.CreateConcurrentSubscriptionWorker(this.EventStoreConnectionString,
                                                                                          this.domainEventHandlerResolver.Object,
                                                                                          this.SubscriptionRepository,
                                                                                          inflight,
                                                                                          pollingInSeconds).UseInMemory();

            await sw.StartAsync(cancellationToken);

            //Give our service time to run
            await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);

            sw.IsRunning.ShouldBeTrue();

            PersistentSubscription ps = sw.GetPersistentSubscription()[0];

            String @event = "{\r\n  \"estateId\": \"4fc2692f-067a-443e-8006-335bf2732248\",\r\n  \"estateName\": \"Demo Estate\"\r\n}\t";

            ps.Connected.ShouldBeTrue();
            ps.PersistentSubscriptionDetails.InflightMessages.ShouldBe(inflight);

            //Manually add events.
            ((InMemoryPersistentSubscriptionsClient)ps.PersistentSubscriptionsClient).WriteEvent(@event, "EstateCreatedEvent", cancellationToken);

            eventHandler1.DomainEvents.Count.ShouldBe(1);
        }