Пример #1
0
        public void TestFacadeFetchKeyByTime()
        {
            DateTime dt = DateTime.Now;

            store.Put(
                "coucou",
                ValueAndTimestamp <int> .Make(120, dt.AddMilliseconds(100).GetMilliseconds()),
                dt.GetMilliseconds());
            var r = facade.Fetch("coucou", dt.GetMilliseconds());

            Assert.IsNotNull(r);
            Assert.AreEqual(120, r);
        }
        public override void Process(K key, V value)
        {
            if (key == null)
            {
                log.LogWarning($"Skipping record due to null key.value =[{value}] topic =[{Context.RecordContext.Topic}] partition =[{Context.RecordContext.Partition}] offset =[{Context.RecordContext.Offset }]");
                droppedRecordsSensor.Record();
                return;
            }

            observedStreamTime = Math.Max(observedStreamTime, Context.Timestamp);
            long closeTime      = observedStreamTime - windowOptions.GracePeriodMs;
            var  matchedWindows = windowOptions.WindowsFor(Context.Timestamp);

            foreach (var entry in matchedWindows)
            {
                long windowStart = entry.Key, windowEnd = entry.Value.EndMs;
                if (windowEnd > closeTime)
                {
                    var oldAggAndTimestamp = windowStore.Fetch(key, windowStart);

                    Agg oldAgg = oldAggAndTimestamp == null ? default : oldAggAndTimestamp.Value;
                                 long newTs;
                                 Agg  newAgg;

                                 if (oldAggAndTimestamp == null)
                                 {
                                     oldAgg = initializer.Apply();
                                     newTs  = Context.Timestamp;
                                 }
                                 else
                                 {
                                     newTs = Math.Max(Context.Timestamp, oldAggAndTimestamp.Timestamp);
                                 }

                                 newAgg = aggregator.Apply(key, value, oldAgg);
                                 windowStore.Put(key, ValueAndTimestamp <Agg> .Make(newAgg, newTs), windowStart);
                                 tupleForwarder.MaybeForward(new Windowed <K>(key, entry.Value), newAgg, sendOldValues ? oldAgg : default, newTs);