public void WindowStoreEnumeratorTestReset() { 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 MeteredWindowEnumerator <string>( store.Fetch(key, date.AddSeconds(-1), date.AddSeconds(1)), (b) => (new StringSerDes()).Deserialize(b, new SerializationContext()), new NoRunnableSensor("s", "s", MetricsRecordingLevel.INFO)); int i = 0; while (enumerator.MoveNext()) { Assert.AreEqual(date.GetMilliseconds(), enumerator.Current.Value.Key); Assert.AreEqual("value", enumerator.Current.Value.Value); ++i; } Assert.AreEqual(1, i); enumerator.Reset(); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(date.GetMilliseconds(), enumerator.Current.Value.Key); Assert.AreEqual("value", enumerator.Current.Value.Value); }
public void WindowStoreEnumeratorTestDispose() { 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 MeteredWindowEnumerator <string>( store.Fetch(key, date.AddSeconds(-1), date.AddSeconds(1)), (b) => (new StringSerDes()).Deserialize(b, new SerializationContext()), new NoRunnableSensor("s", "s", MetricsRecordingLevel.INFO)); enumerator.Dispose(); Assert.Throws <ObjectDisposedException>(() => enumerator.MoveNext()); }