Search in sources :

Example 46 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class SpatialConfigExtractorTest method shouldLogFailureToExtractIndexConfigFromGenericBecauseOfIndexInFailedState.

@Test
void shouldLogFailureToExtractIndexConfigFromGenericBecauseOfIndexInFailedState() throws IOException {
    // given
    unzip(getClass(), ZIP_FAILED_SPATIAL_35_DIR, directory.homePath());
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log myLog = logProvider.getLog(getClass());
    // and
    Path spatialDirectory = directory.homePath().resolve(FAILED_SPATIAL_35_DIR);
    assertTrue(fs.fileExists(spatialDirectory));
    assertTrue(fs.isDirectory(spatialDirectory));
    // when
    List<SpatialFile> spatialFiles = IndexMigration.getSpatialFiles(fs, spatialDirectory);
    SpatialConfigExtractor.indexConfigFromSpatialFile(pageCache, spatialFiles, NULL, myLog, DEFAULT_DATABASE_NAME);
    // then
    String reason = "Index is in FAILED state.";
    assertContainsLogEntry(logProvider, spatialFiles.get(0).getIndexFile(), reason);
}
Also used : Path(java.nio.file.Path) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 47 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class ServerSettingsMigratorTest method testWhitelistSettingsRename.

@Test
void testWhitelistSettingsRename() throws IOException {
    Path confFile = testDirectory.createFile("test.conf");
    Files.write(confFile, List.of("dbms.security.http_auth_whitelist=a,b"));
    Config config = Config.newBuilder().fromFile(confFile).build();
    var logProvider = new AssertableLogProvider();
    config.setLogger(logProvider.getLog(Config.class));
    assertThat(logProvider).forClass(Config.class).forLevel(WARN).containsMessageWithArguments("Use of deprecated setting %s. It is replaced by %s", "dbms.security.http_auth_whitelist", http_auth_allowlist.name());
    assertEquals(List.of("a", "b"), config.get(http_auth_allowlist));
}
Also used : Path(java.nio.file.Path) Config(org.neo4j.configuration.Config) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 48 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class HttpTransactionManagerTest method newTransactionManager.

private static HttpTransactionManager newTransactionManager(DatabaseManagementService managementService, MemoryPool memoryPool) {
    JobScheduler jobScheduler = mock(JobScheduler.class);
    AssertableLogProvider logProvider = new AssertableLogProvider(true);
    var defaultDatabase = "neo4j";
    when(managementService.database(any(String.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String db = (String) args[0];
        if (db.equals(defaultDatabase) || db.equals("system")) {
            return graphWithName(db);
        } else {
            throw new DatabaseNotFoundException("Not found db named " + db);
        }
    });
    return new HttpTransactionManager(managementService, memoryPool, jobScheduler, Clocks.systemClock(), Duration.ofMinutes(1), logProvider);
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) DatabaseNotFoundException(org.neo4j.dbms.api.DatabaseNotFoundException) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider)

Example 49 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class ErrorReporterTest method onlyDatabaseErrorsAreLogged.

@Test
void onlyDatabaseErrorsAreLogged() {
    AssertableLogProvider userLog = new AssertableLogProvider();
    AssertableLogProvider internalLog = new AssertableLogProvider();
    ErrorReporter reporter = newErrorReporter(userLog, internalLog);
    for (Status.Classification classification : Status.Classification.values()) {
        if (classification != Status.Classification.DatabaseError) {
            Status.Code code = newStatusCode(classification);
            Neo4jError error = Neo4jError.from(() -> code, "Database error");
            reporter.report(error);
            assertThat(userLog).doesNotHaveAnyLogs();
            assertThat(internalLog).doesNotHaveAnyLogs();
        }
    }
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) Neo4jError(org.neo4j.bolt.runtime.Neo4jError) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 50 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class GraphDatabaseSettingsTest method testDefaultAddressMigration.

@Test
void testDefaultAddressMigration() {
    String oldDefaultListen = "dbms.connectors.default_listen_address";
    String oldDefaultAdvertised = "dbms.connectors.default_advertised_address";
    var config = Config.newBuilder().setRaw(Map.of(oldDefaultListen, "foo", oldDefaultAdvertised, "bar")).build();
    var logProvider = new AssertableLogProvider();
    config.setLogger(logProvider.getLog(Config.class));
    assertThrows(IllegalArgumentException.class, () -> config.getSetting(oldDefaultListen));
    assertThrows(IllegalArgumentException.class, () -> config.getSetting(oldDefaultAdvertised));
    assertEquals(new SocketAddress("foo"), config.get(default_listen_address));
    assertEquals(new SocketAddress("bar"), config.get(default_advertised_address));
    var messageMatcher = assertThat(logProvider).forClass(Config.class).forLevel(WARN);
    messageMatcher.containsMessageWithArguments("Use of deprecated setting %s. It is replaced by %s", oldDefaultListen, default_listen_address.name()).containsMessageWithArguments("Use of deprecated setting %s. It is replaced by %s", oldDefaultAdvertised, default_advertised_address.name());
}
Also used : SocketAddress(org.neo4j.configuration.helpers.SocketAddress) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Aggregations

AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)202 Test (org.junit.jupiter.api.Test)98 Test (org.junit.Test)63 Path (java.nio.file.Path)29 Log (org.neo4j.logging.Log)24 FakeClock (org.neo4j.time.FakeClock)20 SslPolicyConfig (org.neo4j.configuration.ssl.SslPolicyConfig)14 IOException (java.io.IOException)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 DynamicTest (org.junit.jupiter.api.DynamicTest)12 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)12 SocketAddress (org.neo4j.configuration.helpers.SocketAddress)11 NullLog (org.neo4j.logging.NullLog)11 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)10 BeforeEach (org.junit.jupiter.api.BeforeEach)9 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)9 QueryLogger (org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger)9 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)8 ServerSocket (java.net.ServerSocket)8 Before (org.junit.Before)8