use of io.shardingjdbc.core.executor.ExecutorEngine in project sharding-jdbc by shardingjdbc.
the class ShardingDataSourceTest method assertRenewWithoutChangeExecutorPoolEngine.
@Test
public void assertRenewWithoutChangeExecutorPoolEngine() throws SQLException, NoSuchFieldException, IllegalAccessException {
DataSource originalDataSource = mockDataSource("H2");
Map<String, DataSource> originalDataSourceMap = new HashMap<>(1, 1);
originalDataSourceMap.put("ds", originalDataSource);
ShardingDataSource shardingDataSource = createShardingDataSource(originalDataSourceMap);
ExecutorEngine originExecutorEngine = getExecutorEngine(shardingDataSource);
DataSource newDataSource = mockDataSource("H2");
Map<String, DataSource> newDataSourceMap = new HashMap<>(1, 1);
newDataSourceMap.put("ds", newDataSource);
shardingDataSource.renew(newDataSourceMap, new ShardingRule(createShardingRuleConfig(newDataSourceMap), newDataSourceMap.keySet()), new Properties());
assertThat(originExecutorEngine, is(getExecutorEngine(shardingDataSource)));
}
use of io.shardingjdbc.core.executor.ExecutorEngine in project sharding-jdbc by shardingjdbc.
the class ShardingDataSourceTest method assertRenewWithChangeExecutorEnginePoolSize.
@Test
public void assertRenewWithChangeExecutorEnginePoolSize() throws SQLException, NoSuchFieldException, IllegalAccessException {
DataSource originalDataSource = mockDataSource("H2");
Map<String, DataSource> originalDataSourceMap = new HashMap<>(1, 1);
originalDataSourceMap.put("ds", originalDataSource);
ShardingDataSource shardingDataSource = createShardingDataSource(originalDataSourceMap);
final ExecutorEngine originExecutorEngine = getExecutorEngine(shardingDataSource);
DataSource newDataSource = mockDataSource("H2");
Map<String, DataSource> newDataSourceMap = new HashMap<>(1, 1);
newDataSourceMap.put("ds", newDataSource);
Properties props = new Properties();
props.setProperty(ShardingPropertiesConstant.EXECUTOR_SIZE.getKey(), "100");
shardingDataSource.renew(newDataSourceMap, new ShardingRule(createShardingRuleConfig(newDataSourceMap), newDataSourceMap.keySet()), props);
assertThat(originExecutorEngine, not(getExecutorEngine(shardingDataSource)));
}
use of io.shardingjdbc.core.executor.ExecutorEngine in project sharding-jdbc by shardingjdbc.
the class ShardingDataSourceTest method getExecutorEngine.
private ExecutorEngine getExecutorEngine(final ShardingDataSource shardingDataSource) throws NoSuchFieldException, IllegalAccessException {
Field field = ShardingDataSource.class.getDeclaredField("executorEngine");
field.setAccessible(true);
return (ExecutorEngine) field.get(shardingDataSource);
}
use of io.shardingjdbc.core.executor.ExecutorEngine in project sharding-jdbc by shardingjdbc.
the class ShardingDataSource method renew.
/**
* Renew sharding data source.
*
* @param newDataSourceMap new data source map
* @param newShardingRule new sharding rule
* @param newProps new sharding properties
*/
public void renew(final Map<String, DataSource> newDataSourceMap, final ShardingRule newShardingRule, final Properties newProps) {
ShardingProperties newShardingProperties = new ShardingProperties(null == newProps ? new Properties() : newProps);
int originalExecutorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE);
int newExecutorSize = newShardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE);
if (originalExecutorSize != newExecutorSize) {
ExecutorEngine originalExecutorEngine = executorEngine;
executorEngine = new ExecutorEngine(newExecutorSize);
originalExecutorEngine.close();
}
boolean newShowSQL = newShardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW);
shardingProperties = newShardingProperties;
shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, newShowSQL);
}
use of io.shardingjdbc.core.executor.ExecutorEngine in project sharding-jdbc by shardingjdbc.
the class AbstractBaseExecutorTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ExecutorExceptionHandler.setExceptionThrown(false);
executorEngine = new ExecutorEngine(Runtime.getRuntime().availableProcessors());
overallExecutionEventListener = new TestOverallExecutionEventListener(eventCaller);
dqlExecutionEventListener = new TestDQLExecutionEventListener(eventCaller);
dmlExecutionEventListener = new TestDMLExecutionEventListener(eventCaller);
EventBusInstance.getInstance().register(overallExecutionEventListener);
EventBusInstance.getInstance().register(dqlExecutionEventListener);
EventBusInstance.getInstance().register(dmlExecutionEventListener);
}
Aggregations