Beispiel #1
0
        public void TestIndexing()
        {
            AtomicReferenceArray <Integer> ai = new AtomicReferenceArray <Integer>(SIZE);

            try
            {
                var _ = ai[SIZE];
            }
            catch (IndexOutOfRangeException success)
            {
            }
            try
            {
                var _ = ai[-1];
            }
            catch (IndexOutOfRangeException success)
            {
            }
            try
            {
                ai[SIZE] = null;
            }
            catch (IndexOutOfRangeException success)
            {
            }
            try
            {
                ai[-1] = null;
            }
            catch (IndexOutOfRangeException success)
            {
            }
        }
Beispiel #2
0
        public void TestToString()
        {
            Integer[] a = { two, one, three, four, seven };
            AtomicReferenceArray <Integer> ai = new AtomicReferenceArray <Integer>(a);

            assertEquals(Arrays.ToString(a), ai.ToString());
        }
Beispiel #3
0
        public void TestSerialization()
        {
            AtomicReferenceArray <Integer> l = new AtomicReferenceArray <Integer>(SIZE);

            for (int i = 0; i < SIZE; ++i)
            {
                l[i] = new Integer(-i);
            }

            try
            {
                AtomicReferenceArray <Integer> r = Clone(l);

                assertNotSame(l, r);
                assertEquals(l.Length, r.Length);
                for (int i = 0; i < SIZE; ++i)
                {
                    assertEquals(r[i], l[i]);
                }
            }
            catch (Exception e)
            {
                unexpectedException();
            }
        }
Beispiel #4
0
        public void TestCompareAndSetInMultipleThreads()
        {
            AtomicReferenceArray <Integer> a = new AtomicReferenceArray <Integer>(1);

            a[0] = one;
            Thread t = new Thread(() =>
            {
                while (!a.CompareAndSet(0, two, three))
                {
                    Thread.Yield();
                }
            });

            try
            {
                t.Start();
                assertTrue(a.CompareAndSet(0, one, two));
                t.Join(LONG_DELAY_MS);
                assertFalse(t.IsAlive);
                assertEquals(a[0], three);
            }
            catch (Exception e)
            {
                unexpectedException();
            }
        }
Beispiel #5
0
        public void TestConstructor()
        {
            AtomicReferenceArray <Integer> ai = new AtomicReferenceArray <Integer>(SIZE);

            for (int i = 0; i < SIZE; ++i)
            {
                assertNull(ai[i]);
            }
        }
Beispiel #6
0
        public void TestConstructor2()
        {
            Integer[] a = { two, one, three, four, seven };
            AtomicReferenceArray <Integer> ai = new AtomicReferenceArray <Integer>(a);

            assertEquals(a.Length, ai.Length);
            for (int i = 0; i < a.Length; ++i)
            {
                assertEquals(a[i], ai[i]);
            }
        }
Beispiel #7
0
        public void TestGetAndSet()
        {
            AtomicReferenceArray <Integer> ai = new AtomicReferenceArray <Integer>(SIZE);

            for (int i = 0; i < SIZE; ++i)
            {
                ai[i] = one;
                assertEquals(one, ai.GetAndSet(i, zero));
                assertEquals((Integer)0, ai.GetAndSet(i, m10));
                assertEquals(m10, ai.GetAndSet(i, one));
            }
        }
Beispiel #8
0
        public void TestGetSet()
        {
            AtomicReferenceArray <Integer> ai = new AtomicReferenceArray <Integer>(SIZE);

            for (int i = 0; i < SIZE; ++i)
            {
                ai[i] = one;
                assertEquals(one, ai[i]);
                ai[i] = two;
                assertEquals(two, ai[i]);
                ai[i] = m3;
                assertEquals(m3, ai[i]);
            }
        }
Beispiel #9
0
 public void TestConstructor2NPE()
 {
     try
     {
         Integer[] a = null;
         AtomicReferenceArray <Integer> ai = new AtomicReferenceArray <Integer>(a);
     }
     catch (ArgumentNullException success)
     {
     }
     catch (Exception ex)
     {
         unexpectedException();
     }
 }
Beispiel #10
0
        public void TestCompareAndSet()
        {
            AtomicReferenceArray <Integer> ai = new AtomicReferenceArray <Integer>(SIZE);

            for (int i = 0; i < SIZE; ++i)
            {
                ai[i] = one;
                assertTrue(ai.CompareAndSet(i, one, two));
                assertTrue(ai.CompareAndSet(i, two, m4));
                assertEquals(m4, ai[i]);
                assertFalse(ai.CompareAndSet(i, m5, seven));
                assertFalse((seven.Equals(ai[i])));
                assertTrue(ai.CompareAndSet(i, m4, seven));
                assertEquals(seven, ai[i]);
            }
        }