Search in sources :

Example 31 with DatabaseSelector

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

the class DatabaseSelectorTest method hasHASlavesOneMarkdownTest.

@Test
public void hasHASlavesOneMarkdownTest() 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();
    autoMarkdown(S2);
    DatabaseSelector selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, false, true);
    Assert.assertEquals(S1, selector.select());
    // masterOnly
    ha = new DalHA();
    selector = new DatabaseSelector(new DalHints().setHA(ha), null, ss, true, true);
    assertSelector(selector, ErrorCode.NullLogicDbName);
    ha = new DalHA();
    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 32 with DatabaseSelector

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

the class DatabaseSelectorTest method onlyOneSlaveTest.

@Test
public void onlyOneSlaveTest() throws DalException {
    DataBase db = new DataBase(S1, false, "", S1);
    List<DataBase> dbs = new ArrayList<DataBase>();
    dbs.add(db);
    DatabaseSelector selector = new DatabaseSelector(null, null, dbs, false, true);
    Assert.assertEquals(S1, selector.select());
    selector = new DatabaseSelector(new DalHints().inDatabase(S1), null, dbs, false, true);
    Assert.assertEquals(S1, selector.select());
    selector = new DatabaseSelector(new DalHints().inDatabase(M1), null, dbs, false, true);
    assertSelector(selector, ErrorCode.InvalidDatabaseKeyName);
    // masterOnly
    selector = new DatabaseSelector(null, null, dbs, true, true);
    assertSelector(selector, ErrorCode.NullLogicDbName);
    selector = new DatabaseSelector(null, null, dbs, true, false);
    assertSelector(selector, ErrorCode.NullLogicDbName);
    // test pointed
    selector = new DatabaseSelector(new DalHints().inDatabase(S1), null, dbs, true, true);
    assertSelector(selector, ErrorCode.NullLogicDbName);
    selector = new DatabaseSelector(new DalHints().inDatabase(S1), null, dbs, true, false);
    assertSelector(selector, ErrorCode.NullLogicDbName);
}
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 33 with DatabaseSelector

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

the class DatabaseSelectorTest method onlyOneMasterTest.

@Test
public void onlyOneMasterTest() throws DalException {
    DataBase db = new DataBase(M1, true, "", M1);
    List<DataBase> dbs = new ArrayList<DataBase>();
    dbs.add(db);
    DatabaseSelector selector = new DatabaseSelector(null, dbs, null, false, false);
    Assert.assertEquals(M1, selector.select());
    selector = new DatabaseSelector(null, dbs, null, false, true);
    Assert.assertEquals(M1, selector.select());
    // masterOnly
    selector = new DatabaseSelector(null, dbs, null, true, false);
    Assert.assertEquals(M1, selector.select());
    selector = new DatabaseSelector(null, dbs, null, true, true);
    Assert.assertEquals(M1, selector.select());
}
Also used : 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