本文整理汇总了C#中KeyValueDB.StartTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# KeyValueDB.StartTransaction方法的具体用法?C# KeyValueDB.StartTransaction怎么用?C# KeyValueDB.StartTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyValueDB
的用法示例。
在下文中一共展示了KeyValueDB.StartTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddingContinueToNewFileAfterReopenWithCorruption
public void AddingContinueToNewFileAfterReopenWithCorruption()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(_key1, _key1);
tr.Commit();
}
}
fileCollection.SimulateCorruptionBySetSize(20 + 16);
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
Assert.Equal(0, tr.GetKeyValueCount());
tr.CreateOrUpdateKeyValue(Key2, Key2);
tr.Commit();
}
Console.WriteLine(db.CalcStats());
}
Assert.True(2 <= fileCollection.GetCount());
}
}
示例2: EmptyTransaction
public void EmptyTransaction()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.Commit();
}
}
}
示例3: FirstTransaction
public void FirstTransaction()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
Assert.True(tr.CreateOrUpdateKeyValue(ByteBuffer.NewAsync(_key1), ByteBuffer.NewAsync(new byte[0])));
tr.Commit();
}
}
}
示例4: CanGetSizeOfPair
public void CanGetSizeOfPair()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(ByteBuffer.NewAsync(_key1), ByteBuffer.NewAsync(new byte[1]));
var s = tr.GetStorageSizeOfCurrentKey();
Assert.Equal((uint)_key1.Length, s.Key);
Assert.Equal(1u, s.Value);
}
}
}
示例5: AddingContinueToSameFileAfterReopen
public void AddingContinueToSameFileAfterReopen()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(_key1, _key1);
tr.Commit();
}
}
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(Key2, Key2);
tr.Commit();
}
Console.WriteLine(db.CalcStats());
}
Assert.Equal(2u, fileCollection.GetCount()); // Log + Index
}
}
示例6: CreateOrUpdateKeyValueWorks
public void CreateOrUpdateKeyValueWorks(int length)
{
var valbuf = new byte[length];
new Random(0).NextBytes(valbuf);
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr1 = db.StartTransaction())
{
Assert.True(tr1.CreateOrUpdateKeyValueUnsafe(_key1, valbuf));
Assert.False(tr1.CreateOrUpdateKeyValueUnsafe(_key1, valbuf));
Assert.True(tr1.CreateOrUpdateKeyValueUnsafe(Key2, valbuf));
tr1.Commit();
}
using (var tr2 = db.StartTransaction())
{
Assert.True(tr2.FindExactKey(_key1));
var valbuf2 = tr2.GetValueAsByteArray();
for (int i = 0; i < length; i++)
{
if (valbuf[i] != valbuf2[i])
Assert.Equal(valbuf[i], valbuf2[i]);
}
Assert.True(tr2.FindExactKey(Key2));
valbuf2 = tr2.GetValueAsByteArray();
for (int i = 0; i < length; i++)
{
if (valbuf[i] != valbuf2[i])
Assert.Equal(valbuf[i], valbuf2[i]);
}
}
}
}
示例7: CommitWorks
public void CommitWorks()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr1 = db.StartTransaction())
{
tr1.CreateKey(_key1);
using (var tr2 = db.StartTransaction())
{
Assert.Equal(0, tr2.GetTransactionNumber());
Assert.False(tr2.FindExactKey(_key1));
}
tr1.Commit();
}
using (var tr3 = db.StartTransaction())
{
Assert.Equal(1, tr3.GetTransactionNumber());
Assert.True(tr3.FindExactKey(_key1));
}
}
}
示例8: RepairsOnReopen
public void RepairsOnReopen()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateKey(_key1);
tr.Commit();
}
using (var tr = db.StartTransaction())
{
tr.CreateKey(Key2);
tr.Commit();
}
using (var tr = db.StartTransaction())
{
tr.CreateKey(_key3);
// rollback
}
using (IKeyValueDB db2 = new KeyValueDB(fileCollection))
{
using (var tr = db2.StartTransaction())
{
Assert.True(tr.FindExactKey(_key1));
Assert.True(tr.FindExactKey(Key2));
Assert.False(tr.FindExactKey(_key3));
}
}
}
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
Assert.True(tr.FindExactKey(_key1));
Assert.True(tr.FindExactKey(Key2));
Assert.False(tr.FindExactKey(_key3));
}
}
}
}
示例9: CompressibleValueLoad
public void CompressibleValueLoad()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(_key1, new byte[1000]);
Assert.Equal(new byte[1000], tr.GetValueAsByteArray());
tr.Commit();
}
}
}
}
示例10: AdvancedEraseRangeWorks
void AdvancedEraseRangeWorks(int createKeys, int removeStart, int removeCount)
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
var key = new byte[2];
using (var tr = db.StartTransaction())
{
for (int i = 0; i < createKeys; i++)
{
key[0] = (byte)(i / 256);
key[1] = (byte)(i % 256);
tr.CreateKey(key);
}
tr.Commit();
}
using (var tr = db.StartTransaction())
{
tr.EraseRange(removeStart, removeStart + removeCount - 1);
Assert.Equal(createKeys - removeCount, tr.GetKeyValueCount());
tr.Commit();
}
using (var tr = db.StartTransaction())
{
Assert.Equal(createKeys - removeCount, tr.GetKeyValueCount());
for (int i = 0; i < createKeys; i++)
{
key[0] = (byte)(i / 256);
key[1] = (byte)(i % 256);
if (i >= removeStart && i < removeStart + removeCount)
{
Assert.False(tr.FindExactKey(key), $"{i} should be removed");
}
else
{
Assert.True(tr.FindExactKey(key), $"{i} should be found");
}
}
}
}
}
示例11: PrefixWithFindPrevKeyWorks
public void PrefixWithFindPrevKeyWorks()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateKey(_key1);
tr.CreateKey(Key2);
tr.SetKeyPrefix(ByteBuffer.NewAsync(Key2, 0, 1));
Assert.True(tr.FindFirstKey());
Assert.False(tr.FindPreviousKey());
tr.Commit();
}
}
}
示例12: TwoTransactions
public void TwoTransactions()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr1 = db.StartTransaction())
{
tr1.CreateKey(_key1);
tr1.Commit();
}
using (var tr2 = db.StartTransaction())
{
tr2.CreateKey(Key2);
Assert.True(tr2.FindExactKey(_key1));
Assert.True(tr2.FindExactKey(Key2));
Assert.False(tr2.FindExactKey(_key3));
tr2.Commit();
}
using (var tr3 = db.StartTransaction())
{
Assert.True(tr3.FindExactKey(_key1));
Assert.True(tr3.FindExactKey(Key2));
Assert.False(tr3.FindExactKey(_key3));
}
}
}
示例13: BiggerKey
public void BiggerKey(int prefixLength, int offsetKey, int keyLength)
{
var prefix = new byte[prefixLength];
var keyb = new byte[offsetKey + keyLength];
for (int i = offsetKey; i < offsetKey + keyLength; i++) keyb[i] = (byte)i;
var key = ByteBuffer.NewAsync(keyb, offsetKey, keyLength);
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr1 = db.StartTransaction())
{
tr1.SetKeyPrefix(prefix);
tr1.CreateOrUpdateKeyValue(key, ByteBuffer.NewEmpty());
tr1.Commit();
}
using (var tr2 = db.StartTransaction())
{
tr2.SetKeyPrefix(prefix);
Assert.True(tr2.FindExactKey(key.ToByteArray()));
Assert.Equal(key.ToByteArray(), tr2.GetKeyAsByteArray());
}
}
}
示例14: ReportTransactionLeak
public void ReportTransactionLeak()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (var db = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
{
var logger = new LoggerMock();
db.Logger = logger;
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(_key1, new byte[1]);
tr.Commit();
}
StartLeakingTransaction(db);
GC.Collect(GC.MaxGeneration);
GC.WaitForPendingFinalizers();
Assert.NotNull(logger.Leaked);
Assert.Equal("Leak", logger.Leaked.DescriptionForLeaks);
}
}
}
示例15: OnlyOneWrittingTransactionPossible2
public void OnlyOneWrittingTransactionPossible2()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
var tr1 = db.StartTransaction();
tr1.CreateKey(_key1);
using (var tr2 = db.StartTransaction())
{
tr1.Commit();
tr1.Dispose();
Assert.False(tr2.FindExactKey(_key1));
Assert.Throws<BTDBTransactionRetryException>(() => tr2.CreateKey(Key2));
}
}
}