public void AddThreeItems_RemoveMiddleItem_CheckConsistency() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize<Customer, string> backingFile = new BackingUnknownSize<Customer, string>(path, 100); MMFDictionary<Customer, string> dict = new MMFDictionary<Customer, string>(path, 1000); Customer c1 = new Customer {Name = "Mikael"}; Customer c2 = new Customer {Name = "Svenson"}; Customer c3 = new Customer {Name = "Boss"}; dict.Add(c1, "test"); dict.Add(c2, "test2"); dict.Add(c3, "test3"); var result = dict.Remove(c2); Assert.IsTrue(result); result = dict.Remove(c2); Assert.IsFalse(result); dict.Add(c2, "test2"); result = dict.Remove(c2); Assert.IsTrue(result); var res2 = dict[c3]; Assert.AreEqual("test3", res2); }
public static void InitializeDictionary() { if (_dict == null) { string path = AppDomain.CurrentDomain.BaseDirectory; _dict = new MMFDictionary<int, int>(path,1000); } }
public void AddTwoValues_CheckConsistency() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize<Customer, string> backingFile = new BackingUnknownSize<Customer, string>(path, 100); MMFDictionary<Customer, string> dict = new MMFDictionary<Customer, string>(path,1000); Customer c1 = new Customer {Name = "Mikael"}; Customer c2 = new Customer {Name = "Svenson"}; dict.Add(c1, "test"); dict.Add(c2, "test2"); string result = dict[c1]; Assert.AreEqual("test", result); result = dict[c2]; Assert.AreEqual("test2", result); }
public void LoadExistingDict() { try { var dict = new MMFDictionary<int, int>("test1", 20, PersistenceMode.TemporaryPersist); Assert.AreEqual(2, dict.Count); Assert.AreEqual(0, dict[0]); Assert.AreEqual(1, dict[1]); dict.Dispose(); } catch (AssertionException e) { //assertfailed _errorMessage = e.Message; _error = true; } }
public void Accessing_collection_while_iterating_should_not_thow_exception() { string path = AppDomain.CurrentDomain.BaseDirectory; MMFDictionary<string, CSandboxFileInfo> dictSandboxFileInfo = new MMFDictionary<string, CSandboxFileInfo>(path, 1000); CSandboxFileInfo c = new CSandboxFileInfo {La = "lalalalala", Lu = "lululululu"}; dictSandboxFileInfo.Add("somekey", c); MMFDictionary<string, string> keyDict = new MMFDictionary<string, string>(path, 1000); KeyValuePair<string, string> kvp = new KeyValuePair<string, string>("somekey", "bbbb"); keyDict.Add(kvp); foreach (KeyValuePair<string, string> deSandboxFile in keyDict) { var val = dictSandboxFileInfo[deSandboxFile.Key]; var obj = keyDict[deSandboxFile.Key]; } }
private static void SingelThread_HashCompositeOnDisk() { Console.WriteLine("SingelThread_HashOnDisk"); var dict = new MMFDictionary<int, Person>("SingelThread_HashCompositeOnDisk", 100000); Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < MaxCount; i++) { dict.Add(i, new Person() { Id = i, Name = "Name" + i }); Person p = null; if (!dict.TryGetValue(i,out p)) throw new Exception(); if (i/100000 == 0) { Console.WriteLine("Count: " + i); } } sw.Stop(); Console.WriteLine(sw.Elapsed); }
public void AddValues_VerifyValues() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize<string, string> backingFile = new BackingUnknownSize<string, string>(path, 2000000); MMFDictionary<string, string> dict = new MMFDictionary<string, string>(path, 10000); string prevKey = null; string prevVal = null; for (int i = 0; i < 500000; i++) { string key = Guid.NewGuid().ToString(); string value = Guid.NewGuid().ToString(); dict.Add(key, value); if (prevKey != null) { string result = dict[prevKey]; Assert.AreEqual(prevVal, result); } prevKey = key; prevVal = value; } }
public void IterateAllItems_CheckConsistency2() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize<int, int> backingFile = new BackingUnknownSize<int, int>(path, 100); MMFDictionary<int, int> dict = new MMFDictionary<int, int>(path, 1000, PersistenceMode.TemporaryPersist); dict.Add(1, 1); dict.Add(2, 2); dict.Add(3, 3); int count = 0; foreach (KeyValuePair<int, int> pair in dict) { Assert.AreEqual(pair.Key, pair.Value); count++; } Assert.AreEqual(3, count); }
public void IterateAllItems_CheckConsistency() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize<Customer, string> backingFile = new BackingUnknownSize<Customer, string>(path, 100); MMFDictionary<Customer, string> dict = new MMFDictionary<Customer, string>(path, 1000); Customer c1 = new Customer {Name = "Mikael"}; Customer c2 = new Customer {Name = "Svenson"}; Customer c3 = new Customer {Name = "Boss"}; dict.Add(c1, "Mikael"); dict.Add(c2, "Svenson"); dict.Add(c3, "Boss"); int count = 0; foreach (KeyValuePair<Customer, string> pair in dict) { Assert.AreEqual(pair.Key.Name, pair.Value); count++; } Assert.AreEqual(3, count); }
private static void Threaded_HashOnDisk() { Console.WriteLine("Threaded_HashOnDisk"); var dict = new MMFDictionary<string, string>("Threaded_HashOnDisk", MaxCount); Console.WriteLine("Queuing {0} items to Thread Pool", MaxCount); Console.WriteLine("Queue to Thread Pool 0"); var handles = new System.Collections.Generic.List<WaitHandle>(); var sw = Stopwatch.StartNew(); for (int iItem = 1; iItem < 20; iItem++) { ManualResetEvent mre = new ManualResetEvent(false); handles.Add(mre); ThreadPool.QueueUserWorkItem(d => { for (int i = 0; i < MaxCount/20; i++) { string key = Guid.NewGuid().ToString(); dict.Add(key, key); if(string.IsNullOrEmpty(dict[key])) throw new Exception(); } mre.Set(); }, null); } Console.WriteLine("Waiting for Thread Pool to drain"); WaitHandle.WaitAll(handles.ToArray()); sw.Stop(); Console.WriteLine("Thread Pool has been drained (Event fired)"); Console.WriteLine(sw.Elapsed); }
private static void Threaded_HashCompositeOnDisk() { Console.WriteLine("Threaded_HashOnDisk"); var dict = new MMFDictionary<string, Person>("Threaded_HashCompositeOnDisk", 100000); Console.WriteLine("Queuing {0} items to Thread Pool", MaxCount); Console.WriteLine("Queue to Thread Pool 0"); System.Collections.Generic.List<WaitHandle> handles = new System.Collections.Generic.List<WaitHandle>(); Stopwatch sw = Stopwatch.StartNew(); for (int iItem = 1; iItem < 20; iItem++) { ManualResetEvent mre = new ManualResetEvent(false); handles.Add(mre); ThreadPool.QueueUserWorkItem(d => { for (int i = 0; i < MaxCount / 20; i++) { string key = Guid.NewGuid().ToString(); dict.Add(key, new Person { Id = i, Name = "Name" + i }); Person p = null; if (!dict.TryGetValue(key,out p)) throw new Exception(); } mre.Set(); }, null); } Console.WriteLine("Waiting for Thread Pool to drain"); WaitHandle.WaitAll(handles.ToArray()); sw.Stop(); Console.WriteLine("Thread Pool has been drained (Event fired)"); Console.WriteLine(sw.Elapsed); }
/* private static void Threaded_HashInMemory() { Console.WriteLine("Threaded_HashInMemory"); string path = AppDomain.CurrentDomain.BaseDirectory; DictionaryPersist<string, string> backingFile = new DictionaryPersist<string, string>(path, MaxCount); Dictionary<string, string> dict = new Dictionary<string, string>(backingFile); Console.WriteLine("Queuing {0} items to Thread Pool", MaxCount); Console.WriteLine("Queue to Thread Pool 0"); System.Collections.Generic.List<WaitHandle> handles = new System.Collections.Generic.List<WaitHandle>(); Stopwatch sw = Stopwatch.StartNew(); for (int iItem = 1; iItem < 20; iItem++) { ManualResetEvent mre = new ManualResetEvent(false); handles.Add(mre); ThreadPool.QueueUserWorkItem(d => { for (int i = 0; i < MaxCount/20; i++) { string key = Guid.NewGuid().ToString(); dict.Add(key, key); if (string.IsNullOrEmpty(dict[key])) throw new Exception(); } mre.Set(); }, null); } Console.WriteLine("Waiting for Thread Pool to drain"); WaitHandle.WaitAll(handles.ToArray()); sw.Stop(); Console.WriteLine("Thread Pool has been drained (Event fired)"); Console.WriteLine(sw.Elapsed); } */ private static void SingelThread_HashOnDisk() { Console.WriteLine("SingelThread_HashOnDisk"); //var dict = new Dictionary<string, string>("SingelThread_HashOnDisk", MaxCount); var dict = new MMFDictionary<long, long>("SingelThread_HashOnDisk", MaxCount, PersistenceMode.Persist); Stopwatch sw = Stopwatch.StartNew(); for (long i = 0; i < MaxCount; i++) { //string key = Guid.NewGuid().ToString(); //dict.Add(key, key); //dict.Add(i, i); //if (string.IsNullOrEmpty(dict[key])) throw new Exception(); if (dict[i] != i) throw new Exception(); } sw.Stop(); Console.WriteLine(sw.Elapsed); }
public void When_adding_more_items_to_an_existing_file_validate_the_content() { var dict = new MMFDictionary<int, int>("test1", 20, PersistenceMode.TemporaryPersist); dict[0] = 0; dict[1] = 1; dict = null; GC.WaitForPendingFinalizers(); GC.Collect(); Thread.Sleep(4000); dict = new MMFDictionary<int, int>("test1", 20, PersistenceMode.TemporaryPersist); Assert.AreEqual(2, dict.Count); Assert.AreEqual(0, dict[0]); Assert.AreEqual(1, dict[1]); dict[0] = 2; dict[5] = 5; Assert.AreEqual(3, dict.Count); Assert.AreEqual(2, dict[0]); Assert.AreEqual(5, dict[5]); }
public void When_adding_more_items_to_an_existing_file_validate_the_content3() { using (var dict = new MMFDictionary<string, int>("test1", 20, PersistenceMode.TemporaryPersist)) { dict["new0"] = 0; dict["new1"] = 1; foreach (var kvp in dict) { if (kvp.Key != "new0" && kvp.Key != "new1") Assert.Fail("Error in reading keys"); } } using (var dict = new MMFDictionary<string, int>("test1", 20, PersistenceMode.TemporaryPersist)) { Assert.AreEqual(2, dict.Count); Assert.AreEqual(0, dict["new0"]); Assert.AreEqual(1, dict["new1"]); dict["test0"] = 2; foreach (var kvp in dict) { if (kvp.Key != "new0" && kvp.Key != "new1" && kvp.Key != "test0") Assert.Fail("Error in reading keys"); } Assert.AreEqual(3, dict.Count); Assert.AreEqual(0, dict["new0"]); Assert.AreEqual(1, dict["new1"]); Assert.AreEqual(2, dict["test0"]); } using (var dict = new MMFDictionary<string, int>("test1", 20, PersistenceMode.TemporaryPersist)) { Assert.AreEqual(3, dict.Count); Assert.AreEqual(0, dict["new0"]); Assert.AreEqual(1, dict["new1"]); Assert.AreEqual(2, dict["test0"]); } }