コード例 #1
0
  @Test
  public void testReleaseSavepoint() throws Exception {
    Txn parent = control.beginTransaction(DESTINATION_TABLE);
    TransactionImpl transaction = new TransactionImpl("user", parent, false, control);

    int res = transaction.setSavePoint("first", null);

    Assert.assertEquals("Wrong txn stack size", 2, res);
    transaction.elevate(DESTINATION_TABLE);
    TxnView first = transaction.getTxn();

    res = transaction.setSavePoint("second", null);

    Assert.assertEquals("Wrong txn stack size", 3, res);
    transaction.elevate(DESTINATION_TABLE);
    Txn second = transaction.getTxn();

    // release first, should also commit second
    res = transaction.releaseSavePoint("first", null);

    Assert.assertEquals("Wrong txn stack size", 1, res);

    Assert.assertEquals(Txn.State.COMMITTED, first.getState());
    Assert.assertEquals(Txn.State.COMMITTED, second.getState());
  }
コード例 #2
0
  @Test
  public void testRollbackSavepoint() throws Exception {
    Txn parent = control.beginTransaction(DESTINATION_TABLE);
    TransactionImpl transaction = new TransactionImpl("user", parent, false, control);

    int res = transaction.setSavePoint("first", null);

    Assert.assertEquals("Wrong txn stack size", 2, res);
    transaction.elevate(DESTINATION_TABLE);
    TxnView first = transaction.getTxn();

    res = transaction.setSavePoint("second", null);

    Assert.assertEquals("Wrong txn stack size", 3, res);
    transaction.elevate(DESTINATION_TABLE);
    Txn second = transaction.getTxn();

    // rollback to first, should rollback second
    res = transaction.rollbackToSavePoint("first", null);

    Assert.assertEquals("Wrong txn stack size", 2, res);

    Assert.assertEquals(Txn.State.ROLLEDBACK, first.getState());
    Assert.assertEquals(Txn.State.ROLLEDBACK, second.getState());
  }
コード例 #3
0
  @Test
  public void testSavepointsAreActive() throws Exception {
    Txn parent = control.beginTransaction(DESTINATION_TABLE);
    TransactionImpl transaction = new TransactionImpl("user", parent, false, control);

    int res = transaction.setSavePoint("first", null);

    Assert.assertEquals("Wrong txn stack size", 2, res);

    transaction.elevate(DESTINATION_TABLE);

    Txn parent2 = control.beginTransaction();

    long[] ids = txnStore.getActiveTransactionIds(parent2, DESTINATION_TABLE);
    Assert.assertEquals("Incorrect size", 2, ids.length);
    Assert.assertArrayEquals(
        "Incorrect values", new long[] {parent.getTxnId(), transaction.getTxn().getTxnId()}, ids);

    res = transaction.rollbackToSavePoint("first", null);

    Assert.assertEquals("Wrong txn stack size", 2, res);

    ids = txnStore.getActiveTransactionIds(parent2, DESTINATION_TABLE);
    Assert.assertEquals("Incorrect size", 1, ids.length);
    Assert.assertArrayEquals("Incorrect values", new long[] {parent.getTxnId()}, ids);
  }
コード例 #4
0
 @After
 public void tearDown() throws Exception {
   for (Txn txn : createdParentTxns) {
     txn.rollback(); // rollback the transaction to prevent contamination
   }
 }