Search in sources :

Example 46 with CoreClusterMember

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

the class BoltCausalClusteringIT method shouldUseBookmarkFromAReadSessionInAWriteSession.

@Test
public void shouldUseBookmarkFromAReadSessionInAWriteSession() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    try (Driver driver = GraphDatabase.driver(leader.directURI(), AuthTokens.basic("neo4j", "neo4j"))) {
        inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
            session.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
            return null;
        });
        String bookmark;
        try (Session session = driver.session(AccessMode.READ)) {
            try (Transaction tx = session.beginTransaction()) {
                tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
                tx.success();
            }
            bookmark = session.lastBookmark();
        }
        assertNotNull(bookmark);
        inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
            try (Transaction tx = session.beginTransaction(bookmark)) {
                tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Alistair"));
                tx.success();
            }
            return null;
        });
        try (Session session = driver.session()) {
            Record record = session.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
            assertEquals(2, record.get("count").asInt());
        }
    }
}
Also used : Transaction(org.neo4j.driver.v1.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) Record(org.neo4j.driver.v1.Record) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 47 with CoreClusterMember

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

the class CoreEdgeMetricsIT method shouldMonitorCoreEdge.

@Test
public void shouldMonitorCoreEdge() throws Exception {
    // given
    cluster = clusterRule.startCluster();
    // when
    CoreGraphDatabase coreDB = cluster.awaitLeader(5, TimeUnit.SECONDS).database();
    try (Transaction tx = coreDB.beginTx()) {
        Node node = coreDB.createNode(label("boo"));
        node.setProperty("foobar", "baz_bat");
        tx.success();
    }
    // then
    for (CoreClusterMember db : cluster.coreMembers()) {
        assertAllNodesVisible(db.database());
    }
    for (ReadReplica db : cluster.readReplicas()) {
        assertAllNodesVisible(db.database());
    }
    File coreMetricsDir = new File(cluster.getCoreMemberById(0).homeDir(), csvPath.getDefaultValue());
    assertEventually("append index eventually accurate", () -> readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.APPEND_INDEX)), greaterThan(0L), TIMEOUT, TimeUnit.SECONDS);
    assertEventually("commit index eventually accurate", () -> readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.COMMIT_INDEX)), greaterThan(0L), TIMEOUT, TimeUnit.SECONDS);
    assertEventually("term eventually accurate", () -> readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.TERM)), greaterThanOrEqualTo(0L), TIMEOUT, TimeUnit.SECONDS);
    assertEventually("leader not found eventually accurate", () -> readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.LEADER_NOT_FOUND)), equalTo(0L), TIMEOUT, TimeUnit.SECONDS);
    assertEventually("tx pull requests received eventually accurate", () -> {
        long total = 0;
        for (final File homeDir : cluster.coreMembers().stream().map(CoreClusterMember::homeDir).collect(Collectors.toList())) {
            File metricsDir = new File(homeDir, "metrics");
            total += readLongValue(metricsCsv(metricsDir, CatchUpMetrics.TX_PULL_REQUESTS_RECEIVED));
        }
        return total;
    }, greaterThan(0L), TIMEOUT, TimeUnit.SECONDS);
    assertEventually("tx retries eventually accurate", () -> readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.TX_RETRIES)), equalTo(0L), TIMEOUT, TimeUnit.SECONDS);
    assertEventually("is leader eventually accurate", () -> readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.IS_LEADER)), greaterThanOrEqualTo(0L), TIMEOUT, TimeUnit.SECONDS);
    File readReplicaMetricsDir = new File(cluster.getReadReplicaById(0).homeDir(), "metrics");
    assertEventually("pull update request registered", () -> readLongValue(metricsCsv(readReplicaMetricsDir, PULL_UPDATES)), greaterThan(0L), TIMEOUT, TimeUnit.SECONDS);
    assertEventually("pull update request registered", () -> readLongValue(metricsCsv(readReplicaMetricsDir, PULL_UPDATE_HIGHEST_TX_ID_REQUESTED)), greaterThan(0L), TIMEOUT, TimeUnit.SECONDS);
    assertEventually("pull update response received", () -> readLongValue(metricsCsv(readReplicaMetricsDir, PULL_UPDATE_HIGHEST_TX_ID_RECEIVED)), greaterThan(0L), TIMEOUT, TimeUnit.SECONDS);
    assertEventually("dropped messages eventually accurate", () -> readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.DROPPED_MESSAGES)), greaterThanOrEqualTo(0L), TIMEOUT, TimeUnit.SECONDS);
    assertEventually("queue size eventually accurate", () -> readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.QUEUE_SIZE)), greaterThanOrEqualTo(0L), TIMEOUT, TimeUnit.SECONDS);
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) Transaction(org.neo4j.graphdb.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)47 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)47 Cluster (org.neo4j.causalclustering.discovery.Cluster)20 Node (org.neo4j.graphdb.Node)17 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