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