本文整理汇总了Java中com.taobao.diamond.mockserver.MockServer.setConfigInfo方法的典型用法代码示例。如果您正苦于以下问题:Java MockServer.setConfigInfo方法的具体用法?Java MockServer.setConfigInfo怎么用?Java MockServer.setConfigInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.taobao.diamond.mockserver.MockServer
的用法示例。
在下文中一共展示了MockServer.setConfigInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dynamicChangeGlobalDbNameTest
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
@Test
public void dynamicChangeGlobalDbNameTest() throws InterruptedException {
Map re = tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
Assert.assertEquals(time, String.valueOf(re.get("gmt_create")));
MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(DBKEY_0),
"ip=10.232.31.154\r\nport=3306\r\ndbName=qatest_normal\r\ndbType=mysql\r\ndbStatus=RW\r\n");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
try {
tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(DBKEY_0),
"ip=\r\nport=3306\r\ndbName=qatest_normal\r\ndbType=mysql\r\ndbStatus=RW\r\n");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
Assert.fail();
} catch (Exception ex) {
}
MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(DBKEY_0),
"ip=10.232.31.154\r\nport=3306\r\ndbName=qatest_normal_0\r\ndbType=mysql\r\ndbStatus=RW\r\n");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
re = tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
Assert.assertEquals(time, String.valueOf(re.get("gmt_create")));
}
示例2: dynamicChangeGlobalIpTest
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
@Test
public void dynamicChangeGlobalIpTest() throws InterruptedException {
Map re = tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
Assert.assertEquals(time, String.valueOf(re.get("gmt_create")));
MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(DBKEY_0),
"ip=10.13.40.25\r\nport=3306\r\ndbName=qatest_normal_0\r\ndbType=mysql\r\ndbStatus=RW\r\n");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
try {
tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(DBKEY_0),
"ip=10.13.40.25\r\nport=3306\r\ndbName=qatest_normal_0\r\ndbType=mysql\r\ndbStatus=RW\r\n");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
Assert.fail("");
} catch (Exception ex) {
}
MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(DBKEY_0),
"ip=10.232.31.154\r\nport=3306\r\ndbName=qatest_normal_0\r\ndbType=mysql\r\ndbStatus=RW\r\n");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
re = tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
Assert.assertEquals(time, String.valueOf(re.get("gmt_create")));
}
示例3: moreThanWriteRestraintTest
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
@Test
public void moreThanWriteRestraintTest() throws InterruptedException {
if (ASTATICISM_TEST) {
return;
}
int WriteCount = 20;
int executCount = 10;
MockServer.setConfigInfo(TAtomConstants.getAppDataId(APPNAME, DBKEY_0),
" maxPoolSize=100\r\nuserName=tddl\r\nminPoolSize=1\r\nwriteRestrictTimes=" + executCount + "\r\n");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
String sql = "update normaltbl_0001 set gmt_create=? where pk=?";
Object[] args = new Object[] { nextDay, RANDOM_ID };
for (int i = 0; i < WriteCount; i++) {
try {
int rs = tddlJT.update(sql, args);
Assert.assertEquals(1, rs);
executCount--;
} catch (DataAccessException ex) {
}
}
Assert.assertEquals(0, executCount);
}
示例4: testGroupDataSourceRouteHelper
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
@Test
public void testGroupDataSourceRouteHelper() throws Exception {
try {
TGroupDataSource ds = new TGroupDataSource(GROUP0, APPNAME);
MockServer.setConfigInfo(ds.getFullDbGroupKey(), DSKEY0 + ":rw" + "," + DSKEY1 + ":r");
ds.init();
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
assertEquals(stmt.executeUpdate("insert into tddl_test_0000(id,name) values(100,'str')"), 1);
ResultSet rs = stmt.executeQuery("select id,name from tddl_test_0000 where id=100");
assertTrue(rs.next());
// 如果指定了index,忽略rw限制
ThreadLocalMap.put(ThreadLocalString.DATASOURCE_INDEX, 1);
assertEquals(stmt.executeUpdate("insert into tddl_test_0000(id,name) values(100,'str')"), 1);
rs = stmt.executeQuery("select count(*) from tddl_test_0000 where id=100");
assertTrue(rs.next());
assertEquals(rs.getInt(1), 1);
stmt.close();
conn.close();
} finally {
ThreadLocalMap.put(ThreadLocalString.DATASOURCE_INDEX, null);
}
}
示例5: restore
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
private void restore() throws Exception {
MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(DBKEY_0),
"ip=10.232.31.154\r\nport=3306\r\ndbName=qatest_normal_0\r\ndbType=mysql\r\ndbStatus=RW\r\n");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
Map re = null;
try {
re = tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
} catch (Exception ex) {
MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(DBKEY_0),
"ip=10.232.31.154\r\nport=3306\r\ndbName=qatest_normal_0\r\ndbType=mysql\r\ndbStatus=RW\r\n");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
re = tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
}
Assert.assertEquals("manhong", re.get("name"));
}
示例6: balanceWeightTest
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
@Test
public void balanceWeightTest() throws InterruptedException {
/* 均衡权重(确保推送成功) */
for (int i = 0; i < 2; i++) {
MockServer.setConfigInfo(tds.getFullDbGroupKey(),
"qatest_normal_0:wr10,qatest_normal_0_bac:r10,qatest_normal_1_bac:r10");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
}
int firstCnt = 0;
int secondCnt = 0;
int thirdCnt = 0;
for (int i = 0; i < operationCnt; i++) {
Map rex = tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
if (time.equalsIgnoreCase(String.valueOf(rex.get("gmt_create")))) {
firstCnt++;
} else if (nextDay.equalsIgnoreCase(String.valueOf(rex.get("gmt_create")))) {
secondCnt++;
} else if (theDayAfterTomorow.equalsIgnoreCase(String.valueOf(rex.get("gmt_create")))) {
thirdCnt++;
} else {
Assert.fail("查询结果中出现不该有的数据。gmt_create = " + String.valueOf(rex.get("gmt_create")));
}
}
System.err.println("firstCnt=" + firstCnt + ", secondCnt=" + secondCnt + ", thirdCnt=" + thirdCnt);
Assert.assertEquals(operationCnt, firstCnt + secondCnt + thirdCnt);
checkWeight(operationCnt, firstCnt, 1.0 / 3);
checkWeight(operationCnt, secondCnt, 1.0 / 3);
checkWeight(operationCnt, thirdCnt, 1.0 / 3);
}
示例7: mockConfig
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
private static void mockConfig(String dir, String appName, String groupName, String dbKey) {
String globaStr = PropLoadTestUtil.loadPropFile2String("conf/" + dir + "/globa.properties");
MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(dbKey), globaStr);
String appStr = PropLoadTestUtil.loadPropFile2String("conf/" + dir + "/app.properties");
MockServer.setConfigInfo(TAtomConstants.getAppDataId(appName, dbKey), appStr);
String passwdStr = PropLoadTestUtil.loadPropFile2String("conf/" + dir + "/passwd.properties");
// 解析配置
TAtomDsConfDO tAtomDsConfDO = TAtomConfParser.parserTAtomDsConfDO(globaStr, appStr);
String passwdDataId = TAtomConstants.getPasswdDataId(tAtomDsConfDO.getDbName(),
tAtomDsConfDO.getDbType(),
tAtomDsConfDO.getUserName());
MockServer.setConfigInfo(passwdDataId, passwdStr);
}
示例8: someOfDssWithoutRWeightTest
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
@Test
public void someOfDssWithoutRWeightTest() throws InterruptedException {
/* 有部分DS没有设置权重值(确保推送成功) */
for (int i = 0; i < 2; i++) {
MockServer.setConfigInfo(tds.getFullDbGroupKey(),
"qatest_normal_0:wr1,qatest_normal_0_bac:w,qatest_normal_1_bac:r3");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
}
int firstCnt = 0;
int secondCnt = 0;
int thirdCnt = 0;
for (int i = 0; i < operationCnt; i++) {
Map rex = tddlJT.queryForMap("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
if (time.equalsIgnoreCase(String.valueOf(rex.get("gmt_create")))) {
firstCnt++;
} else if (nextDay.equalsIgnoreCase(String.valueOf(rex.get("gmt_create")))) {
secondCnt++;
} else if (theDayAfterTomorow.equalsIgnoreCase(String.valueOf(rex.get("gmt_create")))) {
thirdCnt++;
} else {
Assert.fail("查询结果中出现不该有的数据。gmt_create = " + String.valueOf(rex.get("gmt_create")));
}
}
System.err.println("firstCnt=" + firstCnt + ", secondCnt=" + secondCnt + ", thirdCnt=" + thirdCnt);
Assert.assertEquals(operationCnt, firstCnt + secondCnt + thirdCnt);
Assert.assertEquals(0, secondCnt);
checkWeight(operationCnt, firstCnt, 1.0 / 4);
checkWeight(operationCnt, thirdCnt, 3.0 / 4);
}
示例9: TGroupDataSource
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
@Test
public void 单个数据库_atom() throws Exception {
TGroupDataSource ds = new TGroupDataSource();
ds.setDbGroupKey(GROUP0);
ds.setAppName(APPNAME);
MockServer.setConfigInfo(ds.getFullDbGroupKey(), DSKEY1 + ":rw");
ds.init();
testCrud(ds);
}
示例10: updateFromReadOnlyDSByDatasourceIndexTest
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
@Test
public void updateFromReadOnlyDSByDatasourceIndexTest() throws InterruptedException {
// 将3个库全部设置为只读(确保推送成功)
for (int i = 0; i < 2; i++) {
MockServer.setConfigInfo(tds.getFullDbGroupKey(),
"qatest_normal_0:r,qatest_normal_0_bac:r,qatest_normal_1_bac:r");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
}
// 插入数据
String sql = "insert into normaltbl_0001 (pk,gmt_create) values (?,?)";
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
int rs = tddlJT.update(sql, new Object[] { RANDOM_ID, time });
Assert.assertTrue(rs > 0);
sql = "select * from normaltbl_0001 where pk=?";
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
Map re = tddlJT.queryForMap(sql, new Object[] { RANDOM_ID });
Assert.assertEquals(time, String.valueOf(re.get("gmt_create")));
// 更新数据
sql = "update normaltbl_0001 set gmt_create=? where pk=?";
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
rs = tddlJT.update(sql, new Object[] { nextDay, RANDOM_ID });
Assert.assertTrue(rs > 0);
sql = "select * from normaltbl_0001 where pk=?";
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
re = tddlJT.queryForMap(sql, new Object[] { RANDOM_ID });
Assert.assertEquals(nextDay, String.valueOf(re.get("gmt_create")));
}
示例11: TGroupDataSource
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
@Test
public void 在只写库上更新后再查询会重用写库上的连接_即使它是一个只写库也不管_atom() throws Exception {
TGroupDataSource ds = new TGroupDataSource();
ds.setDbGroupKey(GROUP0);
ds.setAppName(APPNAME);
MockServer.setConfigInfo(ds.getFullDbGroupKey(), DSKEY0 + ":w" + "," + DSKEY1 + ":r20" + "," + DSKEY2 + ":r30");
ds.init();
testCrud_Read(ds);
}
示例12: oneOfAtomDssInGropuIsOkTest
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
@Test
public void oneOfAtomDssInGropuIsOkTest() throws Exception {
// 改变group中的rw状态(确保推送成功)
for (int i = 0; i < 2; i++) {
MockServer.setConfigInfo(tds.getFullDbGroupKey(),
"qatest_normal_0:NA,qatest_normal_0_bac:r,qatest_normal_1_bac:r");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
}
int successCnt = 0;
for (int i = 0; i < 20; i++) {
tddlJT.queryForList(sql);
successCnt++;
}
Assert.assertEquals(20, successCnt);
// qatest_normal_0状态改为只读(确保推送成功)
for (int i = 0; i < 2; i++) {
MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(DBKEY_0),
"ip=10.232.31.154\r\nport=3306\r\ndbName=qatest_normal_0\r\ndbType=mysql\r\ndbStatus=NA");
MockServer.setConfigInfo(tds.getFullDbGroupKey(),
"qatest_normal_0:wr,qatest_normal_0_bac:r,qatest_normal_1_bac:r");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
}
successCnt = 0;
for (int i = 0; i < 20; i++) {
tddlJT.queryForList(sql);
successCnt++;
}
Assert.assertEquals(20, successCnt);
}
示例13: testChangePasswd
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
private void testChangePasswd(ChangeTestConfig change, ChangeTestConfig restore, String dbType)
throws IOException,
AtomAlreadyInitException,
Exception {
String appName = "tddl_sample";
String dbKey = "unitTestDb-" + dbType;
String configName = "";
String testSql = TAtomDataSourceTest.TEST_SQL;
configName = dbType;
TAtomDataSource tAtomDataSource = createTAtomDataSource(appName, dbKey, configName);
JdbcTemplate jtp = new JdbcTemplate(tAtomDataSource);
int actual = jtp.queryForInt(testSql);
Assert.assertEquals(actual, 1);
// 设置错误的IP进行推送
// 全局配置
String globaStr = PropLoadTestUtil.loadPropFile2String("conf/" + configName + "/globa.properties");
MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(dbKey), globaStr);
// 应用配置
String appStr = PropLoadTestUtil.loadPropFile2String("conf/" + configName + "/app.properties");
MockServer.setConfigInfo(TAtomConstants.getAppDataId(appName, dbKey), appStr);
// 解析配置
TAtomDsConfDO tAtomDsConfDO = TAtomConfParser.parserTAtomDsConfDO(globaStr, appStr);
Properties passwdProp = PropLoadTestUtil.loadPropFromFile("conf/" + configName + "/passwd.properties");
String passwdDataId = TAtomConstants.getPasswdDataId(tAtomDsConfDO.getDbName(),
tAtomDsConfDO.getDbType(),
tAtomDsConfDO.getUserName());
MockServer.setConfigInfo(passwdDataId, PropLoadTestUtil.convertProp2Str(change.doChange(passwdProp)));
Thread.sleep(3000);
// 期待出现错误
boolean result = false;
try {
actual = jtp.queryForInt(testSql);
} catch (Throwable e) {
result = true;
}
Assert.assertTrue(result);
MockServer.setConfigInfo(passwdDataId,
PropLoadTestUtil.convertProp2Str(restore.doChange(PropLoadTestUtil.loadPropFromFile("conf/" + configName
+ "/passwd.properties"))));
Thread.sleep(3000);
// 期待结果正常
actual = jtp.queryForInt(testSql);
Assert.assertEquals(actual, 1);
tAtomDataSource.destroyDataSource();
}
示例14: updateDBUseBalanceWeightTest
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
@Test
public void updateDBUseBalanceWeightTest() throws Exception {
// 跳过本用例测试
if (SOME_SHOULD_NOT_BE_TEST) {
return;
}
// 设置权重(确保推送成功)
for (int i = 0; i < 2; i++) {
MockServer.setConfigInfo(tds.getFullDbGroupKey(),
"qatest_normal_0:w1r10,qatest_normal_0_bac:w1r10,qatest_normal_1_bac:w1r10");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
}
int operationCnt = 1000;
int firstCnt = 0;
int secondCnt = 0;
int thirdCnt = 0;
for (int i = 0; i < operationCnt; i++) {
// 插入数据
int rs = tddlJT.update("insert into normaltbl_0001 (pk,gmt_create) values (?,?)", new Object[] { RANDOM_ID,
time });
Assert.assertTrue(rs > 0);
// 确认更新的atomDS
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
List list = tddlJT.queryForList("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
if (list.size() == 1) {
firstCnt++;
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
clearData(tddlJT, "delete from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
} else {
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(1);
list = tddlJT.queryForList("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
if (list.size() == 1) {
secondCnt++;
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(1);
clearData(tddlJT, "delete from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
} else {
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(2);
list = tddlJT.queryForList("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
if (list.size() == 1) {
thirdCnt++;
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(2);
clearData(tddlJT, "delete from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
} else {
Assert.fail("查不到数据。");
}
}
}
}
Assert.assertEquals(operationCnt, firstCnt + secondCnt + thirdCnt);
System.err.println("firstCnt=" + firstCnt + ", secondCnt=" + secondCnt + ", thirdCnt=" + thirdCnt);
checkWeight(operationCnt, firstCnt, 1.0 / 3);
checkWeight(operationCnt, secondCnt, 1.0 / 3);
checkWeight(operationCnt, thirdCnt, 1.0 / 3);
}
示例15: someOfTheDssWeightAreZeroTest
import com.taobao.diamond.mockserver.MockServer; //导入方法依赖的package包/类
@Test
public void someOfTheDssWeightAreZeroTest() throws InterruptedException {
// 跳过本用例测试
if (SOME_SHOULD_NOT_BE_TEST) {
return;
}
// 设置权重(确保推送成功)
for (int i = 0; i < 2; i++) {
MockServer.setConfigInfo(tds.getFullDbGroupKey(),
"qatest_normal_0:w1r10,qatest_normal_0_bac:w0r10,qatest_normal_1_bac:w3r10");
TimeUnit.SECONDS.sleep(SLEEP_TIME);
}
int operationCnt = 1000;
int firstCnt = 0;
int secondCnt = 0;
int thirdCnt = 0;
for (int i = 0; i < operationCnt; i++) {
// 插入数据
int rs = tddlJT.update("insert into normaltbl_0001 (pk,gmt_create) values (?,?)", new Object[] { RANDOM_ID,
time });
Assert.assertTrue(rs > 0);
// 确认更新的atomDS
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
List list = tddlJT.queryForList("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
if (list.size() == 1) {
firstCnt++;
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
clearData(tddlJT, "delete from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
} else {
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(1);
list = tddlJT.queryForList("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
if (list.size() == 1) {
secondCnt++;
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(1);
clearData(tddlJT, "delete from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
} else {
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(2);
list = tddlJT.queryForList("select * from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
if (list.size() == 1) {
thirdCnt++;
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(2);
clearData(tddlJT, "delete from normaltbl_0001 where pk=?", new Object[] { RANDOM_ID });
} else {
Assert.fail("查不到数据。");
}
}
}
}
System.err.println("firstCnt=" + firstCnt + ", secondCnt=" + secondCnt + ", thirdCnt=" + thirdCnt);
Assert.assertEquals(operationCnt, firstCnt + secondCnt + thirdCnt);
Assert.assertEquals(0, secondCnt);
checkWeight(operationCnt, firstCnt, 1.0 / 4);
checkWeight(operationCnt, thirdCnt, 3.0 / 4);
}