Search in sources :

Example 1 with ClusterConfig

use of com.ctrip.framework.dal.cluster.client.config.ClusterConfig in project dal by ctripcorp.

the class DefaultClusterTest method init.

@BeforeClass
public static void init() {
    ClusterConfigProvider provider = new DefaultLocalConfigProvider("demo-cluster");
    // todo-lhj xiu dance
    ClusterConfig config = provider.getClusterConfig(mockCustomizedOption());
    cluster = config.generate();
}
Also used : ClusterConfigProvider(com.ctrip.framework.dal.cluster.client.config.ClusterConfigProvider) DefaultLocalConfigProvider(com.ctrip.framework.dal.cluster.client.config.DefaultLocalConfigProvider) ClusterConfig(com.ctrip.framework.dal.cluster.client.config.ClusterConfig) BeforeClass(org.junit.BeforeClass)

Example 2 with ClusterConfig

use of com.ctrip.framework.dal.cluster.client.config.ClusterConfig in project dal by ctripcorp.

the class DefaultLocalConfigProviderTest method test.

@Test
public void test() {
    ClusterConfigProvider provider = new DefaultLocalConfigProvider("demo-cluster");
    // todo-lhj xiu dan ce
    ClusterConfig config = provider.getClusterConfig(DefaultClusterTest.mockCustomizedOption());
    LOGGER.info(String.format("cluster config: %s", config.toString()));
}
Also used : ClusterConfigProvider(com.ctrip.framework.dal.cluster.client.config.ClusterConfigProvider) DefaultLocalConfigProvider(com.ctrip.framework.dal.cluster.client.config.DefaultLocalConfigProvider) ClusterConfig(com.ctrip.framework.dal.cluster.client.config.ClusterConfig) Test(org.junit.Test)

Example 3 with ClusterConfig

use of com.ctrip.framework.dal.cluster.client.config.ClusterConfig in project dal by ctripcorp.

the class ClusterConfigParserTest method test.

@Test
public void test() {
    ClusterConfigProvider provider = new DefaultLocalConfigProvider("TestCluster");
    // todo-lhj
    ClusterConfig config = provider.getClusterConfig(new DefaultDalConfigCustomizedOption());
    LOGGER.info(String.format("cluster config: %s", config.toString()));
}
Also used : ClusterConfigProvider(com.ctrip.framework.dal.cluster.client.config.ClusterConfigProvider) DefaultLocalConfigProvider(com.ctrip.framework.dal.cluster.client.config.DefaultLocalConfigProvider) ClusterConfig(com.ctrip.framework.dal.cluster.client.config.ClusterConfig) Test(org.junit.Test)

Example 4 with ClusterConfig

use of com.ctrip.framework.dal.cluster.client.config.ClusterConfig in project dal by ctripcorp.

the class ClusterDatabaseSetTest method testNonShardingCluster.

@Test
public void testNonShardingCluster() {
    ClusterConfigProvider provider = new DefaultLocalConfigProvider("NonShardingCluster");
    // todo-lhj
    ClusterConfig config = provider.getClusterConfig(new DefaultDalConfigCustomizedOption());
    Cluster cluster = config.generate();
    ClusterDatabaseSet databaseSet = new ClusterDatabaseSet("NonShardingCluster", cluster, new DalConnectionLocator() {

        @Override
        public void setup(Collection<DatabaseSet> databaseSets) {
        }

        @Override
        public Connection getConnection(String name) throws Exception {
            return null;
        }

        @Override
        public Connection getConnection(String name, ConnectionAction action) throws Exception {
            return null;
        }

        @Override
        public Connection getConnection(DataSourceIdentity id) throws Exception {
            return null;
        }

        @Override
        public Connection getConnection(DataSourceIdentity id, ConnectionAction action) throws Exception {
            return null;
        }

        @Override
        public IntegratedConfigProvider getIntegratedConfigProvider() {
            return null;
        }

        @Override
        public void setupCluster(Cluster cluster) {
        }

        @Override
        public void uninstallCluster(Cluster cluster) {
        }

        @Override
        public void initialize(Map<String, String> settings) throws Exception {
        }
    });
    Assert.assertFalse(databaseSet.isShardingSupported());
    Assert.assertEquals(1, databaseSet.getMasterDbs().size());
    Assert.assertEquals(0, databaseSet.getSlaveDbs().size());
}
Also used : DataSourceIdentity(com.ctrip.platform.dal.dao.datasource.DataSourceIdentity) Connection(java.sql.Connection) Cluster(com.ctrip.framework.dal.cluster.client.Cluster) ClusterConfigProvider(com.ctrip.framework.dal.cluster.client.config.ClusterConfigProvider) ConnectionAction(com.ctrip.platform.dal.dao.client.ConnectionAction) DefaultLocalConfigProvider(com.ctrip.framework.dal.cluster.client.config.DefaultLocalConfigProvider) ClusterConfig(com.ctrip.framework.dal.cluster.client.config.ClusterConfig) DalConnectionLocator(com.ctrip.platform.dal.dao.client.DalConnectionLocator) Test(org.junit.Test)

Example 5 with ClusterConfig

use of com.ctrip.framework.dal.cluster.client.config.ClusterConfig in project dal by ctripcorp.

the class ClusterConfigAdapter method load.

private void load(DalConnectionStringConfigure configure) {
    ClusterConfig clusterConfig;
    if (configure instanceof InvalidVariableConnectionString) {
        throw new DalRuntimeException("connectionString invalid for db: " + provider.getDbName(), ((InvalidVariableConnectionString) configure).getConnectionStringException());
    }
    if (configure == null)
        throw new RuntimeException("Get null config from mysqlapi for db: " + provider.getDbName());
    if (configure instanceof MultiHostConnectionStringConfigure)
        clusterConfig = buildMultiHostClusterConfig((MultiHostConnectionStringConfigure) configure);
    else
        clusterConfig = buildNormalClusterConfig(configure);
    clusterConfigRef.getAndSet(clusterConfig);
    DalConnectionStringConfigure prev = connStrConfigRef.getAndSet(configure);
    if (prev != null && !equals(prev, configure))
        for (Listener<ClusterConfig> listener : getListeners()) {
            try {
                listener.onChanged(this);
            } catch (Throwable t) {
            // ignore
            }
        }
}
Also used : DalRuntimeException(com.ctrip.platform.dal.exceptions.DalRuntimeException) DalRuntimeException(com.ctrip.platform.dal.exceptions.DalRuntimeException) Listener(com.ctrip.framework.dal.cluster.client.base.Listener) ClusterConfig(com.ctrip.framework.dal.cluster.client.config.ClusterConfig)

Aggregations

ClusterConfig (com.ctrip.framework.dal.cluster.client.config.ClusterConfig)5 ClusterConfigProvider (com.ctrip.framework.dal.cluster.client.config.ClusterConfigProvider)4 DefaultLocalConfigProvider (com.ctrip.framework.dal.cluster.client.config.DefaultLocalConfigProvider)4 Test (org.junit.Test)3 Cluster (com.ctrip.framework.dal.cluster.client.Cluster)1 Listener (com.ctrip.framework.dal.cluster.client.base.Listener)1 ConnectionAction (com.ctrip.platform.dal.dao.client.ConnectionAction)1 DalConnectionLocator (com.ctrip.platform.dal.dao.client.DalConnectionLocator)1 DataSourceIdentity (com.ctrip.platform.dal.dao.datasource.DataSourceIdentity)1 DalRuntimeException (com.ctrip.platform.dal.exceptions.DalRuntimeException)1 Connection (java.sql.Connection)1 BeforeClass (org.junit.BeforeClass)1