public async Task Test_FdbBlob_Can_AppendToBlob() { using (var db = await OpenTestPartitionAsync()) { var location = db.Root["BlobsFromOuterSpace"]; await CleanLocation(db, location); var blob = new FdbBlob(location); Log("Insert blob in 3 chunks..."); await blob.WriteAsync(db, async (tr, state) => { await state.AppendAsync(tr, Value("Attack")); await state.AppendAsync(tr, Value(" of the ")); await state.AppendAsync(tr, Value("Blobs!")); }, this.Cancellation); #if DEBUG await DumpSubspace(db, location); #endif Log("Checking blob size..."); long?size = await blob.ReadAsync(db, (tr, state) => state.GetSizeAsync(tr), this.Cancellation); Log($"> {size:N0}"); Assert.That(size, Is.EqualTo(20)); Log("Checking blob content..."); var data = await blob.ReadAsync(db, (tr, state) => state.ReadAsync(tr, 0, (int)(size ?? 0)), this.Cancellation); Log($"> {data.Count:N0} bytes"); Assert.That(data.ToUnicode(), Is.EqualTo("Attack of the Blobs!")); } }
public async Task Test_FdbBlob_CanAppendLargeChunks() { using (var db = await OpenTestPartitionAsync()) { var location = db.Root["BlobsFromOuterSpace"]; await CleanLocation(db, location); var blob = new FdbBlob(location.ByKey("BigBlob")); var data = Slice.Zero(100_000); for (int i = 0; i < data.Count; i++) { data.Array[data.Offset + i] = (byte)i; } Log("Construct blob by appending chunks..."); for (int i = 0; i < 50; i++) { await blob.WriteAsync(db, (tr, state) => state.AppendAsync(tr, data), this.Cancellation); } Log("Reading blob size:"); long?size = await blob.ReadAsync(db, (tr, state) => state.GetSizeAsync(tr), this.Cancellation);; Log($"> {size:N0}"); Assert.That(size, Is.EqualTo(50 * data.Count)); Log("Reading blob content:"); var s = await blob.ReadAsync(db, (tr, state) => state.ReadAsync(tr, 1234567, 1_000_000), this.Cancellation); Log($"> {s.Count:N0} bytes"); Assert.That(s.Count, Is.EqualTo(1_000_000)); // should contains the correct data for (int i = 0; i < s.Count; i++) { if (s[i] != (byte)((1234567 + i) % data.Count)) { Assert.Fail($"Corrupted blob chunk at {i}: {s[i, i + 128]}"); } } } }