Esempio n. 1
0
        public void TestImmediateAckingTracker()
        {
            var builder = new ConsumerConfigBuilder <byte[]>();

            builder.AcknowledgmentGroupTime(0);
            builder.Topic($"TestAckTracker-{Guid.NewGuid()}");
            builder.SubscriptionName($"TestAckTracker-sub-{Guid.NewGuid()}");
            var conf     = builder.ConsumerConfigurationData;
            var consumer = _client.NewConsumer(builder);
            var unack    = _system.ActorOf(UnAckedChunckedMessageIdSequenceMap.Prop());
            var tracker  = _client.ActorSystem.ActorOf(PersistentAcknowledgmentsGroupingTracker <byte[]> .Prop(unack, consumer.ConsumerActor, consumer.ConsumerActor /*dummy*/, 1, consumer.ConsumerActor, conf));

            var msg1 = new MessageId(5, 1, 0);
            var msg2 = new MessageId(5, 2, 0);

            var isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult();

            Assert.False(isDuplicate);


            tracker.Tell(new AddAcknowledgment(msg1, CommandAck.AckType.Individual, new Dictionary <string, long>()));
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult();
            Assert.False(isDuplicate);

            tracker.Tell(FlushPending.Instance);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult();
            Assert.False(isDuplicate);

            tracker.Tell(new AddAcknowledgment(msg2, CommandAck.AckType.Individual, new Dictionary <string, long>()));
            // Since we were connected, the ack went out immediately
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg2)).GetAwaiter().GetResult();
            Assert.False(isDuplicate);
            tracker.GracefulStop(TimeSpan.FromSeconds(1));
        }
        public void TestAddAndRemove()
        {
            var builder = new ConsumerConfigBuilder <byte[]>();

            builder.Topic("TestAckTracker");
            builder.SubscriptionName("TestAckTracker-sub");
            var consumer = _client.NewConsumer(builder);
            var unack    = _system.ActorOf(UnAckedChunckedMessageIdSequenceMap.Prop());
            var tracker  = _client.ActorSystem.ActorOf(UnAckedMessageTracker.Prop(1000000, 100000, consumer.ConsumerActor, unack));

            var empty = tracker.Ask <bool>(Empty.Instance).GetAwaiter().GetResult();

            Assert.True(empty);

            var size = tracker.Ask <long>(Size.Instance).GetAwaiter().GetResult();

            Assert.Equal(0, size);

            var mid   = new MessageId(1L, 1L, -1);
            var added = tracker.Ask <bool>(new Add(mid)).GetAwaiter().GetResult();

            Assert.True(added);
            added = tracker.Ask <bool>(new Add(mid)).GetAwaiter().GetResult();
            Assert.False(added);
            size = tracker.Ask <long>(Size.Instance).GetAwaiter().GetResult();
            Assert.Equal(1, size);

            tracker.Tell(Clear.Instance);

            added = tracker.Ask <bool>(new Add(mid)).GetAwaiter().GetResult();
            Assert.True(added);

            size = tracker.Ask <long>(Size.Instance).GetAwaiter().GetResult();
            Assert.Equal(1, size);

            var removed = tracker.Ask <bool>(new Remove(mid)).GetAwaiter().GetResult();

            Assert.True(removed);

            empty = tracker.Ask <bool>(Empty.Instance).GetAwaiter().GetResult();
            Assert.True(empty);

            size = tracker.Ask <long>(Size.Instance).GetAwaiter().GetResult();
            Assert.Equal(0, size);
        }
Esempio n. 3
0
        public void TestAckTracker()
        {
            var builder = new ConsumerConfigBuilder <byte[]>();

            builder.AcknowledgmentGroupTime(10000);
            builder.Topic($"TestAckTracker-{Guid.NewGuid()}");
            builder.SubscriptionName($"TestAckTracker-sub-{Guid.NewGuid()}");
            var conf     = builder.ConsumerConfigurationData;
            var consumer = _client.NewConsumer(builder);
            var unack    = _system.ActorOf(UnAckedChunckedMessageIdSequenceMap.Prop());
            var tracker  = _client.ActorSystem.ActorOf(PersistentAcknowledgmentsGroupingTracker <byte[]> .Prop(unack, consumer.ConsumerActor, consumer.ConsumerActor /*dummy*/, 1, consumer.ConsumerActor, conf));

            var msg1        = new MessageId(5, 1, 0);
            var msg2        = new MessageId(5, 2, 0);
            var msg3        = new MessageId(5, 3, 0);
            var msg4        = new MessageId(5, 4, 0);
            var msg5        = new MessageId(5, 5, 0);
            var msg6        = new MessageId(5, 6, 0);
            var isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult();

            Assert.False(isDuplicate);
            tracker.Tell(new AddAcknowledgment(msg1, CommandAck.AckType.Individual, new Dictionary <string, long>()));
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);

            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg2)).GetAwaiter().GetResult();
            Assert.False(isDuplicate);

            tracker.Tell(new AddAcknowledgment(msg5, CommandAck.AckType.Cumulative, new Dictionary <string, long>()));
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg2)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg3)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);

            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg4)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg5)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg6)).GetAwaiter().GetResult();
            Assert.False(isDuplicate);

            // Flush while disconnected. the internal tracking will not change
            tracker.Tell(FlushPending.Instance);

            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg2)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg3)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);

            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg4)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg5)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg6)).GetAwaiter().GetResult();
            Assert.False(isDuplicate);

            tracker.Tell(new AddAcknowledgment(msg6, CommandAck.AckType.Individual, new Dictionary <string, long>()));
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg6)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);

            tracker.Tell(FlushPending.Instance);

            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg1)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg2)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg3)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);

            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg4)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg5)).GetAwaiter().GetResult();
            Assert.True(isDuplicate);
            isDuplicate = tracker.Ask <bool>(new IsDuplicate(msg6)).GetAwaiter().GetResult();
            Assert.False(isDuplicate);

            tracker.GracefulStop(TimeSpan.FromSeconds(1));
        }