GetCount() public method

public GetCount ( ) : uint
return uint
コード例 #1
0
ファイル: KeyValueDBTest.cs プロジェクト: tomasdeml/BTDB
 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
0
ファイル: KeyValueDBTest.cs プロジェクト: Bobris/BTDB
 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
     }
 }
コード例 #3
0
ファイル: KeyValueDBTest.cs プロジェクト: Bobris/BTDB
 public void FastCleanUpOnStartRemovesUselessFiles()
 {
     using (var fileCollection = new InMemoryFileCollection())
     {
         using (var db = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
         {
             using (var tr = db.StartTransaction())
             {
                 tr.CreateOrUpdateKeyValue(_key1, new byte[1024]);
                 tr.CreateOrUpdateKeyValue(Key2, new byte[1024]);
                 tr.Commit();
             }
             using (var tr = db.StartTransaction())
             {
                 tr.EraseAll();
                 tr.Commit();
             }
             Assert.Equal(3u, fileCollection.GetCount()); // 3 Logs
         }
         using (var db = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
         {
             Console.WriteLine(db.CalcStats());
             Assert.Equal(2u, fileCollection.GetCount()); // 1 Log, 1 KeyIndex
         }
     }
 }
コード例 #4
0
ファイル: KeyValueDBTest.cs プロジェクト: Bobris/BTDB
 public void CompactionDoesNotRemoveStillUsedFiles()
 {
     using (var fileCollection = new InMemoryFileCollection())
     {
         using (var db = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024, null))
         {
             using (var tr = db.StartTransaction())
             {
                 tr.CreateOrUpdateKeyValue(_key1, new byte[1024]);
                 tr.CreateOrUpdateKeyValue(Key2, new byte[10]);
                 tr.Commit();
             }
             var longTr = db.StartTransaction();
             using (var tr = db.StartTransaction())
             {
                 tr.FindExactKey(_key1);
                 tr.EraseCurrent();
                 tr.Commit();
             }
             db.Compact(new CancellationToken());
             Assert.Equal(3u, fileCollection.GetCount()); // 2 Logs, 1 KeyIndex
             longTr.Dispose();
             db.Compact(new CancellationToken());
             Assert.Equal(2u, fileCollection.GetCount()); // 1 Log, 1 KeyIndex
             using (var tr = db.StartTransaction())
             {
                 tr.CreateOrUpdateKeyValue(_key3, new byte[10]);
                 tr.Commit();
             }
             using (var db2 = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
             {
                 using (var tr = db2.StartTransaction())
                 {
                     Assert.True(tr.FindExactKey(_key3));
                 }
             }
         }
     }
 }
コード例 #5
0
ファイル: KeyValueDBTest.cs プロジェクト: Bobris/BTDB
 public void AddingContinueToSameFileAfterReopenOfDBWith2TransactionLogFiles()
 {
     using (var fileCollection = new InMemoryFileCollection())
     {
         using (IKeyValueDB db = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
         {
             using (var tr = db.StartTransaction())
             {
                 tr.CreateOrUpdateKeyValue(_key1, new byte[1024]);
                 tr.CreateOrUpdateKeyValue(Key2, new byte[10]);
                 tr.Commit();
             }
         }
         Assert.Equal(2u, fileCollection.GetCount());
         using (IKeyValueDB db = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
         {
             using (var tr = db.StartTransaction())
             {
                 tr.CreateOrUpdateKeyValue(Key2, new byte[1024]);
                 tr.CreateOrUpdateKeyValue(_key3, new byte[10]);
                 tr.Commit();
             }
         }
         Assert.Equal(4u, fileCollection.GetCount());
         using (IKeyValueDB db = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
         {
             using (var tr = db.StartTransaction())
             {
                 tr.CreateOrUpdateKeyValue(Key2, Key2);
                 tr.Commit();
             }
         }
         Assert.Equal(4u, fileCollection.GetCount());
     }
 }
コード例 #6
0
ファイル: KeyValueDBTest.cs プロジェクト: tomasdeml/BTDB
 public void CompactionWaitsForFinishingOldTransactionsBeforeRemovingFiles()
 {
     using (var fileCollection = new InMemoryFileCollection())
     {
         using (var db = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
         {
             using (var tr = db.StartTransaction())
             {
                 tr.CreateOrUpdateKeyValue(_key1, new byte[1024]);
                 tr.CreateOrUpdateKeyValue(Key2, new byte[10]);
                 tr.Commit();
             }
             var longTr = db.StartTransaction();
             using (var tr = db.StartTransaction())
             {
                 tr.FindExactKey(_key1);
                 tr.EraseCurrent();
                 tr.Commit();
             }
             db.Compact();
             Thread.Sleep(2000);
             Console.WriteLine(db.CalcStats());
             Assert.True(4 <= fileCollection.GetCount()); // 2 Logs, 1 Value, 1 KeyIndex, (optinal 1 Unknown (old KeyIndex))
             longTr.Dispose();
             Thread.Sleep(1000);
             Assert.Equal(2u, fileCollection.GetCount()); // 1 Log, 1 KeyIndex
             using (var tr = db.StartTransaction())
             {
                 tr.CreateOrUpdateKeyValue(_key3, new byte[10]);
                 tr.Commit();
             }
             using (var db2 = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
             {
                 using (var tr = db2.StartTransaction())
                 {
                     Assert.True(tr.FindExactKey(_key3));
                 }
             }
         }
     }
 }