Skip to content

Commit

Permalink
Refactor blackhole connector
Browse files Browse the repository at this point in the history
- Remove deprecated beginInsert
- Use method reference instead of lambda
- Use assertEquals if applicable
  • Loading branch information
Lewuathe authored and electrum committed Feb 28, 2020
1 parent ebf1cca commit b5da8a7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public Optional<ConnectorOutputMetadata> finishCreateTable(ConnectorSession sess
}

@Override
public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle)
public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle, List<ColumnHandle> columns)
{
BlackHoleTableHandle handle = (BlackHoleTableHandle) tableHandle;
return new BlackHoleInsertTableHandle(handle.getPageProcessingDelay());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.prestosql.spi.connector.ConnectorPageSink;

import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;

import static io.airlift.concurrent.MoreFutures.toCompletableFuture;
Expand Down Expand Up @@ -52,7 +53,7 @@ public CompletableFuture<?> appendPage(Page page)
private CompletableFuture<Collection<Slice>> scheduleAppend()
{
if (pageProcessingDelayMillis > 0) {
return toCompletableFuture(executorService.schedule(() -> ImmutableList.of(), pageProcessingDelayMillis, MILLISECONDS));
return toCompletableFuture(executorService.schedule((Callable<Collection<Slice>>) ImmutableList::of, pageProcessingDelayMillis, MILLISECONDS));
}
return NON_BLOCKED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import static io.prestosql.testing.TestingConnectorSession.SESSION;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

public class TestBlackHoleMetadata
Expand Down Expand Up @@ -68,8 +67,8 @@ public void tableIsCreatedAfterCommits()
metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());

List<SchemaTableName> tables = metadata.listTables(SESSION, Optional.empty());
assertTrue(tables.size() == 1, "Expected only one table.");
assertTrue(tables.get(0).getTableName().equals("temp_table"), "Expected table with name 'temp_table'");
assertEquals(tables.size(), 1, "Expected only one table.");
assertEquals(tables.get(0).getTableName(), "temp_table", "Expected table with name 'temp_table'");
}

@Test
Expand All @@ -82,7 +81,7 @@ public void testCreateTableInNotExistSchema()
}
catch (PrestoException ex) {
assertEquals(ex.getErrorCode(), NOT_FOUND.toErrorCode());
assertTrue(ex.getMessage().equals("Schema schema1 not found"));
assertEquals(ex.getMessage(), "Schema schema1 not found");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

@Test(singleThreaded = true)
Expand Down Expand Up @@ -90,7 +89,7 @@ public void createTableWhenTableIsAlreadyCreated()
fail("Expected exception to be thrown here!");
}
catch (RuntimeException ex) { // it has to RuntimeException as FailureInfo$FailureException is private
assertTrue(ex.getMessage().equals("line 1:1: Destination table 'blackhole.default.nation' already exists"));
assertEquals(ex.getMessage(), "line 1:1: Destination table 'blackhole.default.nation' already exists");
}
finally {
assertThatQueryReturnsValue("DROP TABLE nation", true);
Expand All @@ -103,8 +102,8 @@ public void blackHoleConnectorUsage()
assertThatQueryReturnsValue("CREATE TABLE nation as SELECT * FROM tpch.tiny.nation", 25L);

List<QualifiedObjectName> tableNames = listBlackHoleTables();
assertTrue(tableNames.size() == 1, "Expected only one table.");
assertTrue(tableNames.get(0).getObjectName().equals("nation"), "Expected 'nation' table.");
assertEquals(tableNames.size(), 1, "Expected only one table.");
assertEquals(tableNames.get(0).getObjectName(), "nation", "Expected 'nation' table.");

assertThatQueryReturnsValue("INSERT INTO nation SELECT * FROM tpch.tiny.nation", 25L);

Expand Down Expand Up @@ -157,7 +156,7 @@ public void testCreateTableInNotExistSchema()
fail("Expected exception to be thrown here!");
}
catch (RuntimeException ex) {
assertTrue(ex.getMessage().equals("Schema schema1 not found"));
assertEquals(ex.getMessage(), "Schema schema1 not found");
}

int tablesAfterCreate = listBlackHoleTables().size();
Expand Down Expand Up @@ -346,7 +345,7 @@ public void pageProcessingDelay()

private void assertThatNoBlackHoleTableIsCreated()
{
assertTrue(listBlackHoleTables().size() == 0, "No blackhole tables expected");
assertEquals(listBlackHoleTables().size(), 0, "No blackhole tables expected");
}

private List<QualifiedObjectName> listBlackHoleTables()
Expand All @@ -364,9 +363,9 @@ private void assertThatQueryReturnsValue(String sql, Object expected, Session se
MaterializedResult rows = session == null ? queryRunner.execute(sql) : queryRunner.execute(session, sql);
MaterializedRow materializedRow = Iterables.getOnlyElement(rows);
int fieldCount = materializedRow.getFieldCount();
assertTrue(fieldCount == 1, format("Expected only one column, but got '%d'", fieldCount));
assertEquals(fieldCount, 1, format("Expected only one column, but got '%d'", fieldCount));
Object value = materializedRow.getField(0);
assertEquals(value, expected);
assertTrue(Iterables.getOnlyElement(rows).getFieldCount() == 1);
assertEquals(Iterables.getOnlyElement(rows).getFieldCount(), 1);
}
}

0 comments on commit b5da8a7

Please sign in to comment.