public void AddAndLookupItems() { MemTable mt = new MemTable (); List<KeyValuePair<Key, Value>> values = new List<KeyValuePair<Key, Value>> (); for (int i = 0; i < 10000; i++) { var randomKey = Key.Random (40); var randomValue = Value.Random (256); values.Add (new KeyValuePair<Key, Value> (randomKey, randomValue)); mt.Add (randomKey, randomValue); } Value value; foreach (var pair in values) { Assert.IsTrue (mt.Lookup (pair.Key, out value)); Assert.AreEqual (pair.Value, value); } Assert.IsFalse (mt.Lookup (Key.Random (40), out value)); Assert.AreEqual (10000 * (40 + 256), mt.Size); Assert.IsTrue (mt.Full); }
public bool Lookup(Key key, out Value value) { return(_memTable.Lookup(key, out value)); }
public void SetItemsMultipleTimes() { MemTable mt = new MemTable (); Dictionary<Key, Value> values = new Dictionary<Key, Value> (); for (int i = 0; i < 10000; i++) { var randomKey = new Key (new ByteArray (BitConverter.GetBytes (i % 10))); var randomValue = Value.Random (256); values [randomKey] = randomValue; mt.Add (randomKey, randomValue); } Value value; foreach (var pair in values) { Assert.IsTrue (mt.Lookup (pair.Key, out value)); Assert.AreEqual (pair.Value, value); } Assert.IsFalse (mt.Lookup (Key.Random (4), out value)); Assert.AreEqual (10, mt.Enumerate ().Count ()); Assert.AreEqual (10, values.Count); }
public void AddAndLookupItemsPersisted() { string path = Path.GetFullPath ("TestData\\AddAndLookupItemsPersisted"); if (!Directory.Exists (path)) Directory.CreateDirectory (path); JournalWriter jw = new JournalWriter ("TestData\\AddAndLookupItemsPersisted", 523, false); List<KeyValuePair<Key, Value>> values = new List<KeyValuePair<Key, Value>> (); for (int i = 0; i < 10000; i++) { var randomKey = Key.Random (40); var randomValue = Value.Random (256); values.Add (new KeyValuePair<Key, Value> (randomKey, randomValue)); jw.Add (randomKey, randomValue); } jw.Close (); MemTable mtl = new MemTable (); mtl.ReadFromJournal ("TestData\\AddAndLookupItemsPersisted", 523); Value value; foreach (var pair in values) { Assert.IsTrue (mtl.Lookup (pair.Key, out value)); Assert.AreEqual (pair.Value, value); } Assert.IsFalse (mtl.Lookup (Key.Random (40), out value)); Assert.AreEqual (10000 * (40 + 256), mtl.Size); Assert.IsTrue (mtl.Full); }