Search in sources :

Example 11 with DataBase

use of com.ctrip.platform.dal.dao.configure.DataBase 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)

Example 12 with DataBase

use of com.ctrip.platform.dal.dao.configure.DataBase 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));
    DatabaseSelector selector;
    selector = new DatabaseSelector(new DalHints().inDatabase(M1), ms, ss, false, true);
    Assert.assertEquals(M1, selector.select());
    selector = new DatabaseSelector(new DalHints().inDatabase(M2), ms, ss, false, true);
    Assert.assertEquals(M2, selector.select());
    selector = new DatabaseSelector(new DalHints().inDatabase(S1), ms, ss, false, true);
    Assert.assertEquals(S1, selector.select());
    selector = new DatabaseSelector(new DalHints().inDatabase(S2), ms, ss, false, true);
    Assert.assertEquals(S2, selector.select());
    selector = new DatabaseSelector(new DalHints().inDatabase(S3), ms, ss, false, true);
    Assert.assertEquals(S3, selector.select());
    autoMarkdown(M1);
    selector = new DatabaseSelector(new DalHints().inDatabase(M2), ms, ss, false, true);
    Assert.assertEquals(M2, selector.select());
    autoMarkdown(S1);
    autoMarkdown(S2);
    selector = new DatabaseSelector(new DalHints().inDatabase(S3), ms, ss, false, true);
    Assert.assertEquals(S3, selector.select());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) 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 13 with DataBase

use of com.ctrip.platform.dal.dao.configure.DataBase 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));
    DatabaseSelector selector;
    autoMarkdown(M1);
    autoMarkdown(M2);
    autoMarkdown(S1);
    autoMarkdown(S2);
    autoMarkdown(S3);
    selector = new DatabaseSelector(new DalHints().inDatabase(M1), ms, ss, false, true);
    assertSelector(selector, ErrorCode.MarkdownConnection);
    selector = new DatabaseSelector(new DalHints().inDatabase(M2), ms, ss, false, true);
    assertSelector(selector, ErrorCode.MarkdownConnection);
    selector = new DatabaseSelector(new DalHints().inDatabase(S1), ms, ss, false, true);
    assertSelector(selector, ErrorCode.MarkdownConnection);
    selector = new DatabaseSelector(new DalHints().inDatabase(S2), ms, ss, false, true);
    assertSelector(selector, ErrorCode.MarkdownConnection);
    selector = new DatabaseSelector(new DalHints().inDatabase(S2), ms, ss, false, true);
    assertSelector(selector, ErrorCode.MarkdownConnection);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) 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 14 with DataBase

use of com.ctrip.platform.dal.dao.configure.DataBase 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 15 with DataBase

use of com.ctrip.platform.dal.dao.configure.DataBase 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)

Aggregations

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