use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class HeartbeatContextImpl method checkSuspectEverybody.
/**
* Returns true iff this instance suspects every other instance currently in the cluster, except for itself.
*/
private boolean checkSuspectEverybody() {
Map<InstanceId, URI> allClusterMembers = getMembers();
Set<InstanceId> suspectedInstances = getSuspicionsFor(getMyId());
int suspected = 0;
for (InstanceId suspectedInstance : suspectedInstances) {
if (allClusterMembers.containsKey(suspectedInstance)) {
suspected++;
}
}
return suspected == allClusterMembers.size() - 1;
}
use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class ClusterMembersSnapshotTest method snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromSlaveToMaster.
@Test
public void snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromSlaveToMaster() throws Exception {
// GIVEN
// -- a snapshot containing one member with a role
ClusterMembersSnapshot snapshot = new ClusterMembersSnapshot(new HANewSnapshotFunction());
URI clusterUri = new URI(URI);
InstanceId instanceId = new InstanceId(1);
MemberIsAvailable event1 = new MemberIsAvailable(SLAVE, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);
snapshot.availableMember(event1);
// WHEN
// -- the same member, although different role, gets added to the snapshot
MemberIsAvailable event2 = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);
snapshot.availableMember(event2);
// THEN
// -- getting the snapshot list should reveal both
assertEquals(1, Iterables.count(snapshot.getCurrentAvailable(instanceId)));
assertThat(snapshot.getCurrentAvailable(instanceId), hasItems(memberIsAvailable(event2)));
assertEquals(1, Iterables.count(snapshot.getCurrentAvailableMembers()));
assertThat(snapshot.getCurrentAvailableMembers(), hasItems(memberIsAvailable(event2)));
}
use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class ClusterMembersSnapshotTest method snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromMasterToSlave.
@Test
public void snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromMasterToSlave() throws Exception {
// GIVEN
// -- a snapshot containing one member with a role
ClusterMembersSnapshot snapshot = new ClusterMembersSnapshot(new HANewSnapshotFunction());
URI clusterUri = new URI(URI);
InstanceId instanceId = new InstanceId(1);
MemberIsAvailable event1 = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);
snapshot.availableMember(event1);
// WHEN
// -- the same member, although different role, gets added to the snapshot
MemberIsAvailable event2 = new MemberIsAvailable(SLAVE, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);
snapshot.availableMember(event2);
// THEN
// -- getting the snapshot list should reveal both
assertEquals(1, Iterables.count(snapshot.getCurrentAvailable(instanceId)));
assertThat(snapshot.getCurrentAvailable(instanceId), hasItems(memberIsAvailable(event2)));
assertEquals(1, Iterables.count(snapshot.getCurrentAvailableMembers()));
assertThat(snapshot.getCurrentAvailableMembers(), hasItems(memberIsAvailable(event2)));
}
use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenAddNewLabelOnSlaveThenThrowException.
@Test
public void givenClusterWithReadOnlySlaveWhenAddNewLabelOnSlaveThenThrowException() throws Throwable {
// Given
ManagedCluster cluster = clusterRule.startCluster();
Node node;
HighlyAvailableGraphDatabase master = cluster.getMaster();
try (Transaction tx = master.beginTx()) {
node = master.createNode();
tx.success();
}
// When
HighlyAvailableGraphDatabase readOnlySlave = cluster.getMemberByServerId(new InstanceId(2));
try (Transaction tx = readOnlySlave.beginTx()) {
Node slaveNode = readOnlySlave.getNodeById(node.getId());
// Then
slaveNode.addLabel(Label.label("FOO"));
tx.success();
fail("Should have thrown exception");
} catch (WriteOperationsNotAllowedException ex) {
// Ok!
}
}
use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenWriteTxOnSlaveThenCommitFails.
@Test
public void givenClusterWithReadOnlySlaveWhenWriteTxOnSlaveThenCommitFails() throws Throwable {
// When
ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase readOnlySlave = cluster.getMemberByServerId(new InstanceId(2));
try (Transaction tx = readOnlySlave.beginTx()) {
readOnlySlave.createNode();
tx.success();
fail("Should have thrown exception");
} catch (WriteOperationsNotAllowedException ex) {
// Then
}
}
Aggregations