Search in sources :

Example 1 with DatabaseConfig

use of com.scalar.db.config.DatabaseConfig in project scalardb by scalar-labs.

the class SchemaLoaderIntegrationTestBase method setUp.

@Before
public void setUp() throws Exception {
    if (!initialized) {
        initialize();
        DatabaseConfig config = getDatabaseConfig();
        namespace1 = getNamespace1();
        namespace2 = getNamespace2();
        writeConfigFile(config.getProperties());
        Map<String, Object> schemaJsonMap = getSchemaJsonMap();
        writeSchemaFile(schemaJsonMap);
        StorageFactory factory = new StorageFactory(config);
        admin = factory.getAdmin();
        consensusCommitAdmin = new ConsensusCommitAdmin(admin, new ConsensusCommitConfig(config.getProperties()));
        initialized = true;
    }
    dropTablesIfExist();
}
Also used : ConsensusCommitConfig(com.scalar.db.transaction.consensuscommit.ConsensusCommitConfig) StorageFactory(com.scalar.db.service.StorageFactory) ConsensusCommitAdmin(com.scalar.db.transaction.consensuscommit.ConsensusCommitAdmin) DatabaseConfig(com.scalar.db.config.DatabaseConfig) Before(org.junit.Before)

Example 2 with DatabaseConfig

use of com.scalar.db.config.DatabaseConfig in project scalardb by scalar-labs.

the class TestUtils method addSuffix.

/**
 * Add a suffix to the metadata database/namespace/schema name and the consensus-commit
 * coordinator table name.
 *
 * @param config the original config
 * @param testName used for the suffix
 * @return config added the suffix
 */
public static DatabaseConfig addSuffix(DatabaseConfig config, String testName) {
    Properties properties = new Properties();
    properties.putAll(config.getProperties());
    // for Cosmos
    String tableMetadataDatabase = properties.getProperty(CosmosConfig.TABLE_METADATA_DATABASE);
    if (tableMetadataDatabase == null) {
        tableMetadataDatabase = CosmosAdmin.METADATA_DATABASE;
    }
    properties.setProperty(CosmosConfig.TABLE_METADATA_DATABASE, tableMetadataDatabase + "_" + testName);
    // for Dynamo
    String tableMetadataNamespace = properties.getProperty(DynamoConfig.TABLE_METADATA_NAMESPACE);
    if (tableMetadataNamespace == null) {
        tableMetadataNamespace = DynamoAdmin.METADATA_NAMESPACE;
    }
    properties.setProperty(DynamoConfig.TABLE_METADATA_NAMESPACE, tableMetadataNamespace + "_" + testName);
    // for JDBC
    String tableMetadataSchema = properties.getProperty(JdbcConfig.TABLE_METADATA_SCHEMA);
    if (tableMetadataSchema == null) {
        tableMetadataSchema = JdbcAdmin.METADATA_SCHEMA;
    }
    properties.setProperty(JdbcConfig.TABLE_METADATA_SCHEMA, tableMetadataSchema + "_" + testName);
    // for consensus-commit
    String coordinatorNamespace = properties.getProperty(ConsensusCommitConfig.COORDINATOR_NAMESPACE);
    if (coordinatorNamespace == null) {
        coordinatorNamespace = Coordinator.NAMESPACE;
    }
    properties.setProperty(ConsensusCommitConfig.COORDINATOR_NAMESPACE, coordinatorNamespace + "_" + testName);
    return new DatabaseConfig(properties);
}
Also used : Properties(java.util.Properties) DatabaseConfig(com.scalar.db.config.DatabaseConfig)

Example 3 with DatabaseConfig

use of com.scalar.db.config.DatabaseConfig in project scalardb by scalar-labs.

the class MultiStorageConfig method loadDatabaseConfigs.

private void loadDatabaseConfigs() {
    String[] storages = getStringArray(getProperties(), STORAGES, null);
    if (storages == null) {
        databaseConfigMap = Collections.emptyMap();
        return;
    }
    ImmutableMap.Builder<String, DatabaseConfig> builder = ImmutableMap.builder();
    for (String storage : storages) {
        Properties dbProps = new Properties();
        for (String propertyName : props.stringPropertyNames()) {
            if (propertyName.startsWith(STORAGES + "." + storage + ".")) {
                dbProps.put(propertyName.replace("multi_storage.storages." + storage + ".", ""), props.getProperty(propertyName));
            }
        }
        if (dbProps.getProperty(DatabaseConfig.STORAGE).equals(MULTI_STORAGE)) {
            throw new IllegalArgumentException("Does not support nested " + MULTI_STORAGE + ": " + storage);
        }
        builder.put(storage, new DatabaseConfig(dbProps));
    }
    databaseConfigMap = builder.build();
}
Also used : ConfigUtils.getString(com.scalar.db.config.ConfigUtils.getString) Properties(java.util.Properties) ImmutableMap(com.google.common.collect.ImmutableMap) DatabaseConfig(com.scalar.db.config.DatabaseConfig)

Example 4 with DatabaseConfig

use of com.scalar.db.config.DatabaseConfig in project scalardb by scalar-labs.

the class CosmosSchemaLoaderWithStorageSpecificArgsIntegrationTest method getCommandArgsForCreationWithCoordinatorTable.

@Override
protected List<String> getCommandArgsForCreationWithCoordinatorTable(String configFile, String schemaFile) throws IOException {
    DatabaseConfig config = new DatabaseConfig(new File(configFile));
    ImmutableList.Builder<String> builder = ImmutableList.<String>builder().add("--cosmos").add("-h").add(config.getContactPoints().get(0)).add("--schema-file").add(schemaFile).add("-p").add(config.getPassword().get());
    CosmosEnv.getDatabasePrefix().ifPresent((prefix) -> builder.add("--table-metadata-database-prefix").add(prefix).add("--coordinator-namespace-prefix").add(prefix));
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) File(java.io.File) DatabaseConfig(com.scalar.db.config.DatabaseConfig)

Example 5 with DatabaseConfig

use of com.scalar.db.config.DatabaseConfig in project scalardb by scalar-labs.

the class JdbcConfigTest method constructor_PropertiesWithInvalidPreparedStatementsPoolPropertiesGiven_ShouldThrowIllegalArgumentException.

@Test
public void constructor_PropertiesWithInvalidPreparedStatementsPoolPropertiesGiven_ShouldThrowIllegalArgumentException() {
    // Arrange
    Properties props = new Properties();
    props.setProperty(DatabaseConfig.CONTACT_POINTS, ANY_JDBC_URL);
    props.setProperty(DatabaseConfig.USERNAME, ANY_USERNAME);
    props.setProperty(DatabaseConfig.PASSWORD, ANY_PASSWORD);
    props.setProperty(DatabaseConfig.STORAGE, JDBC_STORAGE);
    props.setProperty(JdbcConfig.PREPARED_STATEMENTS_POOL_ENABLED, "ddd");
    props.setProperty(JdbcConfig.PREPARED_STATEMENTS_POOL_MAX_OPEN, "eee");
    // Act Assert
    assertThatThrownBy(() -> new JdbcConfig(new DatabaseConfig(props))).isInstanceOf(IllegalArgumentException.class);
}
Also used : Properties(java.util.Properties) DatabaseConfig(com.scalar.db.config.DatabaseConfig) Test(org.junit.jupiter.api.Test)

Aggregations

DatabaseConfig (com.scalar.db.config.DatabaseConfig)66 Properties (java.util.Properties)60 Test (org.junit.jupiter.api.Test)40 StorageFactory (com.scalar.db.service.StorageFactory)6 BasicDataSource (org.apache.commons.dbcp2.BasicDataSource)4 BeforeAll (org.junit.jupiter.api.BeforeAll)3 ImmutableList (com.google.common.collect.ImmutableList)2 ConsensusCommitAdmin (com.scalar.db.transaction.consensuscommit.ConsensusCommitAdmin)2 File (java.io.File)2 Before (org.junit.Before)2 BeforeClass (org.junit.BeforeClass)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ConfigUtils.getString (com.scalar.db.config.ConfigUtils.getString)1 JdbcConfig (com.scalar.db.storage.jdbc.JdbcConfig)1 ConsensusCommitConfig (com.scalar.db.transaction.consensuscommit.ConsensusCommitConfig)1