use of io.trino.sql.tree.StartTransaction in project trino by trinodb.
the class TestStartTransactionTask method testStartTransactionIdleExpiration.
@Test
public void testStartTransactionIdleExpiration() throws Exception {
Session session = sessionBuilder().setClientTransactionSupport().build();
TransactionManager transactionManager = InMemoryTransactionManager.create(new TransactionManagerConfig().setIdleTimeout(// Fast idle timeout
new Duration(1, TimeUnit.MICROSECONDS)).setIdleCheckInterval(new Duration(10, TimeUnit.MILLISECONDS)), scheduledExecutor, new CatalogManager(), executor);
QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
assertFalse(stateMachine.getSession().getTransactionId().isPresent());
getFutureValue(new StartTransactionTask(transactionManager).execute(new StartTransaction(ImmutableList.of()), stateMachine, emptyList(), WarningCollector.NOOP));
assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
assertTrue(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
long start = System.nanoTime();
while (!transactionManager.getAllTransactionInfos().isEmpty()) {
if (Duration.nanosSince(start).toMillis() > 10_000) {
fail("Transaction did not expire in the allotted time");
}
TimeUnit.MILLISECONDS.sleep(10);
}
}
use of io.trino.sql.tree.StartTransaction in project trino by trinodb.
the class TestStartTransactionTask method testStartTransactionTooManyIsolationLevels.
@Test
public void testStartTransactionTooManyIsolationLevels() {
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 Isolation(Isolation.Level.READ_COMMITTED), new Isolation(Isolation.Level.READ_COMMITTED))), stateMachine, emptyList(), WarningCollector.NOOP))).hasErrorCode(SYNTAX_ERROR);
assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
}
use of io.trino.sql.tree.StartTransaction 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))));
}
Aggregations