Search in sources :

Example 1 with ServerStartupException

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();
    }
}
Also used : CommunityNeoServer(org.neo4j.server.CommunityNeoServer) ServerStartupException(org.neo4j.server.ServerStartupException) ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) ServerSocket(java.net.ServerSocket) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 2 with ServerStartupException

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());
    }
}
Also used : LogProvider(org.neo4j.logging.LogProvider) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider) Set(java.util.Set) HashSet(java.util.HashSet) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) Config(org.neo4j.kernel.configuration.Config) ServerStartupException(org.neo4j.server.ServerStartupException) UnableToStartServerException(org.neo4j.desktop.model.exceptions.UnableToStartServerException) Monitors(org.neo4j.kernel.monitoring.Monitors) GraphDatabaseDependencies(org.neo4j.kernel.GraphDatabaseDependencies) StoreLockException(org.neo4j.kernel.StoreLockException) BindException(java.net.BindException)

Example 3 with ServerStartupException

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();
    }
}
Also used : CommunityNeoServer(org.neo4j.server.CommunityNeoServer) ServerStartupException(org.neo4j.server.ServerStartupException) ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) ServerSocket(java.net.ServerSocket) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Aggregations

CommunityNeoServer (org.neo4j.server.CommunityNeoServer)3 ServerStartupException (org.neo4j.server.ServerStartupException)3 ServerSocket (java.net.ServerSocket)2 Test (org.junit.Test)2 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)2 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)2 BindException (java.net.BindException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 UnableToStartServerException (org.neo4j.desktop.model.exceptions.UnableToStartServerException)1 GraphDatabaseDependencies (org.neo4j.kernel.GraphDatabaseDependencies)1 StoreLockException (org.neo4j.kernel.StoreLockException)1 Config (org.neo4j.kernel.configuration.Config)1 Monitors (org.neo4j.kernel.monitoring.Monitors)1 FormattedLogProvider (org.neo4j.logging.FormattedLogProvider)1 LogProvider (org.neo4j.logging.LogProvider)1