Exemple #1
0
        public void TestMockSchemaRegistryInputOutput()
        {
            var config = new StreamConfig <StringSerDes, SchemaProtobufSerDes <Order> >();

            config.ApplicationId     = "test-mock-registry";
            config.SchemaRegistryUrl = "mock://test";

            StreamBuilder builder = new StreamBuilder();

            builder.Stream <string, Order>("test")
            .Filter((k, v) => k.Contains("test"))
            .To("test-output");

            Topology t = builder.Build();

            using (var driver = new TopologyTestDriver(t, config))
            {
                var inputTopic  = driver.CreateInputTopic <string, Order>("test");
                var outputTopic = driver.CreateOuputTopic <string, Order>("test-output", TimeSpan.FromSeconds(5));
                inputTopic.PipeInput("test",
                                     new Order
                {
                    OrderId   = 12,
                    Price     = 150,
                    ProductId = 1
                });
                var r = outputTopic.ReadKeyValue();
                Assert.IsNotNull(r);
                Assert.AreEqual("test", r.Message.Key);
                Assert.AreEqual(12, r.Message.Value.OrderId);
            }
            MockSchemaRegistry.DropScope("test");
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        protected virtual ISchemaRegistryClient GetSchemaRegistryClient(Confluent.SchemaRegistry.SchemaRegistryConfig config)
        {
            string mockScope = MaybeGetScope(config.Url);

            if (mockScope != null)
            {
                return(MockSchemaRegistry.GetClientForScope(mockScope));
            }
            else
            {
                return(new CachedSchemaRegistryClient(config));
            }
        }
Exemple #3
0
        public void TestMockSchemaRegistry()
        {
            var config = new StreamConfig();

            config.ApplicationId     = "app-test";
            config.AutoOffsetReset   = AutoOffsetReset.Earliest;
            config.NumStreamThreads  = 1;
            config.SchemaRegistryUrl = "mock://test";

            config.Acks = Acks.All;
            config.AddConsumerConfig("allow.auto.create.topics", "false");
            config.MaxTaskIdleMs = 50;

            StreamBuilder builder = new StreamBuilder();

            var ss = builder.Stream <string, Order, StringSerDes, SchemaProtobufSerDes <Order> >("test-topic")
                     .Peek((k, v) =>
            {
                Console.WriteLine($"Order #  {v.OrderId }");
            });

            Topology t = builder.Build();

            using (var driver = new TopologyTestDriver(t, config))
            {
                var inputTopic = driver.CreateInputTopic <string, Order, StringSerDes, SchemaProtobufSerDes <Order> >("test-topic");
                inputTopic.PipeInput("test",
                                     new Order
                {
                    OrderId   = 12,
                    Price     = 150,
                    ProductId = 1
                });
            }

            var client = MockSchemaRegistry.GetClientForScope("test");

            Assert.IsAssignableFrom <MockSchemaRegistryClient>(client);
            Assert.NotNull(client.GetSchemaAsync(1).GetAwaiter().GetResult());

            MockSchemaRegistry.DropScope("test");
        }