Skip to content

Commit

Permalink
Use TestTable to ensure test tables are cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
hashhar committed Jul 9, 2021
1 parent 6198afb commit 96be8f2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_TOPN_PUSHDOWN;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_TOPN_PUSHDOWN_WITH_VARCHAR;
import static io.trino.testing.assertions.Assert.assertEventually;
import static io.trino.testing.sql.TestTable.randomTableSuffix;
import static java.lang.String.format;
import static java.util.Locale.ENGLISH;
import static java.util.concurrent.Executors.newCachedThreadPool;
Expand Down Expand Up @@ -1171,17 +1170,16 @@ protected TestView createSleepingView(Duration minimalSleepDuration)
public void testDeleteWithBigintEqualityPredicate()
{
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE) && hasBehavior(SUPPORTS_ROW_LEVEL_DELETE));
String tableName = "test_delete_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT * FROM region", 5);
assertUpdate("DELETE FROM " + tableName + " WHERE regionkey = 1", 1);
assertQuery(
"SELECT regionkey, name FROM " + tableName,
"VALUES "
+ "(0, 'AFRICA'),"
+ "(2, 'ASIA'),"
+ "(3, 'EUROPE'),"
+ "(4, 'MIDDLE EAST')");
assertUpdate("DROP TABLE " + tableName);
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_delete", "AS SELECT * FROM region")) {
assertUpdate("DELETE FROM " + table.getName() + " WHERE regionkey = 1", 1);
assertQuery(
"SELECT regionkey, name FROM " + table.getName(),
"VALUES "
+ "(0, 'AFRICA'),"
+ "(2, 'ASIA'),"
+ "(3, 'EUROPE'),"
+ "(4, 'MIDDLE EAST')");
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,14 @@ public void testDeleteAllDataFromTable()
public void testRowLevelDelete()
{
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE) && hasBehavior(SUPPORTS_ROW_LEVEL_DELETE));
String tableName = "test_delete_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT * FROM region", 5);

assertUpdate("DELETE FROM " + tableName + " WHERE regionkey = 2", 1);
assertThat(query("SELECT * FROM " + tableName + " WHERE regionkey = 2"))
.returnsEmptyResult();
assertThat(query("SELECT cast(regionkey AS integer) FROM " + tableName))
.skippingTypesCheck()
.matches("VALUES 0, 1, 3, 4");

assertUpdate("DROP TABLE " + tableName);
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_delete", "AS SELECT * FROM region")) {
assertUpdate("DELETE FROM " + table.getName() + " WHERE regionkey = 2", 1);
assertThat(query("SELECT * FROM " + table.getName() + " WHERE regionkey = 2"))
.returnsEmptyResult();
assertThat(query("SELECT cast(regionkey AS integer) FROM " + table.getName()))
.skippingTypesCheck()
.matches("VALUES 0, 1, 3, 4");
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,22 +760,20 @@ public void verifySupportsRowLevelDeleteDeclaration()
public void testDeleteAllDataFromTable()
{
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE) && hasBehavior(SUPPORTS_DELETE));
String tableName = "test_delete_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT * FROM nation", 25);
// not using assertUpdate as some connectors provide update count and some not
getQueryRunner().execute("DELETE FROM " + tableName);
assertQuery("SELECT count(*) FROM " + tableName, "VALUES 0");
assertUpdate("DROP TABLE " + tableName);
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_delete", "AS SELECT * FROM region")) {
// not using assertUpdate as some connectors provide update count and some not
getQueryRunner().execute("DELETE FROM " + table.getName());
assertQuery("SELECT count(*) FROM " + table.getName(), "VALUES 0");
}
}

@Test
public void testRowLevelDelete()
{
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE) && hasBehavior(SUPPORTS_ROW_LEVEL_DELETE));
String tableName = "test_delete_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT * FROM nation", 25);
assertUpdate("DELETE FROM " + tableName + " WHERE nationkey = 2", 1);
assertQuery("SELECT count(*) FROM " + tableName, "VALUES 24");
assertUpdate("DROP TABLE " + tableName);
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_delete", "AS SELECT * FROM region")) {
assertUpdate("DELETE FROM " + table.getName() + " WHERE regionkey = 2", 1);
assertQuery("SELECT count(*) FROM " + table.getName(), "VALUES 4");
}
}
}

0 comments on commit 96be8f2

Please sign in to comment.