use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class HaConfigurationValidatorTest method validateSuccess.
@Test
public void validateSuccess() throws Exception {
// when
Config config = Config.embeddedDefaults(stringMap(ClusterSettings.mode.name(), mode.name(), ClusterSettings.server_id.name(), "1", ClusterSettings.initial_hosts.name(), "localhost,remotehost"), Collections.singleton(new HaConfigurationValidator()));
// then
assertEquals(asList(new HostnamePort("localhost"), new HostnamePort("remotehost")), config.get(ClusterSettings.initial_hosts));
assertEquals(new InstanceId(1), config.get(ClusterSettings.server_id));
}
use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class AtomicBroadcastStateTest method shouldNotBroadcastWhenHavingNoQuorumNoCoordinator.
@Test
public void shouldNotBroadcastWhenHavingNoQuorumNoCoordinator() throws Throwable {
// GIVEN
AtomicBroadcastContext context = mock(AtomicBroadcastContext.class);
when(context.hasQuorum()).thenReturn(false);
InstanceId coordinator = id(1);
when(context.getCoordinator()).thenReturn(coordinator);
when(context.getUriForId(coordinator)).thenReturn(uri(1));
when(context.getLog(AtomicBroadcastState.class)).thenReturn(NullLog.getInstance());
final List<Message<?>> messages = new ArrayList<>(1);
MessageHolder outgoing = new MessageHolder() {
@Override
public void offer(Message<? extends MessageType> message) {
messages.add(message);
}
};
// WHEN
broadcasting.handle(context, message(1), outgoing);
// THEN
assertEquals(0, messages.size());
}
use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class DefaultWinnerStrategyTest method shouldNotPickAWinnerIfAllVotesAreForIneligibleCandidates.
@Test
public void shouldNotPickAWinnerIfAllVotesAreForIneligibleCandidates() {
// given
InstanceId instanceOne = new InstanceId(1);
InstanceId instanceTwo = new InstanceId(2);
ClusterContext clusterContext = mock(ClusterContext.class);
final Log log = mock(Log.class);
LogProvider logProvider = new LogProvider() {
@Override
public Log getLog(Class loggingClass) {
return log;
}
@Override
public Log getLog(String name) {
return log;
}
};
when(clusterContext.getLog(DefaultWinnerStrategy.class)).thenReturn(logProvider.getLog(DefaultWinnerStrategy.class));
// when
Collection<Vote> votes = Arrays.asList(new Vote(instanceOne, new NotElectableElectionCredentials()), new Vote(instanceTwo, new NotElectableElectionCredentials()));
DefaultWinnerStrategy strategy = new DefaultWinnerStrategy(clusterContext);
org.neo4j.cluster.InstanceId winner = strategy.pickWinner(votes);
// then
assertNull(winner);
}
use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class SwitchToSlave method checkMyStoreIdAndMastersStoreId.
void checkMyStoreIdAndMastersStoreId(StoreId myStoreId, URI masterUri, DependencyResolver resolver) {
ClusterMembers clusterMembers = resolver.resolveDependency(ClusterMembers.class);
InstanceId serverId = HighAvailabilityModeSwitcher.getServerId(masterUri);
Iterable<ClusterMember> members = clusterMembers.getMembers();
ClusterMember master = firstOrNull(filter(hasInstanceId(serverId), members));
if (master == null) {
throw new IllegalStateException("Cannot find the master among " + members + " with master serverId=" + serverId + " and uri=" + masterUri);
}
StoreId masterStoreId = master.getStoreId();
if (!myStoreId.equals(masterStoreId)) {
throw new MismatchingStoreIdException(myStoreId, master.getStoreId());
} else if (!myStoreId.equalsByUpgradeId(master.getStoreId())) {
throw new BranchedDataException("My store with " + myStoreId + " was updated independently from " + "master's store " + masterStoreId);
}
}
use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.
the class MultiPaxosContextTest method shouldNotConsiderInstanceJoiningWithSameIdAndIpAProblem.
@Test
public void shouldNotConsiderInstanceJoiningWithSameIdAndIpAProblem() throws Exception {
// Given
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
MultiPaxosContext ctx = new MultiPaxosContext(new InstanceId(1), Collections.<ElectionRole>emptyList(), mock(ClusterConfiguration.class), mock(Executor.class), NullLogProvider.getInstance(), new ObjectStreamFactory(), new ObjectStreamFactory(), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
InstanceId joiningId = new InstanceId(12);
String joiningUri = "http://127.0.0.1:900";
// When
ctx.getClusterContext().instanceIsJoining(joiningId, new URI(joiningUri));
// Then
assertFalse(ctx.getClusterContext().isInstanceJoiningFromDifferentUri(joiningId, new URI(joiningUri)));
assertTrue(ctx.getClusterContext().isInstanceJoiningFromDifferentUri(joiningId, new URI("http://127.0.0.1:80")));
assertFalse(ctx.getClusterContext().isInstanceJoiningFromDifferentUri(new InstanceId(13), new URI(joiningUri)));
}
Aggregations