Search in sources :

Example 6 with ShardingProperties

use of io.shardingjdbc.core.constant.ShardingProperties in project sharding-jdbc by shardingjdbc.

the class SpringBootShardingTest method assertWithShardingDataSource.

@Test
public void assertWithShardingDataSource() throws NoSuchFieldException, IllegalAccessException {
    assertTrue(dataSource instanceof ShardingDataSource);
    Field field = ShardingDataSource.class.getDeclaredField("shardingContext");
    field.setAccessible(true);
    ShardingContext shardingContext = (ShardingContext) field.get(dataSource);
    for (DataSource each : shardingContext.getDataSourceMap().values()) {
        assertThat(((BasicDataSource) each).getMaxTotal(), is(16));
    }
    assertTrue(shardingContext.isShowSQL());
    Map<String, Object> configMap = new ConcurrentHashMap<>();
    configMap.put("key1", "value1");
    assertThat(ConfigMapContext.getInstance().getShardingConfig(), is(configMap));
    Field propertiesField = ShardingDataSource.class.getDeclaredField("shardingProperties");
    propertiesField.setAccessible(true);
    ShardingProperties shardingProperties = (ShardingProperties) propertiesField.get(dataSource);
    assertTrue((Boolean) shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW));
    assertThat((Integer) shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE), is(100));
}
Also used : Field(java.lang.reflect.Field) ShardingDataSource(io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource) ShardingProperties(io.shardingjdbc.core.constant.ShardingProperties) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ShardingContext(io.shardingjdbc.core.jdbc.core.ShardingContext) ShardingDataSource(io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ShardingProperties (io.shardingjdbc.core.constant.ShardingProperties)6 Test (org.junit.Test)5 ShardingDataSource (io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource)4 ShardingContext (io.shardingjdbc.core.jdbc.core.ShardingContext)3 Field (java.lang.reflect.Field)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 DataSource (javax.sql.DataSource)3 HashMap (java.util.HashMap)2 BasicDataSource (org.apache.commons.dbcp2.BasicDataSource)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ExecutorEngine (io.shardingjdbc.core.executor.ExecutorEngine)1 SpringShardingDataSource (io.shardingjdbc.spring.datasource.SpringShardingDataSource)1 File (java.io.File)1 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 Properties (java.util.Properties)1