Search in sources :

Example 6 with HazelcastDiscoveryServiceFactory

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));
}
Also used : HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) HashMap(java.util.HashMap) IntFunction(java.util.function.IntFunction) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 7 with HazelcastDiscoveryServiceFactory

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));
    }
}
Also used : HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) HashMap(java.util.HashMap) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) IntFunction(java.util.function.IntFunction) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) Test(org.junit.Test)

Example 8 with HazelcastDiscoveryServiceFactory

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));
}
Also used : HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)8 Cluster (org.neo4j.causalclustering.discovery.Cluster)7 HashMap (java.util.HashMap)4 IntFunction (java.util.function.IntFunction)4 File (java.io.File)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 BooleanSupplier (java.util.function.BooleanSupplier)2 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)2 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1 Integer.parseInt (java.lang.Integer.parseInt)1 Long.parseLong (java.lang.Long.parseLong)1 System.getProperty (java.lang.System.getProperty)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Map (java.util.Map)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1