use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class RecoveryIT method shouldBeConsistentAfterShutdown.
@Test
public void shouldBeConsistentAfterShutdown() throws Exception {
// given
Cluster cluster = clusterRule.startCluster();
fireSomeLoadAtTheCluster(cluster);
Set<File> storeDirs = cluster.coreMembers().stream().map(CoreClusterMember::storeDir).collect(toSet());
assertEventually("All cores have the same data", () -> cluster.coreMembers().stream().map(this::dbRepresentation).collect(toSet()).size(), equalTo(1), 10, TimeUnit.SECONDS);
// when
cluster.shutdown();
// then
storeDirs.forEach(this::assertConsistent);
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class RestartIT method shouldHaveWritableClusterAfterCompleteRestart.
@Test
public void shouldHaveWritableClusterAfterCompleteRestart() throws Exception {
// given
Cluster cluster = clusterRule.startCluster();
cluster.shutdown();
// when
cluster.start();
CoreClusterMember last = cluster.coreTx((db, tx) -> {
Node node = db.createNode(label("boo"));
node.setProperty("foobar", "baz_bat");
tx.success();
});
// then
dataMatchesEventually(last, cluster.coreMembers());
cluster.shutdown();
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class RestartIT method readReplicaTest.
@Test
public void readReplicaTest() throws Exception {
// given
Cluster cluster = clusterRule.withNumberOfCoreMembers(2).withNumberOfReadReplicas(1).startCluster();
// when
final GraphDatabaseService 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();
}
cluster.addCoreMemberWithId(2).start();
cluster.shutdown();
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
for (CoreClusterMember core : cluster.coreMembers()) {
ConsistencyCheckService.Result result = new ConsistencyCheckService().runFullConsistencyCheck(core.storeDir(), Config.embeddedDefaults(), ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), fileSystem, false, new CheckConsistencyConfig(true, true, true, false));
assertTrue("Inconsistent: " + core, result.isSuccessful());
}
for (ReadReplica readReplica : cluster.readReplicas()) {
ConsistencyCheckService.Result result = new ConsistencyCheckService().runFullConsistencyCheck(readReplica.storeDir(), Config.embeddedDefaults(), ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), fileSystem, false, new CheckConsistencyConfig(true, true, true, false));
assertTrue("Inconsistent: " + readReplica, result.isSuccessful());
}
}
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class RestartIT method restartWhileDoingTransactions.
@Test
public void restartWhileDoingTransactions() throws Exception {
// given
Cluster cluster = clusterRule.startCluster();
// when
final GraphDatabaseService coreDB = cluster.getCoreMemberById(0).database();
ExecutorService executor = Executors.newCachedThreadPool();
final AtomicBoolean done = new AtomicBoolean(false);
executor.execute(() -> {
while (!done.get()) {
try (Transaction tx = coreDB.beginTx()) {
Node node = coreDB.createNode(label("boo"));
node.setProperty("foobar", "baz_bat");
tx.success();
} catch (AcquireLockTimeoutException | WriteOperationsNotAllowedException e) {
// expected sometimes
}
}
});
Thread.sleep(500);
cluster.removeCoreMemberWithMemberId(1);
cluster.addCoreMemberWithId(1).start();
Thread.sleep(500);
// then
done.set(true);
executor.shutdown();
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ClusterDiscoveryIT method shouldFindReadWriteAndRouteServers.
@Test
public void shouldFindReadWriteAndRouteServers() throws Exception {
// when
Cluster cluster = clusterRule.withSharedCoreParams(config).withNumberOfReadReplicas(1).startCluster();
// then
int cores = cluster.coreMembers().size();
int readReplicas = cluster.readReplicas().size();
int readEndPoints = expectFollowersAsReadEndPoints ? (cores - 1 + readReplicas) : readReplicas;
for (int i = 0; i < 3; i++) {
List<Map<String, Object>> members = getMembers(cluster.getCoreMemberById(i).database());
assertEquals(1, members.stream().filter(x -> x.get("role").equals("WRITE")).flatMap(x -> Arrays.stream((Object[]) x.get("addresses"))).count());
assertEquals(readEndPoints, members.stream().filter(x -> x.get("role").equals("READ")).flatMap(x -> Arrays.stream((Object[]) x.get("addresses"))).count());
assertEquals(cores, members.stream().filter(x -> x.get("role").equals("ROUTE")).flatMap(x -> Arrays.stream((Object[]) x.get("addresses"))).count());
}
}
Aggregations