Exemplo n.º 1
0
        public void SSWDNoPruneDuringSnapshot()
        {
            var dict = new SnapshotSingleWriterDictionary <int, int>();

            for (int i = 0; i < 10; ++i)
            {
                dict.Add(i, i);
            }

            var view = dict.TakeSnapshot();

            var t = new Task(() => dict.BlockingPruneOldValues());

            t.Start();

            for (int i = 0; i < 10; ++i)
            {
                int actualValue = 0;
                Assert.IsTrue(view.TryGetValue(i, out actualValue));
                Assert.AreEqual(i, actualValue);
            }

            Assert.IsFalse(t.IsCompleted);

            view.Dispose();
            t.Wait();
        }
Exemplo n.º 2
0
        public void SSWDSnapshotViewNotAffectedByNewWrites()
        {
            Prop.ForAll <Tuple <int, int>[]>(kvs => {
                var dict = new SnapshotSingleWriterDictionary <int, int>();

                foreach (var kv in kvs)
                {
                    dict.Add(kv.Item1, kv.Item2);
                }

                using (var view = dict.TakeSnapshot())
                {
                    foreach (var kv in kvs)
                    {
                        dict.Add(kv.Item1, kv.Item2 + 1);
                        int actualValue;

                        Assert.IsTrue(view.TryGetValue(kv.Item1, out actualValue));
                        Assert.AreNotEqual(kv.Item2, actualValue);

                        Assert.IsTrue(dict.TryGetValue(kv.Item1, out actualValue));
                        Assert.AreNotEqual(kv.Item2 + 1, actualValue);
                    }
                }
            });
        }