コード例 #1
0
ファイル: TestTxnLib.java プロジェクト: anukat2015/mantis
  @Test
  public void libTxn_3() {
    Txn.executeRead(
        unit,
        () -> {
          assertEquals("In R, value()", 0, counter2.get());
          assertEquals("In R, get()", 0, counter2.value());
        });

    Txn.executeWrite(
        unit,
        () -> {
          counter2.inc();
          assertEquals("In W, value()", 0, counter2.value());
          assertEquals("In W, get()", 1, counter2.get());
        });

    assertEquals("Direct value()", 1, counter2.value());
    assertEquals("Direct get()", 1, counter2.get());

    Txn.executeRead(
        unit,
        () -> {
          assertEquals("In R, value()", 1, counter2.get());
          assertEquals("In R, get()", 1, counter2.value());
        });
  }
コード例 #2
0
ファイル: TestTxnLib.java プロジェクト: anukat2015/mantis
  @Test
  public void libTxn_4() {
    long v1 = counter1.value();
    long v2 = counter2.value();
    assertEquals(0, v1);
    assertEquals(0, v2);

    // Txn.executeWrite(unit, () -> {

    unit.begin(ReadWrite.WRITE);

    counter1.inc();
    counter2.inc();
    assertEquals("Counter out of step", counter1.get(), counter2.get());
    assertNotEquals("Counter 1 can see wrong state", counter1.get(), counter1.value());
    assertNotEquals("Counter 2 can see wrong state", counter2.get(), counter2.value());
    counter2.inc();
    assertNotEquals("Counter 1 and 2 shoudl differ", counter1.get(), counter2.get());
    unit.commit();
    unit.end();
    // }) ;
    assertEquals("Component 1 inconsistent", 1, counter1.value());
    assertEquals("Component 2 inconsistent", 2, counter2.value());

    Txn.executeRead(
        unit,
        () -> {
          assertEquals("Component 1 inconsistent (R)", 1, counter1.get());
          assertEquals("Component 2 inconsistent (R)", 2, counter2.get());
        });
  }
コード例 #3
0
ファイル: TestTxnLib.java プロジェクト: anukat2015/mantis
  @Test
  public void libTxn_1() {
    long v1 = counter1.value();
    long v2 = counter2.value();
    assertEquals(0, v1);
    assertEquals(0, v2);

    Txn.executeRead(
        unit,
        () -> {
          assertEquals(0, counter1.get());
          assertEquals(0, counter2.get());
        });
  }