Enhance RandomDataSourceSelector

1. shorten the checking interval when validate failed
2. provide some parameters in higher level
3. add a sleep before validation (default 0)
4. validate the DataSource concurrently
This commit is contained in:
DigitalSonic
2019-02-01 18:21:16 +08:00
parent 65fafdb67a
commit b6c90db170
6 changed files with 147 additions and 27 deletions
@@ -30,8 +30,10 @@ public class RandomDataSourceSelectorWithValidationTest {
@Test
public void testOneDataSourceFailAndRecover() throws Exception {
((RandomDataSourceSelector) highAvailableDataSource.getDataSourceSelector()).getValidateThread().setSleepSeconds(3);
((RandomDataSourceSelector) highAvailableDataSource.getDataSourceSelector()).getRecoverThread().setSleepSeconds(3);
RandomDataSourceSelector selector = ((RandomDataSourceSelector) highAvailableDataSource.getDataSourceSelector());
selector.setCheckingIntervalSeconds(3);
selector.getRecoverThread().setSleepSeconds(3);
selector.init();
Thread.sleep(30 * 1000);
@@ -57,7 +59,7 @@ public class RandomDataSourceSelectorWithValidationTest {
@Test
public void testAllDataSourceFail() throws Exception {
((RandomDataSourceSelector) highAvailableDataSource.getDataSourceSelector()).getValidateThread().setSleepSeconds(3);
((RandomDataSourceSelector) highAvailableDataSource.getDataSourceSelector()).getValidateThread().setCheckingIntervalSeconds(3);
((RandomDataSourceSelector) highAvailableDataSource.getDataSourceSelector()).getRecoverThread().setSleepSeconds(3);
Thread.sleep(30 * 1000);