Search in sources :

Example 41 with DatabaseConfig

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

the class MultiStorageConfigTest method constructor_NonExistentStorageForDefaultGiven_ShouldThrowIllegalArgumentException.

@Test
public void constructor_NonExistentStorageForDefaultGiven_ShouldThrowIllegalArgumentException() {
    // Arrange
    Properties props = new Properties();
    props.setProperty(DatabaseConfig.STORAGE, "multi-storage");
    props.setProperty(MultiStorageConfig.STORAGES, "cassandra,mysql");
    props.setProperty(MultiStorageConfig.STORAGES + ".cassandra.storage", "cassandra");
    props.setProperty(MultiStorageConfig.STORAGES + ".cassandra.contact_points", "localhost");
    props.setProperty(MultiStorageConfig.STORAGES + ".cassandra.contact_port", "7000");
    props.setProperty(MultiStorageConfig.STORAGES + ".cassandra.username", "cassandra");
    props.setProperty(MultiStorageConfig.STORAGES + ".cassandra.password", "cassandra");
    props.setProperty(MultiStorageConfig.STORAGES + ".mysql.storage", "jdbc");
    props.setProperty(MultiStorageConfig.STORAGES + ".mysql.contact_points", "jdbc:mysql://localhost:3306/");
    props.setProperty(MultiStorageConfig.STORAGES + ".mysql.username", "root");
    props.setProperty(MultiStorageConfig.STORAGES + ".mysql.password", "mysql");
    props.setProperty(MultiStorageConfig.TABLE_MAPPING, "user.order:cassandra,user.customer:mysql,coordinator.state:cassandra");
    props.setProperty(MultiStorageConfig.NAMESPACE_MAPPING, "namespace1:cassandra,namespace2:mysql");
    // non-existent storage
    props.setProperty(MultiStorageConfig.DEFAULT_STORAGE, "dynamo");
    // Act Assert
    assertThatThrownBy(() -> new MultiStorageConfig(new DatabaseConfig(props))).isInstanceOf(IllegalArgumentException.class);
}
Also used : Properties(java.util.Properties) DatabaseConfig(com.scalar.db.config.DatabaseConfig) Test(org.junit.jupiter.api.Test)

Example 42 with DatabaseConfig

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

the class MultiStorageConfigTest method constructor_WrongStorageNameGiven_ShouldThrowIllegalArgumentException.

@Test
public void constructor_WrongStorageNameGiven_ShouldThrowIllegalArgumentException() {
    Properties props = new Properties();
    // wrong
    props.setProperty(DatabaseConfig.STORAGE, "aaa");
    props.setProperty(MultiStorageConfig.STORAGES, "cassandra,mysql");
    props.setProperty(MultiStorageConfig.STORAGES + ".cassandra.storage", "cassandra");
    props.setProperty(MultiStorageConfig.STORAGES + ".cassandra.contact_points", "localhost");
    props.setProperty(MultiStorageConfig.STORAGES + ".cassandra.contact_port", "7000");
    props.setProperty(MultiStorageConfig.STORAGES + ".cassandra.username", "cassandra");
    props.setProperty(MultiStorageConfig.STORAGES + ".cassandra.password", "cassandra");
    props.setProperty(MultiStorageConfig.STORAGES + ".mysql.storage", "jdbc");
    props.setProperty(MultiStorageConfig.STORAGES + ".mysql.contact_points", "jdbc:mysql://localhost:3306/");
    props.setProperty(MultiStorageConfig.STORAGES + ".mysql.username", "root");
    props.setProperty(MultiStorageConfig.STORAGES + ".mysql.password", "mysql");
    props.setProperty(MultiStorageConfig.TABLE_MAPPING, "user.order:cassandra,user.customer:mysql,coordinator.state:cassandra");
    props.setProperty(MultiStorageConfig.NAMESPACE_MAPPING, "namespace1:cassandra,namespace2:mysql");
    props.setProperty(MultiStorageConfig.DEFAULT_STORAGE, "cassandra");
    // Act Assert
    assertThatThrownBy(() -> new MultiStorageConfig(new DatabaseConfig(props))).isInstanceOf(IllegalArgumentException.class);
}
Also used : Properties(java.util.Properties) DatabaseConfig(com.scalar.db.config.DatabaseConfig) Test(org.junit.jupiter.api.Test)

Example 43 with DatabaseConfig

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

the class GrpcConfigTest method constructor_PropertiesWithInvalidDeadlineDurationMillisGiven_ShouldThrowIllegalArgumentException.

@Test
public void constructor_PropertiesWithInvalidDeadlineDurationMillisGiven_ShouldThrowIllegalArgumentException() {
    // Arrange
    Properties props = new Properties();
    props.setProperty(DatabaseConfig.CONTACT_POINTS, ANY_HOST);
    props.setProperty(DatabaseConfig.STORAGE, "grpc");
    props.setProperty(GrpcConfig.DEADLINE_DURATION_MILLIS, "aaa");
    // Act
    assertThatThrownBy(() -> new GrpcConfig(new DatabaseConfig(props))).isInstanceOf(IllegalArgumentException.class);
}
Also used : Properties(java.util.Properties) DatabaseConfig(com.scalar.db.config.DatabaseConfig) Test(org.junit.jupiter.api.Test)

Example 44 with DatabaseConfig

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

the class GrpcConfigTest method constructor_PropertiesWithValidDeadlineDurationMillisGiven_ShouldLoadProperly.

@Test
public void constructor_PropertiesWithValidDeadlineDurationMillisGiven_ShouldLoadProperly() {
    // Arrange
    Properties props = new Properties();
    props.setProperty(DatabaseConfig.CONTACT_POINTS, ANY_HOST);
    props.setProperty(DatabaseConfig.STORAGE, "grpc");
    props.setProperty(GrpcConfig.DEADLINE_DURATION_MILLIS, "5000");
    // Act
    GrpcConfig config = new GrpcConfig(new DatabaseConfig(props));
    // Assert
    assertThat(config.getHost()).isEqualTo(ANY_HOST);
    assertThat(config.getDeadlineDurationMillis()).isEqualTo(5000);
}
Also used : Properties(java.util.Properties) DatabaseConfig(com.scalar.db.config.DatabaseConfig) Test(org.junit.jupiter.api.Test)

Example 45 with DatabaseConfig

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

the class ConsensusCommitConfigTest method constructor_PropertiesWithCoordinatorNamespaceGiven_ShouldLoadProperly.

@Test
public void constructor_PropertiesWithCoordinatorNamespaceGiven_ShouldLoadProperly() {
    // Arrange
    Properties props = new Properties();
    props.setProperty(ConsensusCommitConfig.COORDINATOR_NAMESPACE, "changed_coordinator");
    // Act
    ConsensusCommitConfig config = new ConsensusCommitConfig(new DatabaseConfig(props));
    // Assert
    assertThat(config.getCoordinatorNamespace()).isPresent();
    assertThat(config.getCoordinatorNamespace().get()).isEqualTo("changed_coordinator");
}
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