Skip to content

Commit

Permalink
Add Namespaces management (scalar-labs#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
Torch3333 authored Aug 23, 2023
1 parent 99e3b76 commit 99010f4
Show file tree
Hide file tree
Showing 73 changed files with 2,694 additions and 1,179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosContainer;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.CosmosStoredProcedure;
import com.azure.cosmos.models.CosmosItemRequestOptions;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
Expand Down Expand Up @@ -34,26 +33,22 @@ public CosmosAdminTestUtils(Properties properties) {
.buildClient();
metadataDatabase =
new CosmosConfig(new DatabaseConfig(properties))
.getTableMetadataDatabase()
.getMetadataDatabase()
.orElse(CosmosAdmin.METADATA_DATABASE);
}

@Override
public void dropMetadataTable() {
client.getDatabase(metadataDatabase).delete();
try {
client.getDatabase(metadataDatabase).read();
} catch (CosmosException e) {
if (e.getStatusCode() != 404) {
throw new RuntimeException("Dropping the metadata table failed", e);
}
}
client
.getDatabase(metadataDatabase)
.getContainer(CosmosAdmin.TABLE_METADATA_CONTAINER)
.delete();
}

@Override
public void truncateMetadataTable() {
CosmosContainer container =
client.getDatabase(metadataDatabase).getContainer(CosmosAdmin.METADATA_CONTAINER);
client.getDatabase(metadataDatabase).getContainer(CosmosAdmin.TABLE_METADATA_CONTAINER);

CosmosPagedIterable<Record> records =
container.queryItems("SELECT t.id FROM t", new CosmosQueryRequestOptions(), Record.class);
Expand All @@ -72,7 +67,7 @@ public void corruptMetadata(String namespace, String table) {
.build();

CosmosContainer container =
client.getDatabase(metadataDatabase).getContainer(CosmosAdmin.METADATA_CONTAINER);
client.getDatabase(metadataDatabase).getContainer(CosmosAdmin.TABLE_METADATA_CONTAINER);
container.upsertItem(corruptedMetadata);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.scalar.db.transaction.consensuscommit.ConsensusCommitAdminIntegrationTestBase;
import java.util.Map;
import java.util.Properties;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class ConsensusCommitAdminIntegrationTestWithDynamo
extends ConsensusCommitAdminIntegrationTestBase {
Expand All @@ -19,56 +17,8 @@ protected Map<String, String> getCreationOptions() {
return DynamoEnv.getCreationOptions();
}

// 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

@Override
protected boolean isIndexOnBooleanColumnSupported() {
return false;
}

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

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

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

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

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

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

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

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

@Disabled
@Test
@Override
public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.scalar.db.api.DistributedStorageAdminIntegrationTestBase;
import java.util.Map;
import java.util.Properties;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class DynamoAdminIntegrationTest extends DistributedStorageAdminIntegrationTestBase {

Expand All @@ -22,52 +20,4 @@ protected Map<String, String> getCreationOptions() {
protected boolean isIndexOnBooleanColumnSupported() {
return false;
}

// 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 createNamespace_ForNonExistingNamespace_ShouldCreateNamespaceProperly() {}

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

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

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

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

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

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

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

@Disabled
@Test
@Override
public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DynamoAdminTestUtils(Properties properties) {
.build();
metadataNamespace =
config.getNamespacePrefix().orElse("")
+ config.getTableMetadataNamespace().orElse(DynamoAdmin.METADATA_NAMESPACE);
+ config.getMetadataNamespace().orElse(DynamoAdmin.METADATA_NAMESPACE);
namespacePrefix = config.getNamespacePrefix().orElse("");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.scalar.db.storage.jdbc;

import com.scalar.db.api.TableMetadata;
import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.transaction.consensuscommit.ConsensusCommitAdminImportTableIntegrationTestBase;
import java.sql.SQLException;
import java.util.Map;
Expand Down Expand Up @@ -47,7 +48,8 @@ public void importTable_ShouldWorkProperly() throws Exception {
@Test
@Override
@EnabledIf("isSqlite")
public void importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationException() {
public void importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationException()
throws ExecutionException {
super.importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.scalar.db.storage.jdbc;

import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.transaction.consensuscommit.ConsensusCommitAdminIntegrationTestBase;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;

public class ConsensusCommitAdminIntegrationTestWithJdbcDatabase
extends ConsensusCommitAdminIntegrationTestBase {
Expand All @@ -13,78 +10,4 @@ public class ConsensusCommitAdminIntegrationTestWithJdbcDatabase
protected Properties getProps(String testName) {
return JdbcEnv.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.

@SuppressWarnings("unused")
private boolean isSqlite() {
return JdbcEnv.isSqlite();
}

@Test
@Override
@DisabledIf("isSqlite")
public void createNamespace_ForNonExistingNamespace_ShouldCreateNamespaceProperly()
throws ExecutionException {
super.createNamespace_ForNonExistingNamespace_ShouldCreateNamespaceProperly();
}

@Test
@Override
@DisabledIf("isSqlite")
public void createNamespace_ForExistingNamespace_ShouldThrowIllegalArgumentException() {
super.createNamespace_ForExistingNamespace_ShouldThrowIllegalArgumentException();
}

@Test
@Override
@DisabledIf("isSqlite")
public void createNamespace_IfNotExists_ForExistingNamespace_ShouldNotThrowAnyException() {
super.createNamespace_IfNotExists_ForExistingNamespace_ShouldNotThrowAnyException();
}

@Test
@Override
@DisabledIf("isSqlite")
public void dropNamespace_ForNonExistingNamespace_ShouldDropNamespaceProperly()
throws ExecutionException {
super.dropNamespace_ForNonExistingNamespace_ShouldDropNamespaceProperly();
}

@Test
@Override
@DisabledIf("isSqlite")
public void dropNamespace_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() {
super.dropNamespace_ForNonExistingNamespace_ShouldThrowIllegalArgumentException();
}

@Test
@Override
@DisabledIf("isSqlite")
public void dropNamespace_ForNonEmptyNamespace_ShouldThrowIllegalArgumentException()
throws ExecutionException {
super.dropNamespace_ForNonEmptyNamespace_ShouldThrowIllegalArgumentException();
}

@Test
@Override
@DisabledIf("isSqlite")
public void dropNamespace_IfExists_ForNonExistingNamespace_ShouldNotThrowAnyException() {
super.dropNamespace_IfExists_ForNonExistingNamespace_ShouldNotThrowAnyException();
}

@Test
@Override
@DisabledIf("isSqlite")
public void namespaceExists_ShouldReturnCorrectResults() throws ExecutionException {
super.namespaceExists_ShouldReturnCorrectResults();
}

@Test
@Override
@DisabledIf("isSqlite")
public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() {
super.createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.scalar.db.api.DistributedStorageAdminImportTableIntegrationTestBase;
import com.scalar.db.api.TableMetadata;
import com.scalar.db.exception.storage.ExecutionException;
import java.sql.SQLException;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -47,7 +48,8 @@ public void importTable_ShouldWorkProperly() throws Exception {
@Test
@Override
@EnabledIf("isSqlite")
public void importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationException() {
public void importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationException()
throws ExecutionException {
super.importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,10 @@ public Map<String, TableMetadata> createExistingDatabaseWithAllDataTypes(String
results.put(table, null);
});

createExistingDatabase(namespace);
execute(sqls.toArray(new String[0]));
return results;
}

public void createExistingDatabase(String namespace) throws SQLException {
execute(rdbEngine.createNamespaceSqls(rdbEngine.enclose(namespace)));
}

public void dropTable(String namespace, String table) throws SQLException {
String dropTable = "DROP TABLE " + rdbEngine.encloseFullTableName(namespace, table);
execute(dropTable);
Expand Down
Loading

0 comments on commit 99010f4

Please sign in to comment.