Search in sources :

Example 1 with SelectionContext

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

the class DatabaseSelectorTest method onlyHaveSlaveTest.

@Test
public void onlyHaveSlaveTest() 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;
    context = getContext(null, ms, ss, true, false);
    assertSelector(context, ErrorCode.NullLogicDbName);
    context = getContext(null, ms, ss, true, true);
    assertSelector(context, ErrorCode.NullLogicDbName);
    context = getContext(null, ms, ss, false, false);
    assertSelector(context, ErrorCode.NullLogicDbName);
    context = getContext(null, ms, ss, false, true);
    assertSelector(context, S1, S2, S3);
    autoMarkdown(S1);
    context = getContext(null, ms, ss, false, true);
    assertSelector(context, S2, S3);
    autoMarkdown(S2);
    context = getContext(null, ms, ss, false, true);
    assertSelector(context, S3);
    autoMarkdown(S3);
    context = getContext(null, ms, ss, false, 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 2 with SelectionContext

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

the class DatabaseSelectorTest method hasOneMarkdownSlaveTest.

@Test
public void hasOneMarkdownSlaveTest() throws DalException {
    autoMarkdown(S1);
    List<DataBase> dbs = new ArrayList<DataBase>();
    dbs.add(new DataBase(S1, false, "", S1));
    dbs.add(new DataBase(S2, false, "", S2));
    SelectionContext context = getContext(new DalHints(), null, dbs, false, true);
    Assert.assertEquals(S2, selector.select(context));
    context = getContext(new DalHints().inDatabase(S2), null, dbs, false, true);
    Assert.assertEquals(S2, selector.select(context));
    context = getContext(new DalHints().inDatabase(S1), null, dbs, false, true);
    assertSelector(context, ErrorCode.MarkdownConnection);
    // masterOnly
    context = getContext(null, null, dbs, true, true);
    assertSelector(context, ErrorCode.NullLogicDbName);
    context = getContext(null, null, dbs, true, false);
    assertSelector(context, ErrorCode.NullLogicDbName);
    context = getContext(new DalHints().inDatabase(S1), null, dbs, true, false);
    assertSelector(context, ErrorCode.NullLogicDbName);
}
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 3 with SelectionContext

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

the class DatabaseSelectorTest method isSelectTest.

@Test
public void isSelectTest() 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(null, ms, ss, false, true);
    String dbName = selector.select(context);
    Assert.assertTrue(dbName.equals(S1) || dbName.equals(S2));
    context = getContext(new DalHints().inDatabase(S1), ms, ss, false, true);
    Assert.assertTrue(selector.select(context).equals(S1));
    context = getContext(new DalHints().inDatabase(S2), ms, ss, false, true);
    Assert.assertTrue(selector.select(context).equals(S2));
    context = getContext(new DalHints().inDatabase(M2), ms, ss, false, true);
    assertSelector(context, M2);
    // masterOnly
    context = getContext(null, ms, ss, true, true);
    dbName = selector.select(context);
    assertSelector(context, M2, M1);
    context = getContext(new DalHints().inDatabase(M1), ms, ss, true, true);
    assertSelector(context, M1);
    context = getContext(new DalHints().inDatabase(M2), ms, ss, true, true);
    assertSelector(context, M2);
    context = getContext(new DalHints().inDatabase(S1), ms, ss, true, 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)

Example 4 with SelectionContext

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

the class DatabaseSelectorTest method onlyHaveSlaveHaMarkdownTest.

@Test
public void onlyHaveSlaveHaMarkdownTest() 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;
    autoMarkdown(S1);
    DalHints hints = new DalHints().setHA(new DalHA());
    matched = newHashSet(S2, S3);
    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 5 with SelectionContext

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

the class DatabaseSelectorTest method desigantedUsedInHaTest.

@Test
public void desigantedUsedInHaTest() 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().setHA(new DalHA().addDB(M1)).inDatabase(M1), ms, ss, false, true);
    assertSelector(context, ErrorCode.NoMoreConnectionToFailOver);
    context = getContext(new DalHints().setHA(new DalHA().addDB(S1)).inDatabase(S1), 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)

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