Search in sources :

Example 1 with TransactionManagerConfig

use of io.trino.transaction.TransactionManagerConfig 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);
    }
}
Also used : TransactionManagerConfig(io.trino.transaction.TransactionManagerConfig) TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(io.trino.transaction.InMemoryTransactionManager) Duration(io.airlift.units.Duration) CatalogManager(io.trino.metadata.CatalogManager) StartTransaction(io.trino.sql.tree.StartTransaction) Session(io.trino.Session) Test(org.testng.annotations.Test)

Aggregations

Duration (io.airlift.units.Duration)1 Session (io.trino.Session)1 CatalogManager (io.trino.metadata.CatalogManager)1 StartTransaction (io.trino.sql.tree.StartTransaction)1 InMemoryTransactionManager (io.trino.transaction.InMemoryTransactionManager)1 InMemoryTransactionManager.createTestTransactionManager (io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager)1 TransactionManager (io.trino.transaction.TransactionManager)1 TransactionManagerConfig (io.trino.transaction.TransactionManagerConfig)1 Test (org.testng.annotations.Test)1