Search in sources :

Example 1 with CommunityBootstrapper

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()));
}
Also used : Path(java.nio.file.Path) ExclusiveWebContainerTestBase(org.neo4j.test.server.ExclusiveWebContainerTestBase) ServerSettings(org.neo4j.server.configuration.ServerSettings) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) HttpRequest(java.net.http.HttpRequest) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) HttpConnector(org.neo4j.configuration.connectors.HttpConnector) Duration(java.time.Duration) Map(java.util.Map) HttpClient(java.net.http.HttpClient) AbstractNeoWebServer(org.neo4j.server.AbstractNeoWebServer) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) DependencyResolver(org.neo4j.common.DependencyResolver) HttpResponse(java.net.http.HttpResponse) Files(java.nio.file.Files) FormattedLogFormat(org.neo4j.logging.FormattedLogFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CommunityBootstrapper(org.neo4j.server.CommunityBootstrapper) TRUE(org.neo4j.configuration.SettingValueParsers.TRUE) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) LogManager(org.apache.logging.log4j.LogManager) AbstractNeoWebServer(org.neo4j.server.AbstractNeoWebServer) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CommunityBootstrapper(org.neo4j.server.CommunityBootstrapper) Test(org.junit.Test)

Example 2 with CommunityBootstrapper

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.")));
}
Also used : File(java.io.File) CommunityBootstrapper(org.neo4j.server.CommunityBootstrapper) Pair(org.neo4j.helpers.collection.Pair) Test(org.junit.Test)

Example 3 with CommunityBootstrapper

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();
}
Also used : NeoServer(org.neo4j.server.NeoServer) ServerBootstrapper(org.neo4j.server.ServerBootstrapper) File(java.io.File) CommunityBootstrapper(org.neo4j.server.CommunityBootstrapper) Bean(org.springframework.context.annotation.Bean)

Aggregations

CommunityBootstrapper (org.neo4j.server.CommunityBootstrapper)3 File (java.io.File)2 Test (org.junit.Test)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpClient (java.net.http.HttpClient)1 HttpRequest (java.net.http.HttpRequest)1 HttpResponse (java.net.http.HttpResponse)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Duration (java.time.Duration)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 DependencyResolver (org.neo4j.common.DependencyResolver)1 Config (org.neo4j.configuration.Config)1 DEFAULT_DATABASE_NAME (org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME)1 TRUE (org.neo4j.configuration.SettingValueParsers.TRUE)1