Search in sources :

Example 26 with AdvertisedSocketAddress

use of org.neo4j.helpers.AdvertisedSocketAddress in project neo4j by neo4j.

the class SharedDiscoveryCoreClient method extractCoreServerInfo.

private static CoreServerInfo extractCoreServerInfo(Config config) {
    AdvertisedSocketAddress raftAddress = config.get(CausalClusteringSettings.raft_advertised_address);
    AdvertisedSocketAddress transactionSource = config.get(CausalClusteringSettings.transaction_advertised_address);
    ClientConnectorAddresses clientConnectorAddresses = ClientConnectorAddresses.extractFromConfig(config);
    return new CoreServerInfo(raftAddress, transactionSource, clientConnectorAddresses);
}
Also used : AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress)

Example 27 with AdvertisedSocketAddress

use of org.neo4j.helpers.AdvertisedSocketAddress in project neo4j by neo4j.

the class TestTopology method adressesForCore.

public static CoreServerInfo adressesForCore(int id) {
    AdvertisedSocketAddress raftServerAddress = new AdvertisedSocketAddress("localhost", 3000 + id);
    AdvertisedSocketAddress catchupServerAddress = new AdvertisedSocketAddress("localhost", 4000 + id);
    AdvertisedSocketAddress boltServerAddress = new AdvertisedSocketAddress("localhost", 5000 + id);
    return new CoreServerInfo(raftServerAddress, catchupServerAddress, wrapAsClientConnectorAddresses(boltServerAddress), asSet("core", "core" + id));
}
Also used : AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress)

Example 28 with AdvertisedSocketAddress

use of org.neo4j.helpers.AdvertisedSocketAddress in project neo4j by neo4j.

the class ServerShufflingProcessorTest method shouldShuffleServers.

@Test
public void shouldShuffleServers() throws Exception {
    // given
    LoadBalancingProcessor delegate = mock(LoadBalancingPlugin.class);
    List<Endpoint> routers = asList(Endpoint.route(new AdvertisedSocketAddress("route", 1)), Endpoint.route(new AdvertisedSocketAddress("route", 2)));
    List<Endpoint> writers = asList(Endpoint.write(new AdvertisedSocketAddress("write", 3)), Endpoint.write(new AdvertisedSocketAddress("write", 4)), Endpoint.write(new AdvertisedSocketAddress("write", 5)));
    List<Endpoint> readers = asList(Endpoint.read(new AdvertisedSocketAddress("read", 6)), Endpoint.read(new AdvertisedSocketAddress("read", 7)), Endpoint.read(new AdvertisedSocketAddress("read", 8)), Endpoint.read(new AdvertisedSocketAddress("read", 9)));
    long ttl = 1000;
    LoadBalancingProcessor.Result result = new LoadBalancingResult(new ArrayList<>(routers), new ArrayList<>(writers), new ArrayList<>(readers), ttl);
    when(delegate.run(any())).thenReturn(result);
    ServerShufflingProcessor plugin = new ServerShufflingProcessor(delegate);
    boolean completeShuffle = false;
    for (// we try many times to make false negatives extremely unlikely
    int i = 0; // we try many times to make false negatives extremely unlikely
    i < 1000; // we try many times to make false negatives extremely unlikely
    i++) {
        // when
        LoadBalancingProcessor.Result shuffledResult = plugin.run(Collections.emptyMap());
        // then: should still contain the same endpoints
        assertThat(shuffledResult.routeEndpoints(), containsInAnyOrder(routers.toArray()));
        assertThat(shuffledResult.writeEndpoints(), containsInAnyOrder(writers.toArray()));
        assertThat(shuffledResult.readEndpoints(), containsInAnyOrder(readers.toArray()));
        assertEquals(shuffledResult.getTimeToLiveMillis(), ttl);
        // but possibly in a different order
        boolean readersEqual = shuffledResult.readEndpoints().equals(readers);
        boolean writersEqual = shuffledResult.writeEndpoints().equals(writers);
        boolean routersEqual = shuffledResult.routeEndpoints().equals(routers);
        if (!readersEqual && !writersEqual && !routersEqual) {
            // we don't stop until it is completely different
            completeShuffle = true;
            break;
        }
    }
    assertTrue(completeShuffle);
}
Also used : LoadBalancingResult(org.neo4j.causalclustering.load_balancing.LoadBalancingResult) Endpoint(org.neo4j.causalclustering.load_balancing.Endpoint) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) LoadBalancingProcessor(org.neo4j.causalclustering.load_balancing.LoadBalancingProcessor) Endpoint(org.neo4j.causalclustering.load_balancing.Endpoint) Test(org.junit.Test)

Example 29 with AdvertisedSocketAddress

use of org.neo4j.helpers.AdvertisedSocketAddress in project neo4j by neo4j.

the class IdleChannelReaperHandlerTest method shouldRemoveChannelViaCallback.

@Test
public void shouldRemoveChannelViaCallback() throws Exception {
    // given
    AdvertisedSocketAddress address = new AdvertisedSocketAddress("localhost", 1984);
    NonBlockingChannels nonBlockingChannels = new NonBlockingChannels();
    nonBlockingChannels.putIfAbsent(address, mock(NonBlockingChannel.class));
    IdleChannelReaperHandler reaper = new IdleChannelReaperHandler(nonBlockingChannels);
    final InetSocketAddress socketAddress = address.socketAddress();
    final Channel channel = mock(Channel.class);
    when(channel.remoteAddress()).thenReturn(socketAddress);
    final ChannelHandlerContext context = mock(ChannelHandlerContext.class);
    when(context.channel()).thenReturn(channel);
    // when
    reaper.userEventTriggered(context, IdleStateEvent.ALL_IDLE_STATE_EVENT);
    // then
    assertNull(nonBlockingChannels.get(address));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Test(org.junit.Test)

Example 30 with AdvertisedSocketAddress

use of org.neo4j.helpers.AdvertisedSocketAddress in project neo4j by neo4j.

the class AdvertisedAddressSettingsTest method shouldParseExplicitSettingValueWhenProvided.

@Test
public void shouldParseExplicitSettingValueWhenProvided() throws Exception {
    // given
    Map<String, String> config = stringMap(GraphDatabaseSettings.default_advertised_address.name(), "server1.example.com", advertised_address_setting.name(), "server1.internal:4000");
    // when
    AdvertisedSocketAddress advertisedSocketAddress = advertised_address_setting.apply(config::get);
    // then
    assertEquals("server1.internal", advertisedSocketAddress.getHostname());
    assertEquals(4000, advertisedSocketAddress.getPort());
}
Also used : AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) Test(org.junit.Test)

Aggregations

AdvertisedSocketAddress (org.neo4j.helpers.AdvertisedSocketAddress)31 Test (org.junit.Test)15 HashMap (java.util.HashMap)7 MemberId (org.neo4j.causalclustering.identity.MemberId)6 BoltConnector (org.neo4j.kernel.configuration.BoltConnector)4 Config (org.neo4j.kernel.configuration.Config)4 BiFunction (java.util.function.BiFunction)3 ClientConnectorAddresses (org.neo4j.causalclustering.discovery.ClientConnectorAddresses)3 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)3 MemberAttributeConfig (com.hazelcast.config.MemberAttributeConfig)2 Channel (io.netty.channel.Channel)2 File (java.io.File)2 InetSocketAddress (java.net.InetSocketAddress)2 URI (java.net.URI)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Before (org.junit.Before)2 ConnectorUri (org.neo4j.causalclustering.discovery.ClientConnectorAddresses.ConnectorUri)2 Cluster (org.neo4j.causalclustering.discovery.Cluster)2 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)2