Beispiel #1
0
        public string[] ConsensusEvents()
        {
            var(lastWindow, _) = consensusCache.GetLastWindow();

            var res = new List <string>();

            foreach (var item in lastWindow)
            {
                res.Add(item);
            }
            return(res.ToArray());
        }
Beispiel #2
0
        public void TestRollingIndex()
        {
            const int size = 10;

            const int testSize = 3 * size;

            var rollingIndex = new RollingIndex <string>(size);

            var items = new List <string>();
            int i;

            string item;

            for (i = 0; i < testSize; i++)
            {
                item = $"item {i}";

                rollingIndex.Add(item, i);

                items.Add(item);
            }
            var(cached, lastIndex) = rollingIndex.GetLastWindow();

            var expectedLastIndex = testSize - 1;

            // last index
            Assert.Equal(expectedLastIndex, lastIndex);

            var start = testSize / (2 * size) * size;
            var count = testSize - start;

            for (i = 0; i < count; i++)
            {
                //Console.WriteLine("{0},{1}", items[start + i], cached[i]);
                Assert.Equal(items[start + i], cached[i]);
            }


            var err = rollingIndex.Add("PassedIndex", expectedLastIndex - 1);

            Assert.Equal(StoreErrorType.PassedIndex, err.StoreErrorType);


            err = rollingIndex.Add("PassedIndex", expectedLastIndex + 2);
            Assert.Equal(StoreErrorType.SkippedIndex, err.StoreErrorType);


            (_, err) = rollingIndex.GetItem(9);
            Assert.Equal(StoreErrorType.TooLate, err.StoreErrorType);


            var indexes = new[] { 10, 17, 29 };

            foreach (var id in indexes)
            {
                (item, err) = rollingIndex.GetItem(id);

                Assert.Null(err);

                item.ShouldCompareTo(items[id]);
            }


            (_, err) = rollingIndex.GetItem(lastIndex + 1);
            Assert.Equal(StoreErrorType.KeyNotFound, err.StoreErrorType);
        }