refactor RandomDataSourceValidateThread

1. add cleanup action at the end of every check
2. change the key of errorCounts from "foo" to "foo-xxxxx"(DruidDataSource.getName())
This commit is contained in:
DigitalSonic
2020-02-06 21:10:17 +08:00
parent 3ebdc2ce4c
commit 5e0dc32798
2 changed files with 70 additions and 34 deletions
@@ -31,6 +31,14 @@ public class RandomDataSourceSelectorWithFilterTest {
String file = "/com/alibaba/druid/pool/ha/ha-datasource.properties";
highAvailableDataSource.setDataSourceFile(file);
highAvailableDataSource.setFilters("haRandomValidator");
RandomDataSourceSelector selector = new RandomDataSourceSelector(highAvailableDataSource);
RandomDataSourceValidateThread thread = new RandomDataSourceValidateThread(selector);
thread.setCheckingIntervalSeconds(2);
selector.setValidateThread(thread);
selector.init();
highAvailableDataSource.setDataSourceSelector(selector);
highAvailableDataSource.init();
initChecker();
}
@@ -45,12 +53,6 @@ public class RandomDataSourceSelectorWithFilterTest {
@Test
public void testSkipValidation() throws Exception {
RandomDataSourceSelector selector = ((RandomDataSourceSelector) highAvailableDataSource.getDataSourceSelector());
RandomDataSourceValidateThread thread = new RandomDataSourceValidateThread(selector);
thread.setCheckingIntervalSeconds(2);
selector.setValidateThread(thread);
selector.init();
Connection conn = highAvailableDataSource.getConnection();
createTable(conn);
String url = conn.getMetaData().getURL();
@@ -63,7 +65,7 @@ public class RandomDataSourceSelectorWithFilterTest {
Thread.sleep(1000);
assertEquals(initValue, checker.getCountValue(url));
Thread.sleep(3000);
Thread.sleep(2500);
int value = checker.getCountValue(url);
LOG.info("URL: " + url + " Value: " + value + " Init: " + initValue);
assertEquals(initValue + 1, value);
@@ -78,12 +80,6 @@ public class RandomDataSourceSelectorWithFilterTest {
@Test
public void testForceValidation() throws Exception {
RandomDataSourceSelector selector = ((RandomDataSourceSelector) highAvailableDataSource.getDataSourceSelector());
RandomDataSourceValidateThread thread = new RandomDataSourceValidateThread(selector);
thread.setCheckingIntervalSeconds(2);
selector.setValidateThread(thread);
selector.init();
Connection conn = highAvailableDataSource.getConnection();
createTable(conn);
String url = conn.getMetaData().getURL();