Search in sources :

Example 16 with CoreClusterMember

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

the class ClusterLeaderStepDownIT method leaderShouldStepDownWhenFollowersAreGone.

@Test
public void leaderShouldStepDownWhenFollowersAreGone() throws Throwable {
    // when
    Cluster cluster = clusterRule.startCluster();
    //Do some work to make sure the cluster is operating normally.
    CoreClusterMember leader = cluster.coreTx((db, tx) -> {
        Node node = db.createNode(Label.label("bam"));
        node.setProperty("bam", "bam");
        tx.success();
    });
    List<CoreClusterMember> followers = cluster.coreMembers().stream().filter(m -> m.raft().currentRole() != Role.LEADER).collect(toList());
    assertEquals(7, followers.size());
    //when
    //shutdown 4 servers, leaving 4 remaining and therefore not a quorum.
    followers.subList(0, 4).forEach(CoreClusterMember::shutdown);
    //then
    assertEventually("Leader should have stepped down.", () -> leader.raft().isLeader(), Matchers.is(false), 2, TimeUnit.MINUTES);
}
Also used : Role(org.neo4j.causalclustering.core.consensus.roles.Role) Label(org.neo4j.graphdb.Label) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) Assert.assertEventually(org.neo4j.test.assertion.Assert.assertEventually) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Rule(org.junit.Rule) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Assert.assertEquals(org.junit.Assert.assertEquals) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 17 with CoreClusterMember

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

the class ClusterMembershipChangeIT method newMemberNotInInitialMembersConfig.

@Test
@Ignore("Incomplete, HC will hang waiting for others to join.")
public void newMemberNotInInitialMembersConfig() throws Throwable {
    // when
    Cluster cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
    List<AdvertisedSocketAddress> onlyServerZero = singletonList(Cluster.socketAddressForServer(0));
    // then
    cluster.addCoreMemberWithIdAndInitialMembers(3, onlyServerZero).start();
    cluster.addCoreMemberWithIdAndInitialMembers(4, onlyServerZero).start();
    cluster.addCoreMemberWithIdAndInitialMembers(5, onlyServerZero).start();
    cluster.removeCoreMemberWithMemberId(0);
    cluster.removeCoreMemberWithMemberId(1);
    cluster.removeCoreMemberWithMemberId(2);
    cluster.shutdown();
    cluster.start();
    List<Object[]> currentMembers;
    for (CoreClusterMember member : cluster.coreMembers()) {
        currentMembers = discoverClusterMembers(member.database());
        assertThat(currentMembers, containsInAnyOrder(new Object[] { "127.0.0.1:8003" }, new Object[] { "127.0.0.1:8004" }, new Object[] { "127.0.0.1:8005" }));
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with CoreClusterMember

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

the class CausalClusteringProceduresIT method coreProceduresShouldBeAvailable.

@Test
public void coreProceduresShouldBeAvailable() throws Throwable {
    String[] coreProcs = new String[] { // Server role
    "dbms.cluster.role", // Discover the cluster topology
    "dbms.cluster.routing.getServers", // Discover appropriate discovery service
    "dbms.cluster.overview", // Kernel built procedures
    "dbms.procedures", // Built in procedure from enterprise
    "dbms.listQueries" };
    for (String procedure : coreProcs) {
        Optional<CoreClusterMember> firstCore = cluster.coreMembers().stream().findFirst();
        assert firstCore.isPresent();
        CoreGraphDatabase database = firstCore.get().database();
        InternalTransaction tx = database.beginTransaction(KernelTransaction.Type.explicit, AUTH_DISABLED);
        Result coreResult = database.execute("CALL " + procedure + "()");
        assertTrue("core with procedure " + procedure, coreResult.hasNext());
        coreResult.close();
        tx.close();
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 19 with CoreClusterMember

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

the class ClusterBindingIT method badFollowerShouldNotJoinCluster.

@Test
public void badFollowerShouldNotJoinCluster() throws Exception {
    // GIVEN
    cluster.coreTx((db, tx) -> {
        Node node = db.createNode(label("boo"));
        node.setProperty("foobar", "baz_bat");
        tx.success();
    });
    CoreClusterMember coreMember = cluster.getCoreMemberById(0);
    cluster.removeCoreMemberWithMemberId(0);
    changeClusterId(coreMember);
    SampleData.createSomeData(100, cluster);
    for (CoreClusterMember db : cluster.coreMembers()) {
        db.coreState().prune();
    }
    // WHEN
    try {
        cluster.addCoreMemberWithId(0).start();
        fail("Should not have joined the cluster");
    } catch (RuntimeException e) {
        assertThat(e.getCause(), instanceOf(LifecycleException.class));
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 20 with CoreClusterMember

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

the class ClusterBindingIT method laggingFollowerShouldDownloadSnapshot.

@Test
public void laggingFollowerShouldDownloadSnapshot() throws Exception {
    // GIVEN
    cluster.coreTx((db, tx) -> {
        Node node = db.createNode(label("boo"));
        node.setProperty("foobar", "baz_bat");
        tx.success();
    });
    cluster.removeCoreMemberWithMemberId(0);
    SampleData.createSomeData(100, cluster);
    for (CoreClusterMember db : cluster.coreMembers()) {
        db.coreState().prune();
    }
    // WHEN
    cluster.addCoreMemberWithId(0).start();
    cluster.awaitLeader();
    // THEN
    assertEquals(3, cluster.healthyCoreMembers().size());
    List<File> coreStoreDirs = storeDirs(cluster.coreMembers());
    cluster.shutdown();
    assertAllStoresHaveTheSameStoreId(coreStoreDirs, fs);
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)45 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)45 Cluster (org.neo4j.causalclustering.discovery.Cluster)20 Node (org.neo4j.graphdb.Node)16 File (java.io.File)12 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)11 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)10 Driver (org.neo4j.driver.v1.Driver)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)9 Session (org.neo4j.driver.v1.Session)9 Rule (org.junit.Rule)8 ClusterRule (org.neo4j.test.causalclustering.ClusterRule)8 TimeUnit (java.util.concurrent.TimeUnit)7 Transaction (org.neo4j.graphdb.Transaction)7 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Role (org.neo4j.causalclustering.core.consensus.roles.Role)5