Skip to content

Commit

Permalink
Switch Cassandra 'Latest' test to BaseConnectorSmokeTest
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Mar 6, 2021
1 parent 29c8eae commit 4cae179
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
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
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 @@ -154,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

0 comments on commit 4cae179

Please sign in to comment.