public DictQueueCacheCursor(IterableDict<string, DictBatchContainer> dict, string streamNamespace, Guid streamGuid)
 {
     _dict = dict;
     _curosr = _dict.GetCursor();
     _streamNamespace = streamNamespace;
     _streamGuid = streamGuid;
 }
Exemple #2
0
        public void CreateFromExistingDict()
        {
            // create new normal dict
            var internalDict = new Dictionary <int, int>();
            // copy the iterable one into it
            var cursor = _dict.GetCursor();
            int i      = 0;

            while (cursor.MoveNext())
            {
                var v = cursor.GetCurrent();
                internalDict.AddOrUpdate(i, v);
                i++;
            }

            // create a new iterable from the normal dict
            var dict = new IterableDict <int, int>(internalDict);

            // read all from the new iterable
            var cursor1     = dict.GetCursor();
            var cursor1Read = new Dictionary <int, int>();
            IterableLinkedListNode <int> curr;

            while (cursor1.MoveNext())
            {
                curr = cursor1.GetCurrentNode();
                Assert.IsNotNull(curr?.Value);
                cursor1Read.AddOrUpdate(curr.Value, dict[curr.Value]);
            }

            // Check that we read the same from the new iterable as the normal dict
            foreach (var pair in internalDict)
            {
                Assert.IsTrue(cursor1Read.ContainsKey(pair.Key));
                Assert.AreEqual(cursor1Read[pair.Key], pair.Value);
            }
        }
Exemple #3
0
        public void ModifyNextNode()
        {
            var cursor1 = _dict.GetCursor();

            var cursor1Read = new Dictionary <int, int>();
            IterableLinkedListNode <int> curr;

            // read
            Assert.IsTrue(cursor1.MoveNext(), "Couldn't read next");
            curr = cursor1.GetCurrentNode();
            Assert.IsNotNull(curr?.Value);
            cursor1Read.AddOrUpdate(curr.Value, _dict[curr.Value]);

            // read
            Assert.IsTrue(cursor1.MoveNext(), "Couldn't read next");
            curr = cursor1.GetCurrentNode();
            Assert.IsNotNull(curr?.Value);
            cursor1Read.Add(curr.Value, _dict[curr.Value]);


            // update next node
            _dict.AddOrUpdate(2, _dict[2] * 2);

            // read the rest
            while (cursor1.MoveNext())
            {
                curr = cursor1.GetCurrentNode();
                Assert.IsNotNull(curr?.Value);
                cursor1Read.AddOrUpdate(curr.Value, _dict[curr.Value]);
            }

            // read from beginning with a new cursor
            var cursor2     = _dict.GetCursor();
            var cursor2Read = new Dictionary <int, int>();

            while (cursor2.MoveNext())
            {
                curr = cursor2.GetCurrentNode();
                Assert.IsNotNull(curr?.Value);
                cursor2Read.AddOrUpdate(curr.Value, _dict[curr.Value]);
            }

            // Check we got the same
            foreach (var pair in cursor1Read)
            {
                Assert.IsTrue(cursor2Read.ContainsKey(pair.Key));
                Assert.AreEqual(cursor2Read[pair.Key], pair.Value);
            }
        }