Search in sources :

Example 11 with AllowAllAccessControl

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

Example 12 with AllowAllAccessControl

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

the class TestMinimalFunctionality method testTopicExists.

@Test
public void testTopicExists() throws Exception {
    QualifiedObjectName name = new QualifiedObjectName("kafka", "default", topicName);
    transaction(queryRunner.getTransactionManager(), new AllowAllAccessControl()).singleStatement().execute(SESSION, session -> {
        Optional<TableHandle> handle = queryRunner.getServer().getMetadata().getTableHandle(session, name);
        assertTrue(handle.isPresent());
    });
}
Also used : AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) TableHandle(com.facebook.presto.metadata.TableHandle) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 13 with AllowAllAccessControl

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

the class TestMinimalFunctionality method testTableExists.

@Test
public void testTableExists() throws Exception {
    QualifiedObjectName name = new QualifiedObjectName("redis", "default", tableName);
    transaction(queryRunner.getTransactionManager(), new AllowAllAccessControl()).singleStatement().execute(SESSION, session -> {
        Optional<TableHandle> handle = queryRunner.getServer().getMetadata().getTableHandle(session, name);
        assertTrue(handle.isPresent());
    });
}
Also used : AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) TableHandle(com.facebook.presto.metadata.TableHandle) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 14 with AllowAllAccessControl

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

the class TestStartTransactionTask method testStartTransactionIdleExpiration.

@Test
public void testStartTransactionIdleExpiration() throws Exception {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = TransactionManager.create(new TransactionManagerConfig().setIdleTimeout(// Fast idle timeout
    new Duration(1, TimeUnit.MICROSECONDS)).setIdleCheckInterval(new Duration(10, TimeUnit.MILLISECONDS)), scheduledExecutor, new CatalogManager(), executor);
    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());
    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 : AccessControlManager(com.facebook.presto.security.AccessControlManager) QueryId(com.facebook.presto.spi.QueryId) Duration(io.airlift.units.Duration) CatalogManager(com.facebook.presto.metadata.CatalogManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) AccessControl(com.facebook.presto.security.AccessControl) TransactionManagerConfig(com.facebook.presto.transaction.TransactionManagerConfig) TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) StartTransaction(com.facebook.presto.sql.tree.StartTransaction) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 15 with AllowAllAccessControl

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

the class TestStartTransactionTask method testStartTransactionTooManyAccessModes.

@Test
public void testStartTransactionTooManyAccessModes() 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 TransactionAccessMode(true), new TransactionAccessMode(true))), 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) TransactionAccessMode(com.facebook.presto.sql.tree.TransactionAccessMode) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) CompletionException(java.util.concurrent.CompletionException) 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

AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)20 QueryId (com.facebook.presto.spi.QueryId)17 Test (org.testng.annotations.Test)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 Session (com.facebook.presto.Session)14 StartTransaction (com.facebook.presto.sql.tree.StartTransaction)7 CompletionException (java.util.concurrent.CompletionException)7 PrestoException (com.facebook.presto.spi.PrestoException)5 Commit (com.facebook.presto.sql.tree.Commit)3 Rollback (com.facebook.presto.sql.tree.Rollback)3 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)2 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)2 TableHandle (com.facebook.presto.metadata.TableHandle)2 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)2 Isolation (com.facebook.presto.sql.tree.Isolation)2 TransactionAccessMode (com.facebook.presto.sql.tree.TransactionAccessMode)2 TransactionInfo (com.facebook.presto.transaction.TransactionInfo)2