Search in sources :

Example 1 with AllowAllAccessControl

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

the class TestHttpRequestSessionFactory method testInvalidTimeZone.

@Test(expectedExceptions = PrestoException.class)
public void testInvalidTimeZone() throws Exception {
    HttpServletRequest request = new MockHttpServletRequest(ImmutableListMultimap.<String, String>builder().put(PRESTO_USER, "testUser").put(PRESTO_TIME_ZONE, "unknown_timezone").build(), "testRemote");
    HttpRequestSessionFactory sessionFactory = new HttpRequestSessionFactory(request);
    sessionFactory.createSession(new QueryId("test_query_id"), createTestTransactionManager(), new AllowAllAccessControl(), new SessionPropertyManager());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) Test(org.testng.annotations.Test)

Example 2 with AllowAllAccessControl

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

the class TestHttpRequestSessionFactory method testCreateSession.

@Test
public void testCreateSession() throws Exception {
    HttpServletRequest request = new MockHttpServletRequest(ImmutableListMultimap.<String, String>builder().put(PRESTO_USER, "testUser").put(PRESTO_SOURCE, "testSource").put(PRESTO_CATALOG, "testCatalog").put(PRESTO_SCHEMA, "testSchema").put(PRESTO_LANGUAGE, "zh-TW").put(PRESTO_TIME_ZONE, "Asia/Taipei").put(PRESTO_CLIENT_INFO, "client-info").put(PRESTO_SESSION, QUERY_MAX_MEMORY + "=1GB").put(PRESTO_SESSION, DISTRIBUTED_JOIN + "=true," + HASH_PARTITION_COUNT + " = 43").put(PRESTO_PREPARED_STATEMENT, "query1=select * from foo,query2=select * from bar").build(), "testRemote");
    HttpRequestSessionFactory sessionFactory = new HttpRequestSessionFactory(request);
    Session session = sessionFactory.createSession(new QueryId("test_query_id"), createTestTransactionManager(), new AllowAllAccessControl(), new SessionPropertyManager());
    assertEquals(session.getQueryId(), new QueryId("test_query_id"));
    assertEquals(session.getUser(), "testUser");
    assertEquals(session.getSource().get(), "testSource");
    assertEquals(session.getCatalog().get(), "testCatalog");
    assertEquals(session.getSchema().get(), "testSchema");
    assertEquals(session.getLocale(), Locale.TAIWAN);
    assertEquals(session.getTimeZoneKey(), getTimeZoneKey("Asia/Taipei"));
    assertEquals(session.getRemoteUserAddress().get(), "testRemote");
    assertEquals(session.getClientInfo().get(), "client-info");
    assertEquals(session.getSystemProperties(), ImmutableMap.<String, String>builder().put(QUERY_MAX_MEMORY, "1GB").put(DISTRIBUTED_JOIN, "true").put(HASH_PARTITION_COUNT, "43").build());
    assertEquals(session.getPreparedStatements(), ImmutableMap.<String, String>builder().put("query1", "select * from foo").put("query2", "select * from bar").build());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 3 with AllowAllAccessControl

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

the class TestMinimalFunctionality method testTableExists.

@Test
public void testTableExists() {
    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.spi.TableHandle) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 4 with AllowAllAccessControl

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

the class TestMinimalFunctionality method testTopicExists.

@Test
public void testTopicExists() {
    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.spi.TableHandle) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 5 with AllowAllAccessControl

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

the class TestRollbackTask method testNoTransactionRollback.

@Test
public void testNoTransactionRollback() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().build();
    QueryStateMachine stateMachine = createQueryStateMachine("ROLLBACK", session, true, transactionManager, executor, metadata);
    RollbackTask rollbackTask = new RollbackTask();
    try {
        getFutureValue(rollbackTask.execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
        fail();
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), NOT_IN_TRANSACTION.toErrorCode());
    }
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) PrestoException(com.facebook.presto.spi.PrestoException) Rollback(com.facebook.presto.sql.tree.Rollback) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Aggregations

AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)32 Test (org.testng.annotations.Test)25 TaskTestUtils.createQueryStateMachine (com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine)18 InMemoryTransactionManager.createTestTransactionManager (com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager)18 TransactionManager (com.facebook.presto.transaction.TransactionManager)18 Session (com.facebook.presto.Session)16 StartTransaction (com.facebook.presto.sql.tree.StartTransaction)7 InMemoryTransactionManager (com.facebook.presto.transaction.InMemoryTransactionManager)7 PrestoException (com.facebook.presto.spi.PrestoException)6 SqlParser (com.facebook.presto.sql.parser.SqlParser)5 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)4 QueryId (com.facebook.presto.spi.QueryId)4 WarningCollector (com.facebook.presto.spi.WarningCollector)4 ColumnDefinition (com.facebook.presto.sql.tree.ColumnDefinition)4 CreateTable (com.facebook.presto.sql.tree.CreateTable)4 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)3 CatalogManager (com.facebook.presto.metadata.CatalogManager)3 TableHandle (com.facebook.presto.spi.TableHandle)3 Commit (com.facebook.presto.sql.tree.Commit)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3