use of com.ctrip.platform.dal.dao.configure.SelectionContext in project dal by ctripcorp.
the class DatabaseSelectorTest method getContext.
private SelectionContext getContext(DalHints hints, List<DataBase> ms, List<DataBase> ss, boolean masterOnly, boolean isSelect) {
SelectionContext ctx = new SelectionContext("", hints == null ? new DalHints() : hints, null, masterOnly, isSelect);
ctx.setMasters(ms);
ctx.setSlaves(ss);
return ctx;
}
use of com.ctrip.platform.dal.dao.configure.SelectionContext in project dal by ctripcorp.
the class DatabaseSelectorTest method notMasterOnlyMarkdownTest.
@Test
public void notMasterOnlyMarkdownTest() 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;
autoMarkdown(S1);
autoMarkdown(S2);
autoMarkdown(S3);
context = getContext(null, ms, ss, false, true);
assertSelector(context, M1, M2);
context = getContext(null, ms, ss, false, false);
assertSelector(context, M1, M2);
setUp();
autoMarkdown(M1);
autoMarkdown(M2);
context = getContext(null, ms, ss, false, true);
assertSelector(context, S1, S2, S3);
context = getContext(null, ms, ss, false, false);
assertSelector(context, ErrorCode.MarkdownConnection);
autoMarkdown(M1);
autoMarkdown(M2);
autoMarkdown(S1);
autoMarkdown(S2);
autoMarkdown(S3);
context = getContext(null, ms, ss, false, true);
assertSelector(context, ErrorCode.MarkdownConnection);
context = getContext(null, ms, ss, false, false);
assertSelector(context, ErrorCode.MarkdownConnection);
}
use of com.ctrip.platform.dal.dao.configure.SelectionContext in project dal by ctripcorp.
the class DatabaseSelectorTest method hasHASlavesOneMarkdownTest.
@Test
public void hasHASlavesOneMarkdownTest() 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();
autoMarkdown(S2);
SelectionContext context = getContext(new DalHints().setHA(ha), null, ss, false, true);
Assert.assertEquals(S1, selector.select(context));
// masterOnly
ha = new DalHA();
context = getContext(new DalHints().setHA(ha), null, ss, true, true);
assertSelector(context, ErrorCode.NullLogicDbName);
ha = new DalHA();
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 hasMixedMasterAndSlaveButOneMasterMarkdownTest.
@Test
public void hasMixedMasterAndSlaveButOneMasterMarkdownTest() 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);
SelectionContext context = getContext(new DalHints(), ms, ss, false, true);
String dbName = selector.select(context);
Assert.assertTrue(dbName.equals(S1) || dbName.equals(S2));
// masterOnly
context = getContext(null, ms, ss, true, true);
Assert.assertEquals(M2, selector.select(context));
context = getContext(null, ms, ss, true, false);
Assert.assertEquals(M2, selector.select(context));
context = getContext(null, ms, ss, false, false);
Assert.assertEquals(M2, selector.select(context));
}
use of com.ctrip.platform.dal.dao.configure.SelectionContext in project dal by ctripcorp.
the class DatabaseSelectorTest method invalidDesigantedDbTest.
@Test
public void invalidDesigantedDbTest() 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;
context = getContext(new DalHints().inDatabase(M1 + M2), ms, ss, false, false);
assertSelector(context, ErrorCode.InvalidDatabaseKeyName);
context = getContext(new DalHints().inDatabase(M1 + M2), ms, ss, true, true);
assertSelector(context, ErrorCode.InvalidDatabaseKeyName);
context = getContext(new DalHints().inDatabase(M1 + M2), ms, ss, true, false);
assertSelector(context, ErrorCode.InvalidDatabaseKeyName);
context = getContext(new DalHints().inDatabase(M1 + M2), ms, ss, false, true);
assertSelector(context, ErrorCode.InvalidDatabaseKeyName);
}
Aggregations