Search in sources :

Example 6 with TransactionManager

use of com.facebook.presto.transaction.TransactionManager in project presto by prestodb.

the class TestStartTransactionTask method testStartTransaction.

@Test
public void testStartTransaction() throws Exception {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "START TRANSACTION", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    getFutureValue(new StartTransactionTask().execute(new StartTransaction(ImmutableList.of()), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
    assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
    assertTrue(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    TransactionInfo transactionInfo = transactionManager.getTransactionInfo(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().get());
    assertFalse(transactionInfo.isAutoCommitContext());
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) TransactionInfo(com.facebook.presto.transaction.TransactionInfo) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) AccessControl(com.facebook.presto.security.AccessControl) StartTransaction(com.facebook.presto.sql.tree.StartTransaction) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 7 with TransactionManager

use of com.facebook.presto.transaction.TransactionManager in project presto by prestodb.

the class TestStartTransactionTask method testStartTransactionTooManyIsolationLevels.

@Test
public void testStartTransactionTooManyIsolationLevels() throws Exception {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "START TRANSACTION", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    try {
        try {
            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()));
            fail();
        } catch (CompletionException e) {
            throw Throwables.propagate(e.getCause());
        }
    } catch (SemanticException e) {
        assertEquals(e.getCode(), INVALID_TRANSACTION_MODE);
    }
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
    assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
    assertFalse(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) CompletionException(java.util.concurrent.CompletionException) Isolation(com.facebook.presto.sql.tree.Isolation) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) AccessControl(com.facebook.presto.security.AccessControl) StartTransaction(com.facebook.presto.sql.tree.StartTransaction) Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException) Test(org.testng.annotations.Test)

Example 8 with TransactionManager

use of com.facebook.presto.transaction.TransactionManager in project presto by prestodb.

the class TestQueryStateMachine method createQueryStateMachineWithTicker.

private QueryStateMachine createQueryStateMachineWithTicker(Ticker ticker) {
    Metadata metadata = MetadataManager.createTestMetadataManager();
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    QueryStateMachine stateMachine = QueryStateMachine.beginWithTicker(QUERY_ID, QUERY, TEST_SESSION, LOCATION, false, transactionManager, accessControl, executor, ticker, metadata);
    stateMachine.setInputs(INPUTS);
    stateMachine.setOutput(OUTPUT);
    stateMachine.setOutputFieldNames(OUTPUT_FIELD_NAMES);
    stateMachine.setUpdateType(UPDATE_TYPE);
    stateMachine.setMemoryPool(MEMORY_POOL);
    for (Entry<String, String> entry : SET_SESSION_PROPERTIES.entrySet()) {
        stateMachine.addSetSessionProperties(entry.getKey(), entry.getValue());
    }
    RESET_SESSION_PROPERTIES.forEach(stateMachine::addResetSessionProperties);
    return stateMachine;
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl)

Example 9 with TransactionManager

use of com.facebook.presto.transaction.TransactionManager in project presto by prestodb.

the class TestRollbackTask method testRollback.

@Test
public void testRollback() throws Exception {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    Session session = sessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "ROLLBACK", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
    assertTrue(stateMachine.getSession().getTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    getFutureValue(new RollbackTask().execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
    assertTrue(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
    assertFalse(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) Rollback(com.facebook.presto.sql.tree.Rollback) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) AccessControl(com.facebook.presto.security.AccessControl) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 10 with TransactionManager

use of com.facebook.presto.transaction.TransactionManager in project presto by prestodb.

the class TestRollbackTask method testNoTransactionRollback.

@Test
public void testNoTransactionRollback() throws Exception {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    Session session = sessionBuilder().build();
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "ROLLBACK", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
    try {
        try {
            getFutureValue(new RollbackTask().execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
            fail();
        } catch (CompletionException e) {
            throw Throwables.propagate(e.getCause());
        }
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), NOT_IN_TRANSACTION.toErrorCode());
    }
    assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
    assertFalse(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) CompletionException(java.util.concurrent.CompletionException) PrestoException(com.facebook.presto.spi.PrestoException) Rollback(com.facebook.presto.sql.tree.Rollback) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) AccessControl(com.facebook.presto.security.AccessControl) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Aggregations

TransactionManager (com.facebook.presto.transaction.TransactionManager)22 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)20 AccessControl (com.facebook.presto.security.AccessControl)18 Test (org.testng.annotations.Test)17 AccessControlManager (com.facebook.presto.security.AccessControlManager)16 Session (com.facebook.presto.Session)15 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)15 QueryId (com.facebook.presto.spi.QueryId)15 StartTransaction (com.facebook.presto.sql.tree.StartTransaction)7 CompletionException (java.util.concurrent.CompletionException)7 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)6 PrestoException (com.facebook.presto.spi.PrestoException)6 Identity (com.facebook.presto.spi.security.Identity)4 ConnectorId (com.facebook.presto.connector.ConnectorId)3 CatalogManager (com.facebook.presto.metadata.CatalogManager)3 Metadata (com.facebook.presto.metadata.Metadata)3 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)3 Commit (com.facebook.presto.sql.tree.Commit)3 ConnectorId.createInformationSchemaConnectorId (com.facebook.presto.connector.ConnectorId.createInformationSchemaConnectorId)2 ConnectorId.createSystemTablesConnectorId (com.facebook.presto.connector.ConnectorId.createSystemTablesConnectorId)2