use of io.prestosql.sql.tree.StartTransaction in project hetu-core by openlookeng.
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());
assertSemanticExceptionThrownBy(() -> getFutureValue(new StartTransactionTask().execute(new StartTransaction(ImmutableList.of(new Isolation(Isolation.Level.READ_COMMITTED), new Isolation(Isolation.Level.READ_COMMITTED))), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList(), new HeuristicIndexerManager(new FileSystemClientManager(), new HetuMetaStoreManager())))).hasErrorCode(INVALID_TRANSACTION_MODE);
assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
}
use of io.prestosql.sql.tree.StartTransaction in project hetu-core by openlookeng.
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))));
}
use of io.prestosql.sql.tree.StartTransaction in project hetu-core by openlookeng.
the class TestStartTransactionTask method testStartTransaction.
@Test
public void testStartTransaction() {
Session session = sessionBuilder().setClientTransactionSupport().build();
TransactionManager transactionManager = createTestTransactionManager();
QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
assertFalse(stateMachine.getSession().getTransactionId().isPresent());
getFutureValue(new StartTransactionTask().execute(new StartTransaction(ImmutableList.of()), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList(), new HeuristicIndexerManager(new FileSystemClientManager(), new HetuMetaStoreManager())));
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());
assertFalse(transactionInfo.isAutoCommitContext());
}
use of io.prestosql.sql.tree.StartTransaction in project hetu-core by openlookeng.
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().execute(new StartTransaction(ImmutableList.of(new Isolation(Isolation.Level.SERIALIZABLE), new TransactionAccessMode(true))), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList(), new HeuristicIndexerManager(new FileSystemClientManager(), new HetuMetaStoreManager())));
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());
}
use of io.prestosql.sql.tree.StartTransaction in project hetu-core by openlookeng.
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().execute(new StartTransaction(ImmutableList.of()), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList(), new HeuristicIndexerManager(new FileSystemClientManager(), new HetuMetaStoreManager())));
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);
}
}
Aggregations