use of org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory in project neo4j by neo4j.
the class ServerPoliciesLoadBalancingIT method shouldFallOverBetweenRules.
@Test
public void shouldFallOverBetweenRules() throws Exception {
Map<String, IntFunction<String>> instanceCoreParams = new HashMap<>();
instanceCoreParams.put(CausalClusteringSettings.server_groups.name(), (id) -> "core" + id + ",core");
Map<String, IntFunction<String>> instanceReplicaParams = new HashMap<>();
instanceReplicaParams.put(CausalClusteringSettings.server_groups.name(), (id) -> "replica" + id + ",replica");
String defaultPolicy = "groups(core) -> min(3); groups(replica1,replica2) -> min(2);";
Map<String, String> coreParams = stringMap(CausalClusteringSettings.cluster_allow_reads_on_followers.name(), "true", CausalClusteringSettings.load_balancing_config.name() + ".server_policies.default", defaultPolicy, CausalClusteringSettings.multi_dc_license.name(), "true");
cluster = new Cluster(testDir.directory("cluster"), 5, 5, new HazelcastDiscoveryServiceFactory(), coreParams, instanceCoreParams, emptyMap(), instanceReplicaParams, Standard.LATEST_NAME);
cluster.start();
// should use the first rule: only cores for reading
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(5, 1, 4, 0));
cluster.getCoreMemberById(3).shutdown();
// one core reader is gone, but we are still fulfilling min(3)
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(4, 1, 3, 0));
cluster.getCoreMemberById(0).shutdown();
// should now fall over to the second rule: use replica1 and replica2
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(3, 1, 0, 2));
cluster.getReadReplicaById(0).shutdown();
// this does not affect replica1 and replica2
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(3, 1, 0, 2));
cluster.getReadReplicaById(1).shutdown();
// should now fall over to use the last rule: all
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(3, 1, 2, 3));
cluster.addCoreMemberWithId(3).start();
// should now go back to first rule
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(4, 1, 3, 0));
}
use of org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory in project neo4j by neo4j.
the class ServerPoliciesLoadBalancingIT method shouldSupportSeveralPolicies.
@Test
public void shouldSupportSeveralPolicies() throws Exception {
Map<String, IntFunction<String>> instanceCoreParams = new HashMap<>();
instanceCoreParams.put(CausalClusteringSettings.server_groups.name(), (id) -> "core" + id + ",core");
Map<String, IntFunction<String>> instanceReplicaParams = new HashMap<>();
instanceReplicaParams.put(CausalClusteringSettings.server_groups.name(), (id) -> "replica" + id + ",replica");
String defaultPolicySpec = "groups(replica0,replica1)";
String policyOneTwoSpec = "groups(replica1,replica2)";
String policyZeroTwoSpec = "groups(replica0,replica2)";
String policyAllReplicasSpec = "groups(replica); halt()";
String allPolicySpec = "all()";
Map<String, String> coreParams = stringMap(CausalClusteringSettings.cluster_allow_reads_on_followers.name(), "true", CausalClusteringSettings.load_balancing_config.name() + ".server_policies.all", allPolicySpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.default", defaultPolicySpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.policy_one_two", policyOneTwoSpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.policy_zero_two", policyZeroTwoSpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.policy_all_replicas", policyAllReplicasSpec, CausalClusteringSettings.multi_dc_license.name(), "true");
cluster = new Cluster(testDir.directory("cluster"), 3, 3, new HazelcastDiscoveryServiceFactory(), coreParams, instanceCoreParams, emptyMap(), instanceReplicaParams, Standard.LATEST_NAME);
cluster.start();
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(3, 1, 2, 3), policyContext("all"));
for (CoreClusterMember core : cluster.coreMembers()) {
CoreGraphDatabase db = core.database();
assertThat(getServers(db, policyContext("default")), new SpecificReplicasMatcher(0, 1));
assertThat(getServers(db, policyContext("policy_one_two")), new SpecificReplicasMatcher(1, 2));
assertThat(getServers(db, policyContext("policy_zero_two")), new SpecificReplicasMatcher(0, 2));
assertThat(getServers(db, policyContext("policy_all_replicas")), new SpecificReplicasMatcher(0, 1, 2));
}
}
use of org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory in project neo4j by neo4j.
the class ServerPoliciesLoadBalancingIT method defaultBehaviourWithAllowReadsOnFollowers.
@Test
public void defaultBehaviourWithAllowReadsOnFollowers() throws Exception {
cluster = new Cluster(testDir.directory("cluster"), 3, 3, new HazelcastDiscoveryServiceFactory(), stringMap(CausalClusteringSettings.cluster_allow_reads_on_followers.name(), "true"), emptyMap(), emptyMap(), emptyMap(), Standard.LATEST_NAME);
cluster.start();
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(3, 1, 2, 3));
}
Aggregations