use of com.ctrip.platform.dal.dao.configure.DataBase in project dal by ctripcorp.
the class DatabaseSelectorTest method hasHASlavesOneMarkdownFailOverTest.
@Test
public void hasHASlavesOneMarkdownFailOverTest() throws DalException {
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));
DalHA ha = new DalHA();
ha.addDB(S1);
autoMarkdown(S2);
DatabaseSelector selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, false, true);
Assert.assertEquals(S3, 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.configure.DataBase in project dal by ctripcorp.
the class DatabaseSelectorTest method validDesigantedDbTest.
@Test
public void validDesigantedDbTest() 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().inDatabase(M1), ms, ss, false, true);
Assert.assertEquals(M1, selector.select());
selector = new DatabaseSelector(new DalHints().inDatabase(M2), ms, ss, false, true);
Assert.assertEquals(M2, selector.select());
selector = new DatabaseSelector(new DalHints().inDatabase(S1), ms, ss, false, true);
Assert.assertEquals(S1, selector.select());
selector = new DatabaseSelector(new DalHints().inDatabase(S2), ms, ss, false, true);
Assert.assertEquals(S2, selector.select());
selector = new DatabaseSelector(new DalHints().inDatabase(S3), ms, ss, false, true);
Assert.assertEquals(S3, selector.select());
autoMarkdown(M1);
selector = new DatabaseSelector(new DalHints().inDatabase(M2), ms, ss, false, true);
Assert.assertEquals(M2, selector.select());
autoMarkdown(S1);
autoMarkdown(S2);
selector = new DatabaseSelector(new DalHints().inDatabase(S3), ms, ss, false, true);
Assert.assertEquals(S3, selector.select());
}
use of com.ctrip.platform.dal.dao.configure.DataBase in project dal by ctripcorp.
the class DatabaseSelectorTest method desigantedMarkdownDbTest.
@Test
public void desigantedMarkdownDbTest() 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;
autoMarkdown(M1);
autoMarkdown(M2);
autoMarkdown(S1);
autoMarkdown(S2);
autoMarkdown(S3);
selector = new DatabaseSelector(new DalHints().inDatabase(M1), ms, ss, false, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
selector = new DatabaseSelector(new DalHints().inDatabase(M2), ms, ss, false, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
selector = new DatabaseSelector(new DalHints().inDatabase(S1), ms, ss, false, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
selector = new DatabaseSelector(new DalHints().inDatabase(S2), ms, ss, false, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
selector = new DatabaseSelector(new DalHints().inDatabase(S2), ms, ss, false, true);
assertSelector(selector, ErrorCode.MarkdownConnection);
}
use of com.ctrip.platform.dal.dao.configure.DataBase 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.configure.DataBase 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);
}
Aggregations