use of com.ctrip.platform.dal.dao.configure.DataBase 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.DataBase 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.DataBase 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.DataBase 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);
}
use of com.ctrip.platform.dal.dao.configure.DataBase in project dal by ctripcorp.
the class DatabaseSelectorTest method masterOnlyHaTest.
@Test
public void masterOnlyHaTest() 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(new DalHints().setHA(new DalHA().addDB(M1)), ms, ss, true, true);
assertSelector(context, M2);
context = getContext(new DalHints().setHA(new DalHA().addDB(M2)), ms, ss, true, true);
assertSelector(context, M1);
context = getContext(new DalHints().setHA(new DalHA().addDB(M1)), ms, ss, true, false);
assertSelector(context, M2);
context = getContext(new DalHints().setHA(new DalHA().addDB(M2)), ms, ss, true, false);
assertSelector(context, M1);
context = getContext(new DalHints().setHA(new DalHA().addDB(M1).addDB(M2)), ms, ss, true, false);
assertSelector(context, ErrorCode.NoMoreConnectionToFailOver);
autoMarkdown(M1);
context = getContext(new DalHints().setHA(new DalHA().addDB(M1)), ms, ss, true, true);
assertSelector(context, M2);
context = getContext(new DalHints().setHA(new DalHA().addDB(M2)), ms, ss, true, true);
assertSelector(context, M2);
autoMarkup(M1);
autoMarkdown(M2);
context = getContext(new DalHints().setHA(new DalHA().addDB(M2)), ms, ss, true, true);
assertSelector(context, M1);
context = getContext(new DalHints().setHA(new DalHA().addDB(M1)), ms, ss, true, true);
assertSelector(context, M1);
autoMarkdown(M1);
context = getContext(new DalHints().setHA(new DalHA().addDB(M1)), ms, ss, true, true);
assertSelector(context, ErrorCode.NoMoreConnectionToFailOver);
context = getContext(new DalHints().setHA(new DalHA().addDB(M2)), ms, ss, true, true);
assertSelector(context, ErrorCode.NoMoreConnectionToFailOver);
context = getContext(new DalHints().setHA(new DalHA().addDB(M1).addDB(M2)), ms, ss, true, false);
assertSelector(context, ErrorCode.NoMoreConnectionToFailOver);
}
Aggregations