Search in sources :

Example 1 with AccessControl

use of com.facebook.presto.security.AccessControl in project presto by prestodb.

the class TestCommitTask method testNoTransactionCommit.

@Test
public void testNoTransactionCommit() throws Exception {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    Session session = sessionBuilder().build();
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "COMMIT", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
    try {
        try {
            getFutureValue(new CommitTask().execute(new Commit(), 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) Commit(com.facebook.presto.sql.tree.Commit) 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) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 2 with AccessControl

use of com.facebook.presto.security.AccessControl in project presto by prestodb.

the class TestDeallocateTask method executeDeallocate.

private Set<String> executeDeallocate(String statementName, String sqlString, Session session) {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), sqlString, session, URI.create("fake://uri"), false, transactionManager, accessControl, executor, metadata);
    Deallocate deallocate = new Deallocate(statementName);
    new DeallocateTask().execute(deallocate, transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList());
    return stateMachine.getDeallocatedPreparedStatements();
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) Deallocate(com.facebook.presto.sql.tree.Deallocate) 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) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) AccessControl(com.facebook.presto.security.AccessControl)

Example 3 with AccessControl

use of com.facebook.presto.security.AccessControl 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 4 with AccessControl

use of com.facebook.presto.security.AccessControl 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 5 with AccessControl

use of com.facebook.presto.security.AccessControl 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)

Aggregations

AccessControl (com.facebook.presto.security.AccessControl)19 TransactionManager (com.facebook.presto.transaction.TransactionManager)19 AccessControlManager (com.facebook.presto.security.AccessControlManager)17 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)17 Session (com.facebook.presto.Session)16 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)16 QueryId (com.facebook.presto.spi.QueryId)15 Test (org.testng.annotations.Test)14 StartTransaction (com.facebook.presto.sql.tree.StartTransaction)7 CompletionException (java.util.concurrent.CompletionException)7 PrestoException (com.facebook.presto.spi.PrestoException)6 Metadata (com.facebook.presto.metadata.Metadata)4 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)3 ConnectorId (com.facebook.presto.connector.ConnectorId)2 CatalogManager (com.facebook.presto.metadata.CatalogManager)2 MetadataUtil.createQualifiedObjectName (com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName)2 ViewDefinition (com.facebook.presto.metadata.ViewDefinition)2 ViewColumn (com.facebook.presto.metadata.ViewDefinition.ViewColumn)2 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)2 SqlParser (com.facebook.presto.sql.parser.SqlParser)2