Search in sources :

Example 6 with CoreClusterMember

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

the class BoltCausalClusteringIT method sessionShouldExpireOnFailingReadQuery.

@Test
public void sessionShouldExpireOnFailingReadQuery() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
    CoreClusterMember coreServer = cluster.getCoreMemberById(0);
    Driver driver = GraphDatabase.driver(coreServer.routingURI(), AuthTokens.basic("neo4j", "neo4j"));
    inExpirableSession(driver, Driver::session, (session) -> {
        session.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
        return null;
    });
    try (Session readSession = driver.session(AccessMode.READ)) {
        // when
        connectedServer(readSession).shutdown();
        // then
        readSession.run("MATCH (n) RETURN n LIMIT 1").consume();
        fail("Should have thrown an exception as the read replica went away mid query");
    } catch (SessionExpiredException sep) {
        // then
        assertThat(sep.getMessage(), containsString("is no longer available"));
    } finally {
        driver.close();
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) SessionExpiredException(org.neo4j.driver.v1.exceptions.SessionExpiredException) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 7 with CoreClusterMember

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

the class BoltCausalClusteringIT method shouldNotBeAbleToWriteOnAReadSession.

@Test
public void shouldNotBeAbleToWriteOnAReadSession() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
    assertEventually("Failed to execute write query on read server", () -> {
        switchLeader(cluster.awaitLeader());
        CoreClusterMember leader = cluster.awaitLeader();
        Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"));
        try (Session session = driver.session(AccessMode.READ)) {
            // when
            session.run("CREATE (n:Person {name: 'Jim'})").consume();
            return false;
        } catch (ClientException ex) {
            assertEquals("Write queries cannot be performed in READ access mode.", ex.getMessage());
            return true;
        } finally {
            driver.close();
        }
    }, is(true), 30, SECONDS);
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) ClientException(org.neo4j.driver.v1.exceptions.ClientException) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 8 with CoreClusterMember

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

the class CoreReplicationIT method shouldReplicateTransactionsToCoreMembers.

@Test
public void shouldReplicateTransactionsToCoreMembers() throws Exception {
    // when
    CoreClusterMember leader = cluster.coreTx((db, tx) -> {
        Node node = db.createNode(label("boo"));
        node.setProperty("foobar", "baz_bat");
        tx.success();
    });
    // then
    assertEquals(1, countNodes(leader));
    dataMatchesEventually(leader, cluster.coreMembers());
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 9 with CoreClusterMember

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

the class CoreToCoreCopySnapshotIT method shouldBeAbleToDownloadLargerFreshSnapshot.

@Test
public void shouldBeAbleToDownloadLargerFreshSnapshot() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    CoreClusterMember source = cluster.coreTx((db, tx) -> {
        createData(db, 1000);
        tx.success();
    });
    // when
    CoreClusterMember follower = cluster.awaitCoreMemberWithRole(Role.FOLLOWER, 5, TimeUnit.SECONDS);
    // shutdown the follower, remove the store, restart
    follower.shutdown();
    deleteDirectoryRecursively(follower.storeDir(), follower.serverId());
    deleteDirectoryRecursively(follower.clusterStateDirectory(), follower.serverId());
    follower.start();
    // then
    assertEquals(DbRepresentation.of(source.database()), DbRepresentation.of(follower.database()));
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 10 with CoreClusterMember

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

the class CoreToCoreCopySnapshotIT method shouldBeAbleToDownloadToNewInstanceAfterPruning.

@Test
public void shouldBeAbleToDownloadToNewInstanceAfterPruning() throws Exception {
    // given
    Map<String, String> params = stringMap(CausalClusteringSettings.state_machine_flush_window_size.name(), "1", CausalClusteringSettings.raft_log_pruning_strategy.name(), "3 entries", CausalClusteringSettings.raft_log_rotation_size.name(), "1K");
    Cluster cluster = clusterRule.withSharedCoreParams(params).startCluster();
    CoreClusterMember leader = cluster.coreTx((db, tx) -> {
        createData(db, 10000);
        tx.success();
    });
    // when
    for (CoreClusterMember coreDb : cluster.coreMembers()) {
        coreDb.coreState().prune();
    }
    // to force a change of leader
    cluster.removeCoreMember(leader);
    leader = cluster.awaitLeader();
    int newDbId = 3;
    cluster.addCoreMemberWithId(newDbId).start();
    CoreGraphDatabase newDb = cluster.getCoreMemberById(newDbId).database();
    // then
    assertEquals(DbRepresentation.of(leader.database()), DbRepresentation.of(newDb));
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) 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