Search in sources :

Example 41 with Cluster

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);
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) File(java.io.File) Test(org.junit.Test)

Example 42 with Cluster

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();
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 43 with Cluster

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());
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Transaction(org.neo4j.graphdb.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) Test(org.junit.Test)

Example 44 with Cluster

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();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AcquireLockTimeoutException(org.neo4j.storageengine.api.lock.AcquireLockTimeoutException) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) ExecutorService(java.util.concurrent.ExecutorService) Cluster(org.neo4j.causalclustering.discovery.Cluster) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 45 with Cluster

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());
    }
}
Also used : Arrays(java.util.Arrays) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) AnonymousContext(org.neo4j.kernel.api.security.AnonymousContext) Settings(org.neo4j.kernel.configuration.Settings) RunWith(org.junit.runner.RunWith) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) Statement(org.neo4j.kernel.api.Statement) KernelAPI(org.neo4j.kernel.api.KernelAPI) Map(java.util.Map) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) Collections.singletonMap(java.util.Collections.singletonMap) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Parameterized(org.junit.runners.Parameterized) Collection(java.util.Collection) Test(org.junit.Test) Cluster(org.neo4j.causalclustering.discovery.Cluster) Type(org.neo4j.kernel.api.KernelTransaction.Type) List(java.util.List) CausalClusteringSettings.cluster_allow_reads_on_followers(org.neo4j.causalclustering.core.CausalClusteringSettings.cluster_allow_reads_on_followers) Rule(org.junit.Rule) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Iterators.asList(org.neo4j.helpers.collection.Iterators.asList) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) ProcedureSignature.procedureName(org.neo4j.kernel.api.proc.ProcedureSignature.procedureName) Matchers.containsString(org.hamcrest.Matchers.containsString) GET_SERVERS_V1(org.neo4j.causalclustering.load_balancing.procedure.ProcedureNames.GET_SERVERS_V1) Assert.assertEquals(org.junit.Assert.assertEquals) Cluster(org.neo4j.causalclustering.discovery.Cluster) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.Test)

Aggregations

Cluster (org.neo4j.causalclustering.discovery.Cluster)52 Test (org.junit.Test)51 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)21 File (java.io.File)14 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)13 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)13 Node (org.neo4j.graphdb.Node)12 Rule (org.junit.Rule)11 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)11 IOException (java.io.IOException)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Transaction (org.neo4j.graphdb.Transaction)10 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)10 ClusterRule (org.neo4j.test.causalclustering.ClusterRule)10 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)9 Map (java.util.Map)8 TimeUnit (java.util.concurrent.TimeUnit)8 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)8 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)8 UnsatisfiedDependencyException (org.neo4j.kernel.impl.util.UnsatisfiedDependencyException)8