use of com.ctrip.platform.dal.dao.configure.SelectionContext 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);
SelectionContext context = getContext(null, dbs, null, false, false);
assertSelector(context, M2);
context = getContext(null, dbs, null, false, true);
assertSelector(context, M2);
// masterOnly
context = getContext(null, dbs, null, true, false);
assertSelector(context, M2);
context = getContext(new DalHints().inDatabase(M2), dbs, null, true, false);
assertSelector(context, M2);
context = getContext(null, dbs, null, true, true);
assertSelector(context, M2);
context = getContext(new DalHints().inDatabase(M2), dbs, null, true, true);
assertSelector(context, M2);
// test pointed db
context = getContext(new DalHints().inDatabase(M1), dbs, null, true, false);
assertSelector(context, ErrorCode.MarkdownConnection);
context = getContext(new DalHints().setHA(new DalHA().addDB(M2)), dbs, null, true, false);
assertSelector(context, M2);
}
use of com.ctrip.platform.dal.dao.configure.SelectionContext 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));
SelectionContext context;
Set<String> matched;
matched = newHashSet(S1, S2, S3);
DalHints hints = new DalHints().setHA(new DalHA());
context = getContext(hints, ms, ss, false, true);
assertSelector(context, matched);
context = getContext(hints, ms, ss, false, true);
assertSelector(context, matched);
context = getContext(hints, ms, ss, false, true);
assertSelector(context, matched);
context = getContext(hints, ms, ss, false, true);
assertSelector(context, ErrorCode.NoMoreConnectionToFailOver);
}
use of com.ctrip.platform.dal.dao.configure.SelectionContext 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);
SelectionContext context = getContext(null, dbs, null, false, false);
assertSelector(context, ErrorCode.MarkdownConnection);
context = getContext(null, dbs, null, false, true);
assertSelector(context, ErrorCode.MarkdownConnection);
// masterOnly
context = getContext(null, dbs, null, true, false);
assertSelector(context, ErrorCode.MarkdownConnection);
context = getContext(null, dbs, null, true, true);
assertSelector(context, ErrorCode.MarkdownConnection);
}
use of com.ctrip.platform.dal.dao.configure.SelectionContext 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);
SelectionContext context = getContext(new DalHints().setHA(ha), null, ss, false, true);
Assert.assertEquals(S3, selector.select(context));
// masterOnly
ha = new DalHA();
ha.addDB(S1);
context = getContext(new DalHints().setHA(ha), null, ss, true, true);
assertSelector(context, ErrorCode.NullLogicDbName);
ha = new DalHA();
ha.addDB(S1);
context = getContext(new DalHints().setHA(ha), null, ss, true, false);
assertSelector(context, ErrorCode.NullLogicDbName);
}
use of com.ctrip.platform.dal.dao.configure.SelectionContext in project dal by ctripcorp.
the class DatabaseSelectorTest method hasMixedMasterAndSlaveButMasterMarkdownTest.
@Test
public void hasMixedMasterAndSlaveButMasterMarkdownTest() throws DalException {
List<DataBase> ms = new ArrayList<DataBase>();
ms.add(new DataBase(M1, true, "", M1));
List<DataBase> ss = new ArrayList<DataBase>();
ss.add(new DataBase(S1, false, "", S1));
ss.add(new DataBase(S2, false, "", S2));
autoMarkdown(M1);
SelectionContext context = getContext(null, ms, ss, false, true);
String dbName = selector.select(context);
Assert.assertTrue(dbName.equals(S1) || dbName.equals(S2));
context = getContext(new DalHints().inDatabase(M1), ms, ss, false, true);
assertSelector(context, ErrorCode.MarkdownConnection);
context = getContext(new DalHints().inDatabase(S1), ms, ss, false, true);
Assert.assertEquals(S1, selector.select(context));
context = getContext(new DalHints().inDatabase(S2), ms, ss, false, true);
Assert.assertEquals(S2, selector.select(context));
// masterOnly
context = getContext(null, ms, ss, true, true);
assertSelector(context, ErrorCode.MarkdownConnection);
context = getContext(null, ms, ss, true, false);
assertSelector(context, ErrorCode.MarkdownConnection);
context = getContext(new DalHints().inDatabase(S1), ms, ss, true, true);
assertSelector(context, ErrorCode.InvalidDatabaseKeyName);
context = getContext(new DalHints().inDatabase(S1), ms, ss, true, false);
assertSelector(context, ErrorCode.InvalidDatabaseKeyName);
}
Aggregations