Search in sources :

Example 1 with Rollback

use of io.trino.sql.tree.Rollback in project trino by trinodb.

the class TestRollbackTask method testNoTransactionRollback.

@Test
public void testNoTransactionRollback() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().build();
    QueryStateMachine stateMachine = createQueryStateMachine("ROLLBACK", session, transactionManager);
    assertTrinoExceptionThrownBy(() -> getFutureValue((Future<?>) new RollbackTask(transactionManager).execute(new Rollback(), stateMachine, emptyList(), WarningCollector.NOOP))).hasErrorCode(NOT_IN_TRANSACTION);
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) Rollback(io.trino.sql.tree.Rollback) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 2 with Rollback

use of io.trino.sql.tree.Rollback in project trino by trinodb.

the class TestRollbackTask method testUnknownTransactionRollback.

@Test
public void testUnknownTransactionRollback() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().setTransactionId(// Use a random transaction ID that is unknown to the system
    TransactionId.create()).build();
    QueryStateMachine stateMachine = createQueryStateMachine("ROLLBACK", session, transactionManager);
    getFutureValue(new RollbackTask(transactionManager).execute(new Rollback(), stateMachine, emptyList(), WarningCollector.NOOP));
    // Still issue clear signal
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) Rollback(io.trino.sql.tree.Rollback) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 3 with Rollback

use of io.trino.sql.tree.Rollback in project trino by trinodb.

the class TestRollbackTask method testRollback.

@Test
public void testRollback() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
    QueryStateMachine stateMachine = createQueryStateMachine("ROLLBACK", session, transactionManager);
    assertTrue(stateMachine.getSession().getTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    getFutureValue(new RollbackTask(transactionManager).execute(new Rollback(), stateMachine, emptyList(), WarningCollector.NOOP));
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) Rollback(io.trino.sql.tree.Rollback) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 4 with Rollback

use of io.trino.sql.tree.Rollback in project trino by trinodb.

the class TestSqlParser method testRollback.

@Test
public void testRollback() {
    assertStatement("ROLLBACK", new Rollback());
    assertStatement("ROLLBACK WORK", new Rollback());
}
Also used : Rollback(io.trino.sql.tree.Rollback) Test(org.junit.jupiter.api.Test)

Aggregations

Rollback (io.trino.sql.tree.Rollback)4 Session (io.trino.Session)3 InMemoryTransactionManager.createTestTransactionManager (io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager)3 TransactionManager (io.trino.transaction.TransactionManager)3 Test (org.testng.annotations.Test)3 Test (org.junit.jupiter.api.Test)1