Beispiel #1
0
        public void TestFetch()
        {
            var id = new TaskId {
                Id = 0, Partition = 0
            };
            var stateManager = new ProcessorStateManager(id,
                                                         new List <Confluent.Kafka.TopicPartition> {
                new Confluent.Kafka.TopicPartition("test", 0)
            }, null, null,
                                                         null);
            var context = new ProcessorContext(UnassignedStreamTask.Create(), config, stateManager,
                                               new StreamMetricsRegistry());

            wrapped.Init(context, inmemorystore);
            wrapped.Put("coucou", 120, 1300);
            Assert.AreEqual(120, wrapped.Fetch("coucou", 1300));
        }
Beispiel #2
0
        public void TestWithUnknwonSerdes()
        {
            wrapped = new MeteredWindowStore <string, int>(inmemorystore, 1000 * 2, null, null, "in-memory-window");
            var id = new TaskId {
                Id = 0, Partition = 0
            };
            var stateManager = new ProcessorStateManager(id,
                                                         new List <Confluent.Kafka.TopicPartition> {
                new Confluent.Kafka.TopicPartition("test", 0)
            }, null, null,
                                                         null);
            var context = new ProcessorContext(UnassignedStreamTask.Create(), config, stateManager,
                                               new StreamMetricsRegistry());

            wrapped.Init(context, inmemorystore);
            Assert.Throws <StreamsException>(() => wrapped.Put("coucou", 120, 1300));
        }
        public void WindowStoreMetricsTest()
        {
            long windowSize = 1000 * 60;
            var  random     = new Random();
            MeteredWindowStore <string, string> meteredWindowStore = new MeteredWindowStore <string, string>(
                new MockInMemoryWindowStore(storeName, TimeSpan.FromDays(1), windowSize),
                windowSize,
                new StringSerDes(),
                new StringSerDes(),
                storeScope);

            store = meteredWindowStore;
            meteredWindowStore.Init(context, meteredWindowStore);

            int  nbMessage = random.Next(0, 250);
            long now1      = DateTime.Now.GetMilliseconds();

            // produce ${nbMessage} messages to input topic (both);
            for (int i = 0; i < nbMessage; ++i)
            {
                meteredWindowStore.Put($"test{i}", $"test{i}", now1);
            }

            meteredWindowStore.Flush();

            long now2 = DateTime.Now.GetMilliseconds();

            for (int i = 0; i < nbMessage; ++i)
            {
                meteredWindowStore.Put($"test{i}", $"test{i}", now2);
            }

            meteredWindowStore.Flush();

            AssertAvgAndMaxLatency(StateStoreMetrics.PUT);
            AssertAvgAndMaxLatency(StateStoreMetrics.FLUSH);

            for (int i = 0; i < nbMessage; ++i)
            {
                meteredWindowStore.Fetch($"test{i}", now1);
            }

            AssertAvgAndMaxLatency(StateStoreMetrics.FETCH);

            meteredWindowStore.Fetch($"test0", now1.FromMilliseconds().AddSeconds(-10),
                                     now1.FromMilliseconds().AddSeconds(10)).ToList();

            AssertAvgAndMaxLatency(StateStoreMetrics.FETCH);

            meteredWindowStore.Fetch($"test0", now1 - 10000,
                                     now1 + 10000).ToList();

            AssertAvgAndMaxLatency(StateStoreMetrics.FETCH);

            var nb = meteredWindowStore.FetchAll(now1.FromMilliseconds().AddSeconds(-10),
                                                 now2.FromMilliseconds().AddSeconds(10)).ToList().Count();

            Assert.AreEqual(nbMessage * 2, nb);

            AssertAvgAndMaxLatency(StateStoreMetrics.FETCH);

            meteredWindowStore.All().ToList();
        }