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