public synchronized void reloadRules() {
        Collection<ShardingSphereRule> toBeReloadedRules = ruleMetaData.getRules().stream()
                .filter(each -> each.getAttributes().findAttribute(MutableDataNodeRuleAttribute.class).isPresent()).collect(Collectors.toList());
        RuleConfiguration ruleConfig = toBeReloadedRules.stream().map(ShardingSphereRule::getConfiguration).findFirst().orElse(null);
        Collection<ShardingSphereRule> rules = new LinkedList<>(ruleMetaData.getRules());
        toBeReloadedRules.stream().findFirst().ifPresent(optional -> {
            rules.removeAll(toBeReloadedRules);
            Map<String, DataSource> dataSources = resourceMetaData.getStorageUnits().entrySet().stream()
                    .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
            rules.add(optional.getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).reloadRule(ruleConfig, name, dataSources, rules));
        });
        ruleMetaData.getRules().clear();
        ruleMetaData.getRules().addAll(rules);
    }
@Test
    void assertReloadRules() {
        Collection<ShardingSphereRule> rules = new LinkedList<>();
        ShardingSphereRule rule0 = mock(ShardingSphereRule.class);
        when(rule0.getConfiguration()).thenReturn(mock(RuleConfiguration.class));
        when(rule0.getAttributes()).thenReturn(new RuleAttributes(mock(MutableDataNodeRuleAttribute.class)));
        rules.add(rule0);
        ShardingSphereRule rule1 = mock(ShardingSphereRule.class);
        when(rule1.getConfiguration()).thenReturn(mock(RuleConfiguration.class));
        when(rule1.getAttributes()).thenReturn(new RuleAttributes());
        rules.add(rule1);
        RuleMetaData ruleMetaData = new RuleMetaData(rules);
        ResourceMetaData resourceMetaData = new ResourceMetaData(Collections.singletonMap("ds", new MockedDataSource()));
        ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", mock(DatabaseType.class), resourceMetaData, ruleMetaData, Collections.emptyMap());
        database.reloadRules();
        assertThat(database.getRuleMetaData().getRules().size(), is(2));
    }