Exemplo n.º 1
0
        public void AtomicObjectCompareAndSetReturnsFalseIfComparisonDoesNotMatch()
        {
            var o = new AtomicObject <string>("bar");

            bool result = o.CompareAndSet("foo", "bar");

            Assert.IsFalse(result);
            Assert.AreEqual("bar", o.Value);
            Assert.AreEqual("bar", (string)o);
        }
Exemplo n.º 2
0
        public void AtomicObjectCompareAndSetReturnsExpectedValuesForFailedMatchesMultiThreaded()
        {
            const int expected = 1000;

            var o = new AtomicObject <string>("foo");

            var values = new ConcurrentCountedSet <bool>();

            System.Threading.Tasks.Parallel.For(0, 1000, i => values.Add(o.CompareAndSet(i % 2 == 0 ? "bar" : "foo", "bar")));

            Assert.AreEqual(expected, values[true] + values[false]);
        }
Exemplo n.º 3
0
        public void AtomicObjectCompareAndSetReturnsExpectedValuesForFailedMatches()
        {
            const int expected = 1000;

            var o = new AtomicObject <string>("foo");

            var values = new ConcurrentCountedSet <bool>();

            for (int i = 0; i < 1000; i++)
            {
                values.Add(o.CompareAndSet(i % 2 == 0 ? "bar" : "foo", "bar"));
            }

            Assert.AreEqual(expected, values[true] + values[false]);
        }