コード例 #1
0
        public void ApplyInternalChangelogTopicsParrallel()
        {
            AdminClientConfig config = new AdminClientConfig();

            config.BootstrapServers = "localhost:9092";

            StreamConfig config2 = new StreamConfig();

            DefaultTopicManager manager = new DefaultTopicManager(config2, kafkaSupplier.GetAdmin(config));

            IDictionary <string, InternalTopicConfig> topics = new Dictionary <string, InternalTopicConfig>();

            topics.Add("topic", new UnwindowedChangelogTopicConfig
            {
                Name             = "topic",
                NumberPartitions = 1
            });

            var r = Parallel.ForEach(new List <int> {
                1, 2, 3, 4
            },
                                     (i) => manager.ApplyAsync(0, topics).GetAwaiter().GetResult());

            Assert.IsTrue(r.IsCompleted);
        }
コード例 #2
0
        public void ApplyInternalChangelogTopicsWithExistingTopics()
        {
            AdminClientConfig config = new AdminClientConfig();

            config.BootstrapServers = "localhost:9092";

            StreamConfig config2 = new StreamConfig();

            DefaultTopicManager manager = new DefaultTopicManager(config2, kafkaSupplier.GetAdmin(config));

            ((SyncProducer)kafkaSupplier.GetProducer(new ProducerConfig())).CreateTopic("topic");

            IDictionary <string, InternalTopicConfig> topics = new Dictionary <string, InternalTopicConfig>();

            topics.Add("topic", new UnwindowedChangelogTopicConfig
            {
                Name             = "topic",
                NumberPartitions = 1
            });
            topics.Add("topic1", new UnwindowedChangelogTopicConfig
            {
                Name             = "topic1",
                NumberPartitions = 1
            });

            var r = manager.ApplyAsync(0, topics).GetAwaiter().GetResult().ToList();

            Assert.AreEqual(1, r.Count);
            Assert.AreEqual("topic1", r[0]);
        }
コード例 #3
0
        public void ApplyInternalChangelogTopicsInvalidDifferentPartition()
        {
            AdminClientConfig config = new AdminClientConfig();

            config.BootstrapServers = "localhost:9092";

            StreamConfig config2 = new StreamConfig();

            DefaultTopicManager manager = new DefaultTopicManager(config2, kafkaSupplier.GetAdmin(config));

            // Create topic with just one partition
            ((SyncProducer)kafkaSupplier.GetProducer(new ProducerConfig())).CreateTopic("topic");

            IDictionary <string, InternalTopicConfig> topics = new Dictionary <string, InternalTopicConfig>();

            topics.Add("topic", new UnwindowedChangelogTopicConfig
            {
                Name             = "topic",
                NumberPartitions = 4
            });

            Assert.Throws <StreamsException>(() => manager.ApplyAsync(0, topics).GetAwaiter().GetResult());
        }