コード例 #1
0
        public void Can_find_bloom_with_fromBlock_offset(long from, long to, long[] blocksSet, int[] levels)
        {
            var storage = CreateBloomStorage(new BloomConfig()
            {
                IndexLevelBucketSizes = levels
            });
            var bloom = new Core.Bloom();

            byte[] bytes = { 1, 2, 3 };
            bloom.Set(bytes);
            foreach (var blockNumber in blocksSet)
            {
                if (blockNumber > storage.MaxBlockNumber + 1)
                {
                    // Assert.Fail($"Missing blocks. Trying inserting {blockNumber}, when current max block is {storage.MaxBlockNumber}.");
                }
                storage.Store(blockNumber, bloom);
            }

            var          bloomEnumeration = storage.GetBlooms(from, to);
            IList <long> foundBlocks      = new List <long>(blocksSet.Length);

            foreach (var b in bloomEnumeration)
            {
                if (b.Matches(bytes) && bloomEnumeration.TryGetBlockNumber(out var block))
                {
                    foundBlocks.Add(block);
                }
            }

            var expectedFoundBlocks = blocksSet.Where(b => b >= from && b <= to).ToArray();

            TestContext.Out.WriteLine($"Expected found blocks: {string.Join(", ", expectedFoundBlocks)}");
            foundBlocks.Should().BeEquivalentTo(expectedFoundBlocks);
        }
コード例 #2
0
        public void Can_safely_insert_concurrently()
        {
            _config.IndexLevelBucketSizes = new[] { byte.MaxValue + 1 };
            var storage = new BloomStorage(_config, _bloomDb, _fileStoreFactory);

            Core.Bloom expectedBloom = new Core.Bloom();
            for (int i = 0; i <= byte.MaxValue; i++)
            {
                expectedBloom.Set(i);
            }

            Parallel.For(0, byte.MaxValue * byte.MaxValue * 2, i =>
            {
                var bloom = new Core.Bloom();
                bloom.Set(i % Core.Bloom.BitLength);
                storage.Store(i, bloom);
            });

            var first = storage.GetBlooms(0, byte.MaxValue * 3).First();

            first.Should().Be(expectedBloom);
        }