Пример #1
0
        public void UnorderedReceiverState_should_load_and_recover_from_snapshot()
        {
            var confirmable1  = new ConfirmableMessageEnvelope(1L, "foo", "bar");
            var confirmable2  = new ConfirmableMessageEnvelope(2L, "foo", "bar");
            var confirmable3  = new ConfirmableMessageEnvelope(1L, "fuber", "bar");
            var timeProvider  = new FakeTimeProvider(DateTime.UtcNow);
            var receiverState = new UnorderedReceiverState(timeProvider);

            // update our initial state
            receiverState.ConfirmProcessing(confirmable1.ConfirmationId, confirmable1.SenderId);
            receiverState.ConfirmProcessing(confirmable2.ConfirmationId, confirmable2.SenderId);
            receiverState.ConfirmProcessing(confirmable3.ConfirmationId, confirmable3.SenderId);

            // save into a snapshot
            var snapshot = receiverState.ToSnapshot();

            snapshot.TrackedIds.Count.Should().Be(2);
            snapshot.TrackedIds[confirmable1.SenderId].Count.Should().Be(2); // two for "foo"
            snapshot.TrackedIds[confirmable3.SenderId].Count.Should().Be(1); // one for "fuber"
            snapshot.TrackedIds[confirmable1.SenderId].Any(x => x.Equals(confirmable1.ConfirmationId)).Should()
            .BeTrue();
            snapshot.TrackedSenders.Count.Should().Be(2);

            // reload snapshot into new state
            var receiverState2 = new UnorderedReceiverState(timeProvider);

            receiverState2.FromSnapshot(snapshot);

            // validate that we've already processed all of the same things as the previous state
            receiverState2.TrackedSenders.Should().BeEquivalentTo(receiverState.TrackedSenders);
            receiverState.AlreadyProcessed(confirmable1.ConfirmationId, confirmable1.SenderId).Should().BeTrue();
            receiverState.AlreadyProcessed(confirmable2.ConfirmationId, confirmable2.SenderId).Should().BeTrue();
            receiverState.AlreadyProcessed(confirmable3.ConfirmationId, confirmable3.SenderId).Should().BeTrue();
        }
        private byte[] ConfirmableEnvelopeToProto(ConfirmableMessageEnvelope e)
        {
            var eP = new Msgs.ConfirmableMessageEnvelope();

            eP.SenderId       = e.SenderId;
            eP.ConfirmationId = e.ConfirmationId;
            eP.Msg            = _wrappedPayloadSupport.PayloadToProto(e.Message);

            return(eP.ToByteArray());
        }
        public void Should_serialize_and_deserialize_ConfirmableMessageEnvelope()
        {
            var cme = new ConfirmableMessageEnvelope(100L, "fuber", "noooooooo");

            var bytes = _deDuplicatingMessageSerializer.ToBinary(cme);
            var cme2  =
                (ConfirmableMessageEnvelope)_deDuplicatingMessageSerializer.FromBinary(bytes,
                                                                                       _deDuplicatingMessageSerializer.Manifest(cme));

            cme2.ConfirmationId.Should().Be(cme.ConfirmationId);
            cme2.SenderId.Should().Be(cme.SenderId);
            cme2.Message.Should().Be(cme.Message);
        }
Пример #4
0
        public void UnorderedReceiverState_should_prune_older_senders_correctly()
        {
            var confirmable   = new ConfirmableMessageEnvelope(1L, "foo", "bar");
            var timeProvider  = new FakeTimeProvider(DateTime.UtcNow);
            var receiverState = new UnorderedReceiverState(timeProvider);

            receiverState.ConfirmProcessing(confirmable.ConfirmationId, confirmable.SenderId);
            timeProvider.SetTime(TimeSpan.FromSeconds(10));

            var prune = receiverState.Prune(TimeSpan.FromSeconds(5));

            prune.prunedSenders.Should().BeEquivalentTo("foo");
        }