Search in sources :

Example 16 with QueryId

use of com.facebook.presto.spi.QueryId 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 17 with QueryId

use of com.facebook.presto.spi.QueryId 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 18 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestResetSessionTask method test.

@Test
public void test() throws Exception {
    Session session = testSessionBuilder(metadata.getSessionPropertyManager()).setSystemProperty("foo", "bar").setCatalogSessionProperty(CATALOG_NAME, "baz", "blah").build();
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "reset foo", session, URI.create("fake://uri"), false, transactionManager, accessControl, executor, metadata);
    getFutureValue(new ResetSessionTask().execute(new ResetSession(QualifiedName.of(CATALOG_NAME, "baz")), transactionManager, metadata, accessControl, stateMachine, emptyList()));
    Set<String> sessionProperties = stateMachine.getResetSessionProperties();
    assertEquals(sessionProperties, ImmutableSet.of("catalog.baz"));
}
Also used : QueryId(com.facebook.presto.spi.QueryId) ResetSession(com.facebook.presto.sql.tree.ResetSession) ResetSession(com.facebook.presto.sql.tree.ResetSession) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 19 with QueryId

use of com.facebook.presto.spi.QueryId 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 20 with QueryId

use of com.facebook.presto.spi.QueryId 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

QueryId (com.facebook.presto.spi.QueryId)42 Test (org.testng.annotations.Test)26 Session (com.facebook.presto.Session)20 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)17 AccessControl (com.facebook.presto.security.AccessControl)15 AccessControlManager (com.facebook.presto.security.AccessControlManager)15 TransactionManager (com.facebook.presto.transaction.TransactionManager)15 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)15 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)10 StartTransaction (com.facebook.presto.sql.tree.StartTransaction)7 CompletionException (java.util.concurrent.CompletionException)7 PrestoException (com.facebook.presto.spi.PrestoException)6 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 DataSize (io.airlift.units.DataSize)5 QueryInfo (com.facebook.presto.execution.QueryInfo)4 MemoryPool (com.facebook.presto.memory.MemoryPool)4 QueryContext (com.facebook.presto.memory.QueryContext)4 ResourceGroupManagerPlugin (com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin)4 H2ResourceGroupsDao (com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao)4