Search in sources :

Example 1 with DalHA

use of com.ctrip.platform.dal.dao.client.DalHA 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);
    DatabaseSelector selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, false, true);
    Assert.assertEquals(S2, selector.select());
    selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)).inDatabase(S1), ms, ss, false, true);
    assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
    // masterOnly
    selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, true, true);
    Assert.assertEquals(M2, selector.select());
    selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)).inDatabase(M1), ms, ss, true, true);
    assertSelector(selector, ErrorCode.MarkdownConnection);
    selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, true, false);
    Assert.assertEquals(M2, selector.select());
    selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)).inDatabase(M1), ms, ss, true, false);
    assertSelector(selector, ErrorCode.MarkdownConnection);
    selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, false, false);
    Assert.assertEquals(M2, selector.select());
    autoMarkdown(M2);
    selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)), ms, ss, false, false);
    assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalHA(com.ctrip.platform.dal.dao.client.DalHA) DatabaseSelector(com.ctrip.platform.dal.dao.configure.DatabaseSelector) ArrayList(java.util.ArrayList) DataBase(com.ctrip.platform.dal.dao.configure.DataBase) Test(org.junit.Test)

Example 2 with DalHA

use of com.ctrip.platform.dal.dao.client.DalHA 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));
    DatabaseSelector selector;
    selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(M1)).inDatabase(M1), ms, ss, false, true);
    assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
    selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(S1)).inDatabase(S1), ms, ss, false, true);
    assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalHA(com.ctrip.platform.dal.dao.client.DalHA) DatabaseSelector(com.ctrip.platform.dal.dao.configure.DatabaseSelector) ArrayList(java.util.ArrayList) DataBase(com.ctrip.platform.dal.dao.configure.DataBase) Test(org.junit.Test)

Example 3 with DalHA

use of com.ctrip.platform.dal.dao.client.DalHA 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;
    DatabaseSelector selector;
    // with markdown
    autoMarkdown(M1);
    DalHints hints = new DalHints().setHA(new DalHA());
    selector = new DatabaseSelector(hints, ms, ss, true, false);
    assertSelector(selector, M2);
    selector = new DatabaseSelector(hints, ms, ss, true, false);
    assertSelector(selector, M2);
    // reset
    hints = new DalHints().setHA(new DalHA());
    autoMarkdown(M2);
    selector = new DatabaseSelector(hints, ms, ss, true, false);
    assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalHA(com.ctrip.platform.dal.dao.client.DalHA) DatabaseSelector(com.ctrip.platform.dal.dao.configure.DatabaseSelector) ArrayList(java.util.ArrayList) DataBase(com.ctrip.platform.dal.dao.configure.DataBase) Test(org.junit.Test)

Example 4 with DalHA

use of com.ctrip.platform.dal.dao.client.DalHA 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));
    DatabaseSelector selector;
    Set<String> matched;
    autoMarkdown(S1);
    DalHints hints = new DalHints().setHA(new DalHA());
    matched = newHashSet(S2, S3);
    selector = new DatabaseSelector(hints, ms, ss, false, true);
    assertSelector(selector, matched);
    selector = new DatabaseSelector(hints, ms, ss, false, true);
    assertSelector(selector, matched);
    selector = new DatabaseSelector(hints, ms, ss, false, true);
    assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalHA(com.ctrip.platform.dal.dao.client.DalHA) DatabaseSelector(com.ctrip.platform.dal.dao.configure.DatabaseSelector) ArrayList(java.util.ArrayList) DataBase(com.ctrip.platform.dal.dao.configure.DataBase) Test(org.junit.Test)

Example 5 with DalHA

use of com.ctrip.platform.dal.dao.client.DalHA 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);
    DatabaseSelector selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, false, true);
    Assert.assertEquals(S3, selector.select());
    // masterOnly
    ha = new DalHA();
    ha.addDB(S1);
    selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, true, true);
    assertSelector(selector, ErrorCode.NullLogicDbName);
    ha = new DalHA();
    ha.addDB(S1);
    selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, true, false);
    assertSelector(selector, ErrorCode.NullLogicDbName);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalHA(com.ctrip.platform.dal.dao.client.DalHA) DatabaseSelector(com.ctrip.platform.dal.dao.configure.DatabaseSelector) ArrayList(java.util.ArrayList) DataBase(com.ctrip.platform.dal.dao.configure.DataBase) Test(org.junit.Test)

Aggregations

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