public async Task Test_FdbMultiMap_Read_Write_Delete() { using (var db = await OpenTestPartitionAsync()) { var location = db.Root["Collections"]["MultiMaps"]; await CleanLocation(db, location); var mapFoos = new FdbMultiMap <string, string>(location.ByKey("Foos"), allowNegativeValues: false); // read non existing value await mapFoos.ReadAsync(db, async (tr, foos) => { bool res = await foos.ContainsAsync(tr, "hello", "world"); Assert.That(res, Is.False, "ContainsAsync('hello','world')"); long?count = await foos.GetCountAsync(tr, "hello", "world"); Assert.That(count, Is.Null, "GetCountAsync('hello', 'world')"); }, this.Cancellation); // add some values await mapFoos.WriteAsync(db, (tr, foos) => { foos.Add(tr, "hello", "world"); foos.Add(tr, "foo", "bar"); foos.Add(tr, "foo", "baz"); }, this.Cancellation); #if DEBUG await DumpSubspace(db, location); #endif // read values back await mapFoos.ReadAsync(db, async (tr, foos) => { long?count = await foos.GetCountAsync(tr, "hello", "world"); Assert.That(count, Is.EqualTo(1), "hello:world"); count = await foos.GetCountAsync(tr, "foo", "bar"); Assert.That(count, Is.EqualTo(1), "foo:bar"); count = await foos.GetCountAsync(tr, "foo", "baz"); Assert.That(count, Is.EqualTo(1), "foo:baz"); }, this.Cancellation); // directly read the value, behind the table's back await mapFoos.ReadAsync(db, async (tr, foos) => { var loc = foos.Subspace.AsDynamic(); var value = await tr.GetAsync(loc.Encode("hello", "world")); Assert.That(value, Is.Not.EqualTo(Slice.Nil)); Assert.That(value.ToInt64(), Is.EqualTo(1)); }, this.Cancellation); // delete the value await mapFoos.WriteAsync(db, (tr, foos) => foos.Remove(tr, "hello", "world"), this.Cancellation); #if FULL_DEBUG await DumpSubspace(db, location); #endif // verify that it is gone await mapFoos.ReadAsync(db, async (tr, foos) => { long?count = await foos.GetCountAsync(tr, "hello", "world"); Assert.That(count, Is.Null); // also check directly var loc = foos.Subspace.AsDynamic(); var data = await tr.GetAsync(loc.Encode("hello", "world")); Assert.That(data, Is.EqualTo(Slice.Nil)); }, this.Cancellation); } }
public async Task Test_FdbMultiMap_Read_Write_Delete() { using (var db = await OpenTestPartitionAsync()) { var location = await GetCleanDirectory(db, "Collections", "MultiMaps"); var map = new FdbMultiMap<string, string>(location.Partition("Foos"), allowNegativeValues: false); // read non existing value using (var tr = db.BeginTransaction(this.Cancellation)) { bool res = await map.ContainsAsync(tr, "hello", "world"); Assert.That(res, Is.False, "ContainsAsync('hello','world')"); long? count = await map.GetCountAsync(tr, "hello", "world"); Assert.That(count, Is.Null, "GetCountAsync('hello', 'world')"); } // add some values using (var tr = db.BeginTransaction(this.Cancellation)) { await map.AddAsync(tr, "hello", "world"); await map.AddAsync(tr, "foo", "bar"); await map.AddAsync(tr, "foo", "baz"); await tr.CommitAsync(); } #if DEBUG await DumpSubspace(db, location); #endif // read values back using (var tr = db.BeginTransaction(this.Cancellation)) { long? count = await map.GetCountAsync(tr, "hello", "world"); Assert.That(count, Is.EqualTo(1), "hello:world"); count = await map.GetCountAsync(tr, "foo", "bar"); Assert.That(count, Is.EqualTo(1), "foo:bar"); count = await map.GetCountAsync(tr, "foo", "baz"); Assert.That(count, Is.EqualTo(1), "foo:baz"); } // directly read the value, behind the table's back using (var tr = db.BeginTransaction(this.Cancellation)) { var value = await tr.GetAsync(map.Subspace.Pack("hello", "world")); Assert.That(value, Is.Not.EqualTo(Slice.Nil)); Assert.That(value.ToInt64(), Is.EqualTo(1)); } // delete the value using (var tr = db.BeginTransaction(this.Cancellation)) { map.Remove(tr, "hello", "world"); await tr.CommitAsync(); } #if DEBUG await DumpSubspace(db, location); #endif // verifiy that it is gone using (var tr = db.BeginTransaction(this.Cancellation)) { long? count = await map.GetCountAsync(tr, "hello", "world"); Assert.That(count, Is.Null); // also check directly var data = await tr.GetAsync(map.Subspace.Pack("hello", "world")); Assert.That(data, Is.EqualTo(Slice.Nil)); } } }
public async Task Test_FdbMultiMap_Read_Write_Delete() { using (var db = await OpenTestPartitionAsync()) { var location = await GetCleanDirectory(db, "Collections", "MultiMaps"); var map = new FdbMultiMap <string, string>(location.Partition.ByKey("Foos"), allowNegativeValues: false); // read non existing value using (var tr = db.BeginTransaction(this.Cancellation)) { bool res = await map.ContainsAsync(tr, "hello", "world"); Assert.That(res, Is.False, "ContainsAsync('hello','world')"); long?count = await map.GetCountAsync(tr, "hello", "world"); Assert.That(count, Is.Null, "GetCountAsync('hello', 'world')"); } // add some values using (var tr = db.BeginTransaction(this.Cancellation)) { await map.AddAsync(tr, "hello", "world"); await map.AddAsync(tr, "foo", "bar"); await map.AddAsync(tr, "foo", "baz"); await tr.CommitAsync(); } #if DEBUG await DumpSubspace(db, location); #endif // read values back using (var tr = db.BeginTransaction(this.Cancellation)) { long?count = await map.GetCountAsync(tr, "hello", "world"); Assert.That(count, Is.EqualTo(1), "hello:world"); count = await map.GetCountAsync(tr, "foo", "bar"); Assert.That(count, Is.EqualTo(1), "foo:bar"); count = await map.GetCountAsync(tr, "foo", "baz"); Assert.That(count, Is.EqualTo(1), "foo:baz"); } // directly read the value, behind the table's back using (var tr = db.BeginTransaction(this.Cancellation)) { var loc = map.Subspace.AsDynamic(); var value = await tr.GetAsync(loc.Keys.Encode("hello", "world")); Assert.That(value, Is.Not.EqualTo(Slice.Nil)); Assert.That(value.ToInt64(), Is.EqualTo(1)); } // delete the value using (var tr = db.BeginTransaction(this.Cancellation)) { map.Remove(tr, "hello", "world"); await tr.CommitAsync(); } #if DEBUG await DumpSubspace(db, location); #endif // verifiy that it is gone using (var tr = db.BeginTransaction(this.Cancellation)) { long?count = await map.GetCountAsync(tr, "hello", "world"); Assert.That(count, Is.Null); // also check directly var loc = map.Subspace.AsDynamic(); var data = await tr.GetAsync(loc.Keys.Encode("hello", "world")); Assert.That(data, Is.EqualTo(Slice.Nil)); } } }