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