use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.
the class UpstreamDatabaseStrategySelectorTest method shouldUseSpecifiedStrategyInPreferenceToDefault.
@Test
public void shouldUseSpecifiedStrategyInPreferenceToDefault() throws Exception {
// given
TopologyService topologyService = mock(TopologyService.class);
MemberId memberId = new MemberId(UUID.randomUUID());
when(topologyService.coreServers()).thenReturn(new CoreTopology(new ClusterId(UUID.randomUUID()), false, mapOf(memberId, mock(CoreServerInfo.class))));
ConnectToRandomCoreServerStrategy shouldNotUse = new ConnectToRandomCoreServerStrategy();
UpstreamDatabaseSelectionStrategy mockStrategy = mock(UpstreamDatabaseSelectionStrategy.class);
when(mockStrategy.upstreamDatabase()).thenReturn(Optional.of(new MemberId(UUID.randomUUID())));
UpstreamDatabaseStrategySelector selector = new UpstreamDatabaseStrategySelector(shouldNotUse, iterable(mockStrategy), null, NullLogProvider.getInstance());
// when
selector.bestUpstreamDatabase();
// then
verify(mockStrategy, times(2)).upstreamDatabase();
}
use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.
the class BatchingMessageHandler method collateAndHandleBatch.
private void collateAndHandleBatch(List<RaftMessages.ClusterIdAwareMessage> batch) {
RaftMessages.NewEntry.BatchRequest batchRequest = null;
ClusterId clusterId = batch.get(0).clusterId();
for (RaftMessages.ClusterIdAwareMessage clusterIdAwareMessage : batch) {
if (batchRequest != null && !clusterIdAwareMessage.clusterId().equals(clusterId)) {
handler.handle(new RaftMessages.ClusterIdAwareMessage(clusterId, batchRequest));
batchRequest = null;
}
clusterId = clusterIdAwareMessage.clusterId();
RaftMessage message = clusterIdAwareMessage.message();
if (message instanceof RaftMessages.NewEntry.Request) {
RaftMessages.NewEntry.Request newEntryRequest = (RaftMessages.NewEntry.Request) message;
if (batchRequest == null) {
batchRequest = new RaftMessages.NewEntry.BatchRequest(batch.size());
}
batchRequest.add(newEntryRequest.content());
} else {
handler.handle(clusterIdAwareMessage);
}
}
if (batchRequest != null) {
handler.handle(new RaftMessages.ClusterIdAwareMessage(clusterId, batchRequest));
}
}
use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.
the class CoreState method handle.
public synchronized void handle(RaftMessages.ClusterIdAwareMessage clusterIdAwareMessage) {
Optional<ClusterId> optionalClusterId = clusterBinder.get();
if (!allowMessageHandling || !optionalClusterId.isPresent()) {
return;
}
ClusterId boundClusterId = optionalClusterId.get();
ClusterId msgClusterId = clusterIdAwareMessage.clusterId();
if (msgClusterId.equals(boundClusterId)) {
try {
ConsensusOutcome outcome = raftMachine.handle(clusterIdAwareMessage.message());
if (outcome.needsFreshSnapshot()) {
downloadSnapshot(clusterIdAwareMessage.message().from());
} else {
notifyCommitted(outcome.getCommitIndex());
}
} catch (Throwable e) {
log.error("Error handling message", e);
raftMachine.panic();
localDatabase.panic(e);
}
} else {
log.info("Discarding message[%s] owing to mismatched clusterId. Expected: %s, Encountered: %s", clusterIdAwareMessage.message(), boundClusterId, msgClusterId);
}
}
use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.
the class CoreTopologyTest method shouldDetectRemovedMembers.
@Test
public void shouldDetectRemovedMembers() throws Exception {
// given
UUID one = UUID.randomUUID();
UUID two = UUID.randomUUID();
Map<MemberId, CoreServerInfo> initialMembers = new HashMap<>();
initialMembers.put(new MemberId(one), mock(CoreServerInfo.class));
initialMembers.put(new MemberId(two), mock(CoreServerInfo.class));
Map<MemberId, CoreServerInfo> newMembers = new HashMap<>();
newMembers.put(new MemberId(two), mock(CoreServerInfo.class));
CoreTopology topology = new CoreTopology(new ClusterId(UUID.randomUUID()), true, initialMembers);
// when
TopologyDifference diff = topology.difference(new CoreTopology(new ClusterId(UUID.randomUUID()), true, newMembers));
// then
assertThat(diff.added().size(), Matchers.equalTo(0));
assertThat(diff.removed().size(), Matchers.equalTo(1));
}
use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.
the class CoreTopologyTest method shouldDetectAddedMembers.
@Test
public void shouldDetectAddedMembers() throws Exception {
// given
UUID one = UUID.randomUUID();
UUID two = UUID.randomUUID();
Map<MemberId, CoreServerInfo> initialMembers = new HashMap<>();
initialMembers.put(new MemberId(one), mock(CoreServerInfo.class));
initialMembers.put(new MemberId(two), mock(CoreServerInfo.class));
Map<MemberId, CoreServerInfo> newMembers = new HashMap<>();
newMembers.put(new MemberId(one), mock(CoreServerInfo.class));
newMembers.put(new MemberId(two), mock(CoreServerInfo.class));
newMembers.put(new MemberId(UUID.randomUUID()), mock(CoreServerInfo.class));
CoreTopology topology = new CoreTopology(new ClusterId(UUID.randomUUID()), true, initialMembers);
// when
TopologyDifference diff = topology.difference(new CoreTopology(new ClusterId(UUID.randomUUID()), true, newMembers));
// then
assertThat(diff.added().size(), Matchers.equalTo(1));
assertThat(diff.removed().size(), Matchers.equalTo(0));
}
Aggregations