Search in sources :

Example 1 with TestingConnectorContext

use of com.facebook.presto.testing.TestingConnectorContext in project presto by prestodb.

the class TestTransactionManager method testTransactionWorkflow.

@Test
public void testTransactionWorkflow() throws Exception {
    try (IdleCheckExecutor executor = new IdleCheckExecutor()) {
        CatalogManager catalogManager = new CatalogManager();
        TransactionManager transactionManager = TransactionManager.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.asyncCommit(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 2 with TestingConnectorContext

use of com.facebook.presto.testing.TestingConnectorContext in project presto by prestodb.

the class TestMySqlPlugin method testCreateConnector.

@Test
public void testCreateConnector() throws Exception {
    Plugin plugin = new MySqlPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    factory.create("test", ImmutableMap.of("connection-url", "test"), new TestingConnectorContext());
}
Also used : ConnectorFactory(com.facebook.presto.spi.connector.ConnectorFactory) TestingConnectorContext(com.facebook.presto.testing.TestingConnectorContext) Plugin(com.facebook.presto.spi.Plugin) Test(org.testng.annotations.Test)

Example 3 with TestingConnectorContext

use of com.facebook.presto.testing.TestingConnectorContext in project presto by prestodb.

the class TestRedisPlugin method testStartup.

@Test
public void testStartup() {
    RedisPlugin plugin = new RedisPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    assertInstanceOf(factory, RedisConnectorFactory.class);
    Connector c = factory.create("test-connector", ImmutableMap.<String, String>builder().put("redis.table-names", "test").put("redis.nodes", "localhost:6379").build(), new TestingConnectorContext());
    assertNotNull(c);
}
Also used : Connector(com.facebook.presto.spi.connector.Connector) ConnectorFactory(com.facebook.presto.spi.connector.ConnectorFactory) TestingConnectorContext(com.facebook.presto.testing.TestingConnectorContext) Test(org.testng.annotations.Test)

Example 4 with TestingConnectorContext

use of com.facebook.presto.testing.TestingConnectorContext in project presto by prestodb.

the class TestAccessControlManager method registerBogusConnector.

private static ConnectorId registerBogusConnector(CatalogManager catalogManager, TransactionManager transactionManager, AccessControl accessControl, String catalogName) {
    ConnectorId connectorId = new ConnectorId(catalogName);
    Connector connector = new TpchConnectorFactory().create(catalogName, ImmutableMap.of(), new TestingConnectorContext());
    InMemoryNodeManager nodeManager = new InMemoryNodeManager();
    MetadataManager metadata = MetadataManager.createTestMetadataManager(catalogManager);
    ConnectorId systemId = createSystemTablesConnectorId(connectorId);
    catalogManager.registerCatalog(new Catalog(catalogName, connectorId, connector, createInformationSchemaConnectorId(connectorId), new InformationSchemaConnector(catalogName, nodeManager, metadata, accessControl), systemId, new SystemConnector(systemId, nodeManager, connector.getSystemTables(), transactionId -> transactionManager.getConnectorTransaction(transactionId, connectorId))));
    return connectorId;
}
Also used : SystemConnector(com.facebook.presto.connector.system.SystemConnector) 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) InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) MetadataManager(com.facebook.presto.metadata.MetadataManager) TestingConnectorContext(com.facebook.presto.testing.TestingConnectorContext) Catalog(com.facebook.presto.metadata.Catalog) ConnectorId.createInformationSchemaConnectorId(com.facebook.presto.connector.ConnectorId.createInformationSchemaConnectorId) ConnectorId.createSystemTablesConnectorId(com.facebook.presto.connector.ConnectorId.createSystemTablesConnectorId) ConnectorId(com.facebook.presto.connector.ConnectorId) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager)

Example 5 with TestingConnectorContext

use of com.facebook.presto.testing.TestingConnectorContext in project presto by prestodb.

the class TestMongoPlugin method testCreateConnector.

@Test
public void testCreateConnector() throws Exception {
    MongoPlugin plugin = new MongoPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    Connector connector = factory.create("test", ImmutableMap.of("mongodb.seeds", seed), new TestingConnectorContext());
    Type type = getOnlyElement(plugin.getTypes());
    assertEquals(type, OBJECT_ID);
    connector.shutdown();
}
Also used : Connector(com.facebook.presto.spi.connector.Connector) Type(com.facebook.presto.spi.type.Type) ConnectorFactory(com.facebook.presto.spi.connector.ConnectorFactory) TestingConnectorContext(com.facebook.presto.testing.TestingConnectorContext) Test(org.testng.annotations.Test)

Aggregations

TestingConnectorContext (com.facebook.presto.testing.TestingConnectorContext)13 Test (org.testng.annotations.Test)10 Connector (com.facebook.presto.spi.connector.Connector)9 ConnectorFactory (com.facebook.presto.spi.connector.ConnectorFactory)6 InformationSchemaConnector (com.facebook.presto.connector.informationSchema.InformationSchemaConnector)4 SystemConnector (com.facebook.presto.connector.system.SystemConnector)4 TpchConnectorFactory (com.facebook.presto.tpch.TpchConnectorFactory)4 CatalogManager (com.facebook.presto.metadata.CatalogManager)3 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)3 Plugin (com.facebook.presto.spi.Plugin)2 ConnectorId (com.facebook.presto.connector.ConnectorId)1 ConnectorId.createInformationSchemaConnectorId (com.facebook.presto.connector.ConnectorId.createInformationSchemaConnectorId)1 ConnectorId.createSystemTablesConnectorId (com.facebook.presto.connector.ConnectorId.createSystemTablesConnectorId)1 Catalog (com.facebook.presto.metadata.Catalog)1 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)1 MetadataManager (com.facebook.presto.metadata.MetadataManager)1 PrestoException (com.facebook.presto.spi.PrestoException)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)1 Type (com.facebook.presto.spi.type.Type)1