Search in sources :

Example 36 with DatabaseConfig

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

the class JdbcConfigTest method constructor_PropertiesWithInvalidAdminConnectionPoolPropertiesGiven_ShouldThrowIllegalArgumentException.

@Test
public void constructor_PropertiesWithInvalidAdminConnectionPoolPropertiesGiven_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.ADMIN_CONNECTION_POOL_MIN_IDLE, "aaa");
    props.setProperty(JdbcConfig.ADMIN_CONNECTION_POOL_MAX_IDLE, "bbb");
    props.setProperty(JdbcConfig.ADMIN_CONNECTION_POOL_MAX_TOTAL, "ccc");
    // 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)

Example 37 with DatabaseConfig

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

the class JdbcConfigTest method constructor_PropertiesWithoutConnectionPoolPropertiesGiven_ShouldLoadProperlyAndUseDefaultValues.

@Test
public void constructor_PropertiesWithoutConnectionPoolPropertiesGiven_ShouldLoadProperlyAndUseDefaultValues() {
    // 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);
    // Act
    JdbcConfig config = new JdbcConfig(new DatabaseConfig(props));
    // Assert
    assertThat(config.getJdbcUrl()).isEqualTo(ANY_JDBC_URL);
    assertThat(config.getUsername().isPresent()).isTrue();
    assertThat(config.getUsername().get()).isEqualTo(ANY_USERNAME);
    assertThat(config.getPassword().isPresent()).isTrue();
    assertThat(config.getPassword().get()).isEqualTo(ANY_PASSWORD);
    assertThat(config.getConnectionPoolMinIdle()).isEqualTo(JdbcConfig.DEFAULT_CONNECTION_POOL_MIN_IDLE);
    assertThat(config.getConnectionPoolMaxIdle()).isEqualTo(JdbcConfig.DEFAULT_CONNECTION_POOL_MAX_IDLE);
    assertThat(config.getConnectionPoolMaxTotal()).isEqualTo(JdbcConfig.DEFAULT_CONNECTION_POOL_MAX_TOTAL);
    assertThat(config.isPreparedStatementsPoolEnabled()).isEqualTo(JdbcConfig.DEFAULT_PREPARED_STATEMENTS_POOL_ENABLED);
    assertThat(config.getPreparedStatementsPoolMaxOpen()).isEqualTo(JdbcConfig.DEFAULT_PREPARED_STATEMENTS_POOL_MAX_OPEN);
    assertThat(config.getIsolation()).isNotPresent();
    assertThat(config.getTableMetadataSchema()).isNotPresent();
    assertThat(config.getTableMetadataConnectionPoolMinIdle()).isEqualTo(JdbcConfig.DEFAULT_TABLE_METADATA_CONNECTION_POOL_MIN_IDLE);
    assertThat(config.getTableMetadataConnectionPoolMaxIdle()).isEqualTo(JdbcConfig.DEFAULT_TABLE_METADATA_CONNECTION_POOL_MAX_IDLE);
    assertThat(config.getTableMetadataConnectionPoolMaxTotal()).isEqualTo(JdbcConfig.DEFAULT_TABLE_METADATA_CONNECTION_POOL_MAX_TOTAL);
}
Also used : Properties(java.util.Properties) DatabaseConfig(com.scalar.db.config.DatabaseConfig) Test(org.junit.jupiter.api.Test)

Example 38 with DatabaseConfig

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

the class JdbcUtilsTest method initDataSourceForTableMetadata_ShouldReturnProperDataSource.

@Test
public void initDataSourceForTableMetadata_ShouldReturnProperDataSource() throws SQLException {
    // Arrange
    Properties properties = new Properties();
    properties.setProperty(DatabaseConfig.CONTACT_POINTS, "jdbc:oracle:thin:@localhost:1521/XEPDB1");
    properties.setProperty(DatabaseConfig.USERNAME, "user");
    properties.setProperty(DatabaseConfig.PASSWORD, "oracle");
    properties.setProperty(DatabaseConfig.STORAGE, "jdbc");
    properties.setProperty(JdbcConfig.TABLE_METADATA_CONNECTION_POOL_MIN_IDLE, "100");
    properties.setProperty(JdbcConfig.TABLE_METADATA_CONNECTION_POOL_MAX_IDLE, "200");
    properties.setProperty(JdbcConfig.TABLE_METADATA_CONNECTION_POOL_MAX_TOTAL, "300");
    JdbcConfig config = new JdbcConfig(new DatabaseConfig(properties));
    // Act
    BasicDataSource tableMetadataDataSource = JdbcUtils.initDataSourceForTableMetadata(config);
    // Assert
    assertThat(tableMetadataDataSource.getUrl()).isEqualTo("jdbc:oracle:thin:@localhost:1521/XEPDB1");
    assertThat(tableMetadataDataSource.getDriver().getClass().getName()).isEqualTo("oracle.jdbc.OracleDriver");
    assertThat(tableMetadataDataSource.getUsername()).isEqualTo("user");
    assertThat(tableMetadataDataSource.getPassword()).isEqualTo("oracle");
    assertThat(tableMetadataDataSource.getMinIdle()).isEqualTo(100);
    assertThat(tableMetadataDataSource.getMaxIdle()).isEqualTo(200);
    assertThat(tableMetadataDataSource.getMaxTotal()).isEqualTo(300);
    tableMetadataDataSource.close();
}
Also used : Properties(java.util.Properties) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) DatabaseConfig(com.scalar.db.config.DatabaseConfig) Test(org.junit.jupiter.api.Test)

Example 39 with DatabaseConfig

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

the class JdbcUtilsTest method initDataSourceForAdmin_ShouldReturnProperDataSource.

@Test
public void initDataSourceForAdmin_ShouldReturnProperDataSource() throws SQLException {
    // Arrange
    Properties properties = new Properties();
    properties.setProperty(DatabaseConfig.CONTACT_POINTS, "jdbc:sqlserver://localhost:1433");
    properties.setProperty(DatabaseConfig.USERNAME, "user");
    properties.setProperty(DatabaseConfig.PASSWORD, "sqlserver");
    properties.setProperty(DatabaseConfig.STORAGE, "jdbc");
    properties.setProperty(JdbcConfig.ADMIN_CONNECTION_POOL_MIN_IDLE, "100");
    properties.setProperty(JdbcConfig.ADMIN_CONNECTION_POOL_MAX_IDLE, "200");
    properties.setProperty(JdbcConfig.ADMIN_CONNECTION_POOL_MAX_TOTAL, "300");
    JdbcConfig config = new JdbcConfig(new DatabaseConfig(properties));
    // Act
    BasicDataSource adminDataSource = JdbcUtils.initDataSourceForAdmin(config);
    // Assert
    assertThat(adminDataSource.getUrl()).isEqualTo("jdbc:sqlserver://localhost:1433");
    assertThat(adminDataSource.getDriver().getClass().getName()).isEqualTo("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    assertThat(adminDataSource.getUsername()).isEqualTo("user");
    assertThat(adminDataSource.getPassword()).isEqualTo("sqlserver");
    assertThat(adminDataSource.getMinIdle()).isEqualTo(100);
    assertThat(adminDataSource.getMaxIdle()).isEqualTo(200);
    assertThat(adminDataSource.getMaxTotal()).isEqualTo(300);
    adminDataSource.close();
}
Also used : Properties(java.util.Properties) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) DatabaseConfig(com.scalar.db.config.DatabaseConfig) Test(org.junit.jupiter.api.Test)

Example 40 with DatabaseConfig

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

the class MultiStorageConfigTest method constructor_NonExistentStorageGivenInNamespaceMapping_ShouldThrowIllegalArgumentException.

@Test
public void constructor_NonExistentStorageGivenInNamespaceMapping_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, // non-existent storage
    "namespace1:cassandra,namespace2:dynamo");
    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)

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