Example #1
0
 public override async Task DoCleanupAsync()
 {
     if (mfd != null)
     {
         mfd.Dispose();
     }
 }
Example #2
0
        public void RandStuff()
        {
            uint nInstances = 100000;

            using (var dict = new MapFileDict <int, DataClass>())
            {
                try
                {
                    for (int lp = 0; lp < 1; lp++)
                    {
                        for (int i = 0; i < nInstances; i++)
                        {
                            var rndInd = _random.Next((int)nInstances);
                            var rnd    = _random.Next(10000) / 10;
                            dict[rndInd] = new DataClass()
                            {
                                int1  = rndInd,
                                uint2 = (uint)rnd,
                                str5  = string.Format("foo{0}", new string('1', rnd))
                            };
                            dict[rndInd].str5 = "bar";
                            var x = dict[rndInd];
                            Assert.AreEqual(rndInd, x.int1, "rnd inst not eq");
                        }
                    }
                    //               throw new InvalidOperationException("Test Passed");
                }
                catch (Exception ex)
                {
                    dict.Dispose();
                    Assert.Fail("exception lp={0} cnt={1} {2}\r\n{3}", 0, dict.Count, dict._MemMap._stats.ToString(), ex.ToString());
                }
                dict.VerifyNoLeaks();
            }
        }
Example #3
0
        private void DoIt(
            uint nInstances,
            int nLoops,
            MapMemTypes mapfileType = MapMemTypes.MapMemTypePageFile,
            bool fDoDeleteStuff     = false,
            bool fUseNormDict       = false
            )
        {
            Assert.AreEqual(IntPtr.Size, 4, "intptr != 4?");
            for (uint iLoop = 0; iLoop < nLoops; iLoop++)
            {
                uint ulInitialFileSize = 0;

                if (fDoDeleteStuff)
                {
                }
                IDictionary <int, DataClass> dict;
                using (var mfd = new MapFileDict <int, DataClass>(ulInitialSize: ulInitialFileSize, mapfileType: mapfileType))
                {
                    if (fUseNormDict)//|| true)
                    {
                        dict = new Dictionary <int, DataClass>();
                    }
                    else
                    {
                        dict = mfd;
                    }
                    try
                    {
                        //                    Assert.IsTrue(mfd._objSize == 36, "obj size = 36");
                        for (int i = 00; i < nInstances; i++)
                        {
                            var testInstance = DataClass.MakeInstance((ulong)i);
                            dict[(int)i] = testInstance;
                            var res = i;

                            var retrievedInstance = dict[(int)i];
                            Assert.AreEqual(testInstance, retrievedInstance, "objects not equal Count=" + dict.Count.ToString());
                            if (fDoDeleteStuff)
                            {
                            }
                        }
                        for (int i = 00; i < nInstances; i++)
                        {
                            var retrievedInstance = dict[i];
                            var testInstance      = DataClass.MakeInstance((ulong)i);
                            Assert.AreEqual(testInstance, retrievedInstance, "objects not equal Count=" + dict.Count.ToString());
                        }
                        //dict.Clear();
                        mfd.VerifyNoLeaks();
                    }
                    catch (Exception ex)
                    {
                        mfd.Dispose();
                        Assert.Fail("exception lp={0} cnt={1} {2}\r\n{3}", iLoop, mfd.Count, mfd._MemMap._stats.ToString(), ex.ToString());
                        throw;
                    }
                }
            }
        }
Example #4
0
        public void DictStuff()
        {
            uint nInstances = 546200;

            nInstances = 100000;
            using (var dict = new MapFileDict <int, string>())
            {
                int i = 0;
                try
                {
                    //                    var randstr = new string('a', 100000);
                    for (i = 0; i < nInstances; i++)
                    {
                        var randstr = new string('a', _random.Next(10000));
                        var teststr = string.Format("Foo {0}, {1}", i, randstr);
                        dict[i] = teststr;
                        var retrieved = dict[i];
                        Assert.AreEqual(teststr, retrieved, "strs not eq " + i.ToString());
                        dict[i] = "bar";
                    }
                    //throw new InvalidOperationException("Test Passed");
                }
                catch (Exception ex)
                {
                    dict.Dispose();
                    Assert.Fail("exception lp={0} cnt={1} {2}\r\n{3}", i, dict.Count, dict._MemMap._stats.ToString(), ex.ToString());
                    throw;
                }
                dict.VerifyNoLeaks();
            }
        }