use of com.ctrip.platform.dal.dao.configure.DataBase in project dal by ctripcorp.
the class DatabaseSelectorTest method hasHAMixedMasterAndSlaveButOneSlaveMarkdownTest.
@Test
public void hasHAMixedMasterAndSlaveButOneSlaveMarkdownTest() 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(S1);
DalHA ha = new DalHA();
ha.addDB(M1);
SelectionContext context = getContext(new DalHints().setHA(ha), ms, ss, false, true);
String dbName = selector.select(context);
Assert.assertTrue(dbName.equals(S2));
// masterOnly
ha = new DalHA();
ha.addDB(M1);
context = getContext(new DalHints().setHA(ha), ms, ss, true, true);
Assert.assertEquals(M2, selector.select(context));
ha = new DalHA();
ha.addDB(M1);
context = getContext(new DalHints().setHA(ha), ms, ss, true, false);
Assert.assertEquals(M2, selector.select(context));
ha = new DalHA();
ha.addDB(M1);
context = getContext(new DalHints().setHA(ha), ms, ss, false, false);
Assert.assertEquals(M2, selector.select(context));
ha = new DalHA();
ha.addDB(M1);
context = getContext(new DalHints().setHA(ha).inDatabase(M1), ms, ss, false, false);
assertSelector(context, ErrorCode.NoMoreConnectionToFailOver);
ha = new DalHA();
ha.addDB(M1);
autoMarkdown(M2);
context = getContext(new DalHints().setHA(ha), ms, ss, false, false);
Assert.assertEquals(M1, selector.select(context));
}
use of com.ctrip.platform.dal.dao.configure.DataBase in project dal by ctripcorp.
the class DatabaseSelectorTest method notSelectTest.
@Test
public void notSelectTest() 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));
SelectionContext context;
context = getContext(new DalHints(), ms, ss, false, false);
String dbName = selector.select(context);
Assert.assertTrue(dbName.equals(M1) || dbName.equals(M2));
context = getContext(new DalHints().inDatabase(M1), ms, ss, false, false);
Assert.assertTrue(selector.select(context).equals(M1));
context = getContext(new DalHints().inDatabase(M2), ms, ss, false, false);
Assert.assertTrue(selector.select(context).equals(M2));
context = getContext(new DalHints().inDatabase(S2), ms, ss, false, false);
assertSelector(context, ErrorCode.InvalidDatabaseKeyName);
// masterOnly
context = getContext(null, ms, ss, true, false);
dbName = selector.select(context);
Assert.assertTrue(dbName.equals(M1) || dbName.equals(M2));
context = getContext(new DalHints().inDatabase(M1), ms, ss, true, false);
Assert.assertTrue(selector.select(context).equals(M1));
context = getContext(new DalHints().inDatabase(M2), ms, ss, true, false);
Assert.assertTrue(selector.select(context).equals(M2));
context = getContext(new DalHints().inDatabase(S2), ms, ss, true, false);
assertSelector(context, ErrorCode.InvalidDatabaseKeyName);
}
use of com.ctrip.platform.dal.dao.configure.DataBase in project dal by ctripcorp.
the class DatabaseSelectorTest method onlyHaveMasterHaTest.
@Test
public void onlyHaveMasterHaTest() 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;
Set<String> matched;
matched = newHashSet(M1, M2);
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);
// reset
matched = newHashSet(M1, M2);
hints = new DalHints().setHA(new DalHA());
context = getContext(hints, ms, ss, false, false);
assertSelector(context, matched);
context = getContext(hints, ms, ss, false, false);
assertSelector(context, matched);
// Master only
matched = newHashSet(M1, M2);
hints = new DalHints().setHA(new DalHA());
context = getContext(hints, ms, ss, true, true);
assertSelector(context, M1, M2);
context = getContext(hints, ms, ss, true, true);
assertSelector(context, M1, M2);
// reset
matched = newHashSet(M1, M2);
hints = new DalHints().setHA(new DalHA());
context = getContext(hints, ms, ss, true, false);
assertSelector(context, M1, M2);
context = getContext(hints, ms, ss, true, false);
assertSelector(context, M1, M2);
}
Aggregations