Search in sources :

Example 11 with SelectionContext

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

the class DatabaseSelectorTest method desigantedMarkdownDbTest.

@Test
public void desigantedMarkdownDbTest() 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(M1);
    autoMarkdown(M2);
    autoMarkdown(S1);
    autoMarkdown(S2);
    autoMarkdown(S3);
    context = getContext(new DalHints().inDatabase(M1), ms, ss, false, true);
    assertSelector(context, ErrorCode.MarkdownConnection);
    context = getContext(new DalHints().inDatabase(M2), ms, ss, false, true);
    assertSelector(context, ErrorCode.MarkdownConnection);
    context = getContext(new DalHints().inDatabase(S1), ms, ss, false, true);
    assertSelector(context, ErrorCode.MarkdownConnection);
    context = getContext(new DalHints().inDatabase(S2), ms, ss, false, true);
    assertSelector(context, ErrorCode.MarkdownConnection);
    context = getContext(new DalHints().inDatabase(S2), ms, ss, false, true);
    assertSelector(context, ErrorCode.MarkdownConnection);
}
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 12 with SelectionContext

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

the class DatabaseSelectorTest method onlyHaveMasterHaMarkdownTest.

@Test
public void onlyHaveMasterHaMarkdownTest() 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;
    // with markdown
    autoMarkdown(M1);
    DalHints hints = new DalHints().setHA(new DalHA());
    context = getContext(hints, ms, ss, true, false);
    assertSelector(context, M2);
    context = getContext(hints, ms, ss, true, false);
    assertSelector(context, M2);
    // reset
    hints = new DalHints().setHA(new DalHA());
    autoMarkdown(M2);
    context = getContext(hints, ms, ss, true, false);
    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 13 with SelectionContext

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

the class DatabaseSelectorTest method validDesigantedDbTest.

@Test
public void validDesigantedDbTest() 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), ms, ss, false, true);
    Assert.assertEquals(M1, selector.select(context));
    context = getContext(new DalHints().inDatabase(M2), ms, ss, false, true);
    Assert.assertEquals(M2, selector.select(context));
    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));
    context = getContext(new DalHints().inDatabase(S3), ms, ss, false, true);
    Assert.assertEquals(S3, selector.select(context));
    autoMarkdown(M1);
    context = getContext(new DalHints().inDatabase(M2), ms, ss, false, true);
    Assert.assertEquals(M2, selector.select(context));
    autoMarkdown(S1);
    autoMarkdown(S2);
    context = getContext(new DalHints().inDatabase(S3), ms, ss, false, true);
    Assert.assertEquals(S3, 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 14 with SelectionContext

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

the class DatabaseSelectorTest method notMasterOnlyTest.

@Test
public void notMasterOnlyTest() 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(null, ms, ss, false, true);
    assertSelector(context, S1, S2, S3);
    context = getContext(null, ms, ss, false, false);
    assertSelector(context, M1, M2);
}
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 15 with SelectionContext

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

the class DatabaseSelectorTest method hasHAMixedMasterAndSlaveButOneMasterMarkdownTest.

@Test
public void hasHAMixedMasterAndSlaveButOneMasterMarkdownTest() 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().setHA(new DalHA().addDB(S1)), ms, ss, false, true);
    Assert.assertEquals(S2, selector.select(context));
    context = getContext(new DalHints().setHA(new DalHA().addDB(S1)).inDatabase(S1), ms, ss, false, true);
    assertSelector(context, ErrorCode.NoMoreConnectionToFailOver);
    // masterOnly
    context = getContext(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, true, true);
    Assert.assertEquals(M2, selector.select(context));
    context = getContext(new DalHints().setHA(new DalHA().addDB(S1)).inDatabase(M1), ms, ss, true, true);
    assertSelector(context, ErrorCode.MarkdownConnection);
    context = getContext(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, true, false);
    Assert.assertEquals(M2, selector.select(context));
    context = getContext(new DalHints().setHA(new DalHA().addDB(S1)).inDatabase(M1), ms, ss, true, false);
    assertSelector(context, ErrorCode.MarkdownConnection);
    context = getContext(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, false, false);
    Assert.assertEquals(M2, selector.select(context));
    autoMarkdown(M2);
    context = getContext(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, false, false);
    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