Search in sources :

Example 26 with SelectionContext

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;
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SelectionContext(com.ctrip.platform.dal.dao.configure.SelectionContext)

Example 27 with SelectionContext

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);
}
Also used : ArrayList(java.util.ArrayList) SelectionContext(com.ctrip.platform.dal.dao.configure.SelectionContext) DataBase(com.ctrip.platform.dal.dao.configure.DataBase) Test(org.junit.Test)

Example 28 with SelectionContext

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);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalHA(com.ctrip.platform.dal.dao.client.DalHA) ArrayList(java.util.ArrayList) SelectionContext(com.ctrip.platform.dal.dao.configure.SelectionContext) DataBase(com.ctrip.platform.dal.dao.configure.DataBase) Test(org.junit.Test)

Example 29 with SelectionContext

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));
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ArrayList(java.util.ArrayList) SelectionContext(com.ctrip.platform.dal.dao.configure.SelectionContext) DataBase(com.ctrip.platform.dal.dao.configure.DataBase) Test(org.junit.Test)

Example 30 with SelectionContext

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);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ArrayList(java.util.ArrayList) SelectionContext(com.ctrip.platform.dal.dao.configure.SelectionContext) DataBase(com.ctrip.platform.dal.dao.configure.DataBase) Test(org.junit.Test)

Aggregations

SelectionContext (com.ctrip.platform.dal.dao.configure.SelectionContext)35 DataBase (com.ctrip.platform.dal.dao.configure.DataBase)33 ArrayList (java.util.ArrayList)33 Test (org.junit.Test)33 DalHints (com.ctrip.platform.dal.dao.DalHints)27 DalHA (com.ctrip.platform.dal.dao.client.DalHA)15