Ejemplo n.º 1
0
        public async Task Different_users_can_use_cache()
        {
            HintBasedCache hintBasedCache = new HintBasedCache(e => new NullDataSet(), LimboLogs.Instance);

            hintBasedCache.Hint(_guidA, 0, 29999);
            hintBasedCache.Hint(_guidB, 30000, 59999);
            await WaitFor(() => hintBasedCache.CachedEpochsCount == 2);

            for (uint i = 0; i < 2; i++)
            {
                Assert.NotNull(hintBasedCache.Get(i));
            }
        }
Ejemplo n.º 2
0
        public async Task Moving_range_evicts_cached_epochs()
        {
            HintBasedCache hintBasedCache = new HintBasedCache(e => new NullDataSet(), LimboLogs.Instance);

            hintBasedCache.Hint(_guidA, 0, 209999);
            hintBasedCache.Hint(_guidA, 30000, 239999);
            await WaitFor(() => hintBasedCache.CachedEpochsCount == 7);

            Assert.Null(hintBasedCache.Get(0));
            for (uint i = 1; i < 8; i++)
            {
                Assert.NotNull(hintBasedCache.Get(i), i.ToString());
            }
        }
Ejemplo n.º 3
0
        public async Task Different_users_can_use_disconnected_epochs()
        {
            HintBasedCache hintBasedCache = new HintBasedCache(e => new NullDataSet(), LimboLogs.Instance);

            hintBasedCache.Hint(_guidA, 0, 29999);
            hintBasedCache.Hint(_guidB, 120000, 149999);
            await WaitFor(() => hintBasedCache.CachedEpochsCount == 2);

            Assert.NotNull(hintBasedCache.Get(0));
            Assert.Null(hintBasedCache.Get(1));
            Assert.Null(hintBasedCache.Get(2));
            Assert.Null(hintBasedCache.Get(3));
            Assert.NotNull(hintBasedCache.Get(4));
        }
Ejemplo n.º 4
0
        public async Task Many_threads()
        {
            int            range          = 10000000;
            HintBasedCache hintBasedCache = new HintBasedCache(e => new NullDataSet(), LimboLogs.Instance);

            void KeepHinting(Guid guid, int start)
            {
                for (int i = start; i <= range; i++)
                {
                    hintBasedCache.Hint(guid, i, i + 120000);
                }
            };

            Task a = new Task(() => KeepHinting(_guidA, 100000));
            Task b = new Task(() => KeepHinting(_guidB, 0));
            Task c = new Task(() => KeepHinting(_guidC, 500000));

            a.Start();
            b.Start();
            c.Start();

            await Task.WhenAll(a, b, c);

            Assert.AreEqual(5, hintBasedCache.CachedEpochsCount);
            for (uint i = (uint)(range / Ethash.EpochLength); i < (uint)((range + 120000) / Ethash.EpochLength); i++)
            {
                Assert.NotNull(hintBasedCache.Get(i));
            }
        }
Ejemplo n.º 5
0
        public void Sync_hint_and_get()
        {
            HintBasedCache hintBasedCache = new HintBasedCache(e => new NullDataSet(), LimboLogs.Instance);

            hintBasedCache.Hint(_guidA, 200000, 200000);
            Assert.NotNull(hintBasedCache.Get((uint)(200000 / Ethash.EpochLength)));
        }
Ejemplo n.º 6
0
        public async Task Can_hint_far()
        {
            HintBasedCache hintBasedCache = new HintBasedCache(e => new NullDataSet(), LimboLogs.Instance);

            hintBasedCache.Hint(_guidA, 1000000000, 1000000000);
            await WaitFor(() => hintBasedCache.CachedEpochsCount == 1);

            Assert.NotNull(hintBasedCache.Get(1000000000 / 30000));
        }
Ejemplo n.º 7
0
        public async Task With_hint_returns_value()
        {
            HintBasedCache hintBasedCache = new HintBasedCache(e => new NullDataSet(), LimboLogs.Instance);

            hintBasedCache.Hint(_guidA, 0, 200000);
            await WaitFor(() => hintBasedCache.CachedEpochsCount == 7);

            for (uint i = 0; i < 7; i++)
            {
                Assert.NotNull(hintBasedCache.Get(i));
            }
        }
Ejemplo n.º 8
0
        public void Throws_on_wide_hint()
        {
            HintBasedCache hintBasedCache = new HintBasedCache(e => new NullDataSet(), LimboLogs.Instance);

            Assert.Throws <InvalidOperationException>(() => hintBasedCache.Hint(_guidA, 0, 1000000000));
        }