Search in sources :

Example 66 with DatabaseConfig

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

the class MultiStorageSchemaLoaderIntegrationTest method getDatabaseConfig.

@Override
protected DatabaseConfig getDatabaseConfig() {
    Properties props = new Properties();
    props.setProperty(DatabaseConfig.STORAGE, "multi-storage");
    // Define storages, storage1 and storage2
    props.setProperty(MultiStorageConfig.STORAGES, "storage1,storage2");
    DatabaseConfig configForStorage1 = MultiStorageEnv.getDatabaseConfigForStorage1();
    props.setProperty(MultiStorageConfig.STORAGES + ".storage1.storage", configForStorage1.getProperties().getProperty(DatabaseConfig.STORAGE));
    props.setProperty(MultiStorageConfig.STORAGES + ".storage1.contact_points", configForStorage1.getProperties().getProperty(DatabaseConfig.CONTACT_POINTS));
    if (configForStorage1.getProperties().containsValue(DatabaseConfig.CONTACT_PORT)) {
        props.setProperty(MultiStorageConfig.STORAGES + ".storage1.contact_port", configForStorage1.getProperties().getProperty(DatabaseConfig.CONTACT_PORT));
    }
    props.setProperty(MultiStorageConfig.STORAGES + ".storage1.username", configForStorage1.getProperties().getProperty(DatabaseConfig.USERNAME));
    props.setProperty(MultiStorageConfig.STORAGES + ".storage1.password", configForStorage1.getProperties().getProperty(DatabaseConfig.PASSWORD));
    DatabaseConfig configForStorage2 = MultiStorageEnv.getDatabaseConfigForStorage2();
    props.setProperty(MultiStorageConfig.STORAGES + ".storage2.storage", configForStorage2.getProperties().getProperty(DatabaseConfig.STORAGE));
    props.setProperty(MultiStorageConfig.STORAGES + ".storage2.contact_points", configForStorage2.getProperties().getProperty(DatabaseConfig.CONTACT_POINTS));
    if (configForStorage2.getProperties().containsValue(DatabaseConfig.CONTACT_PORT)) {
        props.setProperty(MultiStorageConfig.STORAGES + ".storage2.contact_port", configForStorage2.getProperties().getProperty(DatabaseConfig.CONTACT_PORT));
    }
    props.setProperty(MultiStorageConfig.STORAGES + ".storage2.username", configForStorage2.getProperties().getProperty(DatabaseConfig.USERNAME));
    props.setProperty(MultiStorageConfig.STORAGES + ".storage2.password", configForStorage2.getProperties().getProperty(DatabaseConfig.PASSWORD));
    // Define namespace mapping from namespace1 to storage1, from namespace2 to storage2, and from
    // the coordinator namespace to storage1
    props.setProperty(MultiStorageConfig.NAMESPACE_MAPPING, getNamespace1() + ":storage1," + getNamespace2() + ":storage2," + Coordinator.NAMESPACE + ":storage1");
    // The default storage is storage1
    props.setProperty(MultiStorageConfig.DEFAULT_STORAGE, "storage1");
    return new DatabaseConfig(props);
}
Also used : Properties(java.util.Properties) DatabaseConfig(com.scalar.db.config.DatabaseConfig)

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