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!"));
				}

			}
		}
Exemplo n.º 2
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!"));
                }
            }
        }
Exemplo n.º 3
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());
                        }
                    }
                }
            }
        }
		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());
					}
				}

			}
		}