Пример #1
0
        public async Task ValidateAppToken_ApplicationDoesntExist()
        {
            // Arrange
            var applicationToken = Guid.NewGuid();

            A.CallTo(() => _dataStore.GetRegisteredApplicationAsync(applicationToken))
            .Returns(Task.FromResult((RegisteredApplication)null));

            // Act
            async Task Action() => await _sut.ValidateApplicationTokenAsync(applicationToken);

            // Assert
            await Assert.ThrowsAsync <RegisteredApplicationNotFoundException>(Action);
        }
        public async Task Subscription_ValidateAppToken()
        {
            // Arrange
            var appToken = Guid.NewGuid();

            A.CallTo(() => _validateApplicationTokenService.ValidateApplicationTokenAsync(appToken))
            .Returns(new RegisteredApplication());

            // Act
            await _sut.SubscribeAsync(new ServiceSubscription()
            {
                ApplicationToken = appToken
            });

            // Assert
            A.CallTo(() => _validateApplicationTokenService.ValidateApplicationTokenAsync(appToken))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
        public async Task Heartbeat_ValidateAppToken()
        {
            // Arrange
            var serviceSubscription = new ServiceSubscription
            {
                ApplicationToken = Guid.NewGuid()
            };

            A.CallTo(() => _validateApplicationTokenService.ValidateApplicationTokenAsync(serviceSubscription.ApplicationToken))
            .Returns(Task.FromResult(new RegisteredApplication()));

            // Act
            await _sut.Thump(serviceSubscription);

            // Assert
            A.CallTo(() => _validateApplicationTokenService.ValidateApplicationTokenAsync(serviceSubscription.ApplicationToken))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
Пример #4
0
        public async Task <CompassResult> RouteRequest(CompassEvent compassEvent)
        {
            await _validateApplicationTokenService.ValidateApplicationTokenAsync(compassEvent.ApplicationToken);

            var subscriptions =
                await _getServiceSubscriptionsForEventService.GetServiceSubscriptionsAsync(compassEvent);

            _kafkaProducerService.Produce(compassEvent);

            return(await SendToSubscriptionsAsync(compassEvent, subscriptions));
        }
Пример #5
0
        public async Task Thump(ServiceSubscription serviceSubscription)
        {
            var registeredApplication = await _validateApplicationTokenService.ValidateApplicationTokenAsync(serviceSubscription.ApplicationToken);

            registeredApplication.LastSeen = DateTime.UtcNow;
            await _dataStore.UpsertAsync(registeredApplication);

            var subscription = await GetServiceSubscription(serviceSubscription);

            var subscriptionTtl = _compassEnvironment.GetSubscriptionTtl();
            await _dataStore.UpsertAsync(subscription, subscriptionTtl);
        }
        public async Task RouteRequest_ValidateAppToken()
        {
            // Arrange
            var appToken = Guid.NewGuid();
            var compassEvent = new CompassEvent() { EventName = "test", ApplicationToken = appToken };
            var subscriptions = new List<ServiceSubscription>
            {
                new ServiceSubscription()
            };
            A.CallTo(() => _getServiceSubscriptionsForEventService.GetServiceSubscriptionsAsync(compassEvent))
             .Returns(subscriptions);

            // Act
            await _sut.RouteRequest(compassEvent);

            // Assert
            A.CallTo(() => _validateApplicationTokenService.ValidateApplicationTokenAsync(appToken))
             .MustHaveHappened(Repeated.Exactly.Once);
        }
Пример #7
0
        public async Task <ServiceSubscription> SubscribeAsync(ServiceSubscription serviceSubcription)
        {
            var registeredApplication =
                await _validateApplicationTokenService.ValidateApplicationTokenAsync(
                    serviceSubcription.ApplicationToken);

            var subscription = await SaveSubscriptionAsync(serviceSubcription);

            var updateTask = UpdateLastSeenAsync(registeredApplication);

            // TODO: Determine if we should replay events...
            // TODO: How do we prevent duplicate data while replaying events?
            // This could happen if Service A went down, and Service B, listening
            // to the same event is still up when Service A comes back up. It will
            // receive the the event a second time.
            var replayTask = _replayQueuedEventsService.ReplayQueuedEvents(serviceSubcription);

            await Task.WhenAll(new List <Task> {
                replayTask, updateTask
            });

            return(subscription);
        }