Search in sources :

Example 41 with AllowAllAccessControl

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

the class TestStartTransactionTask method testNonTransactionalClient.

@Test
public void testNonTransactionalClient() {
    Session session = sessionBuilder().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, true, transactionManager, executor, metadata);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    StartTransactionTask startTransactionTask = new StartTransactionTask();
    try {
        getFutureValue(startTransactionTask.execute(new StartTransaction(ImmutableList.of()), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
        fail();
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), INCOMPATIBLE_CLIENT.toErrorCode());
    }
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) PrestoException(com.facebook.presto.spi.PrestoException) StartTransaction(com.facebook.presto.sql.tree.StartTransaction) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 42 with AllowAllAccessControl

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

the class TestStartTransactionTask method testStartTransactionTooManyAccessModes.

@Test
public void testStartTransactionTooManyAccessModes() {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, true, transactionManager, executor, metadata);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    try {
        getFutureValue(new StartTransactionTask().execute(new StartTransaction(ImmutableList.of(new TransactionAccessMode(true), new TransactionAccessMode(true))), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
        fail();
    } catch (SemanticException e) {
        assertEquals(e.getCode(), INVALID_TRANSACTION_MODE);
    }
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager) TransactionAccessMode(com.facebook.presto.sql.tree.TransactionAccessMode) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) 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 43 with AllowAllAccessControl

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

the class TestStartTransactionTask method testStartTransaction.

@Test
public void testStartTransaction() {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, true, transactionManager, executor, metadata);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    StartTransactionTask startTransactionTask = new StartTransactionTask();
    getFutureValue(startTransactionTask.execute(new StartTransaction(ImmutableList.of()), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    TransactionInfo transactionInfo = transactionManager.getTransactionInfo(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().get());
    assertFalse(transactionInfo.isAutoCommitContext());
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) TransactionInfo(com.facebook.presto.transaction.TransactionInfo) StartTransaction(com.facebook.presto.sql.tree.StartTransaction) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 44 with AllowAllAccessControl

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

the class TestRollbackTask method testRollback.

@Test
public void testRollback() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
    QueryStateMachine stateMachine = createQueryStateMachine("ROLLBACK", session, true, transactionManager, executor, metadata);
    WarningCollector warningCollector = stateMachine.getWarningCollector();
    RollbackTask rollbackTask = new RollbackTask();
    assertTrue(stateMachine.getSession().getTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    getFutureValue(rollbackTask.execute(new Rollback(), 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) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) WarningCollector(com.facebook.presto.spi.WarningCollector) Rollback(com.facebook.presto.sql.tree.Rollback) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 45 with AllowAllAccessControl

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

the class TestRollbackTask method testUnknownTransactionRollback.

@Test
public void testUnknownTransactionRollback() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().setTransactionId(// Use a random transaction ID that is unknown to the system
    TransactionId.create()).build();
    QueryStateMachine stateMachine = createQueryStateMachine("ROLLBACK", session, true, transactionManager, executor, metadata);
    RollbackTask rollbackTask = new RollbackTask();
    getFutureValue(rollbackTask.execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
    // 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) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) Rollback(com.facebook.presto.sql.tree.Rollback) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

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