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); }
public void CreateInMemoryWindowStore() { var store = new InMemoryWindowStore("store", defaultRetention, (long)defaultSize.TotalMilliseconds); Assert.IsFalse(store.Persistent); Assert.AreEqual("store", store.Name); Assert.AreEqual(0, store.All().ToList().Count); }
public void TestRetention() { var date = DateTime.Now.AddDays(-1); var store = new InMemoryWindowStore("store", TimeSpan.Zero, (long)defaultSize.TotalMilliseconds); store.Put(new Bytes(new byte[1] { 13 }), new byte[0], date.GetMilliseconds()); Assert.AreEqual(0, store.All().ToList().Count); }
public void PutElementsWithNullValue() { var date = DateTime.Now; var key = new Bytes(Encoding.UTF8.GetBytes("test-key")); var store = new InMemoryWindowStore("store", defaultRetention, (long)defaultSize.TotalMilliseconds); store.Put(key, null, date.GetMilliseconds()); var r = store.All().ToList(); Assert.AreEqual(0, r.Count); }
public void WindowedKeyValueEnumeratorTestDispose() { 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 WindowedKeyValueEnumerator <string, string>( store.All(), new StringSerDes(), new StringSerDes()); enumerator.Dispose(); Assert.Throws <ObjectDisposedException>(() => enumerator.MoveNext()); }
public void PutElementsAndUpdateNullValueDifferentWindow() { var date = DateTime.Now; var key = new Bytes(Encoding.UTF8.GetBytes("test-key")); var value = Encoding.UTF8.GetBytes("test"); var store = new InMemoryWindowStore("store", defaultRetention, (long)defaultSize.TotalMilliseconds); store.Put(key, value, date.GetMilliseconds()); store.Put(key, null, date.AddSeconds(1).GetMilliseconds()); var r = store.All().ToList(); Assert.AreEqual(1, r.Count); Assert.AreEqual(value, store.Fetch(key, date.GetMilliseconds())); Assert.IsNull(store.Fetch(key, date.AddSeconds(1).GetMilliseconds())); }
public void TestRetentionWithOpenIt() { var date = DateTime.Now; var key = new Bytes(Encoding.UTF8.GetBytes("test-key")); var value = Encoding.UTF8.GetBytes("test"); var store = new InMemoryWindowStore("store", TimeSpan.FromSeconds(1), (long)defaultSize.TotalMilliseconds); store.Put(key, value, date.GetMilliseconds()); var it = store.All(); it.MoveNext(); Thread.Sleep(2000); store.Put(key, value, date.AddSeconds(4).GetMilliseconds()); var r = it.ToList().Count; Assert.AreEqual(0, r); }
public void WindowedKeyValueEnumeratorWithSerdes() { 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 WindowedKeyValueEnumerator <string, string>( store.All(), new StringSerDes(), new StringSerDes()); var items = enumerator.ToList(); Assert.AreEqual(1, items.Count); Assert.AreEqual("value", items[0].Value); Assert.AreEqual("key", items[0].Key.Key); Assert.AreEqual(TimeSpan.FromSeconds(1), items[0].Key.Window.TotalTime); }
public void WindowedKeyValueEnumeratorTestDispose() { 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)); enumerator.Dispose(); Assert.Throws <ObjectDisposedException>(() => enumerator.MoveNext()); }
public void TestRetention() { var metricsRegistry = new StreamMetricsRegistry(); var mockContext = new Moq.Mock <ProcessorContext>(); mockContext.Setup(c => c.Id).Returns(new TaskId { Id = 0, Partition = 0 }); mockContext.Setup(c => c.Metrics).Returns(metricsRegistry); mockContext.Setup(c => c.Timestamp).Returns(DateTime.Now.GetMilliseconds()); var date = DateTime.Now.AddDays(-1); var store = new InMemoryWindowStore("store", TimeSpan.Zero, (long)defaultSize.TotalMilliseconds); store.Init(mockContext.Object, null); store.Put(new Bytes(new byte[1] { 13 }), new byte[0], date.GetMilliseconds()); Assert.AreEqual(0, store.All().ToList().Count); }
public void WindowedKeyValueEnumeratorTestNext() { 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 WindowedKeyValueEnumerator <string, string>( store.All(), new StringSerDes(), new StringSerDes()); 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); }
public void WindowedKeyValueEnumeratorWithSerdes() { 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)); var items = enumerator.ToList(); Assert.AreEqual(1, items.Count); Assert.AreEqual("value", items[0].Value); Assert.AreEqual("key", items[0].Key.Key); Assert.AreEqual(TimeSpan.FromSeconds(1), items[0].Key.Window.TotalTime); }