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 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 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 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); }