Esempio n. 1
0
        public void Test_Empty_Subspace_Is_Empty()
        {
            var subspace = KeySubspace.FromKey(Slice.Empty);

            Assert.That(subspace, Is.Not.Null, "FdbSubspace.Empty should not return null");
            Assert.That(subspace.GetPrefix(), Is.EqualTo(Slice.Empty), "FdbSubspace.Empty.Key should be equal to Slice.Empty");
            Assert.That(subspace.Copy(), Is.Not.SameAs(subspace));
        }
Esempio n. 2
0
 public void Test_Cannot_Create_Or_Partition_Subspace_With_Slice_Nil()
 {
     Assert.That(() => new KeySubspace(Slice.Nil), Throws.ArgumentException);
     Assert.That(() => KeySubspace.FromKey(Slice.Nil), Throws.ArgumentException);
     //FIXME: typed subspaces refactoring !
     //Assert.That(() => FdbSubspace.Empty.Partition[Slice.Nil], Throws.ArgumentException);
     //Assert.That(() => FdbSubspace.Create(FdbKey.Directory).Partition[Slice.Nil], Throws.ArgumentException);
 }
Esempio n. 3
0
        //TODO: move these methods to FdbTest ?

        /// <summary>Connect to the local test database</summary>
        public static Task <IFdbDatabase> OpenTestDatabaseAsync(CancellationToken ct)
        {
            var options = new FdbConnectionOptions
            {
                ClusterFile    = TestClusterFile,
                DbName         = TestDbName,
                GlobalSpace    = KeySubspace.FromKey(TestGlobalPrefix),
                DefaultTimeout = TimeSpan.FromMilliseconds(DefaultTimeout),
            };

            return(Fdb.OpenAsync(options, ct));
        }
Esempio n. 4
0
        public void Test_Subspace_Copy_Does_Not_Share_Key_Buffer()
        {
            var original = KeySubspace.FromKey(Slice.FromString("Hello"));
            var copy     = original.Copy();

            Assert.That(copy, Is.Not.Null);
            Assert.That(copy, Is.Not.SameAs(original), "Copy should be a new instance");
            Assert.That(copy.GetPrefix(), Is.EqualTo(original.GetPrefix()), "Key should be equal");
            Assert.That(copy.GetPrefix().Array, Is.Not.SameAs(original.GetPrefix().Array), "Key should be a copy of the original");

            Assert.That(copy, Is.EqualTo(original), "Copy and original should be considered equal");
            Assert.That(copy.ToString(), Is.EqualTo(original.ToString()), "Copy and original should have the same string representation");
            Assert.That(copy.GetHashCode(), Is.EqualTo(original.GetHashCode()), "Copy and original should have the same hashcode");
        }
        public async Task Test_Can_Open_Database_With_Non_Empty_GlobalSpace()
        {
            // using a tuple prefix
            using (var db = await Fdb.OpenAsync(new FdbConnectionOptions {
                GlobalSpace = KeySubspace.FromKey(TuPack.EncodeKey("test"))
            }, this.Cancellation))
            {
                Assert.That(db, Is.Not.Null);
                Assert.That(db.GlobalSpace, Is.Not.Null);
                Assert.That(db.GlobalSpace.GetPrefix().ToString(), Is.EqualTo("<02>test<00>"));

                var subspace = db.Partition.ByKey("hello");
                Assert.That(subspace.GetPrefix().ToString(), Is.EqualTo("<02>test<00><02>hello<00>"));

                // keys inside the global space are valid
                Assert.That(db.IsKeyValid(TuPack.EncodeKey("test", 123)), Is.True);

                // keys outside the global space are invalid
                Assert.That(db.IsKeyValid(Slice.FromByte(42)), Is.False);
            }

            // using a random binary prefix
            using (var db = await Fdb.OpenAsync(new FdbConnectionOptions {
                GlobalSpace = KeySubspace.FromKey(new byte[] { 42, 255, 0, 90 }.AsSlice())
            }, this.Cancellation))
            {
                Assert.That(db, Is.Not.Null);
                Assert.That(db.GlobalSpace, Is.Not.Null);
                Assert.That(db.GlobalSpace.GetPrefix().ToString(), Is.EqualTo("*<FF><00>Z"));

                var subspace = db.Partition.ByKey("hello");
                Assert.That(subspace.GetPrefix().ToString(), Is.EqualTo("*<FF><00>Z<02>hello<00>"));

                // keys inside the global space are valid
                Assert.That(db.IsKeyValid(Slice.Unescape("*<FF><00>Z123")), Is.True);

                // keys outside the global space are invalid
                Assert.That(db.IsKeyValid(Slice.FromByte(123)), Is.False);
                Assert.That(db.IsKeyValid(Slice.Unescape("*<FF>")), Is.False);
            }
        }
Esempio n. 6
0
        private static async Task MainAsync(CancellationToken ct)
        {
            // change the path to the native lib if not default
            if (NATIVE_PATH != null)
            {
                Fdb.Options.SetNativeLibPath(NATIVE_PATH);
            }

            // uncomment this to enable network thread tracing
            // FdbCore.TracePath = Path.Combine(Path.GetTempPath(), "fdb");

            int apiVersion = Fdb.GetMaxApiVersion();

            Console.WriteLine("Max API Version: " + apiVersion);

            try
            {
                Console.WriteLine("Starting network thread...");
                Fdb.Start(Fdb.GetDefaultApiVersion());
                Console.WriteLine("> Up and running");

                Console.WriteLine("Connecting to local cluster...");
                using (var cluster = await Fdb.CreateClusterAsync(CLUSTER_FILE, ct))
                {
                    Console.WriteLine("> Connected!");

                    Console.WriteLine("Opening database 'DB'...");
                    using (var db = await cluster.OpenDatabaseAsync(DB_NAME, KeySubspace.FromKey(Slice.FromByte(253)), false, ct))
                    {
                        Console.WriteLine("> Connected to db '{0}'", db.Name);

                        // get coordinators
                        var cf = await Fdb.System.GetCoordinatorsAsync(db, ct);

                        Console.WriteLine("Coordinators: " + cf.ToString());

                        // clear everything
                        using (var tr = db.BeginTransaction(ct))
                        {
                            Console.WriteLine("Clearing subspace " + db.GlobalSpace + " ...");
                            tr.ClearRange(db.GlobalSpace);
                            await tr.CommitAsync();

                            Console.WriteLine("> Database cleared");
                        }

                        Console.WriteLine();

                        await TestSimpleTransactionAsync(db, ct);

                        await BenchInsertSmallKeysAsync(db, N, 16, ct);                         // some guid
                        await BenchInsertSmallKeysAsync(db, N, 60 * 4, ct);                     // one Int32 per minutes, over an hour
                        await BenchInsertSmallKeysAsync(db, N, 512, ct);                        // small JSON payload
                        await BenchInsertSmallKeysAsync(db, N / 5, 4096, ct);                   // typical small cunk size
                        await BenchInsertSmallKeysAsync(db, N / 100, 65536, ct);                // typical medium chunk size
                        await BenchInsertSmallKeysAsync(db, 20, 100_000, ct);                   // Maximum value size (as of beta 1)

                        // insert keys in parrallel
                        await BenchConcurrentInsert(db, 1, 100, 512, ct);
                        await BenchConcurrentInsert(db, 1, 1_000, 512, ct);
                        await BenchConcurrentInsert(db, 1, 10_000, 512, ct);

                        await BenchConcurrentInsert(db, 1, N, 16, ct);
                        await BenchConcurrentInsert(db, 2, N, 16, ct);
                        await BenchConcurrentInsert(db, 4, N, 16, ct);
                        await BenchConcurrentInsert(db, 8, N, 16, ct);
                        await BenchConcurrentInsert(db, 16, N, 16, ct);

                        await BenchSerialWriteAsync(db, N, ct);
                        await BenchSerialReadAsync(db, N, ct);
                        await BenchConcurrentReadAsync(db, N, ct);

                        await BenchClearAsync(db, N, ct);

                        await BenchUpdateSameKeyLotsOfTimesAsync(db, 1000, ct);

                        await BenchUpdateLotsOfKeysAsync(db, 1000, ct);

                        await BenchBulkInsertThenBulkReadAsync(db, 100_000, 50, 128, ct);
                        await BenchBulkInsertThenBulkReadAsync(db, 100_000, 128, 50, ct);
                        await BenchBulkInsertThenBulkReadAsync(db, 1_000_000, 50, 128, ct);

                        await BenchMergeSortAsync(db, 100, 3, 20, ct);
                        await BenchMergeSortAsync(db, 1_000, 10, 100, ct);
                        await BenchMergeSortAsync(db, 100, 100, 100, ct);
                        await BenchMergeSortAsync(db, 100, 1_000, 100, ct);

                        Console.WriteLine("time to say goodbye...");
                    }
                }
            }
            finally
            {
                Console.WriteLine("### DONE ###");
                Fdb.Stop();
            }
#if DEBUG
            //Console.ReadLine();
#endif
        }