use of com.ctrip.platform.dal.dao.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method onlyHaveMasterHaMarkdownTest.
@Test
public void onlyHaveMasterHaMarkdownTest() 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;
// with markdown
autoMarkdown(M1);
DalHints hints = new DalHints().setHA(new DalHA());
selector = new DatabaseSelector(hints, ms, ss, true, false);
assertSelector(selector, M2);
selector = new DatabaseSelector(hints, ms, ss, true, false);
assertSelector(selector, M2);
// reset
hints = new DalHints().setHA(new DalHA());
autoMarkdown(M2);
selector = new DatabaseSelector(hints, ms, ss, true, false);
assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
}
use of com.ctrip.platform.dal.dao.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method notMasterOnlyTest.
@Test
public void notMasterOnlyTest() 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 = 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;
selector = new DatabaseSelector(null, ms, ss, false, true);
assertSelector(selector, S1, S2, S3);
selector = new DatabaseSelector(null, ms, ss, false, false);
assertSelector(selector, M1, M2);
}
use of com.ctrip.platform.dal.dao.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method onlyHaveSlaveHaMarkdownTest.
@Test
public void onlyHaveSlaveHaMarkdownTest() 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;
autoMarkdown(S1);
DalHints hints = new DalHints().setHA(new DalHA());
matched = newHashSet(S2, S3);
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.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method onlyOneSlaveMarkdownTest.
@Test
public void onlyOneSlaveMarkdownTest() {
DataBase db = new DataBase(S1, false, "", S1);
List<DataBase> dbs = new ArrayList<DataBase>();
dbs.add(db);
autoMarkdown(S1);
DatabaseSelector selector = new DatabaseSelector(new DalHints(), null, dbs, false, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
selector = new DatabaseSelector(new DalHints().inDatabase(S1), null, dbs, false, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
selector = new DatabaseSelector(new DalHints().inDatabase(S2), null, dbs, false, true);
assertSelector(selector, ErrorCode.InvalidDatabaseKeyName);
// masterOnly
selector = new DatabaseSelector(null, null, dbs, true, true);
assertSelector(selector, ErrorCode.NullLogicDbName);
selector = new DatabaseSelector(new DalHints().inDatabase(S2), null, dbs, true, true);
assertSelector(selector, ErrorCode.NullLogicDbName);
selector = new DatabaseSelector(null, null, dbs, true, false);
assertSelector(selector, ErrorCode.NullLogicDbName);
selector = new DatabaseSelector(new DalHints().inDatabase(S2), null, dbs, true, false);
assertSelector(selector, ErrorCode.NullLogicDbName);
}
use of com.ctrip.platform.dal.dao.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method onlyOneMasterMarkdownTest.
// The rest tests are all original tests, that I don't think well organized
@Test
public void onlyOneMasterMarkdownTest() {
autoMarkdown(M1);
DataBase db = new DataBase(M1, true, "", M1);
List<DataBase> dbs = new ArrayList<DataBase>();
dbs.add(db);
DatabaseSelector selector = new DatabaseSelector(null, dbs, null, false, false);
assertSelector(selector, ErrorCode.MarkdownConnection);
selector = new DatabaseSelector(null, dbs, null, false, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
// masterOnly
selector = new DatabaseSelector(null, dbs, null, true, false);
assertSelector(selector, ErrorCode.MarkdownConnection);
selector = new DatabaseSelector(null, dbs, null, true, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
}
Aggregations