use of com.ctrip.platform.dal.dao.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method hasHASlavesOneMarkdownTest.
@Test
public void hasHASlavesOneMarkdownTest() 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();
autoMarkdown(S2);
DatabaseSelector selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, false, true);
Assert.assertEquals(S1, selector.select());
// masterOnly
ha = new DalHA();
selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, true, true);
assertSelector(selector, ErrorCode.NullLogicDbName);
ha = new DalHA();
selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, true, false);
assertSelector(selector, ErrorCode.NullLogicDbName);
}
use of com.ctrip.platform.dal.dao.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method onlyOneSlaveTest.
@Test
public void onlyOneSlaveTest() throws DalException {
DataBase db = new DataBase(S1, false, "", S1);
List<DataBase> dbs = new ArrayList<DataBase>();
dbs.add(db);
DatabaseSelector selector = new DatabaseSelector(null, null, dbs, false, true);
Assert.assertEquals(S1, selector.select());
selector = new DatabaseSelector(new DalHints().inDatabase(S1), null, dbs, false, true);
Assert.assertEquals(S1, selector.select());
selector = new DatabaseSelector(new DalHints().inDatabase(M1), null, dbs, false, true);
assertSelector(selector, ErrorCode.InvalidDatabaseKeyName);
// masterOnly
selector = new DatabaseSelector(null, null, dbs, true, true);
assertSelector(selector, ErrorCode.NullLogicDbName);
selector = new DatabaseSelector(null, null, dbs, true, false);
assertSelector(selector, ErrorCode.NullLogicDbName);
// test pointed
selector = new DatabaseSelector(new DalHints().inDatabase(S1), null, dbs, true, true);
assertSelector(selector, ErrorCode.NullLogicDbName);
selector = new DatabaseSelector(new DalHints().inDatabase(S1), 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 onlyOneMasterTest.
@Test
public void onlyOneMasterTest() throws DalException {
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);
Assert.assertEquals(M1, selector.select());
selector = new DatabaseSelector(null, dbs, null, false, true);
Assert.assertEquals(M1, selector.select());
// masterOnly
selector = new DatabaseSelector(null, dbs, null, true, false);
Assert.assertEquals(M1, selector.select());
selector = new DatabaseSelector(null, dbs, null, true, true);
Assert.assertEquals(M1, selector.select());
}
Aggregations