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());
}
}
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());
}
}
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());
}
}
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());
}
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());
}
Aggregations