Search in sources :

Example 1 with CommunityNeoServer

use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.

the class DBMSModuleTest method shouldRegisterAtRootByDefault.

@SuppressWarnings("unchecked")
@Test
public void shouldRegisterAtRootByDefault() throws Exception {
    WebServer webServer = mock(WebServer.class);
    Config config = mock(Config.class);
    CommunityNeoServer neoServer = mock(CommunityNeoServer.class);
    when(neoServer.baseUri()).thenReturn(new URI("http://localhost:7575"));
    when(neoServer.getWebServer()).thenReturn(webServer);
    when(config.get(GraphDatabaseSettings.auth_enabled)).thenReturn(true);
    DBMSModule module = new DBMSModule(webServer, config);
    module.start();
    verify(webServer).addJAXRSClasses(anyList(), anyString(), anyCollection());
}
Also used : CommunityNeoServer(org.neo4j.server.CommunityNeoServer) WebServer(org.neo4j.server.web.WebServer) Config(org.neo4j.kernel.configuration.Config) URI(java.net.URI) Test(org.junit.Test)

Example 2 with CommunityNeoServer

use of org.neo4j.server.CommunityNeoServer 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 CommunityNeoServer

use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningDriverPeriodicCommitQuery.

@Test
public void terminateLongRunningDriverPeriodicCommitQuery() throws Exception {
    GraphDatabaseAPI database = startDatabaseWithTimeoutCustomGuard();
    CommunityNeoServer neoServer = startNeoServer((GraphDatabaseFacade) database);
    org.neo4j.driver.v1.Config driverConfig = getDriverConfig();
    try (Driver driver = GraphDatabase.driver("bolt://localhost:" + boltPortCustomGuard, driverConfig);
        Session session = driver.session()) {
        URL url = prepareTestImportFile(8);
        session.run("USING PERIODIC COMMIT 5 LOAD CSV FROM '" + url + "' AS line CREATE ();").consume();
        fail("Transaction should be already terminated by execution guard.");
    } catch (Exception expected) {
    //
    }
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) Driver(org.neo4j.driver.v1.Driver) URL(java.net.URL) GuardTimeoutException(org.neo4j.kernel.guard.GuardTimeoutException) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) IOException(java.io.IOException) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 4 with CommunityNeoServer

use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningRestTransactionalEndpointQuery.

@Test
public void terminateLongRunningRestTransactionalEndpointQuery() throws Exception {
    GraphDatabaseAPI database = startDatabaseWithTimeout();
    CommunityNeoServer neoServer = startNeoServer((GraphDatabaseFacade) database);
    String transactionEndPoint = HTTP.POST(transactionUri(neoServer)).location();
    fakeClock.forward(3, TimeUnit.SECONDS);
    HTTP.Response response = HTTP.POST(transactionEndPoint, quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
    assertEquals("Response should be successful.", 200, response.status());
    HTTP.Response commitResponse = HTTP.POST(transactionEndPoint + "/commit");
    assertEquals("Transaction should be already closed and not found.", 404, commitResponse.status());
    assertEquals("Transaction should be forcefully closed.", TransactionNotFound.code().serialize(), commitResponse.get("errors").findValue("code").asText());
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) HTTP(org.neo4j.test.server.HTTP) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 5 with CommunityNeoServer

use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningRestTransactionalEndpointWithCustomTimeoutQuery.

@Test
public void terminateLongRunningRestTransactionalEndpointWithCustomTimeoutQuery() throws Exception {
    GraphDatabaseAPI database = startDatabaseWithTimeout();
    CommunityNeoServer neoServer = startNeoServer((GraphDatabaseFacade) database);
    long customTimeout = TimeUnit.SECONDS.toMillis(10);
    HTTP.Response beginResponse = HTTP.withHeaders(HttpHeaderUtils.MAX_EXECUTION_TIME_HEADER, String.valueOf(customTimeout)).POST(transactionUri(neoServer), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
    assertEquals("Response should be successful.", 201, beginResponse.status());
    String transactionEndPoint = beginResponse.location();
    fakeClock.forward(3, TimeUnit.SECONDS);
    HTTP.Response response = HTTP.POST(transactionEndPoint, quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
    assertEquals("Response should be successful.", 200, response.status());
    fakeClock.forward(11, TimeUnit.SECONDS);
    response = HTTP.POST(transactionEndPoint, quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
    assertEquals("Response should be successful.", 200, response.status());
    HTTP.Response commitResponse = HTTP.POST(transactionEndPoint + "/commit");
    assertEquals("Transaction should be already closed and not found.", 404, commitResponse.status());
    assertEquals("Transaction should be forcefully closed.", TransactionNotFound.code().serialize(), commitResponse.get("errors").findValue("code").asText());
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) HTTP(org.neo4j.test.server.HTTP) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

CommunityNeoServer (org.neo4j.server.CommunityNeoServer)9 Test (org.junit.Test)8 Config (org.neo4j.kernel.configuration.Config)5 URI (java.net.URI)4 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)4 WebServer (org.neo4j.server.web.WebServer)4 List (java.util.List)3 Matchers.anyString (org.mockito.Matchers.anyString)3 IOException (java.io.IOException)2 RemoteException (java.rmi.RemoteException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Driver (org.neo4j.driver.v1.Driver)2 Session (org.neo4j.driver.v1.Session)2 GuardTimeoutException (org.neo4j.kernel.guard.GuardTimeoutException)2 ShellException (org.neo4j.shell.ShellException)2 HTTP (org.neo4j.test.server.HTTP)2 BindException (java.net.BindException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1