Optimize the logic in HA Validation.

This commit is contained in:
DigitalSonic
2019-02-25 14:49:45 +08:00
parent 865d052a21
commit c1e73f2fa9
5 changed files with 50 additions and 13 deletions
@@ -40,6 +40,7 @@ public class RandomDataSourceSelectorTest extends BaseRandomDataSourceSelectorTe
assertEquals(10, selector.getValidationSleepSeconds());
assertEquals(10, selector.getValidateThread().getValidationSleepSeconds());
assertEquals(10, selector.getRecoverThread().getValidationSleepSeconds());
assertEquals(5, selector.getBlacklistThreshold());
assertEquals(5, selector.getValidateThread().getBlacklistThreshold());
@@ -31,13 +31,13 @@ public class RandomDataSourceSelectorWithValidationTest {
@Test
public void testOneDataSourceFailAndRecover() throws Exception {
RandomDataSourceSelector selector = ((RandomDataSourceSelector) highAvailableDataSource.getDataSourceSelector());
selector.setCheckingIntervalSeconds(3);
selector.getValidateThread().setCheckingIntervalSeconds(3);
selector.getRecoverThread().setSleepSeconds(3);
selector.init();
DruidDataSource dataSource = (DruidDataSource) highAvailableDataSource.getDataSourceMap().get("foo");
dataSource.setValidationQuery("select xxx from yyy");
Thread.sleep(6 * 1000);
Thread.sleep(10 * 1000);
assertTrue(dataSource.isTestOnReturn());
for (int i = 0; i < 100; i++) {
assertNotEquals(dataSource, selector.get());