예제 #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());
  }
예제 #2
1
  @TransactionalMethod
  public void incButAbort(LongRef... refs) {
    for (LongRef ref : refs) {
      ref.inc();
    }

    getThreadLocalTransaction().abort();
  }
예제 #3
0
 @Test
 public void set() {
   LongRef ref = new LongRef(10);
   long old = ref.set(100);
   assertEquals(10, old);
   assertEquals(100, ref.get());
 }
예제 #4
0
  @Test
  public void awaitTest() {
    final LongRef ref = new LongRef();

    TestThread t =
        new TestThread() {
          @Override
          public void doRun() throws Exception {
            ref.await(2);
          }
        };

    t.start();
    sleepMs(500);

    assertAlive(t);

    ref.set(1);
    sleepMs(500);

    assertAlive(t);

    ref.set(2);
    joinAll(t);
  }
예제 #5
0
  @Test
  public void testHashCode() {
    LongRef ref = new LongRef(10);
    assertEquals(10, ref.hashCode());

    ref.set(200);
    assertEquals(200, ref.hashCode());
  }
예제 #6
0
  @Test
  public void await() {
    LongRef txInt = new LongRef();

    SetThread t = new SetThread(txInt, 3);
    t.start();

    txInt.await(3);
  }
예제 #7
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());
  }
예제 #8
0
  @Test
  public void testEquals() {
    LongRef ref1 = new LongRef(10);
    LongRef ref2 = new LongRef(10);
    LongRef ref3 = new LongRef(20);

    assertFalse(ref1.equals(null));
    assertFalse(ref1.equals(""));
    assertTrue(ref1.equals(ref2));
    assertTrue(ref2.equals(ref1));
    assertTrue(ref1.equals(ref1));
    assertFalse(ref1.equals(ref3));
    assertFalse(ref3.equals(ref1));
  }
예제 #9
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());
  }
예제 #10
0
 @Test
 public void constructorWithSingleArg() {
   LongRef ref = new LongRef(10);
   assertEquals(10, ref.get());
 }
예제 #11
0
 @Test
 public void constructorWithNoArg() {
   LongRef ref = new LongRef();
   assertEquals(0, ref.get());
 }
예제 #12
0
 @Override
 public void doRun() throws Exception {
   sleepMs(300);
   txInt.set(value);
 }