public async Task Test_Can_Open_Database() { //README: if your default cluster is remote, you need to be connected to the netword, or it will fail. // the hard way using (var cluster = await Fdb.CreateClusterAsync(null, this.Cancellation)) { Assert.That(cluster, Is.Not.Null); Assert.That(cluster.Path, Is.Null); using (var db = await cluster.OpenDatabaseAsync("DB", KeySubspace.Empty, false, this.Cancellation)) { Assert.That(db, Is.Not.Null, "Should return a valid object"); Assert.That(db.Name, Is.EqualTo("DB"), "FdbDatabase.Name should match"); Assert.That(db.Cluster, Is.SameAs(cluster), "FdbDatabase.Cluster should point to the parent cluster"); } } // the easy way using (var db = await Fdb.OpenAsync()) { Assert.That(db, Is.Not.Null); Assert.That(db.Name, Is.EqualTo("DB")); Assert.That(db.Cluster, Is.Not.Null); Assert.That(db.Cluster.Path, Is.Null); } }
public async Task Test_Open_Or_CreateCluster_With_Corrupted_ClusterFile_Should_Fail() { // Using a corrupted cluster file should fail with "ConnectionStringInvalid" // write some random bytes into a cluster file string path = System.IO.Path.GetTempFileName(); try { var rnd = new Random(); var bytes = new byte[128]; rnd.NextBytes(bytes); System.IO.File.WriteAllBytes(path, bytes); await TestHelpers.AssertThrowsFdbErrorAsync(() => Fdb.CreateClusterAsync(path, this.Cancellation), FdbError.ConnectionStringInvalid, "Should fail if file is corrupted"); await TestHelpers.AssertThrowsFdbErrorAsync(() => Fdb.OpenAsync(new FdbConnectionOptions { ClusterFile = path }, this.Cancellation), FdbError.ConnectionStringInvalid, "Should fail if file is corrupted"); } finally { System.IO.File.Delete(path); } }
public async Task Test_Open_Or_CreateCluster_With_Invalid_ClusterFile_Path_Should_Fail() { // Missing/Invalid cluster files should fail with "NoClusterFileFound" // file not found await TestHelpers.AssertThrowsFdbErrorAsync(() => Fdb.CreateClusterAsync(@".\file_not_found.cluster", this.Cancellation), FdbError.NoClusterFileFound, "Should fail if cluster file is missing"); await TestHelpers.AssertThrowsFdbErrorAsync(() => Fdb.OpenAsync(new FdbConnectionOptions { ClusterFile = @".\file_not_found.cluster" }, this.Cancellation), FdbError.NoClusterFileFound, "Should fail if cluster file is missing"); // unreachable path await TestHelpers.AssertThrowsFdbErrorAsync(() => Fdb.CreateClusterAsync(@"C:\..\..\fdb.cluster", this.Cancellation), FdbError.NoClusterFileFound, "Should fail if path is malformed"); await TestHelpers.AssertThrowsFdbErrorAsync(() => Fdb.OpenAsync(new FdbConnectionOptions { ClusterFile = @"C:\..\..\fdb.cluster" }, this.Cancellation), FdbError.NoClusterFileFound, "Should fail if path is malformed"); // malformed path await TestHelpers.AssertThrowsFdbErrorAsync(() => Fdb.CreateClusterAsync(@"FOO:\invalid$path!/fdb.cluster", this.Cancellation), FdbError.NoClusterFileFound, "Should fail if path is malformed"); await TestHelpers.AssertThrowsFdbErrorAsync(() => Fdb.OpenAsync(new FdbConnectionOptions { ClusterFile = @"FOO:\invalid$path!/fdb.cluster" }, this.Cancellation), FdbError.NoClusterFileFound, "Should fail if path is malformed"); }
public async Task Test_Can_Connect_To_Local_Cluster() { using (var cluster = await Fdb.CreateClusterAsync(this.Cancellation)) { Assert.That(cluster, Is.Not.Null, "Should return a valid object"); Assert.That(cluster.Path, Is.Null, "FdbCluster.Path should be null"); } }
public void Test_Connecting_To_Cluster_With_Cancelled_Token_Should_Fail() { using (var cts = new CancellationTokenSource()) { cts.Cancel(); Assert.Throws <OperationCanceledException>(() => Fdb.CreateClusterAsync(cts.Token).GetAwaiter().GetResult()); } }
public async Task Test_Open_Database_With_Cancelled_Token_Should_Fail() { using (var cts = new CancellationTokenSource()) { using (var cluster = await Fdb.CreateClusterAsync(cts.Token)) { cts.Cancel(); Assert.That(async() => await cluster.OpenDatabaseAsync("DB", KeySubspace.Empty, false, cts.Token), Throws.InstanceOf <OperationCanceledException>()); } } }
public async Task Test_Open_Database_With_Cancelled_Token_Should_Fail() { using (var cts = new CancellationTokenSource()) { using (var cluster = await Fdb.CreateClusterAsync(cts.Token)) { cts.Cancel(); Assert.Throws <OperationCanceledException>(() => cluster.OpenDatabaseAsync("DB", FdbSubspace.Empty, false, cts.Token).GetAwaiter().GetResult()); } } }
public async Task Test_Open_Database_With_Invalid_Name_Should_Fail() { // As of 1.0, the only accepted database name is "DB". // Any other name should fail with "InvalidDatabaseName" // note: Don't forget to update this test if in the future if the API allows for other names ! using (var cluster = await Fdb.CreateClusterAsync(this.Cancellation)) { await TestHelpers.AssertThrowsFdbErrorAsync(() => cluster.OpenDatabaseAsync("SomeOtherName", KeySubspace.Empty, false, this.Cancellation), FdbError.InvalidDatabaseName, "Passing anything other then 'DB' should fail"); } await TestHelpers.AssertThrowsFdbErrorAsync(() => Fdb.OpenAsync(null, "SomeOtherName"), FdbError.InvalidDatabaseName, "Passing anything other then 'DB' should fail"); await TestHelpers.AssertThrowsFdbErrorAsync(() => Fdb.OpenAsync(null, "SomeOtherName", KeySubspace.Empty), FdbError.InvalidDatabaseName, "Passing anything other then 'DB' should fail"); }
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(); // this will select API version 21 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, new FdbSubspace(FdbTuple.Create(SUBSPACE)), 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); Console.WriteLine("----------"); 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, 4096, ct); // typical small cunk size ////await BenchInsertSmallKeysAsync(db, N / 10, 65536, ct); // typical medium chunk size //await BenchInsertSmallKeysAsync(db, 1, 100000, ct); // Maximum value size (as of beta 1) ////// insert keys in parrallel await BenchConcurrentInsert(db, 1, 100, 512, ct); await BenchConcurrentInsert(db, 1, 1000, 512, ct); await BenchConcurrentInsert(db, 1, 10000, 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 * 1000, 50, 128, ct); await BenchBulkInsertThenBulkReadAsync(db, 100 * 1000, 128, 50, ct); ////await BenchBulkInsertThenBulkReadAsync(db, 1 * 1000 * 1000, 50, 128, ct); await BenchMergeSortAsync(db, 100, 3, 20, ct); await BenchMergeSortAsync(db, 1000, 10, 100, ct); await BenchMergeSortAsync(db, 100, 100, 100, ct); await BenchMergeSortAsync(db, 100, 1000, 100, ct); Console.WriteLine("time to say goodbye..."); } } } finally { Console.WriteLine("### DONE ###"); Fdb.Stop(); } #if DEBUG Console.ReadLine(); #endif }