Skip to content

Commit

Permalink
Backport to branch(3.9): Remove unnecessary `scalardb.cosmos.database…
Browse files Browse the repository at this point in the history
…_prefix` property (#1971)
  • Loading branch information
komamitsu authored Jun 20, 2024
1 parent c42970c commit 96a01d3
Show file tree
Hide file tree
Showing 19 changed files with 4 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.scalar.db.transaction.consensuscommit.ConsensusCommitAdminIntegrationTestBase;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

public class ConsensusCommitAdminIntegrationTestWithCosmos
Expand All @@ -13,26 +12,6 @@ protected Properties getProps(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespace1() {
return getNamespace(super.getNamespace1());
}

@Override
protected String getNamespace2() {
return getNamespace(super.getNamespace2());
}

@Override
protected String getNamespace3() {
return getNamespace(super.getNamespace3());
}

private String getNamespace(String namespace) {
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespace).orElse(namespace);
}

@Override
protected Map<String, String> getCreationOptions() {
return CosmosEnv.getCreationOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.scalar.db.transaction.consensuscommit.ConsensusCommitAdminRepairTableIntegrationTestBase;
import com.scalar.db.util.AdminTestUtils;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import org.junit.jupiter.api.Test;

Expand All @@ -18,16 +17,6 @@ protected Properties getProps(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespace() {
return getNamespace(super.getNamespace());
}

private String getNamespace(String namespace) {
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespace).orElse(namespace);
}

@Override
protected Map<String, String> getCreationOptions() {
return CosmosEnv.getCreationOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.scalar.db.transaction.consensuscommit.ConsensusCommitIntegrationTestBase;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

public class ConsensusCommitIntegrationTestWithCosmos extends ConsensusCommitIntegrationTestBase {
Expand All @@ -12,13 +11,6 @@ protected Properties getProps(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespaceBaseName() {
String namespaceBaseName = super.getNamespaceBaseName();
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespaceBaseName).orElse(namespaceBaseName);
}

@Override
protected Map<String, String> getCreationOptions() {
return CosmosEnv.getCreationOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.scalar.db.transaction.consensuscommit.ConsensusCommitSpecificIntegrationTestBase;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

public class ConsensusCommitSpecificIntegrationTestWithCosmos
Expand All @@ -13,21 +12,6 @@ protected Properties getProperties(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespace1() {
return getNamespace(super.getNamespace1());
}

@Override
protected String getNamespace2() {
return getNamespace(super.getNamespace2());
}

private String getNamespace(String namespace) {
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespace).orElse(namespace);
}

@Override
protected Map<String, String> getCreationOptions() {
return CosmosEnv.getCreationOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.scalar.db.api.DistributedStorageAdminIntegrationTestBase;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

public class CosmosAdminIntegrationTest extends DistributedStorageAdminIntegrationTestBase {
Expand All @@ -12,26 +11,6 @@ protected Properties getProperties(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespace1() {
return getNamespace(super.getNamespace1());
}

@Override
protected String getNamespace2() {
return getNamespace(super.getNamespace2());
}

@Override
protected String getNamespace3() {
return getNamespace(super.getNamespace3());
}

private String getNamespace(String namespace) {
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespace).orElse(namespace);
}

@Override
protected Map<String, String> getCreationOptions() {
return CosmosEnv.getCreationOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.util.AdminTestUtils;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import org.junit.jupiter.api.Test;

Expand All @@ -18,16 +17,6 @@ protected Properties getProperties(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespace() {
return getNamespace(super.getNamespace());
}

private String getNamespace(String namespace) {
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespace).orElse(namespace);
}

@Override
protected Map<String, String> getCreationOptions() {
return CosmosEnv.getCreationOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.scalar.db.api.DistributedStorageColumnValueIntegrationTestBase;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

public class CosmosColumnValueIntegrationTest
Expand All @@ -12,13 +11,6 @@ protected Properties getProperties(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespace() {
String namespace = super.getNamespace();
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespace).orElse(namespace);
}

@Override
protected Map<String, String> getCreationOptions() {
return CosmosEnv.getCreationOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

public class CosmosConditionalMutationIntegrationTest
Expand All @@ -16,13 +15,6 @@ protected Properties getProperties(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespace() {
String namespace = super.getNamespace();
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespace).orElse(namespace);
}

@Override
protected int getThreadNum() {
return 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

import com.google.common.collect.ImmutableMap;
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.transaction.consensuscommit.ConsensusCommitConfig;
import com.scalar.db.transaction.consensuscommit.Coordinator;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

public final class CosmosEnv {
private static final String PROP_COSMOS_URI = "scalardb.cosmos.uri";
private static final String PROP_COSMOS_PASSWORD = "scalardb.cosmos.password";
private static final String PROP_COSMOS_DATABASE_PREFIX = "scalardb.cosmos.database_prefix";
private static final String PROP_COSMOS_CREATE_OPTIONS = "scalardb.cosmos.create_options";

private static final ImmutableMap<String, String> DEFAULT_COSMOS_CREATE_OPTIONS =
Expand All @@ -22,35 +18,19 @@ private CosmosEnv() {}
public static Properties getProperties(String testName) {
String contactPoint = System.getProperty(PROP_COSMOS_URI);
String password = System.getProperty(PROP_COSMOS_PASSWORD);
Optional<String> databasePrefix = getDatabasePrefix();

Properties props = new Properties();
props.setProperty(DatabaseConfig.CONTACT_POINTS, contactPoint);
props.setProperty(DatabaseConfig.PASSWORD, password);
props.setProperty(DatabaseConfig.STORAGE, "cosmos");

if (databasePrefix.isPresent()) {
// Add the prefix and testName as a metadata database suffix
props.setProperty(
CosmosConfig.TABLE_METADATA_DATABASE,
databasePrefix.get() + CosmosAdmin.METADATA_DATABASE + "_" + testName);

props.setProperty(
ConsensusCommitConfig.COORDINATOR_NAMESPACE,
databasePrefix.get() + Coordinator.NAMESPACE);
} else {
// Add testName as a metadata database suffix
props.setProperty(
CosmosConfig.TABLE_METADATA_DATABASE, CosmosAdmin.METADATA_DATABASE + "_" + testName);
}
// Add testName as a metadata database suffix
props.setProperty(
CosmosConfig.TABLE_METADATA_DATABASE, CosmosAdmin.METADATA_DATABASE + "_" + testName);

return props;
}

public static Optional<String> getDatabasePrefix() {
return Optional.ofNullable(System.getProperty(PROP_COSMOS_DATABASE_PREFIX));
}

public static Map<String, String> getCreationOptions() {
String createOptionsString = System.getProperty(PROP_COSMOS_CREATE_OPTIONS);
if (createOptionsString == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.scalar.db.api.DistributedStorageIntegrationTestBase;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

public class CosmosIntegrationTest extends DistributedStorageIntegrationTestBase {
Expand All @@ -12,13 +11,6 @@ protected Properties getProperties(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespace() {
String namespace = super.getNamespace();
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespace).orElse(namespace);
}

@Override
protected Map<String, String> getCreationOptions() {
return CosmosEnv.getCreationOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.scalar.db.api.DistributedStorageMultipleClusteringKeyScanIntegrationTestBase;
import com.scalar.db.io.DataType;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

public class CosmosMultipleClusteringKeyScanIntegrationTest
Expand All @@ -16,13 +15,6 @@ protected Properties getProperties(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespaceBaseName() {
String namespaceBaseName = super.getNamespaceBaseName();
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespaceBaseName).orElse(namespaceBaseName);
}

@Override
protected ListMultimap<DataType, DataType> getClusteringKeyTypes() {
// Return types without BLOB because blob is not supported for clustering key for now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.scalar.db.api.DistributedStorageMultiplePartitionKeyIntegrationTestBase;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

public class CosmosMultiplePartitionKeyIntegrationTest
Expand All @@ -12,13 +11,6 @@ protected Properties getProperties(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespaceBaseName() {
String namespaceBaseName = super.getNamespaceBaseName();
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespaceBaseName).orElse(namespaceBaseName);
}

@Override
protected int getThreadNum() {
return 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.scalar.db.schemaloader.SchemaLoaderIntegrationTestBase;
import com.scalar.db.util.AdminTestUtils;
import java.util.Optional;
import java.util.Properties;

public class CosmosSchemaLoaderIntegrationTest extends SchemaLoaderIntegrationTestBase {
Expand All @@ -12,21 +11,6 @@ protected Properties getProperties(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespace1() {
return getNamespace(super.getNamespace1());
}

@Override
protected String getNamespace2() {
return getNamespace(super.getNamespace2());
}

private String getNamespace(String namespace) {
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespace).orElse(namespace);
}

@Override
protected AdminTestUtils getAdminTestUtils(String testName) {
return new CosmosAdminTestUtils(getProperties(testName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.scalar.db.api.DistributedStorageSecondaryIndexIntegrationTestBase;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

public class CosmosSecondaryIndexIntegrationTest
Expand All @@ -12,13 +11,6 @@ protected Properties getProperties(String testName) {
return CosmosEnv.getProperties(testName);
}

@Override
protected String getNamespace() {
String namespace = super.getNamespace();
Optional<String> databasePrefix = CosmosEnv.getDatabasePrefix();
return databasePrefix.map(prefix -> prefix + namespace).orElse(namespace);
}

@Override
protected Map<String, String> getCreationOptions() {
return CosmosEnv.getCreationOptions();
Expand Down
Loading

0 comments on commit 96a01d3

Please sign in to comment.