Search in sources :

Example 46 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class TestSlaveOnlyCluster method testMasterElectionAfterMasterRecoversInSlaveOnlyCluster.

@Test
public void testMasterElectionAfterMasterRecoversInSlaveOnlyCluster() throws Throwable {
    ManagedCluster cluster = clusterRule.startCluster();
    assertThat(cluster.getServerId(cluster.getMaster()), equalTo(new InstanceId(3)));
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    CountDownLatch masterFailedLatch = createMasterFailLatch(cluster);
    RepairKit repairKit = cluster.fail(master);
    try {
        assertTrue(masterFailedLatch.await(60, TimeUnit.SECONDS));
    } finally {
        repairKit.repair();
    }
    cluster.await(allSeesAllAsAvailable());
    long nodeId = createNodeWithPropertyOn(cluster.getAnySlave(), PROPERTY, VALUE);
    try (Transaction ignore = master.beginTx()) {
        assertThat(master.getNodeById(nodeId).getProperty(PROPERTY), equalTo(VALUE));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) InstanceId(org.neo4j.cluster.InstanceId) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) RepairKit(org.neo4j.kernel.impl.ha.ClusterManager.RepairKit) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 47 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class ClusterStateTest method joinDeniedTimeoutShouldBeHandledWithExceptionIncludingConfiguration.

@Test
public void joinDeniedTimeoutShouldBeHandledWithExceptionIncludingConfiguration() throws Throwable {
    // GIVEN
    ClusterContext context = mock(ClusterContext.class);
    Map<InstanceId, URI> existingMembers = members(1, 2);
    when(context.getLog(any(Class.class))).thenReturn(NullLog.getInstance());
    when(context.getJoiningInstances()).thenReturn(Collections.<URI>emptyList());
    when(context.hasJoinBeenDenied()).thenReturn(true);
    when(context.getJoinDeniedConfigurationResponseState()).thenReturn(configurationResponseState(existingMembers));
    TrackingMessageHolder outgoing = new TrackingMessageHolder();
    // WHEN the join denial actually takes effect (signaled by a join timeout locally)
    ClusterState.joining.handle(context, to(ClusterMessage.joiningTimeout, uri(2)).setHeader(Message.CONVERSATION_ID, "bla"), outgoing);
    // THEN assert that the failure contains the received configuration
    Message<? extends MessageType> response = outgoing.single();
    ClusterEntryDeniedException deniedException = response.getPayload();
    assertEquals(existingMembers, deniedException.getConfigurationResponseState().getMembers());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) TrackingMessageHolder(org.neo4j.cluster.com.message.TrackingMessageHolder) URI(java.net.URI) Test(org.junit.Test)

Example 48 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class ClusterStateTest method joinDeniedHandlingShouldKeepResponseConfiguration.

@Test
public void joinDeniedHandlingShouldKeepResponseConfiguration() throws Throwable {
    // GIVEN
    ClusterContext context = mock(ClusterContext.class);
    when(context.getLog(any(Class.class))).thenReturn(NullLog.getInstance());
    TrackingMessageHolder outgoing = new TrackingMessageHolder();
    Map<InstanceId, URI> members = members(1, 2);
    // WHEN a joining instance receives a denial to join
    ClusterState.discovery.handle(context, to(joinDenied, uri(2), configurationResponseState(members)), outgoing);
    // THEN assert that the response contains the configuration
    verify(context).joinDenied(argThat(new ConfigurationResponseStateMatcher().withMembers(members)));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) TrackingMessageHolder(org.neo4j.cluster.com.message.TrackingMessageHolder) URI(java.net.URI) Test(org.junit.Test)

Example 49 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class MemberIsUnavailableTest method shouldBeDeserializedWhenClusterUriIsNull.

@Test
public void shouldBeDeserializedWhenClusterUriIsNull() throws Exception {
    // Given
    MemberIsUnavailable message = new MemberIsUnavailable("slave", new InstanceId(1), null);
    byte[] serialized = serialize(message);
    // When
    MemberIsUnavailable deserialized = deserialize(serialized);
    // Then
    assertNotSame(message, deserialized);
    assertEquals("slave", message.getRole());
    assertEquals(new InstanceId(1), message.getInstanceId());
    assertNull(message.getClusterUri());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Test(org.junit.Test)

Example 50 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class MemberIsUnavailableTest method shouldBeSerializedWhenClusterUriIsNull.

@Test
public void shouldBeSerializedWhenClusterUriIsNull() throws IOException {
    // Given
    MemberIsUnavailable message = new MemberIsUnavailable("master", new InstanceId(1), null);
    // When
    byte[] serialized = serialize(message);
    // Then
    assertNotEquals(0, serialized.length);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) 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