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 @@ -7,6 +7,7 @@
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.io.DataType;
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 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 @@ -7,6 +7,7 @@
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.io.DataType;
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 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;
import org.junit.jupiter.api.Disabled;
Expand All @@ -19,6 +20,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;
import org.junit.jupiter.api.Disabled;
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 @@ -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 @@ -20,6 +21,11 @@ protected Map<String, String> getCreationOptions() {
return DynamoEnv.getCreationOptions();
}

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

@Override
protected boolean isIndexOnBooleanColumnSupported() {
return false;
Expand Down Expand Up @@ -80,6 +86,11 @@ public void namespaceExists_ShouldReturnCorrectResults() {}
@Override
public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("DynamoDB does not have a concept of namespaces")
public void
dropNamespace_ForNamespaceWithNonScalarDBManagedTables_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("DynamoDB does not support dropping columns")
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
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 @@ -19,6 +20,11 @@ protected Map<String, String> getCreationOptions() {
return DynamoEnv.getCreationOptions();
}

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

@Override
protected boolean isIndexOnBooleanColumnSupported() {
return false;
Expand Down Expand Up @@ -79,6 +85,11 @@ public void namespaceExists_ShouldReturnCorrectResults() {}
@Override
public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("DynamoDB does not have a concept of namespaces")
public void
dropNamespace_ForNamespaceWithNonScalarDBManagedTables_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("DynamoDB does not support dropping columns")
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ public boolean tableExists(String nonPrefixedNamespace, String table) {
}
}

@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 void truncateMetadataTable() {
Map<String, AttributeValue> lastKeyEvaluated = null;
Expand Down Expand Up @@ -139,6 +150,20 @@ 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 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 @@ -16,6 +16,7 @@
import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.io.DataType;
import com.scalar.db.io.Key;
import com.scalar.db.util.AdminTestUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
Expand Down Expand Up @@ -49,6 +50,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 Down Expand Up @@ -159,6 +165,12 @@ private boolean isWideningColumnTypeConversionNotFullySupported() {
return JdbcTestUtils.isOracle(rdbEngine) || JdbcTestUtils.isSqlite(rdbEngine);
}

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

@Test
@Override
@DisabledIf("isDb2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.io.DataType;
import com.scalar.db.io.Key;
import com.scalar.db.util.AdminTestUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
Expand Down Expand Up @@ -50,6 +51,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 Down Expand Up @@ -160,6 +166,12 @@ private boolean isWideningColumnTypeConversionNotFullySupported() {
return JdbcTestUtils.isOracle(rdbEngine) || JdbcTestUtils.isSqlite(rdbEngine);
}

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

@Test
@Override
@DisabledIf("isDb2")
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