Search in sources :

Example 6 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class RoundRobinAccessStrategyTest method pickNode_3_exceptionNode.

@Test
public void pickNode_3_exceptionNode() throws InterruptedException {
    RouteStrategy strategy = getRouteStrategy();
    strategy.init(shardMeta.configuredHosts(), caseInsensitiveProperties);
    routeStrategy.interceptException(new SQLException("test"), new DefaultHostConnection(null, HostSpecOY_1));
    HostSpec hostSpec1 = strategy.pickNode(dalHints);
    HostSpec hostSpec2 = strategy.pickNode(dalHints);
    Assert.assertEquals(HostSpecOY_2, hostSpec1);
    Assert.assertEquals(HostSpecOY_2, hostSpec2);
    TimeUnit.MILLISECONDS.sleep(custom_black_list_timeout + 1);
    // remove from black list
    hostSpec1 = strategy.pickNode(dalHints);
    hostSpec2 = strategy.pickNode(dalHints);
    Assert.assertNotEquals(hostSpec1, hostSpec2);
    strategy.dispose();
}
Also used : SQLException(java.sql.SQLException) DefaultHostConnection(com.ctrip.platform.dal.dao.datasource.cluster.DefaultHostConnection) HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec) Test(org.junit.Test)

Example 7 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class ShardMetaGenerator method addXY.

protected void addXY() {
    hostSpecs.add(new HostSpec(SHAXY_IP1, SHAXY_PORT1, SHAXY, true));
    hostSpecs.add(new HostSpec(SHAXY_IP2, SHAXY_PORT2, SHAXY, true));
}
Also used : HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec)

Example 8 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class ShardMetaGenerator method addRB.

protected void addRB() {
    hostSpecs.add(new HostSpec(SHARB_IP1, SHARB_PORT1, SHARB, true));
    hostSpecs.add(new HostSpec(SHARB_IP2, SHARB_PORT2, SHARB, true));
}
Also used : HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec)

Example 9 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class CompositeRoundRobinAccessStrategyTest method pickNode.

@Test
public void pickNode() throws SQLException {
    HostSpec hostSpec = routeStrategy.pickNode(dalHints);
    // pick from local
    Assert.assertEquals(getRequestZone(), hostSpec.zone());
    HostSpec hostSpec1 = routeStrategy.pickNode(dalHints);
    // pick from local
    Assert.assertEquals(getRequestZone(), hostSpec1.zone());
    // round robin, so not equal
    Assert.assertNotEquals(hostSpec, hostSpec1);
    // test request zone is down
    if (routeStrategy.isWrapperFor(Map.class)) {
        RouteStrategy localRouteStrategy = (RouteStrategy) routeStrategy.unwrap(Map.class).remove(SHAXY);
        Assert.assertNotNull(localRouteStrategy);
    }
    hostSpec = routeStrategy.pickNode(dalHints);
    // not pick from local
    Assert.assertNotEquals(getRequestZone(), hostSpec.zone());
}
Also used : RouteStrategy(com.ctrip.platform.dal.dao.datasource.cluster.strategy.RouteStrategy) HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec) Test(org.junit.Test)

Example 10 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class MGRStrategyTest method pickNode.

@Test
public void pickNode() {
    HostSpec hostSpec1 = routeStrategy.pickNode(dalHints);
    // pick from first
    Assert.assertEquals(getRequestZone(), hostSpec1.zone());
    HostSpec hostSpec2 = routeStrategy.pickNode(dalHints);
    // pick from first
    Assert.assertEquals(getRequestZone(), hostSpec2.zone());
    Assert.assertEquals(hostSpec1, hostSpec2);
    routeStrategy.dispose();
}
Also used : HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec) Test(org.junit.Test)

Aggregations

HostSpec (com.ctrip.framework.dal.cluster.client.base.HostSpec)30 Test (org.junit.Test)11 DalMetadataException (com.ctrip.framework.dal.cluster.client.exception.DalMetadataException)5 SQLException (java.sql.SQLException)5 ConnectionString (com.ctrip.framework.dal.cluster.client.database.ConnectionString)3 Database (com.ctrip.framework.dal.cluster.client.database.Database)3 DalHints (com.ctrip.platform.dal.dao.DalHints)3 HashMap (java.util.HashMap)3 DataSourceConfigure (com.ctrip.platform.dal.dao.configure.DataSourceConfigure)2 RouteStrategy (com.ctrip.platform.dal.dao.datasource.cluster.strategy.RouteStrategy)2 Connection (java.sql.Connection)2 Map (java.util.Map)2 DatabaseConfigImpl (com.ctrip.framework.dal.cluster.client.config.DatabaseConfigImpl)1 DatabaseShardConfigImpl (com.ctrip.framework.dal.cluster.client.config.DatabaseShardConfigImpl)1 CustomDataSourceFactory (com.ctrip.framework.dal.cluster.client.extended.CustomDataSourceFactory)1 ClusterRouteStrategyConfig (com.ctrip.framework.dal.cluster.client.multihost.ClusterRouteStrategyConfig)1 DefaultClusterRouteStrategyConfig (com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig)1 ReadCurrentZoneSlavesFirstStrategyTest (com.ctrip.framework.dal.cluster.client.shard.read.ReadCurrentZoneSlavesFirstStrategyTest)1 ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec (com.ctrip.framework.dal.cluster.client.shard.read.ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec)1 CaseInsensitiveProperties (com.ctrip.framework.dal.cluster.client.util.CaseInsensitiveProperties)1