Search in sources :

Example 6 with CatalogManager

use of com.facebook.presto.metadata.CatalogManager in project presto by prestodb.

the class TestTransactionManager method testFailedTransactionWorkflow.

@Test
public void testFailedTransactionWorkflow() {
    try (IdleCheckExecutor executor = new IdleCheckExecutor()) {
        CatalogManager catalogManager = new CatalogManager();
        TransactionManager transactionManager = InMemoryTransactionManager.create(new TransactionManagerConfig(), executor.getExecutor(), catalogManager, finishingExecutor);
        Connector c1 = new TpchConnectorFactory().create(CATALOG_NAME, ImmutableMap.of(), new TestingConnectorContext());
        registerConnector(catalogManager, transactionManager, CATALOG_NAME, CONNECTOR_ID, c1);
        TransactionId transactionId = transactionManager.beginTransaction(false);
        assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
        TransactionInfo transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertFalse(transactionInfo.isAutoCommitContext());
        assertTrue(transactionInfo.getConnectorIds().isEmpty());
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        ConnectorMetadata metadata = transactionManager.getOptionalCatalogMetadata(transactionId, CATALOG_NAME).get().getMetadata();
        metadata.listSchemaNames(TEST_SESSION.toConnectorSession(CONNECTOR_ID));
        transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertEquals(transactionInfo.getConnectorIds(), ImmutableList.of(CONNECTOR_ID, INFORMATION_SCHEMA_ID, SYSTEM_TABLES_ID));
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        transactionManager.fail(transactionId);
        assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
        try {
            transactionManager.getCatalogMetadata(transactionId, CONNECTOR_ID);
            fail();
        } catch (PrestoException e) {
            assertEquals(e.getErrorCode(), TRANSACTION_ALREADY_ABORTED.toErrorCode());
        }
        assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
        getFutureValue(transactionManager.asyncAbort(transactionId));
        assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
    }
}
Also used : InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) Connector(com.facebook.presto.spi.connector.Connector) SystemConnector(com.facebook.presto.connector.system.SystemConnector) TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) TestingConnectorContext(com.facebook.presto.testing.TestingConnectorContext) PrestoException(com.facebook.presto.spi.PrestoException) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) CatalogManager(com.facebook.presto.metadata.CatalogManager) Test(org.testng.annotations.Test)

Example 7 with CatalogManager

use of com.facebook.presto.metadata.CatalogManager in project presto by prestodb.

the class TestTransactionManager method testExpiration.

@Test
public void testExpiration() throws Exception {
    try (IdleCheckExecutor executor = new IdleCheckExecutor()) {
        InMemoryTransactionManager inMemoryTransactionManager = (InMemoryTransactionManager) InMemoryTransactionManager.create(new TransactionManagerConfig().setIdleTimeout(new Duration(1, TimeUnit.MILLISECONDS)).setIdleCheckInterval(new Duration(5, TimeUnit.MILLISECONDS)), executor.getExecutor(), new CatalogManager(), finishingExecutor);
        TransactionId transactionId = inMemoryTransactionManager.beginTransaction(false);
        assertEquals(inMemoryTransactionManager.getAllTransactionInfos().size(), 1);
        TransactionInfo transactionInfo = inMemoryTransactionManager.getTransactionInfo(transactionId);
        assertFalse(transactionInfo.isAutoCommitContext());
        assertTrue(transactionInfo.getConnectorIds().isEmpty());
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        inMemoryTransactionManager.trySetInactive(transactionId);
        TimeUnit.MILLISECONDS.sleep(100);
        // make sure it is cleaned up
        inMemoryTransactionManager.cleanUpExpiredTransactions();
        assertTrue(inMemoryTransactionManager.getAllTransactionInfos().isEmpty());
    }
}
Also used : Duration(io.airlift.units.Duration) CatalogManager(com.facebook.presto.metadata.CatalogManager) Test(org.testng.annotations.Test)

Example 8 with CatalogManager

use of com.facebook.presto.metadata.CatalogManager in project presto by prestodb.

the class TestTransactionManager method testAbortedTransactionWorkflow.

@Test
public void testAbortedTransactionWorkflow() {
    try (IdleCheckExecutor executor = new IdleCheckExecutor()) {
        CatalogManager catalogManager = new CatalogManager();
        TransactionManager transactionManager = InMemoryTransactionManager.create(new TransactionManagerConfig(), executor.getExecutor(), catalogManager, finishingExecutor);
        Connector c1 = new TpchConnectorFactory().create(CATALOG_NAME, ImmutableMap.of(), new TestingConnectorContext());
        registerConnector(catalogManager, transactionManager, CATALOG_NAME, CONNECTOR_ID, c1);
        TransactionId transactionId = transactionManager.beginTransaction(false);
        assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
        TransactionInfo transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertFalse(transactionInfo.isAutoCommitContext());
        assertTrue(transactionInfo.getConnectorIds().isEmpty());
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        ConnectorMetadata metadata = transactionManager.getOptionalCatalogMetadata(transactionId, CATALOG_NAME).get().getMetadata();
        metadata.listSchemaNames(TEST_SESSION.toConnectorSession(CONNECTOR_ID));
        transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertEquals(transactionInfo.getConnectorIds(), ImmutableList.of(CONNECTOR_ID, INFORMATION_SCHEMA_ID, SYSTEM_TABLES_ID));
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        getFutureValue(transactionManager.asyncAbort(transactionId));
        assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
    }
}
Also used : InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) Connector(com.facebook.presto.spi.connector.Connector) SystemConnector(com.facebook.presto.connector.system.SystemConnector) TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) TestingConnectorContext(com.facebook.presto.testing.TestingConnectorContext) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) CatalogManager(com.facebook.presto.metadata.CatalogManager) Test(org.testng.annotations.Test)

Example 9 with CatalogManager

use of com.facebook.presto.metadata.CatalogManager in project presto by prestodb.

the class TestCreateMaterializedViewTask method setUp.

@BeforeMethod
public void setUp() {
    CatalogManager catalogManager = new CatalogManager();
    Catalog testCatalog = createBogusTestingCatalog(CATALOG_NAME);
    catalogManager.registerCatalog(testCatalog);
    TablePropertyManager tablePropertyManager = new TablePropertyManager();
    tablePropertyManager.addProperties(testCatalog.getConnectorId(), ImmutableList.of(stringProperty("baz", "test property", null, false)));
    ColumnPropertyManager columnPropertyManager = new ColumnPropertyManager();
    columnPropertyManager.addProperties(testCatalog.getConnectorId(), ImmutableList.of());
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    transactionManager = createTestTransactionManager(catalogManager);
    testSession = testSessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
    accessControl = new AllowAllAccessControl();
    executorService = newCachedThreadPool(daemonThreadsNamed("test-%s"));
    metadata = new MockMetadata(functionAndTypeManager, tablePropertyManager, columnPropertyManager, testCatalog.getConnectorId());
}
Also used : ColumnPropertyManager(com.facebook.presto.metadata.ColumnPropertyManager) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) AbstractMockMetadata(com.facebook.presto.metadata.AbstractMockMetadata) TablePropertyManager(com.facebook.presto.metadata.TablePropertyManager) CatalogManager(com.facebook.presto.metadata.CatalogManager) Catalog(com.facebook.presto.metadata.Catalog) TestingSession.createBogusTestingCatalog(com.facebook.presto.testing.TestingSession.createBogusTestingCatalog) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 10 with CatalogManager

use of com.facebook.presto.metadata.CatalogManager in project presto by prestodb.

the class TestCreateTableTask method setUp.

@BeforeMethod
public void setUp() {
    catalogManager = new CatalogManager();
    functionAndTypeManager = createTestFunctionAndTypeManager();
    transactionManager = createTestTransactionManager(catalogManager);
    tablePropertyManager = new TablePropertyManager();
    columnPropertyManager = new ColumnPropertyManager();
    testCatalog = createBogusTestingCatalog(CATALOG_NAME);
    catalogManager.registerCatalog(testCatalog);
    tablePropertyManager.addProperties(testCatalog.getConnectorId(), ImmutableList.of(stringProperty("baz", "test property", null, false)));
    columnPropertyManager.addProperties(testCatalog.getConnectorId(), ImmutableList.of());
    testSession = testSessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
    metadata = new MockMetadata(functionAndTypeManager, tablePropertyManager, columnPropertyManager, testCatalog.getConnectorId(), emptySet());
}
Also used : ColumnPropertyManager(com.facebook.presto.metadata.ColumnPropertyManager) AbstractMockMetadata(com.facebook.presto.metadata.AbstractMockMetadata) TablePropertyManager(com.facebook.presto.metadata.TablePropertyManager) CatalogManager(com.facebook.presto.metadata.CatalogManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

CatalogManager (com.facebook.presto.metadata.CatalogManager)13 Test (org.testng.annotations.Test)7 InformationSchemaConnector (com.facebook.presto.connector.informationSchema.InformationSchemaConnector)3 SystemConnector (com.facebook.presto.connector.system.SystemConnector)3 TablePropertyManager (com.facebook.presto.metadata.TablePropertyManager)3 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)3 Connector (com.facebook.presto.spi.connector.Connector)3 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)3 TestingConnectorContext (com.facebook.presto.testing.TestingConnectorContext)3 TpchConnectorFactory (com.facebook.presto.tpch.TpchConnectorFactory)3 BeforeClass (org.testng.annotations.BeforeClass)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)2 AbstractMockMetadata (com.facebook.presto.metadata.AbstractMockMetadata)2 Catalog (com.facebook.presto.metadata.Catalog)2 ColumnPropertyManager (com.facebook.presto.metadata.ColumnPropertyManager)2 ViewDefinition (com.facebook.presto.metadata.ViewDefinition)2 AccessControlManager (com.facebook.presto.security.AccessControlManager)2 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)2 ConnectorId (com.facebook.presto.spi.ConnectorId)2