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();
}
}
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);
}
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());
}
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()));
}
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));
}
Aggregations