Search in sources :

Example 1 with ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec

use of com.ctrip.framework.dal.cluster.client.shard.read.ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec in project dal by ctripcorp.

the class ReadCurrentZoneSlavesOnlyStrategyTest method pickCurrentZoneSlaveOnly.

@Test
public void pickCurrentZoneSlaveOnly() {
    ReadCurrentZoneSlavesOnlyStrategy strategy = new ReadCurrentZoneSlavesOnlyStrategy();
    strategy.init(ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec(), null);
    strategy.currentZone = "shaoy";
    HostSpec hostSpec = strategy.pickRead(new DalHints());
    assertEquals(strategy.currentZone, hostSpec.getTrimLowerCaseZone());
    strategy.currentZone = "";
    try {
        hostSpec = strategy.pickRead(new DalHints());
        fail();
    } catch (Throwable t) {
        assertEquals(true, t instanceof DalMetadataException);
        assertEquals(" has no database in ", t.getMessage());
    }
    strategy.currentZone = "shaxy";
    try {
        hostSpec = strategy.pickRead(new DalHints());
        fail();
    } catch (Throwable t) {
        assertEquals(true, t instanceof DalMetadataException);
        assertEquals(" has no database in " + strategy.currentZone, t.getMessage());
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalMetadataException(com.ctrip.framework.dal.cluster.client.exception.DalMetadataException) HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec) ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec(com.ctrip.framework.dal.cluster.client.shard.read.ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec) Test(org.junit.Test)

Aggregations

HostSpec (com.ctrip.framework.dal.cluster.client.base.HostSpec)1 DalMetadataException (com.ctrip.framework.dal.cluster.client.exception.DalMetadataException)1 ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec (com.ctrip.framework.dal.cluster.client.shard.read.ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec)1 DalHints (com.ctrip.platform.dal.dao.DalHints)1 Test (org.junit.Test)1