Esempio n. 1
0
        public void Reads_with_count_zero_sends_ReadFinished()
        {
            var reader = CreateReader();

            var req = new ReadRequest(1, 0);
            reader.Tell(req);

            ExpectMsg<ReadFinished>(m => m.RequestID == req.RequestID);
        }
Esempio n. 2
0
        public void ReadRequests_are_forwarded_to_worker()
        {
            var o = new TestContainer(this);

            var req = new ReadRequest(1, 1);
            o.Reader.Tell(req);

            o.ReadProbe.ExpectMsg<ReadRequest>(m => m == req);
        }
Esempio n. 3
0
        public void Reads_with_sequence_above_highest_sends_ReadFinished()
        {
            var reader = CreateReader();

            var req = new ReadRequest(1000, EventCount.Unlimited);
            reader.Tell(req);

            ExpectMsg<ReadFinished>(m => m.RequestID == req.RequestID);
        }
Esempio n. 4
0
        public void Reads_single_event(int sequenceToRead)
        {
            var reader = CreateReader();

            var req = new ReadRequest(sequenceToRead, 1);
            reader.Tell(req);

            ExpectMsg<ReadResponse>(m => m.RequestID == req.RequestID && m.Event.GlobalSequence == sequenceToRead);
            ExpectMsg<ReadFinished>(m => m.RequestID == req.RequestID);
        }
Esempio n. 5
0
        public void Reads_all_events()
        {
            var reader = CreateReader();
            
            var req = new ReadRequest(1, EventCount.Unlimited);

            reader.Tell(req);

            for (int i = 1; i <= TotalEvents; i++)
                ExpectMsg<ReadResponse>(m => m.RequestID == req.RequestID && m.Event.GlobalSequence == i);

            ExpectMsg<ReadFinished>(m => m.RequestID == req.RequestID);
        }
Esempio n. 6
0
        public void Receives_ReadCancelled_on_cancel_request()
        {
            var reader = CreateReader();

            var req = new ReadRequest(1, EventCount.Unlimited);
            reader.Tell(req);
            reader.Tell(new CancelRequest(req.RequestID));

            ExpectMsgEventually<Cancelled>(m => m.RequestID == req.RequestID);
        }
Esempio n. 7
0
        public void Reads_with_initialsequence_and_counts()
        {
            var reader = CreateReader();

            var req = new ReadRequest(7, 3);
            reader.Tell(req);

            ExpectMsg<ReadResponse>(m => m.RequestID == req.RequestID && m.Event.GlobalSequence == 7);
            ExpectMsg<ReadResponse>(m => m.RequestID == req.RequestID && m.Event.GlobalSequence == 8);
            ExpectMsg<ReadResponse>(m => m.RequestID == req.RequestID && m.Event.GlobalSequence == 9);
            ExpectMsg<ReadFinished>(m => m.RequestID == req.RequestID);
        }
Esempio n. 8
0
        public void Receives_ReadAborted_on_store_exception()
        {
            var ex = new Exception();
            var store = MockEventStore.ThrowsOnReadStreams(ex);
            var factory = Substitute.For<IPersistedEventFactory>();

            var props = Props.Create<ReadWorker>(store, factory);
            var actor = Sys.ActorOf(props);

            var req = new ReadRequest(1, EventCount.Unlimited);
            actor.Tell(req);

            ExpectMsg<Aborted>(m => m.RequestID == req.RequestID && m.Exception == ex);
        }
Esempio n. 9
0
        void Ready()
        {
            Receive<IPersistedEvent>(e =>
            {
                var received = e.GlobalSequence;
                var expected = _currentGlobalSequence + 1;

                // if the event is the expected one
                if (received == expected)
                {
                    _currentGlobalSequence++;

                    // publish to the event stream
                    Context.System.EventStream.Publish(e);

                    // if a recovery was requested, cancel as the event already arrived
                    if (_recovery != null)
                    {
                        _firstSequenceAfterGap = 0;
                        _recovery.Cancel();
                        _recovery = null;

                        Stash.UnstashAll();
                    }

                    return;
                }

                // if a gap is detected, stash and start the recovery timeout
                if (received > expected)
                {
                    if (_recovery == null)
                    {
                        _recovery = Context.System.Scheduler.ScheduleTellOnceCancelable(_options.DispatcherRecoveryTimeout, Self, new RecoverCommand(), Self);
                        _firstSequenceAfterGap = received;
                    }
                    else
                    {
                        _firstSequenceAfterGap = Math.Min(_firstSequenceAfterGap, received);
                    }

                    Stash.Stash();
                    return;
                }

                // just ignore events we've seen
                if (received < expected)
                {
                    _log.Debug("Received past event @" + received);
                    return;
                }
            });

            Receive<RecoverCommand>(_ =>
            {
                // if the recovery is null, it means the RecoverCommand was sent
                // but the expected event arrived right before it was cancelled, so just return
                if (_recovery == null)
                    return;

                var initialSequence = _currentGlobalSequence + 1;
                var count = (int) (_firstSequenceAfterGap - initialSequence);

                var request = new ReadRequest(initialSequence, count);
                _requestId = request.RequestID;
                _reader.Tell(request);

                Become(Recovering);
            });
        }
Esempio n. 10
0
        void StartReadRequest()
        {
            var request = new ReadRequest(_globalSequence + 1, _options.EventsPerReadRequest);
            _reader.Tell(request);

            _requestedEvents = request.Count;
            _lastRequestId = request.RequestID;
            _readEvents = 0;
        }
Esempio n. 11
0
 void HandleRequest(ReadRequest r)
 {
     var worker = Context.ActorOf(_workerProps);
     worker.Forward(r);
 }