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
}
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();
}
}
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();
}
}
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;
}
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
}
Aggregations