Search in sources :

Example 6 with DalHA

use of com.ctrip.platform.dal.dao.client.DalHA 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);
    DatabaseSelector selector = new DatabaseSelector(null, dbs, null, false, false);
    assertSelector(selector, M2);
    selector = new DatabaseSelector(null, dbs, null, false, true);
    assertSelector(selector, M2);
    // masterOnly
    selector = new DatabaseSelector(null, dbs, null, true, false);
    assertSelector(selector, M2);
    selector = new DatabaseSelector(new DalHints().inDatabase(M2), dbs, null, true, false);
    assertSelector(selector, M2);
    selector = new DatabaseSelector(null, dbs, null, true, true);
    assertSelector(selector, M2);
    selector = new DatabaseSelector(new DalHints().inDatabase(M2), dbs, null, true, true);
    assertSelector(selector, M2);
    // test pointed db
    selector = new DatabaseSelector(new DalHints().inDatabase(M1), dbs, null, true, false);
    assertSelector(selector, ErrorCode.MarkdownConnection);
    selector = new DatabaseSelector(new DalHints().setHA(new DalHA().addDB(M2)), dbs, null, true, false);
    assertSelector(selector, M2);
}
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 7 with DalHA

use of com.ctrip.platform.dal.dao.client.DalHA 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));
    DatabaseSelector selector;
    Set<String> matched;
    matched = newHashSet(S1, S2, S3);
    DalHints hints = new DalHints().setHA(new DalHA());
    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, 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 8 with DalHA

use of com.ctrip.platform.dal.dao.client.DalHA in project dal by ctripcorp.

the class DatabaseSelectorTest method onlyHaveMasterHaTest.

@Test
public void onlyHaveMasterHaTest() 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;
    Set<String> matched;
    matched = newHashSet(M1, M2);
    DalHints hints = new DalHints().setHA(new DalHA());
    selector = new DatabaseSelector(hints, ms, ss, false, true);
    assertSelector(selector, matched);
    selector = new DatabaseSelector(hints, ms, ss, false, true);
    assertSelector(selector, matched);
    // reset
    matched = newHashSet(M1, M2);
    hints = new DalHints().setHA(new DalHA());
    selector = new DatabaseSelector(hints, ms, ss, false, false);
    assertSelector(selector, matched);
    selector = new DatabaseSelector(hints, ms, ss, false, false);
    assertSelector(selector, matched);
    // Master only
    matched = newHashSet(M1, M2);
    hints = new DalHints().setHA(new DalHA());
    selector = new DatabaseSelector(hints, ms, ss, true, true);
    assertSelector(selector, M1, M2);
    selector = new DatabaseSelector(hints, ms, ss, true, true);
    assertSelector(selector, M1, M2);
    // reset
    matched = newHashSet(M1, M2);
    hints = new DalHints().setHA(new DalHA());
    selector = new DatabaseSelector(hints, ms, ss, true, false);
    assertSelector(selector, M1, M2);
    selector = new DatabaseSelector(hints, ms, ss, true, false);
    assertSelector(selector, M1, M2);
}
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 9 with DalHA

use of com.ctrip.platform.dal.dao.client.DalHA in project dal by ctripcorp.

the class DatabaseSelectorTest method hasHASlavesTest.

@Test
public void hasHASlavesTest() 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();
    ha.addDB(S1);
    DatabaseSelector selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, false, true);
    Assert.assertEquals(S2, 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)

Example 10 with DalHA

use of com.ctrip.platform.dal.dao.client.DalHA in project dal by ctripcorp.

the class DatabaseSelectorTest method hasHASlavesAllNotUsedTest.

@Test
public void hasHASlavesAllNotUsedTest() 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();
    ha.addDB(S1);
    ha.addDB(S2);
    DatabaseSelector selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, false, true);
    assertSelector(selector, ErrorCode.NoMoreConnectionToFailOver);
    // masterOnly
    ha = new DalHA();
    ha.addDB(S1);
    ha.addDB(S2);
    selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, true, true);
    assertSelector(selector, ErrorCode.NullLogicDbName);
    ha = new DalHA();
    ha.addDB(S1);
    ha.addDB(S2);
    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