Search in sources :

Example 6 with SelectionContext

use of com.ctrip.platform.dal.dao.configure.SelectionContext in project dal by ctripcorp.

the class DatabaseSelectorTest method hasOneMarkdownMasterTest.

@Test
public void hasOneMarkdownMasterTest() throws DalException {
    List<DataBase> dbs = new ArrayList<DataBase>();
    dbs.add(new DataBase(M1, true, "", M1));
    dbs.add(new DataBase(M2, true, "", M2));
    autoMarkdown(M1);
    SelectionContext context = getContext(null, dbs, null, false, false);
    assertSelector(context, M2);
    context = getContext(null, dbs, null, false, true);
    assertSelector(context, M2);
    // masterOnly
    context = getContext(null, dbs, null, true, false);
    assertSelector(context, M2);
    context = getContext(new DalHints().inDatabase(M2), dbs, null, true, false);
    assertSelector(context, M2);
    context = getContext(null, dbs, null, true, true);
    assertSelector(context, M2);
    context = getContext(new DalHints().inDatabase(M2), dbs, null, true, true);
    assertSelector(context, M2);
    // test pointed db
    context = getContext(new DalHints().inDatabase(M1), dbs, null, true, false);
    assertSelector(context, ErrorCode.MarkdownConnection);
    context = getContext(new DalHints().setHA(new DalHA().addDB(M2)), dbs, null, true, false);
    assertSelector(context, M2);
}
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 7 with SelectionContext

use of com.ctrip.platform.dal.dao.configure.SelectionContext in project dal by ctripcorp.

the class DatabaseSelectorTest method onlyHaveSlaveHaTest.

@Test
public void onlyHaveSlaveHaTest() throws DalException {
    List<DataBase> ms = null;
    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;
    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);
    context = getContext(hints, ms, ss, false, true);
    assertSelector(context, ErrorCode.NoMoreConnectionToFailOver);
}
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 8 with SelectionContext

use of com.ctrip.platform.dal.dao.configure.SelectionContext in project dal by ctripcorp.

the class DatabaseSelectorTest method onlyOneMasterMarkdownTest.

// The rest tests are all original tests, that I don't think well organized
@Test
public void onlyOneMasterMarkdownTest() {
    autoMarkdown(M1);
    DataBase db = new DataBase(M1, true, "", M1);
    List<DataBase> dbs = new ArrayList<DataBase>();
    dbs.add(db);
    SelectionContext context = getContext(null, dbs, null, false, false);
    assertSelector(context, ErrorCode.MarkdownConnection);
    context = getContext(null, dbs, null, false, true);
    assertSelector(context, ErrorCode.MarkdownConnection);
    // masterOnly
    context = getContext(null, dbs, null, true, false);
    assertSelector(context, ErrorCode.MarkdownConnection);
    context = getContext(null, dbs, null, true, true);
    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 9 with SelectionContext

use of com.ctrip.platform.dal.dao.configure.SelectionContext in project dal by ctripcorp.

the class DatabaseSelectorTest method hasHASlavesOneMarkdownFailOverTest.

@Test
public void hasHASlavesOneMarkdownFailOverTest() throws DalException {
    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));
    DalHA ha = new DalHA();
    ha.addDB(S1);
    autoMarkdown(S2);
    SelectionContext context = getContext(new DalHints().setHA(ha), null, ss, false, true);
    Assert.assertEquals(S3, 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);
}
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 10 with SelectionContext

use of com.ctrip.platform.dal.dao.configure.SelectionContext in project dal by ctripcorp.

the class DatabaseSelectorTest method hasMixedMasterAndSlaveButMasterMarkdownTest.

@Test
public void hasMixedMasterAndSlaveButMasterMarkdownTest() throws DalException {
    List<DataBase> ms = new ArrayList<DataBase>();
    ms.add(new DataBase(M1, true, "", M1));
    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(null, ms, ss, false, true);
    String dbName = selector.select(context);
    Assert.assertTrue(dbName.equals(S1) || dbName.equals(S2));
    context = getContext(new DalHints().inDatabase(M1), ms, ss, false, true);
    assertSelector(context, ErrorCode.MarkdownConnection);
    context = getContext(new DalHints().inDatabase(S1), ms, ss, false, true);
    Assert.assertEquals(S1, selector.select(context));
    context = getContext(new DalHints().inDatabase(S2), ms, ss, false, true);
    Assert.assertEquals(S2, selector.select(context));
    // masterOnly
    context = getContext(null, ms, ss, true, true);
    assertSelector(context, ErrorCode.MarkdownConnection);
    context = getContext(null, ms, ss, true, false);
    assertSelector(context, ErrorCode.MarkdownConnection);
    context = getContext(new DalHints().inDatabase(S1), ms, ss, true, true);
    assertSelector(context, ErrorCode.InvalidDatabaseKeyName);
    context = getContext(new DalHints().inDatabase(S1), ms, ss, true, false);
    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