public void FetchAllTest() { InMemoryWindowStore store1 = new InMemoryWindowStore("store", TimeSpan.FromDays(1), 1000 * 10); InMemoryWindowStore store2 = new InMemoryWindowStore("store", TimeSpan.FromDays(1), 1000 * 10); var dt = DateTime.Now; var valueSerdes = new ValueAndTimestampSerDes <string>(new StringSerDes()); var bytes = new Bytes(Encoding.UTF8.GetBytes("test")); var bytes2 = new Bytes(Encoding.UTF8.GetBytes("test2")); var provider = new MockStateProvider <string, string>(1000 * 10, new StringSerDes(), new StringSerDes(), store1, store2); var composite = new CompositeReadOnlyWindowStore <string, string>(provider, new WindowStoreType <string, string>(), "store"); store1.Put(bytes, valueSerdes.Serialize(ValueAndTimestamp <string> .Make("coucou1", dt.GetMilliseconds()), new SerializationContext()), dt.GetMilliseconds()); store1.Put(bytes2, valueSerdes.Serialize(ValueAndTimestamp <string> .Make("coucou2", dt.GetMilliseconds()), new SerializationContext()), dt.GetMilliseconds()); var result = composite.FetchAll(dt.AddSeconds(-2), dt.AddSeconds(2)); Assert.IsNotNull(result); var items = result.ToList(); Assert.AreEqual(2, items.Count); var c1 = items.FirstOrDefault(kp => kp.Key.Key.Equals("test")); var c2 = items.FirstOrDefault(kp => kp.Key.Key.Equals("test2")); Assert.IsNotNull(c1); Assert.IsNotNull(c2); Assert.AreEqual("coucou1", c1.Value); Assert.AreEqual("coucou2", c2.Value); }
public void ResetTest() { InMemoryKeyValueStore store1 = new InMemoryKeyValueStore("store"); InMemoryKeyValueStore store2 = new InMemoryKeyValueStore("store"); var dt = DateTime.Now.GetMilliseconds(); var valueSerdes = new ValueAndTimestampSerDes <string>(new StringSerDes()); var bytes = new Bytes(Encoding.UTF8.GetBytes("test")); var bytes2 = new Bytes(Encoding.UTF8.GetBytes("test2")); var provider = new MockStateProvider <string, string>(1000 * 10, new StringSerDes(), new StringSerDes(), store1, store2); var composite = new CompositeReadOnlyKeyValueStore <string, string>(provider, storeType, "store"); store1.Put(bytes, valueSerdes.Serialize(ValueAndTimestamp <string> .Make("coucou1", dt), new SerializationContext())); store2.Put(bytes2, valueSerdes.Serialize(ValueAndTimestamp <string> .Make("coucou2", dt), new SerializationContext())); var enumerator = composite.Range("test", "test2"); Assert.IsNotNull(enumerator); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual("test", enumerator.PeekNextKey()); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual("test2", enumerator.PeekNextKey()); Assert.IsFalse(enumerator.MoveNext()); enumerator.Reset(); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual("test", enumerator.PeekNextKey()); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual("test2", enumerator.PeekNextKey()); Assert.IsFalse(enumerator.MoveNext()); }
public void ReverseAllTest() { InMemoryKeyValueStore store1 = new InMemoryKeyValueStore("store"); InMemoryKeyValueStore store2 = new InMemoryKeyValueStore("store"); var dt = DateTime.Now.GetMilliseconds(); var valueSerdes = new ValueAndTimestampSerDes <string>(new StringSerDes()); var bytes = new Bytes(Encoding.UTF8.GetBytes("test")); var bytes2 = new Bytes(Encoding.UTF8.GetBytes("test2")); var provider = new MockStateProvider <string, string>(1000 * 10, new StringSerDes(), new StringSerDes(), store1, store2); var composite = new CompositeReadOnlyKeyValueStore <string, string>(provider, storeType, "store"); store1.Put(bytes, valueSerdes.Serialize(ValueAndTimestamp <string> .Make("coucou1", dt), new SerializationContext())); store1.Put(bytes2, valueSerdes.Serialize(ValueAndTimestamp <string> .Make("coucou1bis", dt), new SerializationContext())); store2.Put(bytes, valueSerdes.Serialize(ValueAndTimestamp <string> .Make("coucou2", dt), new SerializationContext())); store2.Put(bytes2, valueSerdes.Serialize(ValueAndTimestamp <string> .Make("coucou2bis", dt), new SerializationContext())); var result = composite.ReverseAll().ToList(); Assert.IsNotNull(result); Assert.AreEqual(4, result.Count); Assert.AreEqual("test2", result[0].Key); Assert.AreEqual("coucou1bis", result[0].Value); Assert.AreEqual("test", result[1].Key); Assert.AreEqual("coucou1", result[1].Value); Assert.AreEqual("test2", result[2].Key); Assert.AreEqual("coucou2bis", result[2].Value); Assert.AreEqual("test", result[3].Key); Assert.AreEqual("coucou2", result[3].Value); }
public void CountTest() { InMemoryKeyValueStore store1 = new InMemoryKeyValueStore("store"); InMemoryKeyValueStore store2 = new InMemoryKeyValueStore("store"); var dt = DateTime.Now.GetMilliseconds(); var valueSerdes = new ValueAndTimestampSerDes <string>(new StringSerDes()); var bytes = new Bytes(Encoding.UTF8.GetBytes("test")); var bytes2 = new Bytes(Encoding.UTF8.GetBytes("test2")); var provider = new MockStateProvider <string, string>(1000 * 10, new StringSerDes(), new StringSerDes(), store1, store2); var composite = new CompositeReadOnlyKeyValueStore <string, string>(provider, storeType, "store"); store1.Put(bytes, valueSerdes.Serialize(ValueAndTimestamp <string> .Make("coucou1", dt), new SerializationContext())); store2.Put(bytes2, valueSerdes.Serialize(ValueAndTimestamp <string> .Make("coucou2", dt), new SerializationContext())); Assert.AreEqual(2, composite.ApproximateNumEntries()); }
public void FetchTest() { InMemoryWindowStore store1 = new InMemoryWindowStore("store", TimeSpan.FromDays(1), 1000 * 10); InMemoryWindowStore store2 = new InMemoryWindowStore("store", TimeSpan.FromDays(1), 1000 * 10); var dt = DateTime.Now.GetMilliseconds(); var valueSerdes = new ValueAndTimestampSerDes <string>(new StringSerDes()); var bytes = new Bytes(Encoding.UTF8.GetBytes("test")); var provider = new MockStateProvider <string, string>(1000 * 10, new StringSerDes(), new StringSerDes(), store1, store2); var composite = new CompositeReadOnlyWindowStore <string, string>(provider, new WindowStoreType <string, string>(), "store"); store1.Put(bytes, valueSerdes.Serialize(ValueAndTimestamp <string> .Make("coucou1", dt), new SerializationContext()), dt); var result = composite.Fetch("test", dt); Assert.IsNotNull(result); Assert.AreEqual("coucou1", result); }
public void GetTest() { InMemoryKeyValueStore store1 = new InMemoryKeyValueStore("store"); InMemoryKeyValueStore store2 = new InMemoryKeyValueStore("store"); var dt = DateTime.Now.GetMilliseconds(); var valueSerdes = new ValueAndTimestampSerDes <string>(new StringSerDes()); var bytes = new Bytes(Encoding.UTF8.GetBytes("test")); var provider = new MockStateProvider <string, string>(1000 * 10, new StringSerDes(), new StringSerDes(), store1, store2); var composite = new CompositeReadOnlyKeyValueStore <string, string>(provider, storeType, "store"); store1.Put(bytes, valueSerdes.Serialize(ValueAndTimestamp <string> .Make("coucou1", dt))); var result = composite.Get("test"); Assert.IsNotNull(result); Assert.AreEqual("coucou1", result); }
/// <summary> /// Creates a mock state provider for using during testing. /// </summary> /// <returns>The mock StateProvider ready for use.</returns> public BaseStateProvider CreateMockState() { BaseStateProvider config = new MockStateProvider(this); return config; }