public void Test_Subspace_Partitioning_With_Tuple_Suffix() { // start from a parent subspace var parent = new FdbSubspace(Slice.Create(new byte[] { 254 })); Assert.That(parent.Key.ToString(), Is.EqualTo("<FE>")); // create a child subspace using a tuple var child = parent.Partition(FdbTuple.Create("hca")); Assert.That(child, Is.Not.Null); Assert.That(child.Key.ToString(), Is.EqualTo("<FE><02>hca<00>")); // create a tuple from this child subspace var tuple = child.Append(123); Assert.That(tuple, Is.Not.Null); Assert.That(tuple.ToSlice().ToString(), Is.EqualTo("<FE><02>hca<00><15>{")); // derive another tuple from this one var t1 = tuple.Append(false); Assert.That(t1.ToSlice().ToString(), Is.EqualTo("<FE><02>hca<00><15>{<14>")); // check that we could also create the same tuple starting from the parent subspace var t2 = parent.Append("hca", 123, false); Assert.That(t2.ToSlice(), Is.EqualTo(t1.ToSlice())); // cornercase Assert.That(child[FdbTuple.Empty].Key, Is.EqualTo(child.Key)); }
public void Test_Subspace_With_Binary_Prefix() { var subspace = new FdbSubspace(Slice.Create(new byte[] { 42, 255, 0, 127 })); Assert.That(subspace.Key.ToString(), Is.EqualTo("*<FF><00><7F>")); Assert.That(subspace.Copy(), Is.Not.SameAs(subspace)); Assert.That(subspace.Copy().Key, Is.EqualTo(subspace.Key)); // concat(Slice) should append the slice to the binary prefix directly Assert.That(subspace.Concat(Slice.FromInt32(0x01020304)).ToString(), Is.EqualTo("*<FF><00><7F><04><03><02><01>")); Assert.That(subspace.Concat(Slice.FromAscii("hello")).ToString(), Is.EqualTo("*<FF><00><7F>hello")); // pack(...) should use tuple serialization Assert.That(subspace.Pack(123).ToString(), Is.EqualTo("*<FF><00><7F><15>{")); Assert.That(subspace.Pack("hello").ToString(), Is.EqualTo("*<FF><00><7F><02>hello<00>")); Assert.That(subspace.Pack(Slice.FromAscii("world")).ToString(), Is.EqualTo("*<FF><00><7F><01>world<00>")); Assert.That(subspace.Pack(FdbTuple.Create("hello", 123)).ToString(), Is.EqualTo("*<FF><00><7F><02>hello<00><15>{")); // if we derive a tuple from this subspace, it should keep the binary prefix when converted to a key var t = subspace.Append("world", 123, false); Assert.That(t, Is.Not.Null); Assert.That(t.Count, Is.EqualTo(3)); Assert.That(t.Get <string>(0), Is.EqualTo("world")); Assert.That(t.Get <int>(1), Is.EqualTo(123)); Assert.That(t.Get <bool>(2), Is.False); var k = t.ToSlice(); Assert.That(k.ToString(), Is.EqualTo("*<FF><00><7F><02>world<00><15>{<14>")); // if we unpack the key with the binary prefix, we should get a valid tuple var t2 = subspace.Unpack(k); Assert.That(t2, Is.Not.Null); Assert.That(t2.Count, Is.EqualTo(3)); Assert.That(t2.Get <string>(0), Is.EqualTo("world")); Assert.That(t2.Get <int>(1), Is.EqualTo(123)); Assert.That(t2.Get <bool>(2), Is.False); }
public void Test_Subspace_With_Tuple_Prefix() { var subspace = new FdbSubspace(FdbTuple.Create("hello")); Assert.That(subspace.Key.ToString(), Is.EqualTo("<02>hello<00>")); Assert.That(subspace.Copy(), Is.Not.SameAs(subspace)); Assert.That(subspace.Copy().Key, Is.EqualTo(subspace.Key)); // concat(Slice) should append the slice to the tuple prefix directly Assert.That(subspace.Concat(Slice.FromInt32(0x01020304)).ToString(), Is.EqualTo("<02>hello<00><04><03><02><01>")); Assert.That(subspace.Concat(Slice.FromAscii("world")).ToString(), Is.EqualTo("<02>hello<00>world")); // pack(...) should use tuple serialization Assert.That(subspace.Pack(123).ToString(), Is.EqualTo("<02>hello<00><15>{")); Assert.That(subspace.Pack("world").ToString(), Is.EqualTo("<02>hello<00><02>world<00>")); // even though the subspace prefix is a tuple, appending to it will only return the new items var t = subspace.Append("world", 123, false); Assert.That(t, Is.Not.Null); Assert.That(t.Count, Is.EqualTo(3)); Assert.That(t.Get <string>(0), Is.EqualTo("world")); Assert.That(t.Get <int>(1), Is.EqualTo(123)); Assert.That(t.Get <bool>(2), Is.False); // but ToSlice() should include the prefix var k = t.ToSlice(); Assert.That(k.ToString(), Is.EqualTo("<02>hello<00><02>world<00><15>{<14>")); // if we unpack the key with the binary prefix, we should get a valid tuple var t2 = subspace.Unpack(k); Assert.That(t2, Is.Not.Null); Assert.That(t2.Count, Is.EqualTo(3)); Assert.That(t2.Get <string>(0), Is.EqualTo("world")); Assert.That(t2.Get <int>(1), Is.EqualTo(123)); Assert.That(t2.Get <bool>(2), Is.False); }
public void Test_Subspace_With_Binary_Prefix() { var subspace = new FdbSubspace(Slice.Create(new byte[] { 42, 255, 0, 127 })); Assert.That(subspace.Key.ToString(), Is.EqualTo("*<FF><00><7F>")); Assert.That(subspace.Copy(), Is.Not.SameAs(subspace)); Assert.That(subspace.Copy().Key, Is.EqualTo(subspace.Key)); // concat(Slice) should append the slice to the binary prefix directly Assert.That(subspace.Concat(Slice.FromInt32(0x01020304)).ToString(), Is.EqualTo("*<FF><00><7F><04><03><02><01>")); Assert.That(subspace.Concat(Slice.FromAscii("hello")).ToString(), Is.EqualTo("*<FF><00><7F>hello")); // pack(...) should use tuple serialization Assert.That(subspace.Pack(123).ToString(), Is.EqualTo("*<FF><00><7F><15>{")); Assert.That(subspace.Pack("hello").ToString(), Is.EqualTo("*<FF><00><7F><02>hello<00>")); Assert.That(subspace.Pack(Slice.FromAscii("world")).ToString(), Is.EqualTo("*<FF><00><7F><01>world<00>")); Assert.That(subspace.Pack(FdbTuple.Create("hello", 123)).ToString(), Is.EqualTo("*<FF><00><7F><02>hello<00><15>{")); // if we derive a tuple from this subspace, it should keep the binary prefix when converted to a key var t = subspace.Append("world", 123, false); Assert.That(t, Is.Not.Null); Assert.That(t.Count, Is.EqualTo(3)); Assert.That(t.Get<string>(0), Is.EqualTo("world")); Assert.That(t.Get<int>(1), Is.EqualTo(123)); Assert.That(t.Get<bool>(2), Is.False); var k = t.ToSlice(); Assert.That(k.ToString(), Is.EqualTo("*<FF><00><7F><02>world<00><15>{<14>")); // if we unpack the key with the binary prefix, we should get a valid tuple var t2 = subspace.Unpack(k); Assert.That(t2, Is.Not.Null); Assert.That(t2.Count, Is.EqualTo(3)); Assert.That(t2.Get<string>(0), Is.EqualTo("world")); Assert.That(t2.Get<int>(1), Is.EqualTo(123)); Assert.That(t2.Get<bool>(2), Is.False); }
public void Test_Subspace_With_Tuple_Prefix() { var subspace = new FdbSubspace(FdbTuple.Create("hello")); Assert.That(subspace.Key.ToString(), Is.EqualTo("<02>hello<00>")); Assert.That(subspace.Copy(), Is.Not.SameAs(subspace)); Assert.That(subspace.Copy().Key, Is.EqualTo(subspace.Key)); // concat(Slice) should append the slice to the tuple prefix directly Assert.That(subspace.Concat(Slice.FromInt32(0x01020304)).ToString(), Is.EqualTo("<02>hello<00><04><03><02><01>")); Assert.That(subspace.Concat(Slice.FromAscii("world")).ToString(), Is.EqualTo("<02>hello<00>world")); // pack(...) should use tuple serialization Assert.That(subspace.Pack(123).ToString(), Is.EqualTo("<02>hello<00><15>{")); Assert.That(subspace.Pack("world").ToString(), Is.EqualTo("<02>hello<00><02>world<00>")); // even though the subspace prefix is a tuple, appending to it will only return the new items var t = subspace.Append("world", 123, false); Assert.That(t, Is.Not.Null); Assert.That(t.Count, Is.EqualTo(3)); Assert.That(t.Get<string>(0), Is.EqualTo("world")); Assert.That(t.Get<int>(1), Is.EqualTo(123)); Assert.That(t.Get<bool>(2), Is.False); // but ToSlice() should include the prefix var k = t.ToSlice(); Assert.That(k.ToString(), Is.EqualTo("<02>hello<00><02>world<00><15>{<14>")); // if we unpack the key with the binary prefix, we should get a valid tuple var t2 = subspace.Unpack(k); Assert.That(t2, Is.Not.Null); Assert.That(t2.Count, Is.EqualTo(3)); Assert.That(t2.Get<string>(0), Is.EqualTo("world")); Assert.That(t2.Get<int>(1), Is.EqualTo(123)); Assert.That(t2.Get<bool>(2), Is.False); }