use of com.facebook.presto.sql.tree.Rollback in project presto by prestodb.
the class TestRollbackTask method testRollback.
@Test
public void testRollback() throws Exception {
TransactionManager transactionManager = createTestTransactionManager();
AccessControl accessControl = new AccessControlManager(transactionManager);
Session session = sessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "ROLLBACK", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
assertTrue(stateMachine.getSession().getTransactionId().isPresent());
assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
getFutureValue(new RollbackTask().execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
assertTrue(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
assertFalse(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
use of com.facebook.presto.sql.tree.Rollback in project presto by prestodb.
the class TestRollbackTask method testNoTransactionRollback.
@Test
public void testNoTransactionRollback() throws Exception {
TransactionManager transactionManager = createTestTransactionManager();
AccessControl accessControl = new AccessControlManager(transactionManager);
Session session = sessionBuilder().build();
QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "ROLLBACK", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
try {
try {
getFutureValue(new RollbackTask().execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
fail();
} catch (CompletionException e) {
throw Throwables.propagate(e.getCause());
}
} catch (PrestoException e) {
assertEquals(e.getErrorCode(), NOT_IN_TRANSACTION.toErrorCode());
}
assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
assertFalse(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
use of com.facebook.presto.sql.tree.Rollback in project presto by prestodb.
the class TestSqlParser method testRollback.
@Test
public void testRollback() throws Exception {
assertStatement("ROLLBACK", new Rollback());
assertStatement("ROLLBACK WORK", new Rollback());
}
use of com.facebook.presto.sql.tree.Rollback in project presto by prestodb.
the class TestRollbackTask method testUnknownTransactionRollback.
@Test
public void testUnknownTransactionRollback() throws Exception {
TransactionManager transactionManager = createTestTransactionManager();
AccessControl accessControl = new AccessControlManager(transactionManager);
Session session = sessionBuilder().setTransactionId(// Use a random transaction ID that is unknown to the system
TransactionId.create()).build();
QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "ROLLBACK", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
getFutureValue(new RollbackTask().execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
// Still issue clear signal
assertTrue(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
assertFalse(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
Aggregations