public void CanInsertThenRead() { using (var tx = Env.WriteTransaction()) { DocsSchema.Create(tx, "docs", 16); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); SetHelper(docs, "users/1", "Users", 1L, "{'Name': 'Oren'}"); tx.Commit(); } using (var tx = Env.ReadTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); Slice key; Slice.From(tx.Allocator, "users/1", out key); var handle = docs.ReadByKey(key); int size; var read = handle.Read(3, out size); Assert.Equal("{'Name': 'Oren'}", Encoding.UTF8.GetString(read, size)); tx.Commit(); } }
public void CanInsertThenDeleteBySecondary2() { using (var tx = Env.WriteTransaction()) { DocsSchema.Create(tx, "docs", 16); tx.Commit(); } for (int j = 0; j < 10; j++) { using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); for (int i = 0; i < 1000; i++) { SetHelper(docs, "users/" + i, "Users", 1L + i, "{'Name': 'Oren'}"); } tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); var ids = new List <long>(); foreach (var sr in docs.SeekForwardFrom(DocsSchema.Indexes[EtagsSlice], Slices.BeforeAllKeys)) { foreach (var tvr in sr.Results) { ids.Add(tvr.Id); } } foreach (var id in ids) { docs.Delete(id); } tx.Commit(); } using (var tx = Env.ReadTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); Slice val; Slice.From(Allocator, EndianBitConverter.Big.GetBytes(1), out val); var reader = docs.SeekForwardFrom(DocsSchema.Indexes[EtagsSlice], val); Assert.Empty(reader); } } }
public void CanInsertThenUpdateThenByComposite() { using (var tx = Env.WriteTransaction()) { DocsSchema.Create(tx, "docs", 16); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); SetHelper(docs, "users/1", "Users", 1L, "{'Name': 'Oren'}"); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); SetHelper(docs, "users/1", "Users", 2L, "{'Name': 'Eini'}"); tx.Commit(); } using (var tx = Env.ReadTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); bool gotValues = false; Slice str; using (Slice.From(tx.Allocator, "Users", ByteStringType.Immutable, out str)) { foreach (var reader in docs.SeekForwardFrom(DocsSchema.Indexes[EtagAndCollectionSlice], str, 0)) { var valueReader = reader.Key.CreateReader(); Assert.Equal("Users", valueReader.ReadString(5)); Assert.Equal(2L, valueReader.ReadBigEndianInt64()); var handle = reader.Result; int size; Assert.Equal("{'Name': 'Eini'}", Encoding.UTF8.GetString(handle.Reader.Read(3, out size), size)); tx.Commit(); gotValues = true; break; } } Assert.True(gotValues); } }
public void CanInsertThenUpdateThenBySecondary() { using (var tx = Env.WriteTransaction()) { DocsSchema.Create(tx, "docs", 16); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); SetHelper(docs, "users/1", "Users", 1L, "{'Name': 'Oren'}"); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); SetHelper(docs, "users/1", "Users", 2L, "{'Name': 'Eini'}"); tx.Commit(); } using (var tx = Env.ReadTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); Slice etag; bool gotValues = false; using (Slice.From(Allocator, EndianBitConverter.Big.GetBytes(1L), out etag)) { foreach (var reader in docs.SeekForwardFrom(DocsSchema.Indexes[EtagsSlice], etag)) { Assert.Equal(2L, reader.Key.CreateReader().ReadBigEndianInt64()); var handle = reader.Results.Single(); int size; Assert.Equal("{'Name': 'Eini'}", Encoding.UTF8.GetString(handle.Read(3, out size), size)); tx.Commit(); gotValues = true; break; } } Assert.True(gotValues); } }
public void CanInsertThenReadByComposite() { using (var tx = Env.WriteTransaction()) { DocsSchema.Create(tx, "docs", 16); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); SetHelper(docs, "users/1", "Users", 1L, "{'Name': 'Oren'}"); SetHelper(docs, "users/2", "Users", 2L, "{'Name': 'Eini'}"); tx.Commit(); } using (var tx = Env.ReadTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); Slice str; using (Slice.From(tx.Allocator, "Users", ByteStringType.Immutable, out str)) { var seekResults = docs.SeekForwardFrom(DocsSchema.Indexes[EtagAndCollectionSlice], str, 0).GetEnumerator(); Assert.True(seekResults.MoveNext()); var reader = seekResults.Current; var valueReader = reader.Key.CreateReader(); Assert.Equal("Users", valueReader.ReadString(5)); Assert.Equal(1L, valueReader.ReadBigEndianInt64()); var handle = reader.Result.Reader; int size; Assert.Equal("{'Name': 'Oren'}", Encoding.UTF8.GetString(handle.Read(3, out size), size)); Assert.True(seekResults.MoveNext()); reader = seekResults.Current; valueReader = reader.Key.CreateReader(); Assert.Equal("Users", valueReader.ReadString(5)); Assert.Equal(2L, valueReader.ReadBigEndianInt64()); handle = reader.Result.Reader; Assert.Equal("{'Name': 'Eini'}", Encoding.UTF8.GetString(handle.Read(3, out size), size)); Assert.False(seekResults.MoveNext()); } tx.Commit(); } }
public void RavenDB_13840() { using (var tx = Env.WriteTransaction()) { DocsSchema.Create(tx, "docs", 16); tx.Commit(); } var pagesInSection = sizeof(long) * 4 * 4; var numberOfSections = 2; using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); for (int j = 0; j < numberOfSections; j++) { // fill section for (int i = 0; i < pagesInSection; i++) { // fill page SetHelper(docs, "users/" + Guid.NewGuid(), "Users", 2L, new string('a', 1000)); SetHelper(docs, "users/" + Guid.NewGuid(), "Users", 1L, new string('a', 1000)); SetHelper(docs, "users/" + Guid.NewGuid(), "Users", 0L, new string('a', 1000)); SetHelper(docs, "users/" + Guid.NewGuid(), "Users", 0L, new string('a', 1000)); SetHelper(docs, "users/" + Guid.NewGuid(), "Users", 0L, new string('a', 1000)); SetHelper(docs, "users/" + Guid.NewGuid(), "Users", 0L, new string('a', 1000)); SetHelper(docs, "users/" + Guid.NewGuid(), "Users", 0L, new string('a', 1000)); SetHelper(docs, "users/" + Guid.NewGuid(), "Users", 0L, new string('a', 1000)); } } var toDelete = numberOfSections * pagesInSection * 8 - 7; docs.DeleteForwardFrom(DocsSchema.Indexes[EtagsSlice], Slices.BeforeAllKeys, false, toDelete); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); docs.DeleteForwardFrom(DocsSchema.Indexes[EtagsSlice], Slices.BeforeAllKeys, false, long.MaxValue); tx.Commit(); } }
public void HasCorrespondingRootObjectType() { using (var tx = Env.WriteTransaction()) { DocsSchema.Create(tx, "docs", 16); Slice key; Slice.From(tx.Allocator, "docs", out key); Assert.Equal(RootObjectType.Table, tx.GetRootObjectType(key)); tx.Commit(); } using (var tx = Env.ReadTransaction()) { Slice key; Slice.From(tx.Allocator, "docs", out key); Assert.Equal(RootObjectType.Table, tx.GetRootObjectType(key)); } }
public void CanInsertThenDeleteByComposite() { using (var tx = Env.WriteTransaction()) { DocsSchema.Create(tx, "docs", 16); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); SetHelper(docs, "users/1", "Users", 1L, "{'Name': 'Oren'}"); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); Slice key; Slice.From(tx.Allocator, "users/1", out key); docs.DeleteByKey(key); tx.Commit(); } using (var tx = Env.ReadTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); Slice str; using (Slice.From(tx.Allocator, "Users", ByteStringType.Immutable, out str)) { var reader = docs.SeekForwardFrom(DocsSchema.Indexes[EtagAndCollectionSlice], str, 0); Assert.Empty(reader); } } }
public void CanInsertThenDeleteBySecondary() { using (var tx = Env.WriteTransaction()) { DocsSchema.Create(tx, "docs", 16); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); SetHelper(docs, "users/1", "Users", 1L, "{'Name': 'Oren'}"); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); Slice key; Slice.From(tx.Allocator, "users/1", out key); docs.DeleteByKey(key); tx.Commit(); } using (var tx = Env.ReadTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); Slice key; Slice.From(Allocator, EndianBitConverter.Big.GetBytes(1), out key); var reader = docs.SeekForwardFrom(DocsSchema.Indexes[EtagsSlice], key); Assert.Empty(reader); } }
public void IndexPagesWillBeNearby_32() { using (var tx = Env.WriteTransaction()) { DocsSchema.Create(tx, "docs", 16); tx.Commit(); } var largeString = new string('a', 1024); using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); for (int i = 0; i < 250; i++) { SetHelper(docs, "users/" + i, "Users", 1L + i, largeString); } tx.Commit(); } using (var tx = Env.ReadTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); foreach (var index in DocsSchema.Indexes) { var tree = docs.GetTree(index.Value); Assert.NotEqual(1, tree.State.Depth); var pages = tree.AllPages(); var minPage = pages.Min(); var maxPage = pages.Max(); Assert.True((maxPage - minPage) < 128); } } }
public void CanInsertThenDelete() { using (var tx = Env.WriteTransaction()) { DocsSchema.Create(tx, "docs", 16); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); SetHelper(docs, "users/1", "Users", 1L, "{'Name': 'Oren'}"); tx.Commit(); } using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); Slice key; Slice.From(tx.Allocator, "users/1", out key); docs.DeleteByKey(key); tx.Commit(); } using (var tx = Env.ReadTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); Slice key; Slice.From(tx.Allocator, "users/1", out key); TableValueReader reader; Assert.False(docs.ReadByKey(key, out reader)); } }
public void CanDeleteTable() { using (var tx = Env.WriteTransaction()) { DocsSchema.Create(tx, "docs", 16); tx.Commit(); } for (int j = 0; j < 10; j++) { using (var tx = Env.WriteTransaction()) { var docs = tx.OpenTable(DocsSchema, "docs"); for (int i = 0; i < 1000; i++) { SetHelper(docs, "users/" + i, "Users", 1L + i, "{'Name': 'Oren'}"); } tx.Commit(); } } using (var tx = Env.WriteTransaction()) { tx.DeleteTable("docs"); tx.Commit(); } using (var tx = Env.WriteTransaction()) { Assert.Null(tx.LowLevelTransaction.RootObjects.Read("docs")); } }