Skip to content
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 @@ -2,6 +2,7 @@

import com.scalar.db.api.DistributedStorageAdminCaseSensitivityIntegrationTestBase;
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.util.AdminTestUtils;
import java.util.Properties;

public class CassandraAdminCaseSensitivityIntegrationTest
Expand All @@ -18,6 +19,11 @@ protected String getSystemNamespaceName(Properties properties) {
.orElse(DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME);
}

@Override
protected AdminTestUtils getAdminTestUtils(String testName) {
return new CassandraAdminTestUtils(getProperties(testName));
}

@Override
protected boolean isTimestampTypeSupported() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.scalar.db.api.DistributedStorageAdminIntegrationTestBase;
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.util.AdminTestUtils;
import java.util.Properties;

public class CassandraAdminIntegrationTest extends DistributedStorageAdminIntegrationTestBase {
Expand All @@ -17,6 +18,11 @@ protected String getSystemNamespaceName(Properties properties) {
.orElse(DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME);
}

@Override
protected AdminTestUtils getAdminTestUtils(String testName) {
return new CassandraAdminTestUtils(getProperties(testName));
}

@Override
protected boolean isTimestampTypeSupported() {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.scalar.db.storage.cassandra;

import static com.datastax.driver.core.Metadata.quoteIfNecessary;

import com.datastax.driver.core.schemabuilder.SchemaBuilder;
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.util.AdminTestUtils;
import java.util.Properties;
Expand Down Expand Up @@ -28,6 +31,11 @@ public void corruptMetadata(String namespace, String table) {
// Do nothing
}

@Override
public void deleteMetadata(String namespace, String table) throws Exception {
// Do nothing
}

@Override
public boolean namespaceExists(String namespace) {
return clusterManager.getSession().getCluster().getMetadata().getKeyspace(namespace) != null;
Expand All @@ -38,6 +46,14 @@ public boolean tableExists(String namespace, String table) {
return clusterManager.getMetadata(namespace, table) != null;
}

@Override
public void dropTable(String namespace, String table) {
String dropTableQuery =
SchemaBuilder.dropTable(quoteIfNecessary(namespace), quoteIfNecessary(table))
.getQueryString();
clusterManager.getSession().execute(dropTableQuery);
}

@Override
public void close() {
clusterManager.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.scalar.db.api.DistributedStorageAdminCaseSensitivityIntegrationTestBase;
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.util.AdminTestUtils;
import java.util.Map;
import java.util.Properties;

Expand All @@ -18,6 +19,11 @@ protected Map<String, String> getCreationOptions() {
return CosmosEnv.getCreationOptions();
}

@Override
protected AdminTestUtils getAdminTestUtils(String testName) {
return new CosmosAdminTestUtils(getProperties(testName));
}

@Override
protected String getSystemNamespaceName(Properties properties) {
return new CosmosConfig(new DatabaseConfig(properties))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.scalar.db.api.DistributedStorageAdminIntegrationTestBase;
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.util.AdminTestUtils;
import java.util.Map;
import java.util.Properties;

Expand All @@ -17,6 +18,11 @@ protected Map<String, String> getCreationOptions() {
return CosmosEnv.getCreationOptions();
}

@Override
protected AdminTestUtils getAdminTestUtils(String testName) {
return new CosmosAdminTestUtils(getProperties(testName));
}

@Override
protected String getSystemNamespaceName(Properties properties) {
return new CosmosConfig(new DatabaseConfig(properties))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public void corruptMetadata(String namespace, String table) {
container.upsertItem(corruptedMetadata);
}

@Override
public void deleteMetadata(String namespace, String table) {
String fullTableName = getFullTableName(namespace, table);
CosmosContainer container =
client.getDatabase(metadataDatabase).getContainer(CosmosAdmin.METADATA_CONTAINER);
container.deleteItem(
fullTableName, new PartitionKey(fullTableName), new CosmosItemRequestOptions());
}

/**
* Retrieve the stored procedure for the given table
*
Expand Down Expand Up @@ -117,6 +126,11 @@ public boolean tableExists(String namespace, String table) {
return true;
}

@Override
public void dropTable(String namespace, String table) {
client.getDatabase(namespace).getContainer(table).delete();
}

@Override
public void close() {
client.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.scalar.db.api.DistributedStorageAdminCaseSensitivityIntegrationTestBase;
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.util.AdminTestUtils;
import java.util.Map;
import java.util.Properties;
import org.junit.jupiter.api.Disabled;
Expand All @@ -25,6 +26,11 @@ protected boolean isIndexOnBooleanColumnSupported() {
return false;
}

@Override
protected AdminTestUtils getAdminTestUtils(String testName) {
return new DynamoAdminTestUtils(getProperties(testName));
}

@Override
protected String getSystemNamespaceName(Properties properties) {
return new DynamoConfig(new DatabaseConfig(properties))
Expand All @@ -35,6 +41,12 @@ protected String getSystemNamespaceName(Properties properties) {
// Since DynamoDB doesn't have the namespace concept, some behaviors around the namespace are
// different from the other adapters. So disable several tests that check such behaviors

@Disabled
@Test
@Override
public void
dropNamespace_ForNamespaceWithNonScalarDBManagedTables_ShouldThrowIllegalArgumentException() {}

@Disabled
@Test
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.scalar.db.api.DistributedStorageAdminIntegrationTestBase;
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.util.AdminTestUtils;
import java.util.Map;
import java.util.Properties;
import org.junit.jupiter.api.Disabled;
Expand All @@ -24,6 +25,11 @@ protected boolean isIndexOnBooleanColumnSupported() {
return false;
}

@Override
protected AdminTestUtils getAdminTestUtils(String testName) {
return new DynamoAdminTestUtils(getProperties(testName));
}

@Override
protected String getSystemNamespaceName(Properties properties) {
return new DynamoConfig(new DatabaseConfig(properties))
Expand All @@ -34,6 +40,12 @@ protected String getSystemNamespaceName(Properties properties) {
// Since DynamoDB doesn't have the namespace concept, some behaviors around the namespace are
// different from the other adapters. So disable several tests that check such behaviors

@Disabled
@Test
@Override
public void
dropNamespace_ForNamespaceWithNonScalarDBManagedTables_ShouldThrowIllegalArgumentException() {}

@Disabled
@Test
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,31 @@ public void corruptMetadata(String namespace, String table) {
.build());
}

@Override
public void deleteMetadata(String namespace, String table) {
String fullTableName =
getFullTableName(Namespace.of(namespacePrefix, namespace).prefixed(), table);
Map<String, AttributeValue> keyToDelete = new HashMap<>();
keyToDelete.put("table", AttributeValue.builder().s(fullTableName).build());

client.deleteItem(
DeleteItemRequest.builder()
.tableName(getFullTableName(metadataNamespace, DynamoAdmin.METADATA_TABLE))
.key(keyToDelete)
.build());
}

@Override
public void dropTable(String nonPrefixedNamespace, String table) {
String namespace = Namespace.of(namespacePrefix, nonPrefixedNamespace).prefixed();
client.deleteTable(
DeleteTableRequest.builder().tableName(getFullTableName(namespace, table)).build());
if (!waitForTableDeletion(namespace, table)) {
throw new RuntimeException(
String.format("Deleting the %s table timed out", getFullTableName(namespace, table)));
}
}

@Override
public boolean namespaceExists(String namespace) throws Exception {
// Dynamo has no concept of namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.scalar.db.api.DistributedStorageAdminCaseSensitivityIntegrationTestBase;
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.util.AdminTestUtils;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;
Expand All @@ -25,6 +26,11 @@ protected String getSystemNamespaceName(Properties properties) {
.orElse(DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME);
}

@Override
protected AdminTestUtils getAdminTestUtils(String testName) {
return new JdbcAdminTestUtils(getProperties(testName));
}

// Since SQLite doesn't have persistent namespaces, some behaviors around the namespace are
// different from the other adapters. So disable several tests that check such behaviors.

Expand All @@ -33,6 +39,12 @@ private boolean isSqlite() {
return JdbcEnv.isSqlite();
}

@Test
@Override
@DisabledIf("isSqlite")
public void
dropNamespace_ForNamespaceWithNonScalarDBManagedTables_ShouldThrowIllegalArgumentException() {}

@Test
@Override
@DisabledIf("isSqlite")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.scalar.db.api.DistributedStorageAdminIntegrationTestBase;
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.util.AdminTestUtils;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;
Expand All @@ -24,6 +25,11 @@ protected String getSystemNamespaceName(Properties properties) {
.orElse(DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME);
}

@Override
protected AdminTestUtils getAdminTestUtils(String testName) {
return new JdbcAdminTestUtils(getProperties(testName));
}

// Since SQLite doesn't have persistent namespaces, some behaviors around the namespace are
// different from the other adapters. So disable several tests that check such behaviors.

Expand All @@ -32,6 +38,12 @@ private boolean isSqlite() {
return JdbcEnv.isSqlite();
}

@Test
@Override
@DisabledIf("isSqlite")
public void
dropNamespace_ForNamespaceWithNonScalarDBManagedTables_ShouldThrowIllegalArgumentException() {}

@Test
@Override
@DisabledIf("isSqlite")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ public void corruptMetadata(String namespace, String table) throws Exception {
execute(insertCorruptedMetadataStatement);
}

@Override
public void deleteMetadata(String namespace, String table) throws Exception {
String deleteMetadataStatement =
"DELETE FROM "
+ rdbEngine.encloseFullTableName(metadataSchema, JdbcAdmin.METADATA_TABLE)
+ " WHERE "
+ rdbEngine.enclose(JdbcAdmin.METADATA_COL_FULL_TABLE_NAME)
+ " = ?";
try (Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement =
connection.prepareStatement(deleteMetadataStatement)) {
preparedStatement.setString(1, getFullTableName(namespace, table));
preparedStatement.executeUpdate();
}
}

private void execute(String sql) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
JdbcAdmin.execute(connection, sql);
Expand Down Expand Up @@ -112,6 +128,12 @@ public boolean tableExists(String namespace, String table) throws Exception {
}
}

@Override
public void dropTable(String namespace, String table) throws Exception {
String dropTableStatement = "DROP TABLE " + rdbEngine.encloseFullTableName(namespace, table);
execute(dropTableStatement);
}

@Override
public void close() throws SQLException {
dataSource.close();
Expand Down
Loading