Unverified Commit 478186ad authored by 张亮's avatar 张亮 Committed by GitHub
Browse files

Merge pull request #1012 from tristaZero/dev

Enhancement for DCLIntegrateTest
parents 5b158a51 fac3c1f9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -60,6 +60,6 @@ public final class ShardingContext {
        this.executorEngine = executorEngine;
        this.shardingMetaData = shardingMetaData;
        this.showSQL = showSQL;
        shardingDataSourceMetaData = new ShardingDataSourceMetaData(dataSourceMap, shardingRule, databaseType);
        this.shardingDataSourceMetaData = new ShardingDataSourceMetaData(dataSourceMap, shardingRule, databaseType);
    }
}
+0 −37
Original line number Diff line number Diff line
/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

package io.shardingsphere.dbtest.cases.authority.sql;

/**
 * Authority SQL xml entry.
 *
 * @author panjuan
 */
import lombok.Getter;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

@Getter
@XmlAccessorType(XmlAccessType.FIELD)
public final class SQL {
    
    @XmlAttribute(name = "content")
    private String content;
}
+0 −36
Original line number Diff line number Diff line
/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

package io.shardingsphere.dbtest.cases.authority.sql;

import lombok.Getter;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlEnumValue;

/**
 * SQL type for authority.
 *
 * @author panjuan
 */
@Getter
@XmlAccessorType(XmlAccessType.FIELD)
public enum SQLType {
    
    @XmlEnumValue("init") Init, @XmlEnumValue("clean") Clean
}
+42 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import io.shardingsphere.core.api.yaml.YamlMasterSlaveDataSourceFactory;
import io.shardingsphere.core.api.yaml.YamlShardingDataSourceFactory;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.jdbc.core.datasource.ShardingDataSource;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaDataFactory;
import io.shardingsphere.core.parsing.cache.ParsingResultCache;
import io.shardingsphere.dbtest.cases.assertion.IntegrateTestCasesLoader;
import io.shardingsphere.dbtest.env.DatabaseTypeEnvironment;
@@ -44,7 +46,9 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;

@RunWith(Parameterized.class)
@@ -63,6 +67,8 @@ public abstract class BaseIntegrateTest {
    
    private final DataSource dataSource;
    
    private final Map<String, DataSource> instanceDataSourceMap;
    
    static {
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    }
@@ -73,9 +79,11 @@ public abstract class BaseIntegrateTest {
        if (databaseTypeEnvironment.isEnabled()) {
            dataSourceMap = createDataSourceMap(shardingRuleType);
            dataSource = createDataSource(dataSourceMap);
            instanceDataSourceMap = createInstanceDataSourceMap();
        } else {
            dataSourceMap = null;
            dataSource = null;
            instanceDataSourceMap = null;
        }
    }
    
@@ -110,6 +118,40 @@ public abstract class BaseIntegrateTest {
                : YamlShardingDataSourceFactory.createDataSource(dataSourceMap, new File(EnvironmentPath.getShardingRuleResourceFile(shardingRuleType)));
    }
    
    private Map<String, DataSource> createInstanceDataSourceMap() {
        return "masterslave".equals(shardingRuleType) ? dataSourceMap : getShardingInstanceDataSourceMap();
    }
    
    private Map<String, DataSource> getShardingInstanceDataSourceMap() {
        Map<String, DataSource> result = new LinkedHashMap<>();
        Map<String, DataSourceMetaData> dataSourceMetaDataMap = getDataSourceMetaDataMap();
        for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
            if (!isExisted(entry.getKey(), result.keySet(), dataSourceMetaDataMap)) {
                result.put(entry.getKey(), entry.getValue());
            }
        }
        return result;
    }
    
    private boolean isExisted(final String dataSourceName, final Collection<String> existedDataSourceNames,
                              final Map<String, DataSourceMetaData> dataSourceMetaDataMap) {
        for (String each : existedDataSourceNames) {
            if (dataSourceMetaDataMap.get(each).isInSameDatabaseInstance(dataSourceMetaDataMap.get(dataSourceName))) {
                return true;
            }
        }
        return false;
    }
    
    private Map<String, DataSourceMetaData> getDataSourceMetaDataMap() {
        Map<String, DataSourceMetaData> result = new LinkedHashMap<>();
        for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
            result.put(entry.getKey(), DataSourceMetaDataFactory.getDataSourceMetaData
                    (databaseTypeEnvironment.getDatabaseType(), entry.getValue()));
        }
        return result;
    }
    
    @BeforeClass
    public static void createDatabasesAndTables() throws JAXBException, IOException, SQLException {
        for (String each : integrateTestEnvironment.getShardingRuleTypes()) {
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public abstract class BaseDCLIntegrateTest extends SingleIntegrateTest {
    public BaseDCLIntegrateTest(final String sqlCaseId, final String path, final DCLIntegrateTestCaseAssertion assertion, final String shardingRuleType,
                                final DatabaseTypeEnvironment databaseTypeEnvironment, final SQLCaseType caseType) throws IOException, JAXBException, SQLException, ParseException {
        super(sqlCaseId, path, assertion, shardingRuleType, databaseTypeEnvironment, caseType);
        authorityEnvironmentManager = new AuthorityEnvironmentManager(EnvironmentPath.getAuthorityResourcesPath(shardingRuleType), getDataSource(), getDatabaseTypeEnvironment().getDatabaseType());
        authorityEnvironmentManager = new AuthorityEnvironmentManager(EnvironmentPath.getAuthorityResourcesPath(shardingRuleType), getInstanceDataSourceMap(), getDatabaseTypeEnvironment().getDatabaseType());
    }
    
    @Before
Loading