Ejemplo n.º 1
3
  @Test
  public void testInc() {
    LongRef ref = new LongRef(100);

    assertEquals(101, ref.inc());
    assertEquals(101, ref.get());

    assertEquals(111, ref.inc(10));
    assertEquals(111, ref.get());

    assertEquals(100, ref.inc(-11));
    assertEquals(100, ref.get());
  }
Ejemplo n.º 2
0
  @Test
  public void testDec() {
    LongRef ref = new LongRef(100);

    assertEquals(99, ref.dec());
    assertEquals(99, ref.get());

    assertEquals(89, ref.dec(10));
    assertEquals(89, ref.get());

    assertEquals(100, ref.dec(-11));
    assertEquals(100, ref.get());
  }
Ejemplo n.º 3
0
  @Test
  public void testAtomic() {
    LongRef ref1 = new LongRef(10);
    LongRef ref2 = new LongRef(20);

    try {
      incButAbort(ref1, ref2);
      fail();
    } catch (DeadTransactionException expected) {
    }

    assertEquals(10, ref1.get());
    assertEquals(20, ref2.get());
  }
Ejemplo n.º 4
0
 @Test
 public void set() {
   LongRef ref = new LongRef(10);
   long old = ref.set(100);
   assertEquals(10, old);
   assertEquals(100, ref.get());
 }
Ejemplo n.º 5
0
 @Test
 public void constructorWithSingleArg() {
   LongRef ref = new LongRef(10);
   assertEquals(10, ref.get());
 }
Ejemplo n.º 6
0
 @Test
 public void constructorWithNoArg() {
   LongRef ref = new LongRef();
   assertEquals(0, ref.get());
 }