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

Switch Mongo, Kafka, Cassandra 'Latest' tests to BaseConnectorSmokeTest #7182

Merged
merged 4 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public ColumnHandle getDeleteRowIdColumnHandle(ConnectorSession session, Connect
@Override
public ConnectorTableHandle beginDelete(ConnectorSession session, ConnectorTableHandle tableHandle)
{
throw new TrinoException(NOT_SUPPORTED, "This connector only supports delete with primary key or partition key");
throw new TrinoException(NOT_SUPPORTED, "Delete without primary key or partition key is not supported");
}

@Override
Expand All @@ -396,7 +396,7 @@ public OptionalLong executeDelete(ConnectorSession session, ConnectorTableHandle
CassandraTableHandle handle = (CassandraTableHandle) deleteHandle;
Optional<List<CassandraPartition>> partitions = handle.getPartitions();
if (partitions.isEmpty()) {
throw new TrinoException(NOT_SUPPORTED, "Deleting without partition key is unsupported");
throw new TrinoException(NOT_SUPPORTED, "Deleting without partition key is not supported");
}
if (partitions.get().isEmpty()) {
// there are no records of a given partition key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testDropColumn()
public void testDelete()
{
assertThatThrownBy(super::testDelete)
.hasStackTraceContaining("This connector only supports delete with primary key or partition key");
.hasStackTraceContaining("Delete without primary key or partition key is not supported");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
import static org.testng.Assert.assertEquals;

public class TestCassandraIntegrationSmokeTest
// TODO extend BaseConnectorTest
// TODO extend BaseConnectorTest and merge with TestCassandraDistributedQueries
extends AbstractTestIntegrationSmokeTest
{
private static final String KEYSPACE = "smoke_test";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
package io.trino.plugin.cassandra;

import com.google.common.collect.ImmutableMap;
import io.trino.testing.BaseConnectorSmokeTest;
import io.trino.testing.QueryRunner;
import io.trino.testing.TestingConnectorBehavior;

import static io.trino.plugin.cassandra.CassandraQueryRunner.createCassandraQueryRunner;

public class TestCassandraDistributedQueriesLatest
extends BaseCassandraDistributedQueries
public class TestCassandraLatestConnectorSmokeTest
extends BaseConnectorSmokeTest
{
@Override
protected QueryRunner createQueryRunner()
Expand All @@ -28,4 +30,22 @@ protected QueryRunner createQueryRunner()
CassandraServer server = closeAfterClass(new CassandraServer("3.11.9"));
return createCassandraQueryRunner(server, ImmutableMap.of(), REQUIRED_TPCH_TABLES);
}

@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_CREATE_SCHEMA:
return false;

case SUPPORTS_DELETE:
return true;

case SUPPORTS_ROW_LEVEL_DELETE:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.kafka;

import io.trino.testing.BaseConnectorSmokeTest;
import io.trino.testing.QueryRunner;
import io.trino.testing.TestingConnectorBehavior;
import io.trino.testing.kafka.TestingKafka;
import org.testng.SkipException;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class TestKafkaLatestConnectorSmokeTest
extends BaseConnectorSmokeTest
{
@Override
protected QueryRunner createQueryRunner()
throws Exception
{
TestingKafka testingKafka = closeAfterClass(TestingKafka.create("6.0.1"));
return KafkaQueryRunner.builder(testingKafka)
.setTables(REQUIRED_TPCH_TABLES)
.build();
}

@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_CREATE_SCHEMA:
return false;

case SUPPORTS_CREATE_TABLE:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
}

@Override
public void testInsert()
{
assertThatThrownBy(super::testInsert)
.hasMessage("Cannot test INSERT without CREATE TABLE, the test needs to be implemented in a connector-specific way");
// TODO implement the test for Kafka
throw new SkipException("TODO");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.kafka;
package io.trino.plugin.mongodb;

import io.trino.testing.AbstractTestQueries;
import io.trino.testing.QueryRunner;
import io.trino.testing.kafka.TestingKafka;
import io.trino.testing.BaseConnectorSmokeTest;
import io.trino.testing.TestingConnectorBehavior;

public class TestKafkaDistributedLatest
extends AbstractTestQueries
public abstract class BaseMongoConnectorSmokeTest
extends BaseConnectorSmokeTest
{
@Override
protected QueryRunner createQueryRunner()
throws Exception
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
TestingKafka testingKafka = closeAfterClass(TestingKafka.create("6.0.1"));
return KafkaQueryRunner.builder(testingKafka)
.setTables(REQUIRED_TPCH_TABLES)
.build();
switch (connectorBehavior) {
case SUPPORTS_CREATE_SCHEMA:
return false;
default:
return super.hasBehavior(connectorBehavior);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import static io.trino.plugin.mongodb.MongoQueryRunner.createMongoQueryRunner;

public class TestMongo3DistributedQueriesLatest
extends BaseMongoDistributedQueries
public class TestMongo3LatestConnectorSmokeTest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latest are not latest any more. And honestly I do not get why these specific versions are tested :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's consider this out of scope here and see #5804

see also my reply in #7179 (comment)

extends BaseMongoConnectorSmokeTest
{
@Override
protected QueryRunner createQueryRunner()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import static io.trino.plugin.mongodb.MongoQueryRunner.createMongoQueryRunner;

public class TestMongo4DistributedQueriesLatest
extends BaseMongoDistributedQueries
public class TestMongo4LatestConnectorSmokeTest
extends BaseMongoConnectorSmokeTest
{
@Override
protected QueryRunner createQueryRunner()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_CREATE_SCHEMA;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_CREATE_TABLE;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_CREATE_TABLE_WITH_DATA;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_DELETE;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_INSERT;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_ROW_LEVEL_DELETE;
import static io.trino.testing.sql.TestTable.randomTableSuffix;
Expand Down Expand Up @@ -105,7 +106,7 @@ public void testJoin()
public void testCreateTable()
{
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
assertQueryFails("CREATE TABLE xxxx (a bigint, b double)", "This connector does not support create");
assertQueryFails("CREATE TABLE xxxx (a bigint, b double)", "This connector does not support creating tables");
return;
}

Expand All @@ -120,7 +121,7 @@ public void testCreateTable()
public void testCreateTableAsSelect()
{
if (!hasBehavior(SUPPORTS_CREATE_TABLE_WITH_DATA)) {
assertQueryFails("CREATE TABLE xxxx (a bigint, b double) AS VALUES (42, -38.5)", "This connector does not support create");
assertQueryFails("CREATE TABLE xxxx AS SELECT BIGINT '42' a, DOUBLE '-38.5' b", "This connector does not support creating tables with data");
return;
}

Expand All @@ -139,6 +140,10 @@ public void testInsert()
return;
}

if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
throw new AssertionError("Cannot test INSERT without CREATE TABLE, the test needs to be implemented in a connector-specific way");
}

String tableName = "test_create_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " (a bigint, b double)");
assertUpdate("INSERT INTO " + tableName + " (a, b) VALUES (42, -38.5)", 1);
Expand All @@ -150,11 +155,16 @@ public void testInsert()
@Test
public void testDelete()
{
if (!hasBehavior(SUPPORTS_ROW_LEVEL_DELETE)) {
if (!hasBehavior(SUPPORTS_DELETE)) {
assertQueryFails("DELETE FROM region", "This connector does not support deletes");
return;
}

if (!hasBehavior(SUPPORTS_ROW_LEVEL_DELETE)) {
assertQueryFails("DELETE FROM region WHERE regionkey = 2", ".*[Dd]elet(e|ing).*(not |un)supported.*");
return;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public enum TestingConnectorBehavior
SUPPORTS_JOIN_PUSHDOWN_WITH_FULL_JOIN(SUPPORTS_JOIN_PUSHDOWN),
SUPPORTS_JOIN_PUSHDOWN_WITH_DISTINCT_FROM(SUPPORTS_JOIN_PUSHDOWN),

SUPPORTS_CREATE_SCHEMA,

SUPPORTS_CREATE_TABLE,
SUPPORTS_CREATE_TABLE_WITH_DATA(SUPPORTS_CREATE_TABLE),

Expand All @@ -44,8 +46,6 @@ public enum TestingConnectorBehavior
SUPPORTS_DELETE(false),
SUPPORTS_ROW_LEVEL_DELETE(SUPPORTS_DELETE),

SUPPORTS_CREATE_SCHEMA,

/**/;

private final Predicate<Predicate<TestingConnectorBehavior>> hasBehaviorByDefault;
Expand Down