예제 #1
0
        public void ShouldSerializeSnapshots()
        {
            if (!SupportsSerialization)
            {
                return;
            }

            var probe    = CreateTestProbe();
            var metadata = new SnapshotMetadata(Pid, 100L);
            var snap     = new TestPayload(probe.Ref);

            SnapshotStore.Tell(new SaveSnapshot(metadata, snap), _senderProbe.Ref);
            _senderProbe.ExpectMsg <SaveSnapshotSuccess>(o =>
            {
                Assertions.AssertEqual(metadata.PersistenceId, o.Metadata.PersistenceId);
                Assertions.AssertEqual(metadata.SequenceNr, o.Metadata.SequenceNr);
            });

            var pid = Pid;

            SnapshotStore.Tell(new LoadSnapshot(pid, SnapshotSelectionCriteria.Latest, long.MaxValue), _senderProbe.Ref);
            _senderProbe.ExpectMsg <LoadSnapshotResult>(l =>
            {
                Assertions.AssertEqual(pid, l.Snapshot.Metadata.PersistenceId);
                Assertions.AssertEqual(100L, l.Snapshot.Metadata.SequenceNr);
                Assertions.AssertEqual(l.Snapshot.Snapshot, snap);
            });
        }
예제 #2
0
        protected void EventFilter <T>(string message, int occurances, Action intercept) where T : Exception  //TODO: Replace when EventFilter class in akka-testkit\src\main\scala\akka\testkit\TestEventListener.scala has been implemented
        {
            Sys.EventStream.Subscribe(TestActor, typeof(Error));
            intercept();
            for (int i = 0; i < occurances; i++)
            {
                var error = ExpectMsg <Error>();

                Assertions.AssertEqual(typeof(T), error.Cause.GetType());
                Assertions.AssertEqual(message, error.Message);
            }
        }
예제 #3
0
        protected void EventFilterLog <T>(string message, int occurences, Action intercept) where T : LogEvent
        {
            Sys.EventStream.Subscribe(TestActor, typeof(T));
            intercept();
            for (int i = 0; i < occurences; i++)
            {
                var error = ExpectMsg <LogEvent>();

                Assertions.AssertEqual(typeof(T), error.GetType());
                var match = -1 != error.Message.ToString().IndexOf(message, StringComparison.CurrentCultureIgnoreCase);
                Assertions.AssertTrue(match);
            }
        }
예제 #4
0
        public void Journal_should_serialize_events()
        {
            if (!SupportsSerialization)
            {
                return;
            }

            var probe  = CreateTestProbe();
            var @event = new TestPayload(probe.Ref);

            var aw = new AtomicWrite(
                new Persistent(@event, 6L, Pid, sender: ActorRefs.NoSender, writerGuid: WriterGuid));

            Journal.Tell(new WriteMessages(new [] { aw }, probe.Ref, ActorInstanceId));

            probe.ExpectMsg <WriteMessagesSuccessful>();
            var pid        = Pid;
            var writerGuid = WriterGuid;

            probe.ExpectMsg <WriteMessageSuccess>(o =>
            {
                Assertions.AssertEqual(writerGuid, o.Persistent.WriterGuid);
                Assertions.AssertEqual(pid, o.Persistent.PersistenceId);
                Assertions.AssertEqual(6L, o.Persistent.SequenceNr);
                Assertions.AssertTrue(o.Persistent.Sender == ActorRefs.NoSender || o.Persistent.Sender.Equals(Sys.DeadLetters), $"Expected WriteMessagesSuccess.Persistent.Sender to be null or {Sys.DeadLetters}, but found {o.Persistent.Sender}");
                Assertions.AssertEqual(@event, o.Persistent.Payload);
            });

            Journal.Tell(new ReplayMessages(6L, long.MaxValue, long.MaxValue, Pid, _receiverProbe.Ref));

            _receiverProbe.ExpectMsg <ReplayedMessage>(o =>
            {
                Assertions.AssertEqual(writerGuid, o.Persistent.WriterGuid);
                Assertions.AssertEqual(pid, o.Persistent.PersistenceId);
                Assertions.AssertEqual(6L, o.Persistent.SequenceNr);
                Assertions.AssertTrue(o.Persistent.Sender == ActorRefs.NoSender || o.Persistent.Sender.Equals(Sys.DeadLetters), $"Expected WriteMessagesSuccess.Persistent.Sender to be null or {Sys.DeadLetters}, but found {o.Persistent.Sender}");
                Assertions.AssertEqual(@event, o.Persistent.Payload);
            });

            Assertions.AssertEqual(_receiverProbe.ExpectMsg <RecoverySuccess>().HighestSequenceNr, 6L);
        }
예제 #5
0
        public virtual void Journal_should_serialize_Persistent_with_EventAdapter_manifest()
        {
            var probe           = CreateTestProbe();
            var persistentEvent = new Persistent(new TestJournal.MyPayload3("item1"), 1L, Pid, null, false, null, WriterGuid);

            var messages = new List <AtomicWrite>
            {
                new AtomicWrite(persistentEvent)
            };

            Journal.Tell(new WriteMessages(messages, probe.Ref, ActorInstanceId));
            probe.ExpectMsg <WriteMessagesSuccessful>();
            probe.ExpectMsg <WriteMessageSuccess>(m => m.ActorInstanceId == ActorInstanceId && m.Persistent.PersistenceId == Pid);

            Journal.Tell(new ReplayMessages(0, long.MaxValue, long.MaxValue, Pid, probe.Ref));
            var replayed = probe.ExpectMsg <ReplayedMessage>();

            Assertions.AssertEqual(persistentEvent.PersistenceId, replayed.Persistent.PersistenceId);
            Assertions.AssertEqual(persistentEvent.SequenceNr, replayed.Persistent.SequenceNr);
            Assertions.AssertEqual(persistentEvent.Manifest, replayed.Persistent.Manifest);
            Assertions.AssertEqual(".item1.", replayed.Persistent.Payload.AsInstanceOf <TestJournal.MyPayload3>().Data);
            probe.ExpectMsg <RecoverySuccess>();
        }