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(); }
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"); }
public void Should_serialize_and_deserialize_IReceiverStateSnapshot() { var anyOrderReceiverState = new UnorderedReceiverState(); anyOrderReceiverState.ConfirmProcessing(100L, "fuber"); anyOrderReceiverState.ConfirmProcessing(101L, "fuber"); anyOrderReceiverState.ConfirmProcessing(1L, "foo"); anyOrderReceiverState.ConfirmProcessing(1L, "bar"); anyOrderReceiverState.ConfirmProcessing(2L, "foo"); var snapshot = anyOrderReceiverState.ToSnapshot(); var bytes = _deDuplicatingMessageSerializer.ToBinary(snapshot); var snapshot2 = (IReceiverStateSnapshot)_deDuplicatingMessageSerializer.FromBinary(bytes, _deDuplicatingMessageSerializer.Manifest(snapshot)); snapshot.TrackedIds.Should().BeEquivalentTo(snapshot2.TrackedIds); snapshot.TrackedSenders.Should().BeEquivalentTo(snapshot2.TrackedSenders); }