本文整理汇总了C#中BTDB.KVDBLayer.InMemoryFileCollection类的典型用法代码示例。如果您正苦于以下问题:C# InMemoryFileCollection类的具体用法?C# InMemoryFileCollection怎么用?C# InMemoryFileCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InMemoryFileCollection类属于BTDB.KVDBLayer命名空间,在下文中一共展示了InMemoryFileCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateEmptyDatabase
public void CreateEmptyDatabase()
{
using (var fileCollection = new InMemoryFileCollection())
using (new KeyValueDB(fileCollection))
{
}
}
示例2: 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());
}
}
示例3: CreateEmptyCache
public void CreateEmptyCache()
{
using (var fileCollection = new InMemoryFileCollection())
using (new DiskChunkCache(fileCollection, 20, 1000))
{
}
}
示例4: GetFromEmptyCacheReturnsEmptyByteBuffer
public void GetFromEmptyCacheReturnsEmptyByteBuffer()
{
using (var fileCollection = new InMemoryFileCollection())
using (var cache = new DiskChunkCache(fileCollection, 20, 1000))
{
Assert.AreEqual(0, cache.Get(CalcHash(new byte[] { 0 })).Result.Length);
}
}
示例5: EmptyWritingTransaction
public void EmptyWritingTransaction()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartWritingTransaction().Result)
{
tr.Commit();
}
}
}
示例6: 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();
}
}
}
示例7: 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);
}
}
}
示例8: GettingContentMakesItStayLongerDecreasingRate
public void GettingContentMakesItStayLongerDecreasingRate()
{
using (var fileCollection = new InMemoryFileCollection())
{
const int cacheCapacity = 50000;
using (var cache = new DiskChunkCache(fileCollection, 20, cacheCapacity))
{
for (var i = 0; i < 80; i++)
{
Put(cache, i);
for (var j = 0; j < 79 - i; j++)
Get(cache, i);
Assert.LessOrEqual(fileCollection.Enumerate().Sum(f => (long)f.GetSize()), cacheCapacity);
}
Console.WriteLine(cache.CalcStats());
Assert.True(Get(cache, 0));
Assert.False(Get(cache, 60));
}
}
}
示例9: AccessEveryTenthTenTimesMoreMakesItStay
public void AccessEveryTenthTenTimesMoreMakesItStay()
{
using (var fileCollection = new InMemoryFileCollection())
{
const int cacheCapacity = 50000;
using (var cache = new DiskChunkCache(fileCollection, 20, cacheCapacity))
{
for (var i = 0; i < 46; i++)
{
Put(cache, i);
for (var j = 0; j < (i % 5 == 0 ? 10 + i : 1); j++)
Get(cache, i);
if (i==42) Thread.Sleep(500);
Assert.LessOrEqual(fileCollection.Enumerate().Sum(f => (long)f.GetSize()), cacheCapacity);
}
Console.WriteLine(cache.CalcStats());
Assert.True(Get(cache, 0));
Assert.False(Get(cache, 1));
}
}
}
示例10: Run
public void Run()
{
int cnt = 500000;
using (var fc = new InMemoryFileCollection())
using (var db = CreateDb(fc))
{
Measure("Relation: ", new RelationPersonTest(db, cnt));
}
using (var fc = new InMemoryFileCollection())
using (var db = CreateDb(fc))
{
Measure("2 Maps: ", new SingletonPersonTest(db, cnt));
}
using (var db = CreateInMemoryDb())
{
Measure("Relation (mem): ", new RelationPersonTest(db, cnt));
}
using (var db = CreateInMemoryDb())
{
Measure("2 Maps (mem): ", new SingletonPersonTest(db, cnt));
}
}
示例11: 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
}
}
示例12: SetKeyPrefixInOneTransaction
public void SetKeyPrefixInOneTransaction()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
var key = new byte[5];
var value = new byte[100];
var rnd = new Random();
using (var tr = db.StartTransaction())
{
for (byte i = 0; i < 100; i++)
{
key[0] = i;
for (byte j = 0; j < 100; j++)
{
key[4] = j;
rnd.NextBytes(value);
tr.CreateOrUpdateKeyValue(key, value);
}
}
tr.Commit();
}
using (var tr = db.StartTransaction())
{
for (byte i = 0; i < 100; i++)
{
key[0] = i;
tr.SetKeyPrefix(ByteBuffer.NewSync(key, 0, 4));
Assert.Equal(100, tr.GetKeyValueCount());
}
}
}
}
示例13: ALotOf5KbTransactionsWorks
public void ALotOf5KbTransactionsWorks()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
for (int i = 0; i < 5000; i++)
{
var key = new byte[5000];
using (var tr = db.StartTransaction())
{
key[0] = (byte)(i / 256);
key[1] = (byte)(i % 256);
Assert.True(tr.CreateKey(key));
tr.Commit();
}
}
}
}
示例14: 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");
}
}
}
}
}
示例15: SimpleEraseCurrentWorks
public void SimpleEraseCurrentWorks()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateKey(_key1);
tr.CreateKey(Key2);
tr.CreateKey(_key3);
tr.EraseCurrent();
Assert.True(tr.FindFirstKey());
Assert.Equal(_key1, tr.GetKeyAsByteArray());
Assert.True(tr.FindNextKey());
Assert.Equal(Key2, tr.GetKeyAsByteArray());
Assert.False(tr.FindNextKey());
Assert.Equal(2, tr.GetKeyValueCount());
}
}
}