Search in sources :

Example 1 with NeoServer

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

the class ServerManagementTest method shouldBeAbleToRestartServer.

@Test
public void shouldBeAbleToRestartServer() throws Exception {
    // Given
    String dataDirectory1 = baseDir.directory("data1").getAbsolutePath();
    String dataDirectory2 = baseDir.directory("data2").getAbsolutePath();
    Config config = ConfigLoader.loadConfig(Optional.of(baseDir.directory()), EnterpriseServerBuilder.server().withDefaultDatabaseTuning().usingDataDir(dataDirectory1).createConfigFiles(), pair(GraphDatabaseSettings.logs_directory.name(), baseDir.directory("logs").getPath()));
    // When
    NeoServer server = cleanup.add(new EnterpriseNeoServer(config, graphDbDependencies(), NullLogProvider.getInstance()));
    server.start();
    assertNotNull(server.getDatabase().getGraph());
    assertEquals(config.get(DatabaseManagementSystemSettings.database_path).getAbsolutePath(), server.getDatabase().getLocation());
    // Change the database location
    config.augment(stringMap(DatabaseManagementSystemSettings.data_directory.name(), dataDirectory2));
    ServerManagement bean = new ServerManagement(server);
    bean.restartServer();
    // Then
    assertNotNull(server.getDatabase().getGraph());
    assertEquals(config.get(DatabaseManagementSystemSettings.database_path).getAbsolutePath(), server.getDatabase().getLocation());
}
Also used : EnterpriseNeoServer(org.neo4j.server.enterprise.EnterpriseNeoServer) NeoServer(org.neo4j.server.NeoServer) Config(org.neo4j.kernel.configuration.Config) EnterpriseNeoServer(org.neo4j.server.enterprise.EnterpriseNeoServer) Test(org.junit.Test)

Example 2 with NeoServer

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

the class EnterpriseServerIT method shouldBeAbleToStartInHAMode.

@Test
public void shouldBeAbleToStartInHAMode() throws Throwable {
    // Given
    NeoServer server = EnterpriseServerBuilder.server().usingDataDir(folder.getRoot().getAbsolutePath()).withProperty(mode.name(), "HA").withProperty(server_id.name(), "1").withProperty(initial_hosts.name(), ":5001").persistent().build();
    try {
        server.start();
        server.getDatabase();
        assertThat(server.getDatabase().getGraph(), is(instanceOf(HighlyAvailableGraphDatabase.class)));
        Client client = Client.create();
        ClientResponse r = client.resource("http://localhost:7474/db/manage/server/ha").accept(APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(200, r.getStatus());
        assertThat(r.getEntity(String.class), containsString("master"));
    } finally {
        server.stop();
    }
}
Also used : NeoServer(org.neo4j.server.NeoServer) ClientResponse(com.sun.jersey.api.client.ClientResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(com.sun.jersey.api.client.Client) Test(org.junit.Test)

Example 3 with NeoServer

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

the class ServerMetricsIT method shouldShowServerMetrics.

@Test
public void shouldShowServerMetrics() throws Throwable {
    // Given
    String path = folder.getRoot().getAbsolutePath();
    File metricsPath = new File(path + "/metrics");
    NeoServer server = EnterpriseServerBuilder.server().usingDataDir(path).withProperty(MetricsSettings.metricsEnabled.name(), "true").withProperty(MetricsSettings.csvEnabled.name(), "true").withProperty(MetricsSettings.csvPath.name(), metricsPath.getPath()).withProperty(MetricsSettings.csvInterval.name(), "100ms").persistent().build();
    try {
        // when
        server.start();
        String host = "http://localhost:7474" + ServerSettings.rest_api_path.getDefaultValue() + "/transaction/commit";
        for (int i = 0; i < 5; i++) {
            ClientResponse r = Client.create().resource(host).accept(APPLICATION_JSON).type(APPLICATION_JSON).post(ClientResponse.class, "{ 'statements': [ { 'statement': 'CREATE ()' } ] }");
            assertEquals(200, r.getStatus());
        }
        // then
        assertMetricsExists(metricsPath, ServerMetrics.THREAD_JETTY_ALL);
        assertMetricsExists(metricsPath, ServerMetrics.THREAD_JETTY_IDLE);
    } finally {
        server.stop();
    }
}
Also used : NeoServer(org.neo4j.server.NeoServer) ClientResponse(com.sun.jersey.api.client.ClientResponse) File(java.io.File) Test(org.junit.Test)

Example 4 with NeoServer

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

the class HTTPLoggingIT method givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess.

@Test
public void givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess() throws Exception {
    // given
    String directoryPrefix = testName.getMethodName();
    File logDirectory = testDirectory.directory(directoryPrefix + "-logdir");
    final String query = "?explicitlyEnabled=" + randomString();
    NeoServer server = CommunityServerBuilder.server().withDefaultDatabaseTuning().persistent().withProperty(ServerSettings.http_logging_enabled.name(), Settings.TRUE).withProperty(GraphDatabaseSettings.logs_directory.name(), logDirectory.getAbsolutePath()).usingDataDir(testDirectory.directory(directoryPrefix + "-dbdir").getAbsolutePath()).build();
    try {
        server.start();
        FunctionalTestHelper functionalTestHelper = new FunctionalTestHelper(server);
        // when
        JaxRsResponse response = new RestRequest().get(functionalTestHelper.managementUri() + query);
        assertThat(response.getStatus(), is(HttpStatus.SC_OK));
        response.close();
        // then
        File httpLog = new File(logDirectory, "http.log");
        assertEventually("request appears in log", fileContentSupplier(httpLog), containsString(query), 5, TimeUnit.SECONDS);
    } finally {
        server.stop();
    }
}
Also used : NeoServer(org.neo4j.server.NeoServer) RestRequest(org.neo4j.server.rest.RestRequest) FunctionalTestHelper(org.neo4j.server.helpers.FunctionalTestHelper) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) FileUtils.readTextFile(org.neo4j.io.fs.FileUtils.readTextFile) File(java.io.File) Test(org.junit.Test)

Example 5 with NeoServer

use of org.neo4j.server.NeoServer in project neo4j-documentation by neo4j.

the class ServerHelper method createServer.

private static NeoServer createServer(CommunityServerBuilder builder, boolean persistent, File path) throws IOException {
    if (persistent) {
        builder = builder.persistent();
    }
    NeoServer server = builder.usingDataDir(path != null ? path.getAbsolutePath() : null).build();
    checkServerCanStart(server.baseUri().getHost(), server.baseUri().getPort());
    server.start();
    return server;
}
Also used : NeoServer(org.neo4j.server.NeoServer)

Aggregations

NeoServer (org.neo4j.server.NeoServer)13 Test (org.junit.Test)10 File (java.io.File)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 FileUtils.readTextFile (org.neo4j.io.fs.FileUtils.readTextFile)4 Client (com.sun.jersey.api.client.Client)3 FunctionalTestHelper (org.neo4j.doc.server.helpers.FunctionalTestHelper)2 JaxRsResponse (org.neo4j.doc.server.rest.JaxRsResponse)2 RestRequest (org.neo4j.doc.server.rest.RestRequest)2 Config (org.neo4j.kernel.configuration.Config)2 FunctionalTestHelper (org.neo4j.server.helpers.FunctionalTestHelper)2 JaxRsResponse (org.neo4j.server.rest.JaxRsResponse)2 RestRequest (org.neo4j.server.rest.RestRequest)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Function (java.util.function.Function)1 Configuration (org.apache.commons.configuration.Configuration)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Mockito (org.mockito.Mockito)1