use of com.ctrip.platform.dal.dao.configure.DatabaseSelector 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);
}
use of com.ctrip.platform.dal.dao.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method notMasterOnlyHaMarkdownTest.
@Test
public void notMasterOnlyHaMarkdownTest() 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;
Set<String> matched;
autoMarkdown(S1);
matched = newHashSet(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);
autoMarkdown(M1);
selector = new DatabaseSelector(hints, ms, ss, false, true);
assertSelector(selector, M2);
selector = new DatabaseSelector(hints, ms, ss, false, true);
assertSelector(selector, M2);
}
use of com.ctrip.platform.dal.dao.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method onlyHaveMasterTest.
@Test
public void onlyHaveMasterTest() 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;
selector = new DatabaseSelector(null, ms, ss, false, true);
assertSelector(selector, M1, M2);
selector = new DatabaseSelector(null, ms, ss, false, false);
assertSelector(selector, M1, M2);
// Master only
selector = new DatabaseSelector(null, ms, ss, true, true);
assertSelector(selector, M1, M2);
selector = new DatabaseSelector(null, ms, ss, true, false);
assertSelector(selector, M1, M2);
autoMarkdown(M1);
selector = new DatabaseSelector(null, ms, ss, true, false);
assertSelector(selector, M2);
autoMarkdown(M2);
selector = new DatabaseSelector(null, ms, ss, true, false);
assertSelector(selector, ErrorCode.MarkdownConnection);
}
use of com.ctrip.platform.dal.dao.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method notMasterOnlyHaTest.
@Test
public void notMasterOnlyHaTest() 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;
Set<String> 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);
matched = newHashSet(M1, M2);
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 notSelectTest.
@Test
public void notSelectTest() 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));
DatabaseSelector selector = new DatabaseSelector(new DalHints(), ms, ss, false, false);
String dbName = selector.select();
Assert.assertTrue(dbName.equals(M1) || dbName.equals(M2));
selector = new DatabaseSelector(new DalHints().inDatabase(M1), ms, ss, false, false);
Assert.assertTrue(selector.select().equals(M1));
selector = new DatabaseSelector(new DalHints().inDatabase(M2), ms, ss, false, false);
Assert.assertTrue(selector.select().equals(M2));
selector = new DatabaseSelector(new DalHints().inDatabase(S2), ms, ss, false, false);
assertSelector(selector, ErrorCode.InvalidDatabaseKeyName);
// masterOnly
selector = new DatabaseSelector(null, ms, ss, true, false);
dbName = selector.select();
Assert.assertTrue(dbName.equals(M1) || dbName.equals(M2));
selector = new DatabaseSelector(new DalHints().inDatabase(M1), ms, ss, true, false);
Assert.assertTrue(selector.select().equals(M1));
selector = new DatabaseSelector(new DalHints().inDatabase(M2), ms, ss, true, false);
Assert.assertTrue(selector.select().equals(M2));
selector = new DatabaseSelector(new DalHints().inDatabase(S2), ms, ss, true, false);
assertSelector(selector, ErrorCode.InvalidDatabaseKeyName);
}
Aggregations