Search in sources :

Example 1 with TransactionAccessMode

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

the class TestStartTransactionTask method testStartTransactionTooManyAccessModes.

@Test
public void testStartTransactionTooManyAccessModes() {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    assertTrinoExceptionThrownBy(() -> getFutureValue(new StartTransactionTask(transactionManager).execute(new StartTransaction(ImmutableList.of(new TransactionAccessMode(true), new TransactionAccessMode(true))), stateMachine, emptyList(), WarningCollector.NOOP))).hasErrorCode(SYNTAX_ERROR);
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(io.trino.transaction.InMemoryTransactionManager) TransactionAccessMode(io.trino.sql.tree.TransactionAccessMode) StartTransaction(io.trino.sql.tree.StartTransaction) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 2 with TransactionAccessMode

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

the class TestStartTransactionTask method testStartTransactionExplicitModes.

@Test
public void testStartTransactionExplicitModes() {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    getFutureValue(new StartTransactionTask(transactionManager).execute(new StartTransaction(ImmutableList.of(new Isolation(Isolation.Level.SERIALIZABLE), new TransactionAccessMode(true))), stateMachine, emptyList(), WarningCollector.NOOP));
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    TransactionInfo transactionInfo = transactionManager.getTransactionInfo(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().get());
    assertEquals(transactionInfo.getIsolationLevel(), IsolationLevel.SERIALIZABLE);
    assertTrue(transactionInfo.isReadOnly());
    assertFalse(transactionInfo.isAutoCommitContext());
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(io.trino.transaction.InMemoryTransactionManager) TransactionAccessMode(io.trino.sql.tree.TransactionAccessMode) Isolation(io.trino.sql.tree.Isolation) TransactionInfo(io.trino.transaction.TransactionInfo) StartTransaction(io.trino.sql.tree.StartTransaction) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 3 with TransactionAccessMode

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

the class TestSqlParser method testStartTransaction.

@Test
public void testStartTransaction() {
    assertStatement("START TRANSACTION", new StartTransaction(ImmutableList.of()));
    assertStatement("START TRANSACTION ISOLATION LEVEL READ UNCOMMITTED", new StartTransaction(ImmutableList.of(new Isolation(Isolation.Level.READ_UNCOMMITTED))));
    assertStatement("START TRANSACTION ISOLATION LEVEL READ COMMITTED", new StartTransaction(ImmutableList.of(new Isolation(Isolation.Level.READ_COMMITTED))));
    assertStatement("START TRANSACTION ISOLATION LEVEL REPEATABLE READ", new StartTransaction(ImmutableList.of(new Isolation(Isolation.Level.REPEATABLE_READ))));
    assertStatement("START TRANSACTION ISOLATION LEVEL SERIALIZABLE", new StartTransaction(ImmutableList.of(new Isolation(Isolation.Level.SERIALIZABLE))));
    assertStatement("START TRANSACTION READ ONLY", new StartTransaction(ImmutableList.of(new TransactionAccessMode(true))));
    assertStatement("START TRANSACTION READ WRITE", new StartTransaction(ImmutableList.of(new TransactionAccessMode(false))));
    assertStatement("START TRANSACTION ISOLATION LEVEL READ COMMITTED, READ ONLY", new StartTransaction(ImmutableList.of(new Isolation(Isolation.Level.READ_COMMITTED), new TransactionAccessMode(true))));
    assertStatement("START TRANSACTION READ ONLY, ISOLATION LEVEL READ COMMITTED", new StartTransaction(ImmutableList.of(new TransactionAccessMode(true), new Isolation(Isolation.Level.READ_COMMITTED))));
    assertStatement("START TRANSACTION READ WRITE, ISOLATION LEVEL SERIALIZABLE", new StartTransaction(ImmutableList.of(new TransactionAccessMode(false), new Isolation(Isolation.Level.SERIALIZABLE))));
}
Also used : TransactionAccessMode(io.trino.sql.tree.TransactionAccessMode) Isolation(io.trino.sql.tree.Isolation) StartTransaction(io.trino.sql.tree.StartTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

StartTransaction (io.trino.sql.tree.StartTransaction)3 TransactionAccessMode (io.trino.sql.tree.TransactionAccessMode)3 Session (io.trino.Session)2 Isolation (io.trino.sql.tree.Isolation)2 InMemoryTransactionManager (io.trino.transaction.InMemoryTransactionManager)2 InMemoryTransactionManager.createTestTransactionManager (io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager)2 TransactionManager (io.trino.transaction.TransactionManager)2 Test (org.testng.annotations.Test)2 TransactionInfo (io.trino.transaction.TransactionInfo)1 Test (org.junit.jupiter.api.Test)1