Java Code Examples for com.taobao.diamond.mockserver.MockServer#setConfigInfos()

The following examples show how to use com.taobao.diamond.mockserver.MockServer#setConfigInfos() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupTestCase.java    From tddl5 with Apache License 2.0 6 votes vote down vote up
protected static void setGroupMockInfo(String groupPath, String key) throws Exception {
    // 获取group信息
    String groupStr = LoadPropsUtil.loadProps2OneLine(groupPath, key);
    if (groupStr == null || StringUtils.isBlank(groupStr)) {
        throw new Exception("指定path = " + groupPath + ",key = " + key + "的group信息为null或者为空字符。");
    }

    // 获取atom信息
    dataMap = new HashMap<String, String>();
    String[] atomArr = groupStr.split(",");
    for (String atom : atomArr) {
        atom = atom.trim();
        atom = atom.substring(0, atom.indexOf(":"));
        initAtomConfig(ATOM_PATH + File.separator + atom, APPNAME, atom);
    }

    // 获取groupkey
    dataMap.put(TGroupDataSource.getFullDbGroupKey(key), groupStr);

    // 建立MockServer
    MockServer.setConfigInfos(dataMap);

    // 获取JdbcTemplate
    tddlJT = getJT(key);
}
 
Example 2
Source File: GroupTestCase.java    From tddl with Apache License 2.0 6 votes vote down vote up
protected static void setGroupMockInfo(String groupPath, String key) throws Exception {
    // 获取group信息
    String groupStr = LoadPropsUtil.loadProps2OneLine(groupPath, key);
    if (groupStr == null || StringUtils.isBlank(groupStr)) {
        throw new Exception("指定path = " + groupPath + ",key = " + key + "的group信息为null或者为空字符。");
    }

    // 获取atom信息
    dataMap = new HashMap<String, String>();
    String[] atomArr = groupStr.split(",");
    for (String atom : atomArr) {
        atom = atom.trim();
        atom = atom.substring(0, atom.indexOf(":"));
        initAtomConfig(ATOM_PATH + File.separator + atom, APPNAME, atom);
    }

    // 获取groupkey
    dataMap.put(TGroupDataSource.getFullDbGroupKey(key), groupStr);

    // 建立MockServer
    MockServer.setConfigInfos(dataMap);

    // 获取JdbcTemplate
    tddlJT = getJT(key);
}
 
Example 3
Source File: ChangeMasterSlaveTest.java    From tddl5 with Apache License 2.0 5 votes vote down vote up
@Test
public void dynamicAddMasterDSTest() throws Exception {
    // 主备切换之前,正常执行一条sql
    String sql = "insert into normaltbl_0001 (pk,gmt_create) values (?,?)";
    tddlJT.update(sql, new Object[] { RANDOM_ID, time });

    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
    Map re = tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
    Assert.assertEquals(time, String.valueOf(re.get("gmt_create")));
    // 清除数据
    clearData(tddlJT, "delete from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });

    // 加库,并将写库转移到新加入的库
    dataMap = new HashMap<String, String>();
    initAtomConfig(ATOM_NORMAL_1_PATH, APPNAME, DBKEY_1); // 加库qatest_normal_1
    dataMap.put(tds.getFullDbGroupKey(),
        "qatest_normal_0:r,qatest_normal_0_bac:r,qatest_normal_1_bac:r,qatest_normal_1:wr");
    // 主备切换(确保推送成功)
    for (int i = 0; i < 3; i++) {
        MockServer.setConfigInfos(dataMap);
        TimeUnit.SECONDS.sleep(SLEEP_TIME);
    }

    // 主备切换之后,正常执行一条sql
    clearData(tddlJT, "delete from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
    sql = "insert into normaltbl_0001 (pk,gmt_create) values (?,?)";
    // 主备切换之后,正常执行一条sql
    tddlJT.update(sql, new Object[] { RANDOM_ID, time });

    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(3);
    re = tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
    Assert.assertEquals(time, String.valueOf(re.get("gmt_create")));
}
 
Example 4
Source File: AtomTestCase.java    From tddl5 with Apache License 2.0 5 votes vote down vote up
protected static void setAtomMockInfo(String path, String appName, String dbKey) throws Exception {
    dataMap = new HashMap<String, String>();

    // -----------------db1
    initAtomConfig(path, appName, dbKey);

    // -----------------MockServer
    MockServer.setConfigInfos(dataMap);
}
 
Example 5
Source File: ChangeMasterSlaveTest.java    From tddl with Apache License 2.0 5 votes vote down vote up
@Test
public void dynamicAddMasterDSTest() throws Exception {
    // 主备切换之前,正常执行一条sql
    String sql = "insert into normaltbl_0001 (pk,gmt_create) values (?,?)";
    tddlJT.update(sql, new Object[] { RANDOM_ID, time });

    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
    Map re = tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
    Assert.assertEquals(time, String.valueOf(re.get("gmt_create")));
    // 清除数据
    clearData(tddlJT, "delete from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });

    // 加库,并将写库转移到新加入的库
    dataMap = new HashMap<String, String>();
    initAtomConfig(ATOM_NORMAL_1_PATH, APPNAME, DBKEY_1); // 加库qatest_normal_1
    dataMap.put(tds.getFullDbGroupKey(),
        "qatest_normal_0:r,qatest_normal_0_bac:r,qatest_normal_1_bac:r,qatest_normal_1:wr");
    // 主备切换(确保推送成功)
    for (int i = 0; i < 3; i++) {
        MockServer.setConfigInfos(dataMap);
        TimeUnit.SECONDS.sleep(SLEEP_TIME);
    }

    // 主备切换之后,正常执行一条sql
    clearData(tddlJT, "delete from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
    sql = "insert into normaltbl_0001 (pk,gmt_create) values (?,?)";
    // 主备切换之后,正常执行一条sql
    tddlJT.update(sql, new Object[] { RANDOM_ID, time });

    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(3);
    re = tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
    Assert.assertEquals(time, String.valueOf(re.get("gmt_create")));
}
 
Example 6
Source File: AtomTestCase.java    From tddl with Apache License 2.0 5 votes vote down vote up
protected static void setAtomMockInfo(String path, String appName, String dbKey) throws Exception {
    dataMap = new HashMap<String, String>();

    // -----------------db1
    initAtomConfig(path, appName, dbKey);

    // -----------------MockServer
    MockServer.setConfigInfos(dataMap);
}
 
Example 7
Source File: BaseAtomGroupTestCase.java    From tddl5 with Apache License 2.0 4 votes vote down vote up
protected static void setMatrixMockInfo(String groupsPath, String key, boolean isOracle) throws Exception {
    // -----------------获取groups信息
    String groupsStr = LoadPropsUtil.loadProps2OneLine(groupsPath, key);
    if (groupsStr == null || StringUtils.isBlank(groupsStr)) {
        throw new Exception("指定path = " + groupsPath + ",key = " + key + "的groups信息为null或者为空字符。");
    }

    // -----------------oracle or mysql
    String groupPath = BaseAtomGroupTestCase.GROUP_PATH;
    String atomPath = BaseAtomGroupTestCase.ATOM_PATH;
    if (isOracle) {
        groupPath = BaseAtomGroupTestCase.GROUP_ORA_PATH;
        atomPath = BaseAtomGroupTestCase.ATOM_ORA_PATH;
    }

    // -----------------获取group信息
    BaseAtomGroupTestCase.dataMap = new HashMap<String, String>();
    String[] groupArr = groupsStr.split(",");

    for (String group : groupArr) {
        group = group.trim();
        String groupStr = "";
        groupStr = LoadPropsUtil.loadProps2OneLine(groupPath + group + BaseAtomGroupTestCase.PROPERTIES_FILE, group);
        if (groupsStr != null && StringUtils.isNotBlank(groupsStr)) {
            // 获取atom信息
            String[] atomArr = groupStr.split(",");
            for (String atom : atomArr) {
                atom = atom.trim();
                atom = atom.substring(0, atom.indexOf(":"));
                BaseAtomGroupTestCase.initAtomConfig(atomPath + atom, BaseAtomGroupTestCase.APPNAME, atom);
            }
            // 获取groupkey
            BaseAtomGroupTestCase.dataMap.put(TGroupDataSource.getFullDbGroupKey(group), groupStr);
        }
    }

    // -----------------dbgroups
    BaseAtomGroupTestCase.dataMap.put(new MessageFormat("com.taobao.tddl.v1_{0}_dbgroups").format(new Object[] { BaseAtomGroupTestCase.APPNAME }),
        groupsStr);

    // 建立MockServer
    MockServer.setConfigInfos(BaseAtomGroupTestCase.dataMap);
}
 
Example 8
Source File: BaseAtomGroupTestCase.java    From tddl with Apache License 2.0 4 votes vote down vote up
protected static void setMatrixMockInfo(String groupsPath, String key, boolean isOracle) throws Exception {
    // -----------------获取groups信息
    String groupsStr = LoadPropsUtil.loadProps2OneLine(groupsPath, key);
    if (groupsStr == null || StringUtils.isBlank(groupsStr)) {
        throw new Exception("指定path = " + groupsPath + ",key = " + key + "的groups信息为null或者为空字符。");
    }

    // -----------------oracle or mysql
    String groupPath = BaseAtomGroupTestCase.GROUP_PATH;
    String atomPath = BaseAtomGroupTestCase.ATOM_PATH;
    if (isOracle) {
        groupPath = BaseAtomGroupTestCase.GROUP_ORA_PATH;
        atomPath = BaseAtomGroupTestCase.ATOM_ORA_PATH;
    }

    // -----------------获取group信息
    BaseAtomGroupTestCase.dataMap = new HashMap<String, String>();
    String[] groupArr = groupsStr.split(",");

    for (String group : groupArr) {
        group = group.trim();
        String groupStr = "";
        groupStr = LoadPropsUtil.loadProps2OneLine(groupPath + group + BaseAtomGroupTestCase.PROPERTIES_FILE, group);
        if (groupsStr != null && StringUtils.isNotBlank(groupsStr)) {
            // 获取atom信息
            String[] atomArr = groupStr.split(",");
            for (String atom : atomArr) {
                atom = atom.trim();
                atom = atom.substring(0, atom.indexOf(":"));
                BaseAtomGroupTestCase.initAtomConfig(atomPath + atom, BaseAtomGroupTestCase.APPNAME, atom);
            }
            // 获取groupkey
            BaseAtomGroupTestCase.dataMap.put(TGroupDataSource.getFullDbGroupKey(group), groupStr);
        }
    }

    // -----------------dbgroups
    BaseAtomGroupTestCase.dataMap.put(new MessageFormat(ConfigServerHelper.DATA_ID_DB_GROUP_KEYS).format(new Object[] { BaseAtomGroupTestCase.APPNAME }),
        groupsStr);

    // 建立MockServer
    MockServer.setConfigInfos(BaseAtomGroupTestCase.dataMap);
}