use of com.ctrip.platform.dal.dao.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method onlyHaveSlaveTest.
@Test
public void onlyHaveSlaveTest() 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;
selector = new DatabaseSelector(null, ms, ss, true, false);
assertSelector(selector, ErrorCode.NullLogicDbName);
selector = new DatabaseSelector(null, ms, ss, true, true);
assertSelector(selector, ErrorCode.NullLogicDbName);
selector = new DatabaseSelector(null, ms, ss, false, false);
assertSelector(selector, ErrorCode.NullLogicDbName);
selector = new DatabaseSelector(null, ms, ss, false, true);
assertSelector(selector, S1, S2, S3);
autoMarkdown(S1);
selector = new DatabaseSelector(null, ms, ss, false, true);
assertSelector(selector, S2, S3);
autoMarkdown(S2);
selector = new DatabaseSelector(null, ms, ss, false, true);
assertSelector(selector, S3);
autoMarkdown(S3);
selector = new DatabaseSelector(null, ms, ss, false, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
}
use of com.ctrip.platform.dal.dao.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method masterOnlyTest.
@Test
public void masterOnlyTest() 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;
// make sure no slave is qualified
autoMarkdown(S1);
autoMarkdown(S2);
autoMarkdown(S3);
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, true);
assertSelector(selector, M2);
selector = new DatabaseSelector(null, ms, ss, true, false);
assertSelector(selector, M2);
autoMarkdown(M2);
selector = new DatabaseSelector(null, ms, ss, true, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
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 hasHAMixedMasterAndSlaveButOneMasterMarkdownTest.
@Test
public void hasHAMixedMasterAndSlaveButOneMasterMarkdownTest() 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));
autoMarkdown(M1);
DatabaseSelector selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, false, true);
Assert.assertEquals(S2, selector.select());
selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)).inDatabase(S1), ms, ss, false, true);
assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
// masterOnly
selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, true, true);
Assert.assertEquals(M2, selector.select());
selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)).inDatabase(M1), ms, ss, true, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, true, false);
Assert.assertEquals(M2, selector.select());
selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)).inDatabase(M1), ms, ss, true, false);
assertSelector(selector, ErrorCode.MarkdownConnection);
selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, false, false);
Assert.assertEquals(M2, selector.select());
autoMarkdown(M2);
selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, false, false);
assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
}
use of com.ctrip.platform.dal.dao.configure.DatabaseSelector in project dal by ctripcorp.
the class DatabaseSelectorTest method desigantedUsedInHaTest.
@Test
public void desigantedUsedInHaTest() 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(new DalHints().setHA(new DalHA().addDB(M1)).inDatabase(M1), ms, ss, false, true);
assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)).inDatabase(S1), 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 hasOneMarkdownSlaveTest.
@Test
public void hasOneMarkdownSlaveTest() throws DalException {
autoMarkdown(S1);
List<DataBase> dbs = new ArrayList<DataBase>();
dbs.add(new DataBase(S1, false, "", S1));
dbs.add(new DataBase(S2, false, "", S2));
DatabaseSelector selector = new DatabaseSelector(new DalHints(), null, dbs, false, true);
Assert.assertEquals(S2, selector.select());
selector = new DatabaseSelector(new DalHints().inDatabase(S2), null, dbs, false, true);
Assert.assertEquals(S2, selector.select());
selector = new DatabaseSelector(new DalHints().inDatabase(S1), null, dbs, false, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
// 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);
selector = new DatabaseSelector(new DalHints().inDatabase(S1), null, dbs, true, false);
assertSelector(selector, ErrorCode.NullLogicDbName);
}
Aggregations