use of org.neo4j.server.ServerStartupException in project neo4j-documentation by neo4j.
the class NeoServerPortConflictDocIT 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.server.ServerStartupException in project neo4j by neo4j.
the class DatabaseActions method start.
public void start() throws UnableToStartServerException {
if (isRunning()) {
throw new UnableToStartServerException("Already started");
}
Config config = model.getConfig();
Monitors monitors = new Monitors();
LogProvider userLogProvider = FormattedLogProvider.toOutputStream(System.out);
GraphDatabaseDependencies dependencies = GraphDatabaseDependencies.newDependencies().userLogProvider(userLogProvider).monitors(monitors);
server = new CommunityNeoServer(config, dependencies, userLogProvider);
try {
server.start();
} catch (ServerStartupException e) {
server = null;
Set<Class> causes = extractCauseTypes(e);
if (causes.contains(StoreLockException.class)) {
throw new UnableToStartServerException("Unable to lock store. Are you running another Neo4j process against this database?");
}
if (causes.contains(BindException.class)) {
throw new UnableToStartServerException("Unable to bind to port. Are you running another Neo4j process on this computer?");
}
throw new UnableToStartServerException(e.getMessage());
}
}
use of org.neo4j.server.ServerStartupException in project neo4j-documentation by neo4j.
the class NeoServerPortConflictDocIT 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();
}
}
Aggregations