Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce BaseConnectorTest, merging AbstractTestDistributedQueries and AbstractTestIntegrationSmokeTest #6989

Merged
merged 7 commits into from
Feb 23, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.assertj.core.api.Assertions.assertThat;

public class TestAccumuloIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.jdbc;

import com.google.common.collect.ImmutableMap;
import io.trino.testing.AbstractTestDistributedQueries;
import io.trino.testing.QueryRunner;
import io.trino.testing.sql.JdbcSqlExecutor;
import io.trino.testing.sql.TestTable;
import io.trino.tpch.TpchTable;
import org.testng.SkipException;

import java.util.Map;
import java.util.Optional;
import java.util.Properties;

import static io.trino.plugin.jdbc.H2QueryRunner.createH2QueryRunner;

public class TestJdbcCachingQueries
// TODO define shorter tests set that exercises various read and write scenarios (a.k.a. "a smoke test")
extends AbstractTestDistributedQueries
{
private Map<String, String> properties;

@Override
protected QueryRunner createQueryRunner()
throws Exception
{
properties = ImmutableMap.<String, String>builder()
.putAll(TestingH2JdbcModule.createProperties())
.put("metadata.cache-ttl", "10m")
.put("metadata.cache-missing", "true")
.put("allow-drop-table", "true")
.build();
return createH2QueryRunner(TpchTable.getTables(), properties);
}

@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;
}

@Override
public void testLargeIn(int valuesCount)
{
throw new SkipException("This test should pass with H2, but takes too long (currently over a mninute) and is not that important");
}

@Override
protected TestTable createTableWithDefaultColumns()
{
return new TestTable(
getSqlExecutor(),
"tpch.table",
"(col_required BIGINT NOT NULL," +
"col_nullable BIGINT," +
"col_default BIGINT DEFAULT 43," +
"col_nonnull_default BIGINT NOT NULL DEFAULT 42," +
"col_required2 BIGINT NOT NULL)");
}

@Override
protected Optional<DataMappingTestSetup> filterDataMappingSmokeTestData(DataMappingTestSetup dataMappingTestSetup)
{
String typeBaseName = dataMappingTestSetup.getTrinoTypeName().replaceAll("\\([^()]*\\)", "");
switch (typeBaseName) {
case "boolean":
case "decimal":
case "char":
case "varbinary":
case "time":
case "timestamp":
case "timestamp with time zone":
return Optional.of(dataMappingTestSetup.asUnsupported());
}

return Optional.of(dataMappingTestSetup);
}

private JdbcSqlExecutor getSqlExecutor()
{
return new JdbcSqlExecutor(properties.get("connection-url"), new Properties());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.jdbc;

import com.google.common.collect.ImmutableMap;
import io.trino.testing.BaseConnectorTest;
import io.trino.testing.QueryRunner;
import io.trino.testing.sql.JdbcSqlExecutor;
import io.trino.testing.sql.TestTable;
import io.trino.tpch.TpchTable;
import org.testng.SkipException;

import java.util.Map;
import java.util.Optional;
import java.util.Properties;

import static io.trino.plugin.jdbc.H2QueryRunner.createH2QueryRunner;

public class TestJdbcConnectorTest
extends BaseConnectorTest
{
private Map<String, String> properties;

@Override
protected QueryRunner createQueryRunner()
throws Exception
{
properties = ImmutableMap.<String, String>builder()
.putAll(TestingH2JdbcModule.createProperties())
.put("allow-drop-table", "true")
.build();
return createH2QueryRunner(TpchTable.getTables(), properties);
}

@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;
}

@Override
public void testLargeIn(int valuesCount)
{
throw new SkipException("This test should pass with H2, but takes too long (currently over a mninute) and is not that important");
}

@Override
protected TestTable createTableWithDefaultColumns()
{
return new TestTable(
getSqlExecutor(),
"tpch.table",
"(col_required BIGINT NOT NULL," +
"col_nullable BIGINT," +
"col_default BIGINT DEFAULT 43," +
"col_nonnull_default BIGINT NOT NULL DEFAULT 42," +
"col_required2 BIGINT NOT NULL)");
}

@Override
protected Optional<DataMappingTestSetup> filterDataMappingSmokeTestData(DataMappingTestSetup dataMappingTestSetup)
{
String typeBaseName = dataMappingTestSetup.getTrinoTypeName().replaceAll("\\([^()]*\\)", "");
switch (typeBaseName) {
case "boolean":
case "decimal":
case "char":
case "varbinary":
case "time":
case "timestamp":
case "timestamp with time zone":
return Optional.of(dataMappingTestSetup.asUnsupported());
}

return Optional.of(dataMappingTestSetup);
}

private JdbcSqlExecutor getSqlExecutor()
{
return new JdbcSqlExecutor(properties.get("connection-url"), new Properties());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static java.lang.String.format;

public class TestJdbcIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
private final Map<String, String> properties = TestingH2JdbcModule.createProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

@Test
public class TestBigQueryIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
private BigQuerySqlExecutor bigQuerySqlExecutor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import static org.testng.Assert.assertEquals;

public class TestCassandraIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
private static final String KEYSPACE = "smoke_test";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.assertj.core.api.Assertions.assertThat;

public abstract class BaseDruidIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
protected static final String SELECT_FROM_ORDERS = "SELECT " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import static org.testng.Assert.assertTrue;

public abstract class BaseElasticsearchSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
private final String image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
import static org.testng.FileAssert.assertFile;

public class TestHiveIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
private static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import static org.testng.Assert.assertTrue;

public abstract class AbstractTestIcebergSmoke
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
private static final Pattern WITH_CLAUSE_EXTRACTER = Pattern.compile(".*(WITH\\s*\\([^)]*\\))\\s*$", Pattern.DOTALL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import static org.apache.kafka.clients.producer.ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG;

public class TestKafkaIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
private TestingKafka testingKafka;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static org.testng.Assert.assertTrue;

public abstract class AbstractKuduIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
private TestingKuduServer kuduServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.testng.Assert.assertTrue;

public class TestMemSqlIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
protected TestingMemSqlServer memSqlServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

@Test(singleThreaded = true)
public class TestMongoIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
private MongoServer server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static org.testng.Assert.assertTrue;

abstract class BaseMySqlIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
protected TestingMySqlServer mysqlServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static org.testng.Assert.assertTrue;

public abstract class BaseOracleIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static org.testng.Assert.fail;

public class TestPhoenixIntegrationSmokeTest
// TODO extend BaseConnectorTest
extends AbstractTestIntegrationSmokeTest
{
private TestingPhoenixServer testingPhoenixServer;
Expand Down
Loading