コード例 #1
0
        public async Task ShouldCompleteWhenCanceled()
        {
            var mock = new MockConsumer <K, V>();

            var(control, probe) = CreateCommitableSource(mock)
                                  .ToMaterialized(this.SinkProbe <CommittableMessage <K, V> >(), Keep.Both)
                                  .Run(Sys.Materializer());

            probe.Request(100);
            mock.VerifyNotClosed();
            probe.Cancel();
            await control.IsShutdown.WithTimeout(RemainingOrDefault);

            mock.VerifyClosed();
        }
コード例 #2
0
        public async Task ShouldCompleteWhenStopped()
        {
            var mock = new MockConsumer <K, V>();

            var(control, probe) = CreateCommitableSource(mock)
                                  .ToMaterialized(this.SinkProbe <CommittableMessage <K, V> >(), Keep.Both)
                                  .Run(Sys.Materializer());

            probe.Request(100);

            await control.Shutdown().WithTimeout(TimeSpan.FromSeconds(10));

            probe.ExpectComplete();
            mock.VerifyClosed();
        }
コード例 #3
0
        private Source <CommittableMessage <K, V>, IControl> CreateSourceWithMetadata(
            MockConsumer <K, V> mock,
            Func <ConsumeResult <K, V>, string> metadataFromRecord,
            string groupId  = "group1",
            string[] topics = null)
        {
            var settings = ConsumerSettings <K, V> .Create(Sys, Deserializers.Utf8, Deserializers.Utf8)
                           .WithGroupId(groupId)
                           .WithConsumerFactory(_ => mock.Mock);

            mock.Settings = settings;

            return(KafkaConsumer.CommitWithMetadataSource(
                       settings,
                       Subscriptions.Topics(topics),
                       metadataFromRecord));
        }
コード例 #4
0
        private Source <CommittableMessage <K, V>, IControl> CreateCommitableSource(
            MockConsumer <K, V> mock, string groupId = "group1", string[] topics = null)
        {
            topics ??= new[] { "topic" };
            var settings = ConsumerSettings <K, V> .Create(Sys, Deserializers.Utf8, Deserializers.Utf8)
                           .WithGroupId(groupId)
                           .WithCloseTimeout(MockConsumer.CloseTimeout)
                           .WithStopTimeout(MockConsumer.CloseTimeout)
                           .WithCommitTimeout(TimeSpan.FromMilliseconds(500))
                           .WithConsumerFactory(_ => mock.Mock);

            mock.Settings = settings;

            return(KafkaConsumer.CommittableSource(
                       settings,
                       Subscriptions.Topics(topics)));
        }
コード例 #5
0
        private async Task CheckMessagesReceiving(List <List <CommittableMessage <K, V> > > msgss)
        {
            var mock = new MockConsumer <K, V>();

            var(control, probe) = CreateCommitableSource(mock)
                                  .ToMaterialized(this.SinkProbe <CommittableMessage <K, V> >(), Keep.Both)
                                  .Run(Sys.Materializer());

            probe.Request(msgss.Select(t => t.Count).Sum());
            foreach (var chunk in msgss)
            {
                mock.Enqueue(chunk.Select(l => l.Record).ToList());
            }

            var messages = msgss.SelectMany(m => m).Select(m => m);

            foreach (var message in messages)
            {
                var received = probe.ExpectNext();
                received.Record.Message.Key.Should().Be(message.Record.Message.Key);
                received.Record.Message.Value.Should().Be(message.Record.Message.Value);
            }
            await control.Shutdown().WithTimeout(RemainingOrDefault);
        }