コード例 #1
0
        public void CanPersist()
        {
            using (var context = new TransactionOperationContext(Env, 1024, 1024, SharedMultipleUseFlag.None))
            {
                var key1 = context.GetLazyString("orders/1");

                using (var tx = Env.WriteTransaction())
                {
                    var tree = tx.CreateTree("Filters");

                    using (var filter = new CollectionOfBloomFilters.BloomFilter64(0, tree, writable: true, allocator: context.Allocator))
                    {
                        Assert.True(filter.Add(key1));
                        Assert.Equal(1, filter.Count);
                    }

                    tx.Commit();
                }

                using (var tx = Env.WriteTransaction())
                {
                    var tree = tx.CreateTree("Filters");

                    using (var filter = new CollectionOfBloomFilters.BloomFilter64(0, tree, writable: false, allocator: context.Allocator))
                    {
                        Assert.False(filter.Add(key1));
                        Assert.Equal(1, filter.Count);
                    }
                }

                context.ReturnMemory(key1.AllocatedMemoryData);
            }
        }
コード例 #2
0
        public void CheckReadonly()
        {
            using (var context = new TransactionOperationContext(Env, 1024, 1024, SharedMultipleUseFlag.None))
            {
                using (var tx = context.OpenWriteTransaction())
                {
                    var tree = context.Transaction.InnerTransaction.CreateTree("BloomFilters");
                    tree.Increment("Count64", 2);

                    using (var filter = new CollectionOfBloomFilters.BloomFilter64(0, tree, writable: true, allocator: context.Allocator))
                    {
                        Assert.False(filter.ReadOnly);
                        filter.MakeReadOnly();
                        Assert.True(filter.ReadOnly);
                    }

                    tx.Commit();
                }

                using (context.OpenWriteTransaction())
                {
                    using (var collection = CollectionOfBloomFilters.Load(CollectionOfBloomFilters.Mode.X64, context))
                    {
                        Assert.Equal(2, collection.Count);

                        Assert.True(collection[0].ReadOnly);
                        Assert.False(collection[1].ReadOnly);
                    }
                }
            }
        }
コード例 #3
0
        public void CheckWritability()
        {
            using (var context = new TransactionOperationContext(Env, 1024, 1024, 32 * 1024, SharedMultipleUseFlag.None))
            {
                var key1 = context.GetLazyString("orders/1");
                var key2 = context.GetLazyString("orders/2");

                using (var tx = Env.WriteTransaction())
                {
                    var tree = tx.CreateTree("Filters");

                    using (var filter = new CollectionOfBloomFilters.BloomFilter64(0, tree, writable: true, allocator: context.Allocator))
                    {
                        Assert.True(filter.Add(key1));
                        Assert.Equal(1, filter.Count);
                        Assert.True(filter.Writable);
                        Assert.False(filter.ReadOnly);

                        filter.Flush();
                    }

                    tx.Commit();
                }

                using (var tx = Env.WriteTransaction())
                {
                    var tree = tx.CreateTree("Filters");

                    using (var filter = new CollectionOfBloomFilters.BloomFilter64(0, tree, writable: false, allocator: context.Allocator))
                    {
                        Assert.False(filter.Writable);

                        Assert.False(filter.Add(key1));
                        Assert.Equal(1, filter.Count);
                        Assert.False(filter.Writable);

                        Assert.True(filter.Add(key2));
                        Assert.Equal(2, filter.Count);
                        Assert.True(filter.Writable);
                    }
                }
            }
        }
コード例 #4
0
        public void Basic()
        {
            using (var context = new TransactionOperationContext(Env, 1024, 1024, 32 * 1024, SharedMultipleUseFlag.None))
            {
                using (var tx = Env.WriteTransaction())
                {
                    var tree = tx.CreateTree("Filters");

                    var key1 = context.GetLazyString("orders/1");
                    var key2 = context.GetLazyString("orders/2");

                    using (var filter = new CollectionOfBloomFilters.BloomFilter64(0, BloomFilterVersion.CurrentVersion, tree, writable: true, allocator: context.Allocator))
                    {
                        Assert.False(filter.Contains(key1));
                        Assert.False(filter.Contains(key2));
                        Assert.Equal(0, filter.Count);

                        Assert.True(filter.Add(key1));
                        Assert.True(filter.Contains(key1));
                        Assert.False(filter.Contains(key2));
                        Assert.Equal(1, filter.Count);

                        Assert.False(filter.Add(key1));
                        Assert.True(filter.Contains(key1));
                        Assert.False(filter.Contains(key2));
                        Assert.Equal(1, filter.Count);

                        Assert.True(filter.Add(key2));
                        Assert.True(filter.Contains(key1));
                        Assert.True(filter.Contains(key2));
                        Assert.Equal(2, filter.Count);

                        Assert.False(filter.Add(key1));
                        Assert.True(filter.Contains(key1));
                        Assert.True(filter.Contains(key2));
                        Assert.Equal(2, filter.Count);
                    }

                    tx.Commit();
                }
            }
        }