Search in sources :

Example 1 with ConfigurationRequestState

use of org.neo4j.cluster.protocol.cluster.ClusterMessage.ConfigurationRequestState in project neo4j by neo4j.

the class ClusterStateTest method discoveredInstancesShouldNotFilterByDefault.

@Test
public void discoveredInstancesShouldNotFilterByDefault() throws Throwable {
    // GIVEN
    ClusterContext context = mock(ClusterContext.class);
    when(context.getLog(any(Class.class))).thenReturn(NullLog.getInstance());
    when(context.getUriForId(id(2))).thenReturn(uri(2));
    when(context.getUriForId(id(3))).thenReturn(uri(3));
    List<ConfigurationRequestState> discoveredInstances = new LinkedList<>();
    when(context.getDiscoveredInstances()).thenReturn(discoveredInstances);
    MessageHolder outgoing = mock(MessageHolder.class);
    ConfigurationRequestState configurationRequestFromTwo = configuration(2);
    Message<ClusterMessage> messageFromTwo = to(configurationRequest, uri(1), configurationRequestFromTwo).setHeader(Message.FROM, uri(2).toString());
    ConfigurationRequestState configurationRequestFromThree = configuration(3);
    Message<ClusterMessage> messageFromThree = to(configurationRequest, uri(1), configurationRequestFromThree).setHeader(Message.FROM, uri(3).toString());
    // WHEN
    // We receive a configuration request from an instance which we haven't contacted
    ClusterState.discovery.handle(context, messageFromTwo, outgoing);
    // THEN
    // Since the setting is on, it should be added to the list anyway
    assertTrue(discoveredInstances.contains(configurationRequestFromTwo));
    // WHEN
    // Another contacts us as well
    ClusterState.discovery.handle(context, messageFromThree, outgoing);
    // Then
    // That should be in as well
    assertTrue(discoveredInstances.contains(configurationRequestFromTwo));
    assertTrue(discoveredInstances.contains(configurationRequestFromThree));
}
Also used : TrackingMessageHolder(org.neo4j.cluster.com.message.TrackingMessageHolder) MessageHolder(org.neo4j.cluster.com.message.MessageHolder) ConfigurationRequestState(org.neo4j.cluster.protocol.cluster.ClusterMessage.ConfigurationRequestState) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with ConfigurationRequestState

use of org.neo4j.cluster.protocol.cluster.ClusterMessage.ConfigurationRequestState in project neo4j by neo4j.

the class ClusterStateTest method discoveredInstancesShouldBeOnlyOnesWeHaveContactedDirectly.

@Test
public void discoveredInstancesShouldBeOnlyOnesWeHaveContactedDirectly() throws Throwable {
    // GIVEN
    ClusterContext context = mock(ClusterContext.class);
    when(context.getLog(any(Class.class))).thenReturn(NullLog.getInstance());
    when(context.getUriForId(id(2))).thenReturn(uri(2));
    List<ConfigurationRequestState> discoveredInstances = new LinkedList<>();
    when(context.getDiscoveredInstances()).thenReturn(discoveredInstances);
    when(context.shouldFilterContactingInstances()).thenReturn(true);
    MessageHolder outgoing = mock(MessageHolder.class);
    ConfigurationRequestState configurationRequestFromTwo = configuration(2);
    Message<ClusterMessage> message = to(configurationRequest, uri(1), configurationRequestFromTwo).setHeader(Message.FROM, uri(2).toString());
    // WHEN
    // We receive a configuration request from an instance which we haven't contacted
    ClusterState.discovery.handle(context, message, outgoing);
    // THEN
    // It shouldn't be added to the discovered instances
    assertTrue(discoveredInstances.isEmpty());
    // WHEN
    // It subsequently contacts us
    when(context.haveWeContactedInstance(configurationRequestFromTwo)).thenReturn(true);
    ClusterState.discovery.handle(context, message, outgoing);
    // Then
    assertTrue(discoveredInstances.contains(configurationRequestFromTwo));
}
Also used : TrackingMessageHolder(org.neo4j.cluster.com.message.TrackingMessageHolder) MessageHolder(org.neo4j.cluster.com.message.MessageHolder) ConfigurationRequestState(org.neo4j.cluster.protocol.cluster.ClusterMessage.ConfigurationRequestState) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 3 with ConfigurationRequestState

use of org.neo4j.cluster.protocol.cluster.ClusterMessage.ConfigurationRequestState in project neo4j by neo4j.

the class ClusterStateTest method shouldSetDiscoveryHeaderProperly.

@Test
public void shouldSetDiscoveryHeaderProperly() throws Throwable {
    // GIVEN
    ClusterContext context = mock(ClusterContext.class);
    when(context.getLog(any(Class.class))).thenReturn(NullLog.getInstance());
    when(context.getUriForId(id(2))).thenReturn(uri(2));
    when(context.getJoiningInstances()).thenReturn(singletonList(uri(2)));
    List<ConfigurationRequestState> discoveredInstances = new LinkedList<>();
    when(context.getDiscoveredInstances()).thenReturn(discoveredInstances);
    TrackingMessageHolder outgoing = new TrackingMessageHolder();
    ClusterMessage.ConfigurationTimeoutState timeoutState = new ClusterMessage.ConfigurationTimeoutState(3);
    Message<ClusterMessage> message = internal(configurationTimeout, timeoutState);
    String discoveryHeader = "1,2,3";
    when(context.generateDiscoveryHeader()).thenReturn(discoveryHeader);
    // WHEN
    // We receive a configuration request from an instance which we haven't contacted
    ClusterState.discovery.handle(context, message, outgoing);
    // THEN
    // It shouldn't be added to the discovered instances
    assertEquals(discoveryHeader, outgoing.first().getHeader(DISCOVERED));
}
Also used : TrackingMessageHolder(org.neo4j.cluster.com.message.TrackingMessageHolder) ConfigurationRequestState(org.neo4j.cluster.protocol.cluster.ClusterMessage.ConfigurationRequestState) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

LinkedList (java.util.LinkedList)3 Test (org.junit.Test)3 TrackingMessageHolder (org.neo4j.cluster.com.message.TrackingMessageHolder)3 ConfigurationRequestState (org.neo4j.cluster.protocol.cluster.ClusterMessage.ConfigurationRequestState)3 MessageHolder (org.neo4j.cluster.com.message.MessageHolder)2