Ejemplo n.º 1
0
        public void TestAtomicReference()
        {
            var o = new Order {
                Id = 1, Name = "1"
            };
            var r = AtomicReference <Order> .From(o);

            Assert.Same(o, r.Value);
            Assert.Equal(1, r.Value.Id);
            Assert.Equal("1", r.Value.Name);
        }
Ejemplo n.º 2
0
        public void TestAtomicReferenceCas()
        {
            var o = new Order {
                Id = 1, Name = "1"
            };
            var r = AtomicReference <Order> .From(o);

            var n = new Order {
                Id = 2, Name = "2"
            };

            Assert.True(r.CompareExchange(n, o));
            Assert.Same(n, r.Value);
            Assert.Equal(2, r.Value.Id);
            Assert.Equal("2", r.Value.Name);
        }
Ejemplo n.º 3
0
        public void TestAtomicReferenceExchange()
        {
            var o = new Order {
                Id = 1, Name = "1"
            };
            var r = AtomicReference <Order> .From(o);

            var n1 = new Order {
                Id = 3, Name = "3"
            };

            Assert.True(r.Exchange(n1));
            Assert.Same(n1, r.Value);
            Assert.Equal(3, r.Value.Id);
            Assert.Equal("3", r.Value.Name);
            var c = (Order)r;

            Assert.Equal(3, c.Id);
            Assert.Equal("3", c.Name);
        }