Example #1
0
        public void WindowedKeyValueEnumeratorTestReset()
        {
            var date  = DateTime.Now;
            var key   = new Bytes(Encoding.UTF8.GetBytes("key"));
            var store = new InMemoryWindowStore("store", TimeSpan.FromSeconds(10),
                                                (long)TimeSpan.FromSeconds(1).TotalMilliseconds);

            store.Put(key, Encoding.UTF8.GetBytes("value"), date.GetMilliseconds());

            var enumerator = new MeteredWindowedKeyValueEnumerator <string, string>(
                store.All(),
                (b) => (new StringSerDes()).Deserialize(b, new SerializationContext()),
                (b) => (new StringSerDes()).Deserialize(b, new SerializationContext()),
                new NoRunnableSensor("s", "s", MetricsRecordingLevel.INFO));
            int i = 0;

            while (enumerator.MoveNext())
            {
                Assert.AreEqual("key", enumerator.Current.Value.Key.Key);
                Assert.AreEqual("value", enumerator.Current.Value.Value);
                ++i;
            }

            Assert.AreEqual(1, i);
            enumerator.Reset();
            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual("key", enumerator.Current.Value.Key.Key);
            Assert.AreEqual("value", enumerator.Current.Value.Value);
        }