Search in sources :

Example 21 with AdvertisedSocketAddress

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

the class IdleChannelReaperHandler method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent && evt == IdleStateEvent.ALL_IDLE_STATE_EVENT) {
        final InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress();
        final AdvertisedSocketAddress address = new AdvertisedSocketAddress(socketAddress.getHostName(), socketAddress.getPort());
        nonBlockingChannels.remove(address);
    }
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) InetSocketAddress(java.net.InetSocketAddress) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress)

Example 22 with AdvertisedSocketAddress

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

the class UserDefinedConfigurationStrategyTest method fakeReadReplicaTopology.

static ReadReplicaTopology fakeReadReplicaTopology(MemberId... readReplicaIds) {
    assert readReplicaIds.length > 0;
    Map<MemberId, ReadReplicaInfo> readReplicas = new HashMap<>();
    int offset = 0;
    for (MemberId memberId : readReplicaIds) {
        readReplicas.put(memberId, new ReadReplicaInfo(new ClientConnectorAddresses(singletonList(new ClientConnectorAddresses.ConnectorUri(ClientConnectorAddresses.Scheme.bolt, new AdvertisedSocketAddress("localhost", 11000 + offset)))), new AdvertisedSocketAddress("localhost", 10000 + offset)));
        offset++;
    }
    return new ReadReplicaTopology(readReplicas);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) HashMap(java.util.HashMap) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ClientConnectorAddresses(org.neo4j.causalclustering.discovery.ClientConnectorAddresses) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology)

Example 23 with AdvertisedSocketAddress

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

the class HazelcastClusterTopologyTest method shouldCollectMembersAsAMap.

@Test
public void shouldCollectMembersAsAMap() throws Exception {
    // given
    Set<Member> hazelcastMembers = new HashSet<>();
    List<MemberId> coreMembers = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        MemberId memberId = new MemberId(UUID.randomUUID());
        coreMembers.add(memberId);
        Config config = Config.defaults();
        HashMap<String, String> settings = new HashMap<>();
        settings.put(CausalClusteringSettings.transaction_advertised_address.name(), "tx:" + (i + 1));
        settings.put(CausalClusteringSettings.raft_advertised_address.name(), "raft:" + (i + 1));
        settings.put(new BoltConnector("bolt").type.name(), "BOLT");
        settings.put(new BoltConnector("bolt").enabled.name(), "true");
        settings.put(new BoltConnector("bolt").advertised_address.name(), "bolt:" + (i + 1));
        settings.put(new BoltConnector("http").type.name(), "HTTP");
        settings.put(new BoltConnector("http").enabled.name(), "true");
        settings.put(new BoltConnector("http").advertised_address.name(), "http:" + (i + 1));
        config.augment(settings);
        Map<String, Object> attributes = buildMemberAttributesForCore(memberId, config).getAttributes();
        hazelcastMembers.add(new MemberImpl(new Address("localhost", i), null, attributes, false));
    }
    // when
    Map<MemberId, CoreServerInfo> coreMemberMap = toCoreMemberMap(hazelcastMembers, NullLog.getInstance(), hzInstance);
    // then
    for (int i = 0; i < 5; i++) {
        CoreServerInfo coreServerInfo = coreMemberMap.get(coreMembers.get(i));
        assertEquals(new AdvertisedSocketAddress("tx", i + 1), coreServerInfo.getCatchupServer());
        assertEquals(new AdvertisedSocketAddress("raft", i + 1), coreServerInfo.getRaftServer());
        assertEquals(new AdvertisedSocketAddress("bolt", i + 1), coreServerInfo.connectors().boltAddress());
        assertEquals(coreServerInfo.groups(), GROUPS);
    }
}
Also used : Address(com.hazelcast.nio.Address) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) HashMap(java.util.HashMap) BoltConnector(org.neo4j.kernel.configuration.BoltConnector) Config(org.neo4j.kernel.configuration.Config) MemberImpl(com.hazelcast.client.impl.MemberImpl) ArrayList(java.util.ArrayList) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) Matchers.anyString(org.mockito.Matchers.anyString) MemberId(org.neo4j.causalclustering.identity.MemberId) Member(com.hazelcast.core.Member) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with AdvertisedSocketAddress

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

the class ClientConnectorAddressesTest method shouldSerializeToString.

@Test
public void shouldSerializeToString() throws Exception {
    // given
    ClientConnectorAddresses connectorAddresses = new ClientConnectorAddresses(asList(new ConnectorUri(bolt, new AdvertisedSocketAddress("host", 1)), new ConnectorUri(http, new AdvertisedSocketAddress("host", 2)), new ConnectorUri(https, new AdvertisedSocketAddress("host", 3))));
    // when
    ClientConnectorAddresses out = ClientConnectorAddresses.fromString(connectorAddresses.toString());
    // then
    assertEquals(connectorAddresses, out);
}
Also used : AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ConnectorUri(org.neo4j.causalclustering.discovery.ClientConnectorAddresses.ConnectorUri) Test(org.junit.Test)

Example 25 with AdvertisedSocketAddress

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

the class ClientConnectorAddressesTest method shouldSerializeWithNoHttpsAddress.

@Test
public void shouldSerializeWithNoHttpsAddress() throws Exception {
    // given
    ClientConnectorAddresses connectorAddresses = new ClientConnectorAddresses(asList(new ConnectorUri(bolt, new AdvertisedSocketAddress("host", 1)), new ConnectorUri(http, new AdvertisedSocketAddress("host", 2))));
    // when
    ClientConnectorAddresses out = ClientConnectorAddresses.fromString(connectorAddresses.toString());
    // then
    assertEquals(connectorAddresses, out);
}
Also used : AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ConnectorUri(org.neo4j.causalclustering.discovery.ClientConnectorAddresses.ConnectorUri) 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