Search in sources :

Example 1 with MasterSlaveRule

use of io.shardingjdbc.core.rule.MasterSlaveRule in project sharding-jdbc by shardingjdbc.

the class MasterSlaveDataSource method renew.

/**
 * Renew master-slave data source.
 *
 * @param dataSourceMap data source map
 * @param masterSlaveRuleConfig new master-slave rule configuration
 */
public void renew(final Map<String, DataSource> dataSourceMap, final MasterSlaveRuleConfiguration masterSlaveRuleConfig) {
    this.dataSourceMap = dataSourceMap;
    this.masterSlaveRule = new MasterSlaveRule(masterSlaveRuleConfig);
}
Also used : MasterSlaveRule(io.shardingjdbc.core.rule.MasterSlaveRule)

Example 2 with MasterSlaveRule

use of io.shardingjdbc.core.rule.MasterSlaveRule in project sharding-jdbc by shardingjdbc.

the class MasterSlaveNamespaceTest method assertRefMasterSlaveDataSource.

@Test
public void assertRefMasterSlaveDataSource() {
    MasterSlaveLoadBalanceAlgorithm randomStrategy = this.applicationContext.getBean("randomStrategy", MasterSlaveLoadBalanceAlgorithm.class);
    MasterSlaveRule masterSlaveRule = getMasterSlaveRule("refMasterSlaveDataSource");
    assertTrue(masterSlaveRule.getLoadBalanceAlgorithm() == randomStrategy);
}
Also used : MasterSlaveLoadBalanceAlgorithm(io.shardingjdbc.core.api.algorithm.masterslave.MasterSlaveLoadBalanceAlgorithm) RoundRobinMasterSlaveLoadBalanceAlgorithm(io.shardingjdbc.core.api.algorithm.masterslave.RoundRobinMasterSlaveLoadBalanceAlgorithm) RandomMasterSlaveLoadBalanceAlgorithm(io.shardingjdbc.core.api.algorithm.masterslave.RandomMasterSlaveLoadBalanceAlgorithm) MasterSlaveRule(io.shardingjdbc.core.rule.MasterSlaveRule) Test(org.junit.Test)

Example 3 with MasterSlaveRule

use of io.shardingjdbc.core.rule.MasterSlaveRule in project sharding-jdbc by shardingjdbc.

the class OrchestrationMasterSlaveNamespaceTest method assertRefMasterSlaveDataSource.

@Test
public void assertRefMasterSlaveDataSource() {
    MasterSlaveLoadBalanceAlgorithm randomStrategy = this.applicationContext.getBean("randomStrategy", MasterSlaveLoadBalanceAlgorithm.class);
    MasterSlaveRule masterSlaveRule = getMasterSlaveRule("refMasterSlaveDataSource");
    assertTrue(EqualsBuilder.reflectionEquals(masterSlaveRule.getLoadBalanceAlgorithm(), randomStrategy));
}
Also used : MasterSlaveLoadBalanceAlgorithm(io.shardingjdbc.core.api.algorithm.masterslave.MasterSlaveLoadBalanceAlgorithm) RoundRobinMasterSlaveLoadBalanceAlgorithm(io.shardingjdbc.core.api.algorithm.masterslave.RoundRobinMasterSlaveLoadBalanceAlgorithm) RandomMasterSlaveLoadBalanceAlgorithm(io.shardingjdbc.core.api.algorithm.masterslave.RandomMasterSlaveLoadBalanceAlgorithm) MasterSlaveRule(io.shardingjdbc.core.rule.MasterSlaveRule) Test(org.junit.Test)

Example 4 with MasterSlaveRule

use of io.shardingjdbc.core.rule.MasterSlaveRule in project sharding-jdbc by shardingjdbc.

the class OrchestrationMasterSlaveNamespaceTest method assertTypeMasterSlaveDataSource.

@Test
public void assertTypeMasterSlaveDataSource() {
    MasterSlaveRule randomSlaveRule = getMasterSlaveRule("randomMasterSlaveDataSource");
    MasterSlaveRule roundRobinSlaveRule = getMasterSlaveRule("roundRobinMasterSlaveDataSource");
    assertTrue(randomSlaveRule.getLoadBalanceAlgorithm() instanceof RandomMasterSlaveLoadBalanceAlgorithm);
    assertTrue(roundRobinSlaveRule.getLoadBalanceAlgorithm() instanceof RoundRobinMasterSlaveLoadBalanceAlgorithm);
}
Also used : RoundRobinMasterSlaveLoadBalanceAlgorithm(io.shardingjdbc.core.api.algorithm.masterslave.RoundRobinMasterSlaveLoadBalanceAlgorithm) RandomMasterSlaveLoadBalanceAlgorithm(io.shardingjdbc.core.api.algorithm.masterslave.RandomMasterSlaveLoadBalanceAlgorithm) MasterSlaveRule(io.shardingjdbc.core.rule.MasterSlaveRule) Test(org.junit.Test)

Example 5 with MasterSlaveRule

use of io.shardingjdbc.core.rule.MasterSlaveRule in project sharding-jdbc by shardingjdbc.

the class OrchestrationMasterSlaveNamespaceTest method assertDefaultMaserSlaveDataSource.

@Test
public void assertDefaultMaserSlaveDataSource() {
    MasterSlaveRule masterSlaveRule = getMasterSlaveRule("defaultMasterSlaveDataSource");
    assertThat(masterSlaveRule.getMasterDataSourceName(), is("dbtbl_0_master"));
    assertTrue(masterSlaveRule.getSlaveDataSourceNames().contains("dbtbl_0_slave_0"));
    assertTrue(masterSlaveRule.getSlaveDataSourceNames().contains("dbtbl_0_slave_1"));
}
Also used : MasterSlaveRule(io.shardingjdbc.core.rule.MasterSlaveRule) Test(org.junit.Test)

Aggregations

MasterSlaveRule (io.shardingjdbc.core.rule.MasterSlaveRule)7 Test (org.junit.Test)6 RandomMasterSlaveLoadBalanceAlgorithm (io.shardingjdbc.core.api.algorithm.masterslave.RandomMasterSlaveLoadBalanceAlgorithm)4 RoundRobinMasterSlaveLoadBalanceAlgorithm (io.shardingjdbc.core.api.algorithm.masterslave.RoundRobinMasterSlaveLoadBalanceAlgorithm)4 MasterSlaveLoadBalanceAlgorithm (io.shardingjdbc.core.api.algorithm.masterslave.MasterSlaveLoadBalanceAlgorithm)2