use of org.neo4j.server.CommunityBootstrapper in project neo4j by neo4j.
the class HttpStructuredLoggingIT method shouldLogRequestsInStructuredFormat.
@Test
public void shouldLogRequestsInStructuredFormat() throws Exception {
var bootstrapper = new CommunityBootstrapper();
HttpResponse<String> response;
Path httpLogPath;
try {
bootstrapper.start(folder.homePath(), Map.of(HttpConnector.listen_address.name(), "localhost:0", ServerSettings.http_log_format.name(), FormattedLogFormat.JSON.name(), ServerSettings.http_logging_enabled.name(), TRUE, HttpConnector.enabled.name(), TRUE));
var dependencyResolver = getDependencyResolver(bootstrapper.getDatabaseManagementService());
var baseUri = dependencyResolver.resolveDependency(AbstractNeoWebServer.class).getBaseUri();
var config = dependencyResolver.resolveDependency(Config.class);
var request = HttpRequest.newBuilder().uri(baseUri).timeout(Duration.ofSeconds(10)).header("Accept", "application/json").header("User-Agent", HttpStructuredLoggingIT.class.getSimpleName()).GET().build();
// Just ask the discovery api for a response we don't actually care of
httpLogPath = config.get(ServerSettings.http_log_path);
response = HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
} finally {
bootstrapper.stop();
// Make sure the log manager flushes everything.
LogManager.shutdown();
}
assertThat(response.statusCode()).isEqualTo(200);
var httpLogLines = Files.readAllLines(httpLogPath).stream().map(s -> {
try {
return OBJECT_MAPPER.readValue(s, MAP_TYPE);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
assertThat(httpLogLines).anyMatch(logEntry -> logEntry.getOrDefault("message", "").contains(HttpStructuredLoggingIT.class.getSimpleName()));
}
use of org.neo4j.server.CommunityBootstrapper in project neo4j by neo4j.
the class StartupLoggingIT method shouldLogHelpfulStartupMessages.
@Test
public void shouldLogHelpfulStartupMessages() throws Throwable {
CommunityBootstrapper boot = new CommunityBootstrapper();
Pair[] propertyPairs = getPropertyPairs();
boot.start(homeDir.directory(), Optional.of(new File("nonexistent-file.conf")), propertyPairs);
boot.stop();
List<String> captured = suppressOutput.getOutputVoice().lines();
assertThat(captured, containsAtLeastTheseLines(warn("Config file \\[nonexistent-file.conf\\] does not exist."), info("Starting..."), info("Started."), info("Remote interface available at http://.+:7474/"), info("Stopping..."), info("Stopped.")));
}
use of org.neo4j.server.CommunityBootstrapper in project open-kilda by telstra.
the class TestConfig method graphDatabaseService.
/**
* Neo4j Server bean.
* Runs Neo4j server for integration tests and returns {@link GraphDatabaseService} instance.
*
* @return {@link GraphDatabaseService}
*/
@Bean(destroyMethod = "shutdown")
public GraphDatabaseService graphDatabaseService() {
String homeDir = "./target";
String configFile = "./src/test/resources/neo4j.conf";
ServerBootstrapper serverBootstrapper = new CommunityBootstrapper();
int i = serverBootstrapper.start(new File(homeDir), Optional.of(new File(configFile)));
switch(i) {
case ServerBootstrapper.OK:
logger.debug("Server started");
break;
case ServerBootstrapper.GRAPH_DATABASE_STARTUP_ERROR_CODE:
logger.error("Server failed to start: graph database startup error");
break;
case ServerBootstrapper.WEB_SERVER_STARTUP_ERROR_CODE:
logger.error("Server failed to start: web server startup error");
break;
default:
logger.error("Server failed to start: unknown error");
break;
}
NeoServer neoServer = serverBootstrapper.getServer();
return neoServer.getDatabase().getGraph();
}
Aggregations