本文整理汇总了C#中WriteBatch.Add方法的典型用法代码示例。如果您正苦于以下问题:C# WriteBatch.Add方法的具体用法?C# WriteBatch.Add怎么用?C# WriteBatch.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WriteBatch
的用法示例。
在下文中一共展示了WriteBatch.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read_Items_From_Both_WriteBatch_And_Snapshot
public void Read_Items_From_Both_WriteBatch_And_Snapshot()
{
using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
{
Env.CreateTree(tx, "tree");
tx.Environment.CreateTree(tx,"tree").Add("foo1", StreamFor("foo1"));
tx.Commit();
}
using (var writeBatch = new WriteBatch())
using (var snapshot = Env.CreateSnapshot())
{
writeBatch.Add("foo2", StreamFor("foo2"), "tree");
var foo1ReadResult = snapshot.Read("tree", "foo1", writeBatch);
var foo2ReadResult = snapshot.Read("tree", "foo2", writeBatch);
var foo2ReadResultThatShouldBeNull = snapshot.Read("tree", "foo2");
Assert.NotNull(foo1ReadResult);
Assert.NotNull(foo2ReadResult);
Assert.Null(foo2ReadResultThatShouldBeNull);
Assert.Equal(foo1ReadResult.Reader.ToStringValue(), "foo1");
Assert.Equal(foo2ReadResult.Reader.ToStringValue(), "foo2");
}
}
示例2: ReadVersion_Items_From_Both_WriteBatch_And_Snapshot_WithoutVersionNumber
public void ReadVersion_Items_From_Both_WriteBatch_And_Snapshot_WithoutVersionNumber()
{
using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
{
Env.CreateTree(tx, "tree");
tx.Environment.CreateTree(tx,"tree").Add("foo1", StreamFor("foo1"));
tx.Commit();
}
using (var writeBatch = new WriteBatch())
using (var snapshot = Env.CreateSnapshot())
{
writeBatch.Add("foo2", StreamFor("foo2"), "tree");
var foor1Version = snapshot.ReadVersion("tree", "foo1", writeBatch);
var foo2Version = snapshot.ReadVersion("tree", "foo2", writeBatch);
var foo2VersionThatShouldBe0 = snapshot.ReadVersion("tree", "foo2");
Assert.Equal(1, foor1Version);
Assert.Equal(0, foo2Version); //added to write batch without version number, so 0 is version number that is fetched
Assert.Equal(0, foo2VersionThatShouldBe0);
}
}
示例3: Should_be_able_to_read_and_write_lots_of_data
public void Should_be_able_to_read_and_write_lots_of_data()
{
CreatTestSchema();
var writeBatch = new WriteBatch();
var testData = GenerateTestData().ToList();
foreach (var dataPair in testData)
writeBatch.Add(dataPair.Key, StreamFor(dataPair.Value), TestTreeName);
Env.Writer.Write(writeBatch);
using (var snapshot = Env.CreateSnapshot())
{
using (var iterator = snapshot.Iterate(TestTreeName))
{
Assert.True(iterator.Seek(Slice.BeforeAllKeys));
do
{
var value = iterator.CreateReaderForCurrent().ToStringValue();
var extractedDataPair = new KeyValuePair<string, string>(iterator.CurrentKey.ToString(), value);
Assert.Contains(extractedDataPair,testData);
} while (iterator.MoveNext());
}
}
}
示例4: ReadVersion_Items_From_Both_WriteBatch_And_Snapshot
public void ReadVersion_Items_From_Both_WriteBatch_And_Snapshot()
{
using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
{
Env.CreateTree(tx, "tree");
tx.Environment.CreateTree(tx,"tree").Add("foo1", StreamFor("foo1"));
tx.Commit();
}
using (var writeBatch = new WriteBatch())
using (var snapshot = Env.CreateSnapshot())
{
writeBatch.Add("foo2", StreamFor("foo2"), "tree", 1);
var foor1Version = snapshot.ReadVersion("tree", "foo1", writeBatch);
var foo2Version = snapshot.ReadVersion("tree", "foo2", writeBatch);
var foo2VersionThatShouldBe0 = snapshot.ReadVersion("tree", "foo2");
Assert.Equal(1, foor1Version);
Assert.Equal(2, foo2Version); //is not committed yet
Assert.Equal(0, foo2VersionThatShouldBe0);
}
}
示例5: Add
public virtual void Add(WriteBatch writeBatch, string key, byte[] value, ushort? expectedVersion = null)
{
var stream = new BufferPoolMemoryStream(BufferPool);
stream.Write(value, 0, value.Length);
stream.Position = 0;
writeBatch.Add(key, stream, TableName, expectedVersion);
}
示例6: BatchConcurrencyExceptionShouldNotBeThrown
public void BatchConcurrencyExceptionShouldNotBeThrown()
{
var batch1 = new WriteBatch();
batch1.Add("key/1", StreamFor("123"), Constants.RootTreeName, 0);
Env.Writer.Write(batch1);
using (var snapshot = Env.CreateSnapshot())
{
var version = snapshot.ReadVersion(Constants.RootTreeName, "key/1", batch1);
Assert.Equal(1, version);
batch1 = new WriteBatch();
batch1.Add("key/1", StreamFor("123"), Constants.RootTreeName, version);
version = snapshot.ReadVersion(Constants.RootTreeName, "key/1", batch1);
batch1.Add("key/1", StreamFor("123"), Constants.RootTreeName, version);
Env.Writer.Write(batch1);
}
}
示例7: Should_be_able_to_read_and_write_small_values
public void Should_be_able_to_read_and_write_small_values()
{
CreatTestSchema();
var writeBatch = new WriteBatch();
writeBatch.Add("key",StreamFor("value"),TestTreeName);
Env.Writer.Write(writeBatch);
using (var snapshot = Env.CreateSnapshot())
{
var storedValue = Encoding.UTF8.GetString(snapshot.Read(TestTreeName, "key").Reader.AsStream().ReadData());
Assert.Equal("value",storedValue);
}
}
示例8: SingleItemBatchTest
public void SingleItemBatchTest()
{
var batch = new WriteBatch();
batch.Add("key/1", new MemoryStream(Encoding.UTF8.GetBytes("123")), Constants.RootTreeName);
Env.Writer.Write(batch);
using (var snapshot = Env.CreateSnapshot())
{
var reader = snapshot.Read(null, "key/1").Reader;
Assert.Equal("123", reader.ToStringValue());
}
}
示例9: BatchConcurrencyExceptionShouldBeThrownWhenVersionMismatch
public void BatchConcurrencyExceptionShouldBeThrownWhenVersionMismatch()
{
var batch1 = new WriteBatch();
batch1.Add("key/1", StreamFor("123"), Constants.RootTreeName, 0);
Env.Writer.Write(batch1);
var batch2 = new WriteBatch();
batch2.Add("key/1", StreamFor("123"), Constants.RootTreeName, 2);
var e = Assert.Throws<AggregateException>(() => Env.Writer.Write(batch2)).InnerException;
Assert.Equal("Cannot add 'key/1' to 'Root' tree. Version mismatch. Expected: 2. Actual: 1.", e.Message);
var batch3 = new WriteBatch();
batch3.Delete("key/1", Constants.RootTreeName, 2);
e = Assert.Throws<AggregateException>(() => Env.Writer.Write(batch3)).InnerException;
Assert.Equal("Cannot delete 'key/1' to 'Root' tree. Version mismatch. Expected: 2. Actual: 1.", e.Message);
}
示例10: WriteSomethingToVoron
public void WriteSomethingToVoron()
{
var serializer = new JsonSerializer();
using (var storage = new StorageEnvironment(StorageEnvironmentOptions.GetInMemory()))
{
using (var tx = storage.NewTransaction(TransactionFlags.ReadWrite))
{
storage.CreateTree(tx, "foos");
tx.Commit();
}
{
var ms = new MemoryStream();
var batch = new WriteBatch();
var foo = new Foo { Id = "hello", Value = 99 };
using (var writer = new StreamWriter(ms))
{
serializer.Serialize(new JsonTextWriter(writer), foo);
writer.Flush();
ms.Position = 0;
//var key = new Slice(EndianBitConverter.Big.GetBytes(counter++));
batch.Add(foo.Id, ms, "foos");
storage.Writer.Write(batch);
}
}
using (var tx = storage.NewTransaction(TransactionFlags.Read))
{
var foos = tx.GetTree("foos");
var readResult = foos.Read(tx, "hello");
using (var stream = readResult.Reader.AsStream())
{
var foo = serializer.Deserialize<Foo>(new JsonTextReader(new StreamReader(stream)));
Assert.Equal(99, foo.Value);
}
}
}
}
示例11: RebalancerIssue
public void RebalancerIssue()
{
const int DocumentCount = 750;
var rand = new Random();
var testBuffer = new byte[757];
rand.NextBytes(testBuffer);
using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
{
Env.CreateTree(tx, "tree1");
tx.Commit();
}
var batch = new WriteBatch();
for (var i = 0; i < DocumentCount; i++)
{
batch.Add("Foo" + i, new MemoryStream(testBuffer), "tree1");
}
Env.Writer.Write(batch);
batch = new WriteBatch();
for (var i = 0; i < DocumentCount; i++)
{
if (i >= 180)
continue;
batch.Delete("Foo" + i, "tree1");
}
Env.Writer.Write(batch);
using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
{
var t1 = tx.Environment.State.GetTree(tx,"tree1");
t1.Delete("Foo180"); // rebalancer fails to move 1st node from one branch to another
}
}
示例12: BatchDelete
public void BatchDelete()
{
var batch1 = new WriteBatch();
batch1.Add("key/1", StreamFor("123"), Constants.RootTreeName);
Env.Writer.Write(batch1);
using (var tx = Env.NewTransaction(TransactionFlags.Read))
{
Assert.Equal(1, tx.State.Root.ReadVersion("key/1"));
}
var batch2 = new WriteBatch();
batch2.Delete("key/1", Constants.RootTreeName);
Env.Writer.Write(batch2);
using (var tx = Env.NewTransaction(TransactionFlags.Read))
{
Assert.Equal(0, tx.State.Root.ReadVersion("key/1"));
}
}
示例13: SplittersAndRebalancersShouldNotChangeNodeVersion
public void SplittersAndRebalancersShouldNotChangeNodeVersion()
{
const int DocumentCount = 100000;
var rand = new Random();
var testBuffer = new byte[123];
rand.NextBytes(testBuffer);
Tree t1 = null;
using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
{
t1 = Env.CreateTree(tx, "tree1");
tx.Commit();
}
var batch = new WriteBatch();
for (var i = 0; i < DocumentCount; i++)
{
batch.Add("Foo" + i, new MemoryStream(testBuffer), "tree1");
}
Env.Writer.Write(batch);
batch = new WriteBatch();
using (var snapshot = Env.CreateSnapshot())
{
for (var i = 0; i < DocumentCount; i++)
{
var result = snapshot.Read("tree1", "Foo" + 1, null);
batch.Delete("Foo" + i, "tree1", result.Version);
}
}
Env.Writer.Write(batch);
}
示例14: ReadVersion_The_Same_Item_Both_WriteBatch_And_Snapshot_WriteBatch_Takes_Precedence
public void ReadVersion_The_Same_Item_Both_WriteBatch_And_Snapshot_WriteBatch_Takes_Precedence()
{
using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
{
Env.CreateTree(tx, "tree");
tx.Environment.CreateTree(tx,"tree").Add("foo1", StreamFor("foo1"));
tx.Commit();
}
using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
{
tx.Environment.CreateTree(tx,"tree").Add("foo1", StreamFor("updated foo1"));
tx.Commit();
}
using (var writeBatch = new WriteBatch())
using (var snapshot = Env.CreateSnapshot())
{
writeBatch.Add("foo1", StreamFor("updated foo1 2"), "tree", 2);
var foo1Version = snapshot.ReadVersion("tree", "foo1", writeBatch);
var foo1VersionThatShouldBe2 = snapshot.ReadVersion("tree", "foo1");
Assert.Equal(3, foo1Version);
Assert.Equal(2, foo1VersionThatShouldBe2);
}
}
示例15: Main
public static void Main()
{
var basePath = @"C:\Work\ravendb-3.0\Raven.Voron\Voron.Tryout\bin\Debug\v4";
var win = new Win32MemoryMapPager(Path.Combine(basePath, "v2", "Raven.voron"));
var lin = new Win32MemoryMapPager(Path.Combine(basePath, "v2l", "Raven.voron"));
var winPage = (PageHeader*)win.AcquirePagePointer(0);
var linPage = (PageHeader*)lin.AcquirePagePointer(0);
return;
var path = "v4";
if (Directory.Exists(path))
Directory.Delete(path, true);
Console.WriteLine(Process.GetCurrentProcess().Id);
using (var env = new StorageEnvironment(StorageEnvironmentOptions.ForPath(path)))
{
var batch = new WriteBatch();
batch.Add("[email protected]", "Oren Eini", "Names");
env.Writer.Write(batch);
using (var snp = env.CreateSnapshot())
{
var reader = snp.Read("Names", "[email protected]");
if (reader == null)
{
Console.WriteLine("Couldn't find it");
}
else
{
Console.WriteLine(reader.Reader.ToStringValue());
}
}
}
using (var env = new StorageEnvironment(StorageEnvironmentOptions.ForPath(path)))
{
// using (var snp = env.CreateSnapshot())
// {
// var reader = snp.Read ("Names", "[email protected]");
// if (reader == null)
// {
// Console.WriteLine ("Couldn't find it");
// }
// else
// {
// Console.WriteLine (reader.Reader.ToStringValue());
// }
// }
}
using (var env = new StorageEnvironment(StorageEnvironmentOptions.ForPath(path)))
{
using (var snp = env.CreateSnapshot())
{
var reader = snp.Read("Names", "[email protected]");
if (reader == null)
{
Console.WriteLine("Couldn't find it");
}
else
{
Console.WriteLine(reader.Reader.ToStringValue());
}
}
}
Console.WriteLine("Done");
}