Search in sources :

Example 36 with CoreClusterMember

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

the class CoreReplicationIT method shouldNotAllowTokenCreationFromAFollowerWithNoInitialTokens.

@Test
public void shouldNotAllowTokenCreationFromAFollowerWithNoInitialTokens() throws Exception {
    // given
    CoreClusterMember leader = cluster.coreTx((db, tx) -> {
        db.createNode();
        tx.success();
    });
    awaitForDataToBeApplied(leader);
    dataMatchesEventually(leader, cluster.coreMembers());
    CoreGraphDatabase follower = cluster.getDbWithRole(Role.FOLLOWER).database();
    // when
    try (Transaction tx = follower.beginTx()) {
        follower.getAllNodes().iterator().next().setProperty("name", "Mark");
        tx.success();
        fail("Should have thrown exception");
    } catch (WriteOperationsNotAllowedException ignored) {
        // expected
        assertThat(ignored.getMessage(), containsString("No write operations are allowed"));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 37 with CoreClusterMember

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

the class CoreReplicationIT method shouldReplicateToCoreMembersAddedAfterInitialTransactions.

@Test
public void shouldReplicateToCoreMembersAddedAfterInitialTransactions() throws Exception {
    // when
    CoreClusterMember last = null;
    for (int i = 0; i < 15; i++) {
        last = cluster.coreTx((db, tx) -> {
            Node node = db.createNode();
            node.setProperty("foobar", "baz_bat");
            tx.success();
        });
    }
    cluster.addCoreMemberWithId(3).start();
    cluster.addCoreMemberWithId(4).start();
    // then
    assertEquals(15, countNodes(last));
    dataMatchesEventually(last, cluster.coreMembers());
}
Also used : Role(org.neo4j.causalclustering.core.consensus.roles.Role) Label(org.neo4j.graphdb.Label) Iterables.count(org.neo4j.helpers.collection.Iterables.count) TimeoutException(java.util.concurrent.TimeoutException) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) Node(org.neo4j.graphdb.Node) Assert.assertThat(org.junit.Assert.assertThat) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Assert.fail(org.junit.Assert.fail) Transaction(org.neo4j.graphdb.Transaction) Before(org.junit.Before) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test) Label.label(org.neo4j.graphdb.Label.label) Cluster(org.neo4j.causalclustering.discovery.Cluster) RuleChain(org.junit.rules.RuleChain) TimeUnit(java.util.concurrent.TimeUnit) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) VerboseTimeout(org.neo4j.test.rule.VerboseTimeout) Predicates.await(org.neo4j.function.Predicates.await) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Cluster.dataMatchesEventually(org.neo4j.causalclustering.discovery.Cluster.dataMatchesEventually) Assert.assertEquals(org.junit.Assert.assertEquals) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 38 with CoreClusterMember

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

the class CoreReplicationIT method shouldReplicateTransactionToCoreMemberAddedAfterInitialStartUp.

@Test
public void shouldReplicateTransactionToCoreMemberAddedAfterInitialStartUp() throws Exception {
    // given
    cluster.getCoreMemberById(0).shutdown();
    cluster.addCoreMemberWithId(3).start();
    cluster.getCoreMemberById(0).start();
    cluster.coreTx((db, tx) -> {
        Node node = db.createNode();
        node.setProperty("foobar", "baz_bat");
        tx.success();
    });
    // when
    cluster.addCoreMemberWithId(4).start();
    CoreClusterMember last = cluster.coreTx((db, tx) -> {
        Node node = db.createNode();
        node.setProperty("foobar", "baz_bat");
        tx.success();
    });
    // then
    assertEquals(2, countNodes(last));
    dataMatchesEventually(last, cluster.coreMembers());
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 39 with CoreClusterMember

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

the class ServerPoliciesLoadBalancingIT method shouldSupportSeveralPolicies.

@Test
public void shouldSupportSeveralPolicies() throws Exception {
    Map<String, IntFunction<String>> instanceCoreParams = new HashMap<>();
    instanceCoreParams.put(CausalClusteringSettings.server_groups.name(), (id) -> "core" + id + ",core");
    Map<String, IntFunction<String>> instanceReplicaParams = new HashMap<>();
    instanceReplicaParams.put(CausalClusteringSettings.server_groups.name(), (id) -> "replica" + id + ",replica");
    String defaultPolicySpec = "groups(replica0,replica1)";
    String policyOneTwoSpec = "groups(replica1,replica2)";
    String policyZeroTwoSpec = "groups(replica0,replica2)";
    String policyAllReplicasSpec = "groups(replica); halt()";
    String allPolicySpec = "all()";
    Map<String, String> coreParams = stringMap(CausalClusteringSettings.cluster_allow_reads_on_followers.name(), "true", CausalClusteringSettings.load_balancing_config.name() + ".server_policies.all", allPolicySpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.default", defaultPolicySpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.policy_one_two", policyOneTwoSpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.policy_zero_two", policyZeroTwoSpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.policy_all_replicas", policyAllReplicasSpec, CausalClusteringSettings.multi_dc_license.name(), "true");
    cluster = new Cluster(testDir.directory("cluster"), 3, 3, new HazelcastDiscoveryServiceFactory(), coreParams, instanceCoreParams, emptyMap(), instanceReplicaParams, Standard.LATEST_NAME);
    cluster.start();
    assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(3, 1, 2, 3), policyContext("all"));
    for (CoreClusterMember core : cluster.coreMembers()) {
        CoreGraphDatabase db = core.database();
        assertThat(getServers(db, policyContext("default")), new SpecificReplicasMatcher(0, 1));
        assertThat(getServers(db, policyContext("policy_one_two")), new SpecificReplicasMatcher(1, 2));
        assertThat(getServers(db, policyContext("policy_zero_two")), new SpecificReplicasMatcher(0, 2));
        assertThat(getServers(db, policyContext("policy_all_replicas")), new SpecificReplicasMatcher(0, 1, 2));
    }
}
Also used : HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) HashMap(java.util.HashMap) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) IntFunction(java.util.function.IntFunction) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) Test(org.junit.Test)

Example 40 with CoreClusterMember

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

the class TransactionLogRecoveryIT method readReplicaShouldStartAfterPartialTransactionWriteCrash.

@Test
public void readReplicaShouldStartAfterPartialTransactionWriteCrash() throws Exception {
    // given: a fully synced cluster with some data
    dataMatchesEventually(createEmptyNodes(cluster, 10), cluster.readReplicas());
    // when: shutting down a read replica
    ReadReplica readReplica = cluster.getReadReplicaById(0);
    readReplica.shutdown();
    // and making sure there will be something new to pull
    CoreClusterMember lastWrites = createEmptyNodes(cluster, 10);
    dataMatchesEventually(lastWrites, cluster.coreMembers());
    // and writing a partial tx
    writePartialTx(readReplica.storeDir());
    // then: we should still be able to start
    readReplica.start();
    // and become fully synced again
    dataMatchesEventually(lastWrites, singletonList(readReplica));
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) 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