public void setup()
        {
            _exception = null;
            try
            {
                _point = new HeadingEventReader(10);
            }
            catch (Exception ex)
            {
                _exception = ex;
            }

            _distibutionPointCorrelationId = Guid.NewGuid();
            _point.Start(
                _distibutionPointCorrelationId,
                new TransactionFileEventReader(
                    _bus, _distibutionPointCorrelationId, new EventPosition(0, -1), new RealTimeProvider()));
            _point.Handle(
                new ProjectionCoreServiceMessage.CommittedEventDistributed(
                    _distibutionPointCorrelationId, new EventPosition(20, 10), "stream", 10, false,
                    ResolvedEvent.Sample(Guid.NewGuid(), "type", false, new byte[0], new byte[0])));
            _point.Handle(
                new ProjectionCoreServiceMessage.CommittedEventDistributed(
                    _distibutionPointCorrelationId, new EventPosition(40, 30), "stream", 11, false,
                    ResolvedEvent.Sample(Guid.NewGuid(), "type", false, new byte[0], new byte[0])));
            _subscription = new FakeProjectionSubscription();
            _projectionSubscriptionId = Guid.NewGuid();
            var subscribed = _point.TrySubscribe(_projectionSubscriptionId, _subscription, 30);
            Assert.IsTrue(subscribed); // ensure we really unsubscribing.. even if it is tested elsewhere
            _point.Unsubscribe(_projectionSubscriptionId);
        }
Ejemplo n.º 2
0
        public void Handle(ReaderSubscriptionManagement.Pause message)
        {
            if (!_pausedSubscriptions.Add(message.SubscriptionId))
            {
                throw new InvalidOperationException("Already paused projection");
            }

            IReaderSubscription projectionSubscription;

            if (!_subscriptions.TryGetValue(message.SubscriptionId, out projectionSubscription))
            {
                return; // may be already unsubscribed when self-unsubscribing
            }
            var eventReaderId = _subscriptionEventReaders[message.SubscriptionId];

            if (eventReaderId == Guid.Empty) // head
            {
                _subscriptionEventReaders.Remove(message.SubscriptionId);
                _headingEventReader.Unsubscribe(message.SubscriptionId);
                var forkedEventReaderId = Guid.NewGuid();
                var forkedEventReader   = projectionSubscription.CreatePausedEventReader(
                    _publisher, _ioDispatcher, forkedEventReaderId);
                _subscriptionEventReaders.Add(message.SubscriptionId, forkedEventReaderId);
                _eventReaderSubscriptions.Add(forkedEventReaderId, message.SubscriptionId);
                _eventReaders.Add(forkedEventReaderId, forkedEventReader);
                _publisher.Publish(
                    new EventReaderSubscriptionMessage.ReaderAssignedReader(
                        message.SubscriptionId, forkedEventReaderId));
            }
            else
            {
                _eventReaders[eventReaderId].Pause();
            }
        }
Ejemplo n.º 3
0
        public void Handle(ReaderSubscriptionManagement.Pause message)
        {
            if (!_pausedSubscriptions.Add(message.SubscriptionId))
            {
                throw new InvalidOperationException("Already paused projection");
            }
            var projectionSubscription = _subscriptions[message.SubscriptionId];
            var eventReaderId          = _subscriptionEventReaders[message.SubscriptionId];

            if (eventReaderId == Guid.Empty) // head
            {
                _subscriptionEventReaders.Remove(message.SubscriptionId);
                _headingEventReader.Unsubscribe(message.SubscriptionId);
                var forkedEventReaderId = Guid.NewGuid();
                var forkedEventReader   = projectionSubscription.CreatePausedEventReader(_publisher, forkedEventReaderId);
                _subscriptionEventReaders.Add(message.SubscriptionId, forkedEventReaderId);
                _eventReaderSubscriptions.Add(forkedEventReaderId, message.SubscriptionId);
                _eventReaders.Add(forkedEventReaderId, forkedEventReader);
                _publisher.Publish(
                    new ReaderSubscriptionManagement.ReaderAssignedReader(message.SubscriptionId, forkedEventReaderId));
            }
            else
            {
                _eventReaders[eventReaderId].Pause();
            }
        }