Skip to content

Commit

Permalink
Merge TestRedisDistributed with TestRedisIntegrationSmokeTest
Browse files Browse the repository at this point in the history
Merge `TestRedisDistributed` into `TestRedisIntegrationSmokeTest`
utilizing `BaseConnectorTest` base class.
  • Loading branch information
findepi committed Feb 23, 2021
1 parent 40752e2 commit 0feb871
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

import com.google.common.collect.ImmutableMap;
import io.trino.plugin.redis.util.RedisServer;
import io.trino.testing.AbstractTestQueries;
import io.trino.testing.BaseConnectorTest;
import io.trino.testing.QueryRunner;
import io.trino.tpch.TpchTable;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

@Test
public class TestRedisDistributed
extends AbstractTestQueries
import static io.trino.plugin.redis.RedisQueryRunner.createRedisQueryRunner;

public class TestRedisConnectorTest
extends BaseConnectorTest
{
private RedisServer redisServer;

Expand All @@ -32,12 +32,60 @@ protected QueryRunner createQueryRunner()
throws Exception
{
redisServer = new RedisServer();
return RedisQueryRunner.createRedisQueryRunner(redisServer, ImmutableMap.of(), "string", TpchTable.getTables());
return createRedisQueryRunner(redisServer, ImmutableMap.of(), "string", TpchTable.getTables());
}

@AfterClass(alwaysRun = true)
public void destroy()
{
redisServer.close();
}

@Override
protected boolean supportsCreateSchema()
{
return false;
}

@Override
protected boolean supportsCreateTable()
{
return false;
}

@Override
protected boolean supportsInsert()
{
return false;
}

@Override
protected boolean supportsDelete()
{
return false;
}

@Override
protected boolean supportsViews()
{
return false;
}

@Override
protected boolean supportsArrays()
{
return false;
}

@Override
protected boolean supportsCommentOnTable()
{
return false;
}

@Override
protected boolean supportsCommentOnColumn()
{
return false;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@
public abstract class AbstractTestDistributedQueries
extends AbstractTestQueries
{
protected boolean supportsCreateSchema()
{
return true;
}

protected boolean supportsCreateTable()
{
return true;
}

protected boolean supportsInsert()
{
return true;
}

protected boolean supportsDelete()
{
return true;
Expand Down Expand Up @@ -161,6 +176,11 @@ public void testResetSession()
public void testCreateTable()
{
String tableName = "test_create_" + randomTableSuffix();
if (!supportsCreateTable()) {
assertQueryFails("CREATE TABLE " + tableName + " (a bigint, b double, c varchar)", "This connector does not support creating tables");
return;
}

assertUpdate("CREATE TABLE " + tableName + " (a bigint, b double, c varchar)");
assertTrue(getQueryRunner().tableExists(getSession(), tableName));
assertTableColumnNames(tableName, "a", "b", "c");
Expand Down Expand Up @@ -206,6 +226,10 @@ public void testCreateTable()
public void testCreateTableAsSelect()
{
String tableName = "test_ctas" + randomTableSuffix();
if (!supportsCreateTable()) {
assertQueryFails("CREATE TABLE IF NOT EXISTS " + tableName + " AS SELECT name, regionkey FROM nation", "This connector does not support creating tables with data");
return;
}
assertUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " AS SELECT name, regionkey FROM nation", "SELECT count(*) FROM nation");
assertTableColumnNames(tableName, "name", "regionkey");
assertUpdate("DROP TABLE " + tableName);
Expand Down Expand Up @@ -296,6 +320,8 @@ protected void assertCreateTableAsSelect(Session session, @Language("SQL") Strin
@Test
public void testRenameTable()
{
skipTestUnless(supportsCreateTable());

String tableName = "test_rename_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT 123 x", 1);

Expand Down Expand Up @@ -326,14 +352,12 @@ public void testRenameTable()
@Test
public void testCommentTable()
{
String tableName = "test_comment_" + randomTableSuffix();
if (!supportsCommentOnTable()) {
assertUpdate("CREATE TABLE " + tableName + "(a integer)");
assertQueryFails("COMMENT ON TABLE " + tableName + " IS 'new comment'", "This connector does not support setting table comments");
assertUpdate("DROP TABLE " + tableName);
assertQueryFails("COMMENT ON TABLE nation IS 'new comment'", "This connector does not support setting table comments");
return;
}

String tableName = "test_comment_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + "(a integer)");

// comment set
Expand Down Expand Up @@ -377,14 +401,12 @@ private String getTableComment(String tableName)
@Test
public void testCommentColumn()
{
String tableName = "test_comment_column_" + randomTableSuffix();
if (!supportsCommentOnColumn()) {
assertUpdate("CREATE TABLE " + tableName + "(a integer)");
assertQueryFails("COMMENT ON COLUMN " + tableName + ".a IS 'new comment'", "This connector does not support setting column comments");
assertUpdate("DROP TABLE " + tableName);
assertQueryFails("COMMENT ON COLUMN nation.nationkey IS 'new comment'", "This connector does not support setting column comments");
return;
}

String tableName = "test_comment_column_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + "(a integer)");

// comment set
Expand Down Expand Up @@ -427,6 +449,8 @@ private String getColumnComment(String tableName, String columnName)
@Test
public void testRenameColumn()
{
skipTestUnless(supportsCreateTable());

String tableName = "test_rename_column_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT 'some value' x", 1);

Expand Down Expand Up @@ -458,6 +482,8 @@ public void testRenameColumn()
@Test
public void testDropColumn()
{
skipTestUnless(supportsCreateTable());

String tableName = "test_drop_column_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT 123 x, 456 y, 111 a", 1);

Expand All @@ -480,6 +506,8 @@ public void testDropColumn()
@Test
public void testAddColumn()
{
skipTestUnless(supportsCreateTable());

String tableName = "test_add_column_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT CAST('first' AS varchar) x", 1);

Expand Down Expand Up @@ -516,6 +544,11 @@ public void testAddColumn()
@Test
public void testInsert()
{
if (!supportsInsert()) {
assertQueryFails("INSERT INTO nation(nationkey) VALUES (42)", "This connector does not support inserts");
return;
}

String query = "SELECT phone, custkey, acctbal FROM customer";

String tableName = "test_insert_" + randomTableSuffix();
Expand Down Expand Up @@ -556,6 +589,8 @@ public void testInsert()
@Test
public void testInsertUnicode()
{
skipTestUnless(supportsInsert());

String tableName = "test_insert_unicode_" + randomTableSuffix();

assertUpdate("CREATE TABLE " + tableName + "(test varchar)");
Expand Down Expand Up @@ -586,6 +621,8 @@ public void testInsertUnicode()
@Test
public void testInsertArray()
{
skipTestUnless(supportsInsert());

String tableName = "test_insert_array_" + randomTableSuffix();
if (!supportsArrays()) {
assertThatThrownBy(() -> query("CREATE TABLE " + tableName + " (a array(bigint))"))
Expand All @@ -606,18 +643,15 @@ public void testInsertArray()
@Test
public void testDelete()
{
// delete half the table, then delete the rest
String tableName = "test_delete_" + randomTableSuffix();

if (!supportsDelete()) {
assertUpdate("CREATE TABLE " + tableName + " AS SELECT * FROM orders WITH NO DATA", 0);
assertQueryFails("DELETE FROM " + tableName, "This connector does not support deletes");
assertUpdate("DROP TABLE " + tableName);
assertQueryFails("DELETE FROM nation", "This connector does not support deletes");
return;
}

String tableName = "test_delete_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT * FROM orders", "SELECT count(*) FROM orders");

// delete half the table, then delete the rest
assertUpdate("DELETE FROM " + tableName + " WHERE orderkey % 2 = 0", "SELECT count(*) FROM orders WHERE orderkey % 2 = 0");
assertQuery("SELECT * FROM " + tableName, "SELECT * FROM orders WHERE orderkey % 2 <> 0");

Expand Down Expand Up @@ -958,6 +992,8 @@ public void testShowCreateView()
@Test
public void testQueryLoggingCount()
{
skipTestUnless(supportsCreateTable());

QueryManager queryManager = getDistributedQueryRunner().getCoordinator().getQueryManager();
executeExclusively(() -> {
assertEventually(
Expand Down Expand Up @@ -1013,9 +1049,12 @@ public void testShowSchemasFromOther()
assertTrue(result.getOnlyColumnAsSet().containsAll(ImmutableSet.of(INFORMATION_SCHEMA, "tiny", "sf1")));
}

// TODO move to to engine-only
@Test
public void testSymbolAliasing()
{
skipTestUnless(supportsCreateTable());

String tableName = "test_symbol_aliasing" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT 1 foo_1, 2 foo_2_4", 1);
assertQuery("SELECT foo_1, foo_2_4 FROM " + tableName, "SELECT 1, 2");
Expand All @@ -1026,6 +1065,9 @@ public void testSymbolAliasing()
@Flaky(issue = "https://github.com/trinodb/trino/issues/5172", match = "AssertionError: expected \\[.*\\] but found \\[.*\\]")
public void testWrittenStats()
{
skipTestUnless(supportsCreateTable());
skipTestUnless(supportsInsert());

String tableName = "test_written_stats_" + randomTableSuffix();
String sql = "CREATE TABLE " + tableName + " AS SELECT * FROM nation";
ResultWithQueryId<MaterializedResult> resultResultWithQueryId = getDistributedQueryRunner().executeWithQueryId(getSession(), sql);
Expand All @@ -1050,6 +1092,10 @@ public void testWrittenStats()
public void testCreateSchema()
{
String schemaName = "test_schema_create_" + randomTableSuffix();
if (!supportsCreateSchema()) {
assertQueryFails("CREATE SCHEMA " + schemaName, "This connector does not support creating schemas");
return;
}
assertThat(computeActual("SHOW SCHEMAS").getOnlyColumnAsSet()).doesNotContain(schemaName);
assertUpdate("CREATE SCHEMA " + schemaName);
assertThat(computeActual("SHOW SCHEMAS").getOnlyColumnAsSet()).contains(schemaName);
Expand All @@ -1061,6 +1107,8 @@ public void testCreateSchema()
@Test
public void testInsertForDefaultColumn()
{
skipTestUnless(supportsInsert());

try (TestTable testTable = createTableWithDefaultColumns()) {
assertUpdate(format("INSERT INTO %s (col_required, col_required2) VALUES (1, 10)", testTable.getName()), 1);
assertUpdate(format("INSERT INTO %s VALUES (2, 3, 4, 5, 6)", testTable.getName()), 1);
Expand All @@ -1071,11 +1119,16 @@ public void testInsertForDefaultColumn()
}
}

protected abstract TestTable createTableWithDefaultColumns();
protected TestTable createTableWithDefaultColumns()
{
throw new UnsupportedOperationException();
}

@Test(dataProvider = "testColumnNameDataProvider")
public void testColumnName(String columnName)
{
skipTestUnless(supportsCreateTable());

if (!requiresDelimiting(columnName)) {
testColumnName(columnName, false);
}
Expand Down Expand Up @@ -1175,6 +1228,8 @@ protected String dataMappingTableName(String trinoTypeName)
@Test(dataProvider = "testDataMappingSmokeTestDataProvider")
public void testDataMappingSmokeTest(DataMappingTestSetup dataMappingTestSetup)
{
skipTestUnless(supportsCreateTable());

String trinoTypeName = dataMappingTestSetup.getTrinoTypeName();
String sampleValueLiteral = dataMappingTestSetup.getSampleValueLiteral();
String highValueLiteral = dataMappingTestSetup.getHighValueLiteral();
Expand Down

0 comments on commit 0feb871

Please sign in to comment.