Search in sources :

Example 16 with ListenSocketAddress

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

the class TestJetty9WebServer method shouldBeAbleToRestart.

@Test
public void shouldBeAbleToRestart() throws Throwable {
    // given
    webServer = new Jetty9WebServer(NullLogProvider.getInstance(), Config.empty());
    webServer.setAddress(new ListenSocketAddress("127.0.0.1", 7878));
    // when
    webServer.start();
    webServer.stop();
    webServer.start();
// then no exception
}
Also used : ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) Test(org.junit.Test)

Example 17 with ListenSocketAddress

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

the class NeoServerPortConflictIT method shouldComplainIfServerHTTPSPortIsAlreadyTaken.

@Test
public void shouldComplainIfServerHTTPSPortIsAlreadyTaken() throws IOException, InterruptedException {
    ListenSocketAddress unContestedAddress = new ListenSocketAddress("localhost", 8888);
    ListenSocketAddress contestedAddress = new ListenSocketAddress("localhost", 9999);
    try (ServerSocket ignored = new ServerSocket(contestedAddress.getPort(), 0, InetAddress.getByName(contestedAddress.getHostname()))) {
        AssertableLogProvider logProvider = new AssertableLogProvider();
        CommunityNeoServer server = CommunityServerBuilder.server(logProvider).onAddress(unContestedAddress).onHttpsAddress(contestedAddress).withHttpsEnabled().usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
        try {
            server.start();
            fail("Should have reported failure to start");
        } catch (ServerStartupException e) {
            assertThat(e.getMessage(), containsString("Starting Neo4j failed"));
        }
        logProvider.assertAtLeastOnce(AssertableLogProvider.inLog(containsString("CommunityNeoServer")).error("Failed to start Neo4j on %s: %s", unContestedAddress, format("At least one of the addresses %s or %s is already in use, cannot bind to it.", unContestedAddress, contestedAddress)));
        server.stop();
    }
}
Also used : ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) ServerSocket(java.net.ServerSocket) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 18 with ListenSocketAddress

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

the class NeoServerPortConflictIT method shouldComplainIfServerPortIsAlreadyTaken.

@Test
public void shouldComplainIfServerPortIsAlreadyTaken() throws IOException, InterruptedException {
    ListenSocketAddress contestedAddress = new ListenSocketAddress("localhost", 9999);
    try (ServerSocket ignored = new ServerSocket(contestedAddress.getPort(), 0, InetAddress.getByName(contestedAddress.getHostname()))) {
        AssertableLogProvider logProvider = new AssertableLogProvider();
        CommunityNeoServer server = CommunityServerBuilder.server(logProvider).onAddress(contestedAddress).usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
        try {
            server.start();
            fail("Should have reported failure to start");
        } catch (ServerStartupException e) {
            assertThat(e.getMessage(), containsString("Starting Neo4j failed"));
        }
        logProvider.assertAtLeastOnce(AssertableLogProvider.inLog(containsString("CommunityNeoServer")).error("Failed to start Neo4j on %s: %s", contestedAddress, format("Address %s is already in use, cannot bind to it.", contestedAddress)));
        server.stop();
    }
}
Also used : ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) ServerSocket(java.net.ServerSocket) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 19 with ListenSocketAddress

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

the class HazelcastCoreTopologyService method createHazelcastInstance.

private HazelcastInstance createHazelcastInstance() {
    System.setProperty(WAIT_SECONDS_BEFORE_JOIN.getName(), "1");
    JoinConfig joinConfig = new JoinConfig();
    joinConfig.getMulticastConfig().setEnabled(false);
    joinConfig.getAwsConfig().setEnabled(false);
    TcpIpConfig tcpIpConfig = joinConfig.getTcpIpConfig();
    tcpIpConfig.setEnabled(true);
    List<AdvertisedSocketAddress> initialMembers = config.get(CausalClusteringSettings.initial_discovery_members);
    for (AdvertisedSocketAddress address : initialMembers) {
        tcpIpConfig.addMember(address.toString());
    }
    Setting<ListenSocketAddress> discovery_listen_address = CausalClusteringSettings.discovery_listen_address;
    ListenSocketAddress hazelcastAddress = config.get(discovery_listen_address);
    InterfacesConfig interfaces = new InterfacesConfig();
    interfaces.addInterface(hazelcastAddress.getHostname());
    NetworkConfig networkConfig = new NetworkConfig();
    networkConfig.setInterfaces(interfaces);
    networkConfig.setPort(hazelcastAddress.getPort());
    networkConfig.setJoin(joinConfig);
    networkConfig.setPortAutoIncrement(false);
    com.hazelcast.config.Config c = new com.hazelcast.config.Config();
    c.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), String.valueOf(10_000));
    c.setProperty(MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "10");
    c.setProperty(MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "10");
    c.setProperty(INITIAL_MIN_CLUSTER_SIZE.getName(), String.valueOf(minimumClusterSizeThatCanTolerateOneFaultForExpectedClusterSize()));
    c.setProperty(LOGGING_TYPE.getName(), "none");
    c.setNetworkConfig(networkConfig);
    MemberAttributeConfig memberAttributeConfig = HazelcastClusterTopology.buildMemberAttributesForCore(myself, config);
    c.setMemberAttributeConfig(memberAttributeConfig);
    logConnectionInfo(initialMembers);
    JobScheduler.JobHandle logJob = scheduler.schedule("HazelcastHealth", HAZELCAST_IS_HEALTHY_TIMEOUT_MS, () -> log.warn("The server has not been able to connect in a timely fashion to the " + "cluster. Please consult the logs for more details. Rebooting the server may " + "solve the problem."));
    try {
        hazelcastInstance = Hazelcast.newHazelcastInstance(c);
        logJob.cancel(true);
    } catch (HazelcastException e) {
        String errorMessage = String.format("Hazelcast was unable to start with setting: %s = %s", discovery_listen_address.name(), config.get(discovery_listen_address));
        userLog.error(errorMessage);
        log.error(errorMessage, e);
        throw new RuntimeException(e);
    }
    List<String> groups = config.get(CausalClusteringSettings.server_groups);
    refreshGroups(hazelcastInstance, myself.getUuid().toString(), groups);
    return hazelcastInstance;
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) InterfacesConfig(com.hazelcast.config.InterfacesConfig) HazelcastException(com.hazelcast.core.HazelcastException) JoinConfig(com.hazelcast.config.JoinConfig) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) Config(org.neo4j.kernel.configuration.Config) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) JoinConfig(com.hazelcast.config.JoinConfig) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig)

Example 20 with ListenSocketAddress

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

the class TestJetty9WebServer method shouldBeAbleToUsePortZero.

@Test
public void shouldBeAbleToUsePortZero() throws Exception {
    // Given
    webServer = new Jetty9WebServer(NullLogProvider.getInstance(), Config.empty());
    webServer.setAddress(new ListenSocketAddress("localhost", 0));
    // When
    webServer.start();
// Then no exception
}
Also used : ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) Test(org.junit.Test)

Aggregations

ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)26 Test (org.junit.Test)23 Config (org.neo4j.kernel.configuration.Config)15 BoltConnector (org.neo4j.kernel.configuration.BoltConnector)8 AdvertisedSocketAddress (org.neo4j.helpers.AdvertisedSocketAddress)4 HttpConnector (org.neo4j.kernel.configuration.HttpConnector)4 ServerSocket (java.net.ServerSocket)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 BiFunction (java.util.function.BiFunction)2 NettyServer (org.neo4j.bolt.transport.NettyServer)2 Configuration (org.neo4j.graphdb.config.Configuration)2 Setting (org.neo4j.graphdb.config.Setting)2 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)2 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)2 InterfacesConfig (com.hazelcast.config.InterfacesConfig)1 JoinConfig (com.hazelcast.config.JoinConfig)1 MemberAttributeConfig (com.hazelcast.config.MemberAttributeConfig)1 NetworkConfig (com.hazelcast.config.NetworkConfig)1