Search in sources :

Example 1 with StartTransaction

use of com.facebook.presto.sql.tree.StartTransaction in project presto by prestodb.

the class TestStartTransactionTask method testStartTransactionExplicitModes.

@Test
public void testStartTransactionExplicitModes() 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(new Isolation(Isolation.Level.SERIALIZABLE), new TransactionAccessMode(true))), 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());
    assertEquals(transactionInfo.getIsolationLevel(), IsolationLevel.SERIALIZABLE);
    assertTrue(transactionInfo.isReadOnly());
    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) TransactionAccessMode(com.facebook.presto.sql.tree.TransactionAccessMode) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) Isolation(com.facebook.presto.sql.tree.Isolation) 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 2 with StartTransaction

use of com.facebook.presto.sql.tree.StartTransaction in project presto by prestodb.

the class TestStartTransactionTask method testNonTransactionalClient.

@Test
public void testNonTransactionalClient() throws Exception {
    Session session = sessionBuilder().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()), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
            fail();
        } catch (CompletionException e) {
            throw Throwables.propagate(e.getCause());
        }
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), INCOMPATIBLE_CLIENT.toErrorCode());
    }
    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) PrestoException(com.facebook.presto.spi.PrestoException) 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 3 with StartTransaction

use of com.facebook.presto.sql.tree.StartTransaction in project presto by prestodb.

the class TestStartTransactionTask method testNestedTransaction.

@Test
public void testNestedTransaction() throws Exception {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    Session session = sessionBuilder().setTransactionId(TransactionId.create()).setClientTransactionSupport().build();
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "START TRANSACTION", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
    try {
        try {
            getFutureValue(new StartTransactionTask().execute(new StartTransaction(ImmutableList.of()), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
            fail();
        } catch (CompletionException e) {
            throw Throwables.propagate(e.getCause());
        }
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), NOT_SUPPORTED.toErrorCode());
    }
    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) PrestoException(com.facebook.presto.spi.PrestoException) 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 4 with StartTransaction

use of com.facebook.presto.sql.tree.StartTransaction 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 5 with StartTransaction

use of com.facebook.presto.sql.tree.StartTransaction 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)

Aggregations

StartTransaction (com.facebook.presto.sql.tree.StartTransaction)8 Test (org.testng.annotations.Test)8 Session (com.facebook.presto.Session)7 AccessControl (com.facebook.presto.security.AccessControl)7 AccessControlManager (com.facebook.presto.security.AccessControlManager)7 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)7 QueryId (com.facebook.presto.spi.QueryId)7 TransactionManager (com.facebook.presto.transaction.TransactionManager)7 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)7 CompletionException (java.util.concurrent.CompletionException)4 Isolation (com.facebook.presto.sql.tree.Isolation)3 TransactionAccessMode (com.facebook.presto.sql.tree.TransactionAccessMode)3 PrestoException (com.facebook.presto.spi.PrestoException)2 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)2 TransactionInfo (com.facebook.presto.transaction.TransactionInfo)2 CatalogManager (com.facebook.presto.metadata.CatalogManager)1 TransactionManagerConfig (com.facebook.presto.transaction.TransactionManagerConfig)1 Duration (io.airlift.units.Duration)1