Search in sources :

Example 11 with Cluster

use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.

the class RestartIT method restartSecondServer.

@Test
public void restartSecondServer() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    // when
    cluster.removeCoreMemberWithMemberId(1);
    cluster.addCoreMemberWithId(1).start();
    // then
    cluster.shutdown();
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 12 with Cluster

use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.

the class RestartIT method restartFirstServer.

@Test
public void restartFirstServer() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    // when
    cluster.removeCoreMemberWithMemberId(0);
    cluster.addCoreMemberWithId(0).start();
    // then
    cluster.shutdown();
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 13 with Cluster

use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.

the class ServerGroupsIT method shouldUpdateGroupsOnStart.

@Test
public void shouldUpdateGroupsOnStart() throws Exception {
    AtomicReference<String> suffix = new AtomicReference<>("before");
    List<List<String>> expected;
    Map<String, IntFunction<String>> instanceCoreParams = new HashMap<>();
    instanceCoreParams.put(CausalClusteringSettings.server_groups.name(), (id) -> String.join(", ", makeCoreGroups(suffix.get(), id)));
    Map<String, IntFunction<String>> instanceReplicaParams = new HashMap<>();
    instanceReplicaParams.put(CausalClusteringSettings.server_groups.name(), (id) -> String.join(", ", makeReplicaGroups(suffix.get(), id)));
    int nServers = 3;
    cluster = new Cluster(testDir.directory("cluster"), nServers, nServers, new HazelcastDiscoveryServiceFactory(), emptyMap(), instanceCoreParams, emptyMap(), instanceReplicaParams, Standard.LATEST_NAME);
    // when
    cluster.start();
    // then
    expected = new ArrayList<>();
    for (CoreClusterMember core : cluster.coreMembers()) {
        expected.add(makeCoreGroups(suffix.get(), core.serverId()));
        expected.add(makeReplicaGroups(suffix.get(), core.serverId()));
    }
    for (CoreClusterMember core : cluster.coreMembers()) {
        assertEventually(core + " should have groups", () -> getServerGroups(core.database()), new GroupsMatcher(expected), 30, SECONDS);
    }
    // when
    expected.remove(makeCoreGroups(suffix.get(), 1));
    expected.remove(makeReplicaGroups(suffix.get(), 2));
    cluster.getCoreMemberById(1).shutdown();
    cluster.getReadReplicaById(2).shutdown();
    // should update groups of restarted servers
    suffix.set("after");
    cluster.addCoreMemberWithId(1).start();
    cluster.addReadReplicaWithId(2).start();
    expected.add(makeCoreGroups(suffix.get(), 1));
    expected.add(makeReplicaGroups(suffix.get(), 2));
    // then
    for (CoreClusterMember core : cluster.coreMembers()) {
        assertEventually(core + " should have groups", () -> getServerGroups(core.database()), new GroupsMatcher(expected), 30, SECONDS);
    }
}
Also used : HashMap(java.util.HashMap) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) AtomicReference(java.util.concurrent.atomic.AtomicReference) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) IntFunction(java.util.function.IntFunction) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Example 14 with Cluster

use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.

the class ServerPoliciesLoadBalancingIT method defaultBehaviour.

@Test
public void defaultBehaviour() throws Exception {
    cluster = new Cluster(testDir.directory("cluster"), 3, 3, new HazelcastDiscoveryServiceFactory(), emptyMap(), 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)

Example 15 with Cluster

use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.

the class WillNotBecomeLeaderIT method clusterShouldNotElectNewLeader.

@Test
public void clusterShouldNotElectNewLeader() throws Exception {
    // given
    int leaderId = 0;
    clusterRule.withInstanceCoreParam(CausalClusteringSettings.refuse_to_be_leader, (x) -> {
        if (x == leaderId) {
            return "false";
        } else {
            return "true";
        }
    });
    Cluster cluster = clusterRule.createCluster();
    cluster.start();
    assertEquals(leaderId, cluster.awaitLeader().serverId());
    cluster.coreTx((db, tx) -> {
        Node node = db.createNode(label("boo"));
        node.setProperty("foobar", "baz_bat");
        tx.success();
    });
    // When
    cluster.removeCoreMemberWithMemberId(leaderId);
    // Then
    try {
        cluster.awaitLeader(10, SECONDS);
        fail("Should not have elected a leader");
    } catch (TimeoutException ex) {
    // Successful
    }
}
Also used : Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Aggregations

Cluster (org.neo4j.causalclustering.discovery.Cluster)52 Test (org.junit.Test)51 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)21 File (java.io.File)14 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)13 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)13 Node (org.neo4j.graphdb.Node)12 Rule (org.junit.Rule)11 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)11 IOException (java.io.IOException)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Transaction (org.neo4j.graphdb.Transaction)10 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)10 ClusterRule (org.neo4j.test.causalclustering.ClusterRule)10 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)9 Map (java.util.Map)8 TimeUnit (java.util.concurrent.TimeUnit)8 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)8 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)8 UnsatisfiedDependencyException (org.neo4j.kernel.impl.util.UnsatisfiedDependencyException)8