use of com.ctrip.platform.dal.dao.client.DalHA in project dal by ctripcorp.
the class DatabaseSelectorTest method hasOneMarkdownMasterTest.
@Test
public void hasOneMarkdownMasterTest() throws DalException {
List<DataBase> dbs = new ArrayList<DataBase>();
dbs.add(new DataBase(M1, true, "", M1));
dbs.add(new DataBase(M2, true, "", M2));
autoMarkdown(M1);
DatabaseSelector selector = new DatabaseSelector(null, dbs, null, false, false);
assertSelector(selector, M2);
selector = new DatabaseSelector(null, dbs, null, false, true);
assertSelector(selector, M2);
// masterOnly
selector = new DatabaseSelector(null, dbs, null, true, false);
assertSelector(selector, M2);
selector = new DatabaseSelector(new DalHints().inDatabase(M2), dbs, null, true, false);
assertSelector(selector, M2);
selector = new DatabaseSelector(null, dbs, null, true, true);
assertSelector(selector, M2);
selector = new DatabaseSelector(new DalHints().inDatabase(M2), dbs, null, true, true);
assertSelector(selector, M2);
// test pointed db
selector = new DatabaseSelector(new DalHints().inDatabase(M1), dbs, null, true, false);
assertSelector(selector, ErrorCode.MarkdownConnection);
selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(M2)), dbs, null, true, false);
assertSelector(selector, M2);
}
use of com.ctrip.platform.dal.dao.client.DalHA in project dal by ctripcorp.
the class DatabaseSelectorTest method onlyHaveSlaveHaTest.
@Test
public void onlyHaveSlaveHaTest() throws DalException {
List<DataBase> ms = null;
List<DataBase> ss = new ArrayList<DataBase>();
ss.add(new DataBase(S1, false, "", S1));
ss.add(new DataBase(S2, false, "", S2));
ss.add(new DataBase(S3, false, "", S3));
DatabaseSelector selector;
Set<String> matched;
matched = newHashSet(S1, S2, S3);
DalHints hints = new DalHints().setHA(new DalHA());
selector = new DatabaseSelector(hints, ms, ss, false, true);
assertSelector(selector, matched);
selector = new DatabaseSelector(hints, ms, ss, false, true);
assertSelector(selector, matched);
selector = new DatabaseSelector(hints, ms, ss, false, true);
assertSelector(selector, matched);
selector = new DatabaseSelector(hints, ms, ss, false, true);
assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
}
use of com.ctrip.platform.dal.dao.client.DalHA in project dal by ctripcorp.
the class DatabaseSelectorTest method onlyHaveMasterHaTest.
@Test
public void onlyHaveMasterHaTest() throws DalException {
List<DataBase> ms = new ArrayList<DataBase>();
ms.add(new DataBase(M1, true, "", M1));
ms.add(new DataBase(M2, true, "", M2));
List<DataBase> ss = null;
DatabaseSelector selector;
Set<String> matched;
matched = newHashSet(M1, M2);
DalHints hints = new DalHints().setHA(new DalHA());
selector = new DatabaseSelector(hints, ms, ss, false, true);
assertSelector(selector, matched);
selector = new DatabaseSelector(hints, ms, ss, false, true);
assertSelector(selector, matched);
// reset
matched = newHashSet(M1, M2);
hints = new DalHints().setHA(new DalHA());
selector = new DatabaseSelector(hints, ms, ss, false, false);
assertSelector(selector, matched);
selector = new DatabaseSelector(hints, ms, ss, false, false);
assertSelector(selector, matched);
// Master only
matched = newHashSet(M1, M2);
hints = new DalHints().setHA(new DalHA());
selector = new DatabaseSelector(hints, ms, ss, true, true);
assertSelector(selector, M1, M2);
selector = new DatabaseSelector(hints, ms, ss, true, true);
assertSelector(selector, M1, M2);
// reset
matched = newHashSet(M1, M2);
hints = new DalHints().setHA(new DalHA());
selector = new DatabaseSelector(hints, ms, ss, true, false);
assertSelector(selector, M1, M2);
selector = new DatabaseSelector(hints, ms, ss, true, false);
assertSelector(selector, M1, M2);
}
use of com.ctrip.platform.dal.dao.client.DalHA in project dal by ctripcorp.
the class DatabaseSelectorTest method hasHASlavesTest.
@Test
public void hasHASlavesTest() throws DalException {
List<DataBase> ss = new ArrayList<DataBase>();
ss.add(new DataBase(S1, false, "", S1));
ss.add(new DataBase(S2, false, "", S2));
DalHA ha = new DalHA();
ha.addDB(S1);
DatabaseSelector selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, false, true);
Assert.assertEquals(S2, selector.select());
// masterOnly
ha = new DalHA();
ha.addDB(S1);
selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, true, true);
assertSelector(selector, ErrorCode.NullLogicDbName);
ha = new DalHA();
ha.addDB(S1);
selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, true, false);
assertSelector(selector, ErrorCode.NullLogicDbName);
}
use of com.ctrip.platform.dal.dao.client.DalHA in project dal by ctripcorp.
the class DatabaseSelectorTest method hasHASlavesAllNotUsedTest.
@Test
public void hasHASlavesAllNotUsedTest() throws DalException {
List<DataBase> ss = new ArrayList<DataBase>();
ss.add(new DataBase(S1, false, "", S1));
ss.add(new DataBase(S2, false, "", S2));
DalHA ha = new DalHA();
ha.addDB(S1);
ha.addDB(S2);
DatabaseSelector selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, false, true);
assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
// masterOnly
ha = new DalHA();
ha.addDB(S1);
ha.addDB(S2);
selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, true, true);
assertSelector(selector, ErrorCode.NullLogicDbName);
ha = new DalHA();
ha.addDB(S1);
ha.addDB(S2);
selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, true, false);
assertSelector(selector, ErrorCode.NullLogicDbName);
}
Aggregations