DBVariablesCheck extends AbstractCrossDcIntervalCheck { protected void doCheck() { refreshInterestedDataSources(); interestedDataSources.forEach(dataSourceName -> { DataSource dataSource = dataSourceManager.getDataSource(dataSourceName); if (null == dataSource) return; DatabaseVariablesCheck databaseCheck = MapUtils.getOrCreate(databaseVariablesCheckMap, dataSourceName, () -> { DatabaseVariablesCheck databaseVariablesCheck = new DatabaseVariablesCheck(); variableCheckers.forEach(databaseVariablesCheck::addChecker); return databaseVariablesCheck; }); databaseCheck.check(dataSource); }); }  @PostConstruct @Override void postConstruct();  }
@Test public void testDoCheck() { AtomicInteger checkCnt = new AtomicInteger(0); Mockito.doAnswer(invocation -> { DataSource targetDatasource = invocation.getArgumentAt(0, DataSource.class); logger.info("[testDoCheck] check datasource {}", targetDatasource.getDescriptor()); Matcher matcher = idPattern.matcher(targetDatasource.getDescriptor().getId()); Assert.assertTrue(matcher.find()); Assert.assertEquals(userName, targetDatasource.getDescriptor().getProperty("user", null)); Assert.assertEquals(password, targetDatasource.getDescriptor().getProperty("password", null)); String datasourceUrl = targetDatasource.getDescriptor().getProperty("url", null); Assert.assertTrue(targetDbUrls.contains(datasourceUrl)); checkCnt.incrementAndGet(); return null; }).when(checker).check(Matchers.any()); dbVariablesCheck.doCheck(); Assert.assertEquals(2, checkCnt.get()); }