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