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]}");
                    }
                }
            }
        }
        public async Task Test_FdbBlob_NotFound_Blob_Is_Empty()
        {
            using (var db = await OpenTestPartitionAsync())
            {
                var location = db.Root["BlobsFromOuterSpace"];
                await CleanLocation(db, location);

                var blob = new FdbBlob(location.ByKey("Empty"));

                long?size = await blob.ReadAsync(db, (tr, state) => state.GetSizeAsync(tr), this.Cancellation);

                Assert.That(size, Is.Null, "Non existing blob should have no size");
            }
        }
예제 #4
0
        public async Task Test_FdbBlob_CanAppendLargeChunks()
        {
            using (var db = await OpenTestPartitionAsync())
            {
                var location = await GetCleanDirectory(db, "BlobsFromOuterSpace");

                // clear previous values
                await DeleteSubspace(db, location);

                var blob = new FdbBlob(location.Partition.ByKey("BigBlob"));

                var data = new byte[100 * 1000];
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = (byte)i;
                }

                for (int i = 0; i < 50; i++)
                {
                    using (var tr = db.BeginTransaction(this.Cancellation))
                    {
                        await blob.AppendAsync(tr, Slice.Create(data));

                        await tr.CommitAsync();
                    }
                }

                using (var tr = db.BeginTransaction(this.Cancellation))
                {
                    long?size = await blob.GetSizeAsync(tr);

                    Assert.That(size, Is.EqualTo(50 * data.Length));

                    var s = await blob.ReadAsync(tr, 1234567, 1 * 1000 * 1000);

                    Assert.That(s.Count, Is.EqualTo(1 * 1000 * 1000));

                    // should contains the correct data
                    for (int i = 0; i < s.Count; i++)
                    {
                        if (s.Array[i + s.Offset] != (byte)((1234567 + i) % data.Length))
                        {
                            Assert.Fail("Corrupted blob chunk at " + i + ": " + s[i, i + 128].ToString());
                        }
                    }
                }
            }
        }
예제 #5
0
        public async Task Test_FdbBlob_Can_AppendToBlob()
        {
            using (var db = await OpenTestPartitionAsync())
            {
                var location = await GetCleanDirectory(db, "BlobsFromOuterSpace");

                // clear previous values
                await DeleteSubspace(db, location);

                var blob = new FdbBlob(location.Partition.ByKey("BobTheBlob"));

                using (var tr = db.BeginTransaction(this.Cancellation))
                {
                    await blob.AppendAsync(tr, Slice.FromString("Attack"));

                    await blob.AppendAsync(tr, Slice.FromString(" of the "));

                    await blob.AppendAsync(tr, Slice.FromString("Blobs!"));

                    await tr.CommitAsync();
                }

#if DEBUG
                await DumpSubspace(db, location);
#endif

                using (var tr = db.BeginTransaction(this.Cancellation))
                {
                    long?size = await blob.GetSizeAsync(tr);

                    Assert.That(size, Is.EqualTo(20));

                    Slice data = await blob.ReadAsync(tr, 0, (int)(size ?? 0));

                    Assert.That(data.ToUnicode(), Is.EqualTo("Attack of the Blobs!"));
                }
            }
        }
		public async Task Test_FdbBlob_Can_AppendToBlob()
		{
			using (var db = await OpenTestPartitionAsync())
			{
				var location = await GetCleanDirectory(db, "BlobsFromOuterSpace");

				// clear previous values
				await DeleteSubspace(db, location);

				var blob = new FdbBlob(location.Partition.ByKey("BobTheBlob"));

				using (var tr = db.BeginTransaction(this.Cancellation))
				{
					await blob.AppendAsync(tr, Slice.FromString("Attack"));
					await blob.AppendAsync(tr, Slice.FromString(" of the "));
					await blob.AppendAsync(tr, Slice.FromString("Blobs!"));

					await tr.CommitAsync();
				}

#if DEBUG
				await DumpSubspace(db, location);
#endif

				using (var tr = db.BeginTransaction(this.Cancellation))
				{
					long? size = await blob.GetSizeAsync(tr);
					Assert.That(size, Is.EqualTo(20));

					Slice data = await blob.ReadAsync(tr, 0, (int)(size ?? 0));
					Assert.That(data.ToUnicode(), Is.EqualTo("Attack of the Blobs!"));
				}

			}
		}
		public async Task Test_FdbBlob_CanAppendLargeChunks()
		{
			using (var db = await OpenTestPartitionAsync())
			{
				var location = await GetCleanDirectory(db, "BlobsFromOuterSpace");

				// clear previous values
				await DeleteSubspace(db, location);

				var blob = new FdbBlob(location.Partition.ByKey("BigBlob"));

				var data = new byte[100 * 1000];
				for (int i = 0; i < data.Length; i++) data[i] = (byte)i;

				for (int i = 0; i < 50; i++)
				{
					using (var tr = db.BeginTransaction(this.Cancellation))
					{
						await blob.AppendAsync(tr, Slice.Create(data));
						await tr.CommitAsync();
					}
				}

				using (var tr = db.BeginTransaction(this.Cancellation))
				{
					long? size = await blob.GetSizeAsync(tr);
					Assert.That(size, Is.EqualTo(50 * data.Length));

					var s = await blob.ReadAsync(tr, 1234567, 1 * 1000 * 1000);
					Assert.That(s.Count, Is.EqualTo(1 * 1000 * 1000));

					// should contains the correct data
					for (int i = 0; i < s.Count; i++)
					{
						if (s.Array[i + s.Offset] != (byte)((1234567 + i) % data.Length)) Assert.Fail("Corrupted blob chunk at " + i + ": " + s[i, i + 128].ToString());
					}
				}

			}
		}