Source:
public void testCreateTableDoesNotThrowAlreadyExistsExceptionWhenIfExists() throws Exception { CatalogManager catalogManager = new CatalogManager(); TypeManager typeManager = new TypeRegistry(); TransactionManager transactionManager = createTestTransactionManager(catalogManager); Catalog bogusTestingCatalog = createBogusTestingCatalog(CATALOG_NAME); AtomicReference<Boolean> metadataCreateTableCalled = new AtomicReference<>(Boolean.FALSE); MetadataManager metadata = new MetadataManager( new FeaturesConfig(), typeManager, new BlockEncodingManager(typeManager), new SessionPropertyManager(), new SchemaPropertyManager(), new TablePropertyManager(), transactionManager) { @Override public Optional<TableHandle> getTableHandle(Session session, QualifiedObjectName tableName) { return Optional.empty(); } @Override public void createTable(Session session, String catalogName, ConnectorTableMetadata tableMetadata) { metadataCreateTableCalled.set(Boolean.TRUE); throw new PrestoException(ALREADY_EXISTS, "Test that we ignore ALREADY_EXISTS exceptions when notExists set"); } }; AccessControl accessControl = new AccessControlManager(transactionManager); metadata.getTablePropertyManager().addProperties(bogusTestingCatalog.getConnectorId(), ImmutableList.of(stringSessionProperty( "baz", "test property", null, false))); catalogManager.registerCatalog(bogusTestingCatalog); CreateTable statement = new CreateTable(QualifiedName.of("test_table"), ImmutableList.of(new ColumnDefinition("a", "BIGINT", Optional.empty())), true, ImmutableMap.of(), Optional.empty()); Session session = testSessionBuilder() .setCatalog(CATALOG_NAME) .setSchema(TINY_SCHEMA_NAME) .setTransactionId(transactionManager.beginTransaction(false)) .build(); QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("create_table"), "CREATE TABLE", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata); assertTrue(stateMachine.getSession().getTransactionId().isPresent()); assertEquals(transactionManager.getAllTransactionInfos().size(), 1); getFutureValue(new CreateTableTask().execute(statement, transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList())); assertTrue(metadataCreateTableCalled.get()); }

Target:
public void testCreateTableDoesNotThrowAlreadyExistsExceptionWhenIfExists() throws Exception { CatalogManager catalogManager = new CatalogManager(); Catalog bogusTestingCatalog = createBogusTestingCatalog(CATALOG_NAME); TypeManager typeManager = new TypeRegistry(); TransactionManager transactionManager = createTestTransactionManager(catalogManager); TablePropertyManager tablePropertyManager = new TablePropertyManager(); tablePropertyManager.addProperties(bogusTestingCatalog.getConnectorId(), ImmutableList.of(stringSessionProperty( "baz", "test property", null, false))); MockMetadata metadata = new MockMetadata(); RuntimeException createTableException = new PrestoException(ALREADY_EXISTS, "Test that we ignore ALREADY_EXISTS exceptions when notExists set"); metadata.setTypeManager(typeManager); metadata.setCreateTableException(createTableException); metadata.setTablePropertyManager(tablePropertyManager); metadata.setCatalogHandle(bogusTestingCatalog.getConnectorId()); catalogManager.registerCatalog(bogusTestingCatalog); CreateTable statement = new CreateTable(QualifiedName.of("test_table"), ImmutableList.of(new ColumnDefinition("a", "BIGINT", Optional.empty())), true, ImmutableMap.of(), Optional.empty()); Session session = testSessionBuilder() .setCatalog(CATALOG_NAME) .setSchema(TINY_SCHEMA_NAME) .setTransactionId(transactionManager.beginTransaction(false)) .build(); getFutureValue(new CreateTableTask().internalExecute(statement, metadata, new AllowAllAccessControl(), session, emptyList())); assertEquals(metadata.getCreateTableCallCount(), 1); }