public void available_capacity_is_tracked_with_acked_messages() { var client1Envelope = new FakeEnvelope(); var client2Envelope = new FakeEnvelope(); var reader = new FakeCheckpointReader(); const string subsctiptionStream = "$ce-streamName"; PersistentSubscriptionParams settings = PersistentSubscriptionToStreamParamsBuilder .CreateFor(subsctiptionStream, "groupName") .WithEventLoader(new FakeStreamReader()) .WithCheckpointReader(reader) .WithCheckpointWriter(new FakeCheckpointWriter(x => { })) .WithMessageParker(new FakeMessageParker()) .CustomConsumerStrategy(new PinnedPersistentSubscriptionConsumerStrategy(new XXHashUnsafe())) .StartFromCurrent(); var consumerStrategy = (PinnedPersistentSubscriptionConsumerStrategy)settings.ConsumerStrategy; var sub = new Core.Services.PersistentSubscription.PersistentSubscription(settings); reader.Load(null); var correlationId1 = Guid.NewGuid(); sub.AddClient(correlationId1, Guid.NewGuid(), "connection-1", client1Envelope, 14, "foo", "bar"); Assert.That(consumerStrategy.AvailableCapacity, Is.EqualTo(14)); var correlationId2 = Guid.NewGuid(); sub.AddClient(correlationId2, Guid.NewGuid(), "connection-2", client2Envelope, 10, "foo", "bar"); Assert.That(consumerStrategy.AvailableCapacity, Is.EqualTo(24)); var message1 = Guid.NewGuid(); sub.NotifyLiveSubscriptionMessage(Helper.BuildLinkEvent(message1, subsctiptionStream, 0, Helper.BuildFakeEvent(Guid.NewGuid(), "type", "streamName-1", 0), false)); Assert.That(consumerStrategy.AvailableCapacity, Is.EqualTo(23)); var message2 = Guid.NewGuid(); sub.NotifyLiveSubscriptionMessage(Helper.BuildLinkEvent(message2, subsctiptionStream, 1, Helper.BuildFakeEvent(Guid.NewGuid(), "type", "streamName-2", 0), false)); Assert.That(consumerStrategy.AvailableCapacity, Is.EqualTo(22)); sub.AcknowledgeMessagesProcessed(correlationId1, new[] { message1 }); Assert.That(consumerStrategy.AvailableCapacity, Is.EqualTo(23)); sub.AcknowledgeMessagesProcessed(correlationId2, new[] { message2 }); Assert.That(consumerStrategy.AvailableCapacity, Is.EqualTo(24)); }
public void available_capacity_is_tracked() { var client1Envelope = new FakeEnvelope(); var client2Envelope = new FakeEnvelope(); var reader = new FakeCheckpointReader(); const string subsctiptionStream = "$ce-streamName"; PersistentSubscriptionParams settings = PersistentSubscriptionToStreamParamsBuilder .CreateFor(subsctiptionStream, "groupName") .WithEventLoader(new FakeStreamReader()) .WithCheckpointReader(reader) .WithCheckpointWriter(new FakeCheckpointWriter(x => { })) .WithMessageParker(new FakeMessageParker()) .CustomConsumerStrategy(new PinnedPersistentSubscriptionConsumerStrategy(new XXHashUnsafe())) .StartFromCurrent(); var consumerStrategy = (PinnedPersistentSubscriptionConsumerStrategy)settings.ConsumerStrategy; var sub = new Core.Services.PersistentSubscription.PersistentSubscription(settings); reader.Load(null); var client1Id = Guid.NewGuid(); sub.AddClient(Guid.NewGuid(), client1Id, "connection-1", client1Envelope, 14, "foo", "bar"); Assert.That(consumerStrategy.AvailableCapacity, Is.EqualTo(14)); var client2Id = Guid.NewGuid(); sub.AddClient(Guid.NewGuid(), client2Id, "connection-2", client2Envelope, 10, "foo", "bar"); Assert.That(consumerStrategy.AvailableCapacity, Is.EqualTo(24)); sub.RemoveClientByConnectionId(client2Id); Assert.That(consumerStrategy.AvailableCapacity, Is.EqualTo(14)); sub.RemoveClientByConnectionId(client1Id); Assert.That(consumerStrategy.AvailableCapacity, Is.EqualTo(0)); }