use of org.neo4j.function.ThrowingSupplier in project neo4j by neo4j.
the class ReadReplicaReplicationIT method shouldEventuallyPullTransactionDownToAllReadReplicas.
@Test
public void shouldEventuallyPullTransactionDownToAllReadReplicas() throws Exception {
// given
Cluster cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
int nodesBeforeReadReplicaStarts = 1;
cluster.coreTx((db, tx) -> {
db.schema().constraintFor(Label.label("Foo")).assertPropertyIsUnique("foobar").create();
tx.success();
});
// when
for (int i = 0; i < 100; i++) {
cluster.coreTx((db, tx) -> {
createData(db, nodesBeforeReadReplicaStarts);
tx.success();
});
}
Set<Path> labelScanStoreFiles = new HashSet<>();
cluster.coreTx((db, tx) -> gatherLabelScanStoreFiles(db, labelScanStoreFiles));
AtomicBoolean labelScanStoreCorrectlyPlaced = new AtomicBoolean(false);
Monitors monitors = new Monitors();
ReadReplica rr = cluster.addReadReplicaWithIdAndMonitors(0, monitors);
Path readReplicateStoreDir = rr.storeDir().toPath().toAbsolutePath();
monitors.addMonitorListener((FileCopyMonitor) file -> {
Path relativPath = readReplicateStoreDir.relativize(file.toPath().toAbsolutePath());
relativPath = relativPath.subpath(1, relativPath.getNameCount());
if (labelScanStoreFiles.contains(relativPath)) {
labelScanStoreCorrectlyPlaced.set(true);
}
});
rr.start();
for (int i = 0; i < 100; i++) {
cluster.coreTx((db, tx) -> {
createData(db, nodesBeforeReadReplicaStarts);
tx.success();
});
}
// then
for (final ReadReplica server : cluster.readReplicas()) {
GraphDatabaseService readReplica = server.database();
try (Transaction tx = readReplica.beginTx()) {
ThrowingSupplier<Long, Exception> nodeCount = () -> count(readReplica.getAllNodes());
assertEventually("node to appear on read replica", nodeCount, is(400L), 1, MINUTES);
for (Node node : readReplica.getAllNodes()) {
assertThat(node.getProperty("foobar").toString(), startsWith("baz_bat"));
}
tx.success();
}
}
assertTrue(labelScanStoreCorrectlyPlaced.get());
}
Aggregations