Search in sources :

Example 1 with DelegatingTransactionManager

use of com.facebook.presto.transaction.DelegatingTransactionManager in project presto by prestodb.

the class TestQueryStateMachine method testTransitionToCanceledAfterTransitionToFinishing.

@Test
public void testTransitionToCanceledAfterTransitionToFinishing() {
    SettableFuture<?> commitFuture = SettableFuture.create();
    TransactionManager transactionManager = new DelegatingTransactionManager(createTestTransactionManager()) {

        @Override
        public ListenableFuture<?> asyncCommit(TransactionId transactionId) {
            return allAsList(commitFuture, super.asyncCommit(transactionId));
        }
    };
    QueryStateMachine stateMachine = createQueryStateMachine(transactionManager);
    stateMachine.transitionToFinishing();
    assertEquals(stateMachine.getQueryState(), FINISHING);
    assertTrue(stateMachine.transitionToCanceled());
    assertEquals(stateMachine.getQueryState(), FAILED);
    commitFuture.set(null);
    assertEquals(stateMachine.getQueryState(), FAILED);
    assertEquals(stateMachine.getFailureInfo().get().getMessage(), "Query was canceled");
}
Also used : DelegatingTransactionManager(com.facebook.presto.transaction.DelegatingTransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) DelegatingTransactionManager(com.facebook.presto.transaction.DelegatingTransactionManager) TransactionId(com.facebook.presto.transaction.TransactionId) Test(org.testng.annotations.Test)

Example 2 with DelegatingTransactionManager

use of com.facebook.presto.transaction.DelegatingTransactionManager in project presto by prestodb.

the class TestQueryStateMachine method testCommitFailure.

@Test
public void testCommitFailure() {
    SettableFuture<?> commitFuture = SettableFuture.create();
    TransactionManager transactionManager = new DelegatingTransactionManager(createTestTransactionManager()) {

        @Override
        public ListenableFuture<?> asyncCommit(TransactionId transactionId) {
            return allAsList(commitFuture, super.asyncCommit(transactionId));
        }
    };
    QueryStateMachine stateMachine = createQueryStateMachine(transactionManager);
    stateMachine.transitionToFinishing();
    // after transitioning to finishing, the transaction is gone
    assertEquals(stateMachine.getQueryState(), FINISHING);
    assertFalse(stateMachine.transitionToFailed(new RuntimeException("failed")));
    assertEquals(stateMachine.getQueryState(), FINISHING);
    commitFuture.setException(new RuntimeException("transaction failed"));
    tryGetFutureValue(stateMachine.getStateChange(FAILED), 2, SECONDS);
    assertEquals(stateMachine.getQueryState(), FAILED);
    assertEquals(stateMachine.getFailureInfo().get().getMessage(), "transaction failed");
}
Also used : DelegatingTransactionManager(com.facebook.presto.transaction.DelegatingTransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) DelegatingTransactionManager(com.facebook.presto.transaction.DelegatingTransactionManager) TransactionId(com.facebook.presto.transaction.TransactionId) Test(org.testng.annotations.Test)

Example 3 with DelegatingTransactionManager

use of com.facebook.presto.transaction.DelegatingTransactionManager in project presto by prestodb.

the class TestQueryStateMachine method testTransitionToFailedAfterTransitionToFinishing.

@Test
public void testTransitionToFailedAfterTransitionToFinishing() {
    SettableFuture<?> commitFuture = SettableFuture.create();
    TransactionManager transactionManager = new DelegatingTransactionManager(createTestTransactionManager()) {

        @Override
        public ListenableFuture<?> asyncCommit(TransactionId transactionId) {
            return allAsList(commitFuture, super.asyncCommit(transactionId));
        }
    };
    QueryStateMachine stateMachine = createQueryStateMachine(transactionManager);
    stateMachine.transitionToFinishing();
    assertEquals(stateMachine.getQueryState(), FINISHING);
    assertFalse(stateMachine.transitionToFailed(new RuntimeException("failed")));
    assertEquals(stateMachine.getQueryState(), FINISHING);
    commitFuture.set(null);
    tryGetFutureValue(stateMachine.getStateChange(FINISHED), 2, SECONDS);
    assertEquals(stateMachine.getQueryState(), FINISHED);
}
Also used : DelegatingTransactionManager(com.facebook.presto.transaction.DelegatingTransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) DelegatingTransactionManager(com.facebook.presto.transaction.DelegatingTransactionManager) TransactionId(com.facebook.presto.transaction.TransactionId) Test(org.testng.annotations.Test)

Aggregations

DelegatingTransactionManager (com.facebook.presto.transaction.DelegatingTransactionManager)3 InMemoryTransactionManager.createTestTransactionManager (com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager)3 TransactionId (com.facebook.presto.transaction.TransactionId)3 TransactionManager (com.facebook.presto.transaction.TransactionManager)3 Test (org.testng.annotations.Test)3