Пример #1
0
        public void TestFetchAll()
        {
            var dt = DateTime.Now;
            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, dt.GetMilliseconds());
            var list = wrapped.FetchAll(dt.AddSeconds(-1), dt.AddSeconds(2)).ToList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(dt.GetMilliseconds(), list[0].Key.Window.StartMs);
            Assert.AreEqual("coucou", list[0].Key.Key);
            Assert.AreEqual(120, list[0].Value);
        }
        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();
        }