Search in sources :

Example 71 with InstanceId

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));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Config(org.neo4j.kernel.configuration.Config) HostnamePort(org.neo4j.helpers.HostnamePort) Test(org.junit.Test)

Example 72 with InstanceId

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());
}
Also used : MessageHolder(org.neo4j.cluster.com.message.MessageHolder) Message(org.neo4j.cluster.com.message.Message) InstanceId(org.neo4j.cluster.InstanceId) ArrayList(java.util.ArrayList) MessageType(org.neo4j.cluster.com.message.MessageType) Test(org.junit.Test)

Example 73 with InstanceId

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);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) InstanceId(org.neo4j.cluster.InstanceId) Log(org.neo4j.logging.Log) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) LogProvider(org.neo4j.logging.LogProvider) NotElectableElectionCredentials(org.neo4j.cluster.protocol.election.NotElectableElectionCredentials) Test(org.junit.Test)

Example 74 with InstanceId

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);
    }
}
Also used : ClusterMember(org.neo4j.kernel.ha.cluster.member.ClusterMember) StoreId(org.neo4j.kernel.impl.store.StoreId) InstanceId(org.neo4j.cluster.InstanceId) ClusterMembers.hasInstanceId(org.neo4j.kernel.ha.cluster.member.ClusterMembers.hasInstanceId) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) ClusterMembers(org.neo4j.kernel.ha.cluster.member.ClusterMembers) BranchedDataException(org.neo4j.kernel.ha.BranchedDataException)

Example 75 with InstanceId

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)));
}
Also used : Executor(java.util.concurrent.Executor) ElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ElectionCredentialsProvider) InstanceId(org.neo4j.cluster.InstanceId) Config(org.neo4j.kernel.configuration.Config) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) Timeouts(org.neo4j.cluster.timeout.Timeouts) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) URI(java.net.URI) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory) Test(org.junit.Test)

Aggregations

InstanceId (org.neo4j.cluster.InstanceId)154 Test (org.junit.Test)129 URI (java.net.URI)47 Config (org.neo4j.kernel.configuration.Config)37 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)36 Timeouts (org.neo4j.cluster.timeout.Timeouts)32 Executor (java.util.concurrent.Executor)28 ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)28 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)27 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)27 HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)27 MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)24 AcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore)18 MessageHolder (org.neo4j.cluster.com.message.MessageHolder)16 Message (org.neo4j.cluster.com.message.Message)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 ClusterMemberAvailability (org.neo4j.cluster.member.ClusterMemberAvailability)13 ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)12 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)12