Search in sources :

Example 46 with AllowAllAccessControl

use of com.facebook.presto.security.AllowAllAccessControl in project urban-eureka by errir503.

the class TestCommitTask method testUnknownTransactionCommit.

@Test
public void testUnknownTransactionCommit() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().setTransactionId(// Use a random transaction ID that is unknown to the system
    TransactionId.create()).build();
    QueryStateMachine stateMachine = createQueryStateMachine("COMMIT", session, true, transactionManager, executor, metadata);
    try {
        CommitTask commitTask = new CommitTask();
        getFutureValue(commitTask.execute(new Commit(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
        fail();
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), UNKNOWN_TRANSACTION.toErrorCode());
    }
    // Still issue clear signal
    assertTrue(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) Commit(com.facebook.presto.sql.tree.Commit) 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) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 47 with AllowAllAccessControl

use of com.facebook.presto.security.AllowAllAccessControl in project urban-eureka by errir503.

the class TestCommitTask method testNoTransactionCommit.

@Test
public void testNoTransactionCommit() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().build();
    QueryStateMachine stateMachine = createQueryStateMachine("COMMIT", session, true, transactionManager, executor, metadata);
    try {
        CommitTask commitTask = new CommitTask();
        getFutureValue(commitTask.execute(new Commit(), 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) Commit(com.facebook.presto.sql.tree.Commit) 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) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 48 with AllowAllAccessControl

use of com.facebook.presto.security.AllowAllAccessControl in project urban-eureka by errir503.

the class TestCommitTask method testCommit.

@Test
public void testCommit() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
    QueryStateMachine stateMachine = createQueryStateMachine("COMMIT", session, true, transactionManager, executor, metadata);
    assertTrue(stateMachine.getSession().getTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    CommitTask commitTask = new CommitTask();
    getFutureValue(commitTask.execute(new Commit(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
    assertTrue(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) Commit(com.facebook.presto.sql.tree.Commit) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 49 with AllowAllAccessControl

use of com.facebook.presto.security.AllowAllAccessControl in project urban-eureka by errir503.

the class TestCreateTableTask method testCreateTableNotExistsFalse.

@Test
public void testCreateTableNotExistsFalse() {
    CreateTable statement = new CreateTable(QualifiedName.of("test_table"), ImmutableList.of(new ColumnDefinition(identifier("a"), "BIGINT", true, emptyList(), Optional.empty())), false, ImmutableList.of(), Optional.empty());
    try {
        getFutureValue(new CreateTableTask().internalExecute(statement, metadata, new AllowAllAccessControl(), testSession, emptyList()));
        fail("expected exception");
    } catch (RuntimeException e) {
        // Expected
        assertTrue(e instanceof PrestoException);
        PrestoException prestoException = (PrestoException) e;
        assertEquals(prestoException.getErrorCode(), ALREADY_EXISTS.toErrorCode());
    }
    assertEquals(metadata.getCreateTableCallCount(), 1);
}
Also used : AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) CreateTable(com.facebook.presto.sql.tree.CreateTable) PrestoException(com.facebook.presto.spi.PrestoException) ColumnDefinition(com.facebook.presto.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Example 50 with AllowAllAccessControl

use of com.facebook.presto.security.AllowAllAccessControl in project urban-eureka by errir503.

the class TestDeallocateTask method executeDeallocate.

private Set<String> executeDeallocate(String statementName, String sqlString, Session session) {
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine(sqlString, session, false, transactionManager, executor, metadata);
    Deallocate deallocate = new Deallocate(new Identifier(statementName));
    DeallocateTask deallocateTask = new DeallocateTask();
    deallocateTask.execute(deallocate, transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList());
    return stateMachine.getDeallocatedPreparedStatements();
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) Identifier(com.facebook.presto.sql.tree.Identifier) Deallocate(com.facebook.presto.sql.tree.Deallocate) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl)

Aggregations

AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)64 Test (org.testng.annotations.Test)48 TaskTestUtils.createQueryStateMachine (com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine)36 InMemoryTransactionManager.createTestTransactionManager (com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager)36 TransactionManager (com.facebook.presto.transaction.TransactionManager)36 Session (com.facebook.presto.Session)33 StartTransaction (com.facebook.presto.sql.tree.StartTransaction)14 InMemoryTransactionManager (com.facebook.presto.transaction.InMemoryTransactionManager)14 PrestoException (com.facebook.presto.spi.PrestoException)12 SqlParser (com.facebook.presto.sql.parser.SqlParser)10 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)8 TableHandle (com.facebook.presto.spi.TableHandle)8 WarningCollector (com.facebook.presto.spi.WarningCollector)8 ColumnDefinition (com.facebook.presto.sql.tree.ColumnDefinition)8 CreateTable (com.facebook.presto.sql.tree.CreateTable)8 CatalogManager (com.facebook.presto.metadata.CatalogManager)6 Identifier (com.facebook.presto.sql.tree.Identifier)6 Rollback (com.facebook.presto.sql.tree.Rollback)6 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)5 QueryId (com.facebook.presto.spi.QueryId)5