public void PutTwoElementDifferentKeyDifferentTime()
        {
            var date  = DateTime.Now;
            var dt2   = date.AddSeconds(1);
            var key   = new Bytes(Encoding.UTF8.GetBytes("test-key"));
            var key2  = new Bytes(Encoding.UTF8.GetBytes("coucou-key"));
            var store = new InMemoryWindowStore("store", defaultRetention, (long)defaultSize.TotalMilliseconds);

            store.Put(key, BitConverter.GetBytes(100), date.GetMilliseconds());
            store.Put(key2, BitConverter.GetBytes(300), dt2.GetMilliseconds());
            var r = store.Fetch(key, date.GetMilliseconds());

            Assert.IsNotNull(r);
            Assert.AreEqual(BitConverter.GetBytes(100), r);

            r = store.Fetch(key, dt2.GetMilliseconds());
            Assert.IsNull(r);

            r = store.Fetch(key2, dt2.GetMilliseconds());
            Assert.IsNotNull(r);
            Assert.AreEqual(BitConverter.GetBytes(300), r);

            r = store.Fetch(key2, date.GetMilliseconds());
            Assert.IsNull(r);
        }
        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 FetchKeyDoesNotExist()
        {
            var date  = DateTime.Now;
            var store = new InMemoryWindowStore("store", defaultRetention, (long)defaultSize.TotalMilliseconds);

            Assert.IsNull(store.Fetch(new Bytes(new byte[0]), 100));
        }
        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 EmptyWindowStoreIteratorTest()
        {
            var dt         = DateTime.Now;
            var store      = new InMemoryWindowStore("store", TimeSpan.FromSeconds(1), (long)defaultSize.TotalMilliseconds);
            var enumerator = store.Fetch(new Bytes(null), dt.AddDays(1), dt);

            Assert.IsAssignableFrom <EmptyWindowStoreEnumerator <byte[]> >(enumerator);
            Assert.IsFalse(enumerator.MoveNext());
            enumerator.Reset();
            Assert.AreEqual(0, enumerator.ToList().Count);
        }
        public void PutOneElement()
        {
            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, BitConverter.GetBytes(100), date.GetMilliseconds());
            var r = store.Fetch(key, date.GetMilliseconds());

            Assert.IsNotNull(r);
            Assert.AreEqual(BitConverter.GetBytes(100), r);
        }
示例#7
0
        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 WindowStoreEnumerator <string>(store.Fetch(key, date.AddSeconds(-1), date.AddSeconds(1)), new StringSerDes());

            enumerator.Dispose();
            Assert.Throws <ObjectDisposedException>(() => enumerator.MoveNext());
        }
示例#8
0
        public void WindowStoreEnumeratorWithSerdes()
        {
            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 WindowStoreEnumerator <string>(store.Fetch(key, date.AddSeconds(-1), date.AddSeconds(1)), new StringSerDes());
            var items      = enumerator.ToList();

            Assert.AreEqual(1, items.Count);
            Assert.AreEqual("value", items[0].Value);
            Assert.AreEqual(date.GetMilliseconds(), items[0].Key);
        }
        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());
        }
        public void WindowStoreEnumeratorWithSerdes()
        {
            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));
            var items = enumerator.ToList();

            Assert.AreEqual(1, items.Count);
            Assert.AreEqual("value", items[0].Value);
            Assert.AreEqual(date.GetMilliseconds(), items[0].Key);
        }
示例#11
0
        public void WindowStoreEnumeratorTestNext()
        {
            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 WindowStoreEnumerator <string>(store.Fetch(key, date.AddSeconds(-1), date.AddSeconds(1)), new StringSerDes());
            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);
        }