Search in sources :

Example 11 with LogService

use of org.neo4j.logging.internal.LogService in project neo4j by neo4j.

the class GraphDatabaseInternalLogIT method shouldNotWriteDebugToInternalDiagnosticsLogByDefault.

@Test
void shouldNotWriteDebugToInternalDiagnosticsLogByDefault() throws Exception {
    // Given
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDir.homePath()).setConfig(GraphDatabaseSettings.logs_directory, testDir.directory("logs").toAbsolutePath()).build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    // When
    LogService logService = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(LogService.class);
    logService.getInternalLog(getClass()).debug("A debug entry");
    managementService.shutdown();
    Path internalLog = testDir.directory("logs").resolve(INTERNAL_LOG_FILE);
    // Then
    assertThat(Files.isRegularFile(internalLog)).isEqualTo(true);
    assertThat(Files.size(internalLog)).isGreaterThan(0L);
    assertEquals(0, countOccurrences(internalLog, "A debug entry"));
}
Also used : Path(java.nio.file.Path) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) LogService(org.neo4j.logging.internal.LogService) Test(org.junit.jupiter.api.Test)

Example 12 with LogService

use of org.neo4j.logging.internal.LogService in project neo4j by neo4j.

the class MessageDecoderTest method shouldLogContentOfTheMessageOnError.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void shouldLogContentOfTheMessageOnError(Neo4jPack packerUnderTest) throws Exception {
    this.packerUnderTest = packerUnderTest;
    BoltRequestMessageReader requestMessageReader = mock(BoltRequestMessageReader.class);
    RuntimeException error = new RuntimeException("Hello!");
    doThrow(error).when(requestMessageReader).read(any());
    LogService logService = mock(LogService.class);
    Log log = mock(Log.class);
    when(logService.getInternalLog(MessageDecoder.class)).thenReturn(log);
    channel = new EmbeddedChannel(new MessageDecoder(packerUnderTest::newUnpacker, requestMessageReader, logService));
    byte[] messageBytes = packMessageWithSignature(RunMessage.SIGNATURE);
    var e = assertThrows(RuntimeException.class, () -> channel.writeInbound(Unpooled.wrappedBuffer(messageBytes)));
    assertEquals(error, e);
    assertMessageHexDumpLogged(log, messageBytes);
}
Also used : MessageDecoder(org.neo4j.bolt.transport.pipeline.MessageDecoder) BoltRequestMessageReader(org.neo4j.bolt.messaging.BoltRequestMessageReader) Log(org.neo4j.logging.Log) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) NullLogService(org.neo4j.logging.internal.NullLogService) LogService(org.neo4j.logging.internal.LogService) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with LogService

use of org.neo4j.logging.internal.LogService in project neo4j by neo4j.

the class MessageDecoderTest method shouldLogContentOfTheMessageOnIOError.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void shouldLogContentOfTheMessageOnIOError(Neo4jPack packerUnderTest) throws Exception {
    this.packerUnderTest = packerUnderTest;
    BoltConnection connection = mock(BoltConnection.class);
    BoltResponseMessageWriter responseMessageHandler = mock(BoltResponseMessageWriter.class);
    BoltRequestMessageReader requestMessageReader = new BoltRequestMessageReaderV3(connection, responseMessageHandler, mock(ChannelProtector.class), NullLogService.getInstance());
    LogService logService = mock(LogService.class);
    Log log = mock(Log.class);
    when(logService.getInternalLog(MessageDecoder.class)).thenReturn(log);
    channel = new EmbeddedChannel(new MessageDecoder(packerUnderTest::newUnpacker, requestMessageReader, logService));
    byte invalidMessageSignature = Byte.MAX_VALUE;
    byte[] messageBytes = packMessageWithSignature(invalidMessageSignature);
    assertThrows(BoltIOException.class, () -> channel.writeInbound(Unpooled.wrappedBuffer(messageBytes)));
    assertMessageHexDumpLogged(log, messageBytes);
}
Also used : BoltResponseMessageWriter(org.neo4j.bolt.messaging.BoltResponseMessageWriter) ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) MessageDecoder(org.neo4j.bolt.transport.pipeline.MessageDecoder) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) BoltRequestMessageReader(org.neo4j.bolt.messaging.BoltRequestMessageReader) Log(org.neo4j.logging.Log) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) BoltRequestMessageReaderV3(org.neo4j.bolt.v3.messaging.BoltRequestMessageReaderV3) NullLogService(org.neo4j.logging.internal.NullLogService) LogService(org.neo4j.logging.internal.LogService) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 14 with LogService

use of org.neo4j.logging.internal.LogService in project neo4j by neo4j.

the class StoreMigratorTest method shouldExtractTransactionInformationFromMetaDataStore.

@Test
void shouldExtractTransactionInformationFromMetaDataStore() throws Exception {
    // given
    // ... variables
    long txId = 42;
    int checksum = 123456789;
    long timestamp = 919191919191919191L;
    TransactionId expected = new TransactionId(txId, checksum, timestamp);
    // ... and files
    Path neoStore = databaseLayout.metadataStore();
    Files.createFile(neoStore);
    // ... and mocks
    Config config = mock(Config.class);
    LogService logService = mock(LogService.class);
    // when
    // ... data in record
    setRecord(pageCache, neoStore, LAST_TRANSACTION_ID, txId, databaseLayout.getDatabaseName(), NULL);
    setRecord(pageCache, neoStore, LAST_TRANSACTION_CHECKSUM, checksum, databaseLayout.getDatabaseName(), NULL);
    setRecord(pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP, timestamp, databaseLayout.getDatabaseName(), NULL);
    // ... and with migrator
    RecordStorageMigrator migrator = new RecordStorageMigrator(fileSystem, pageCache, config, logService, jobScheduler, PageCacheTracer.NULL, batchImporterFactory, INSTANCE);
    TransactionId actual = migrator.extractTransactionIdInformation(neoStore, txId, databaseLayout, NULL);
    // then
    assertEquals(expected, actual);
}
Also used : Path(java.nio.file.Path) Config(org.neo4j.configuration.Config) NullLogService(org.neo4j.logging.internal.NullLogService) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) LogService(org.neo4j.logging.internal.LogService) TransactionId(org.neo4j.storageengine.api.TransactionId) Test(org.junit.jupiter.api.Test)

Example 15 with LogService

use of org.neo4j.logging.internal.LogService in project neo4j by neo4j.

the class StoreMigratorTest method shouldGenerateTransactionInformationWhenLogsNotPresent.

@Test
void shouldGenerateTransactionInformationWhenLogsNotPresent() throws Exception {
    // given
    long txId = 42;
    Path neoStore = databaseLayout.metadataStore();
    Files.createFile(neoStore);
    Config config = mock(Config.class);
    LogService logService = new SimpleLogService(NullLogProvider.getInstance(), NullLogProvider.getInstance());
    // when
    // ... transaction info not in neo store
    assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_ID, databaseLayout.getDatabaseName(), NULL));
    assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_CHECKSUM, databaseLayout.getDatabaseName(), NULL));
    assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP, databaseLayout.getDatabaseName(), NULL));
    // ... and with migrator
    RecordStorageMigrator migrator = new RecordStorageMigrator(fileSystem, pageCache, config, logService, jobScheduler, PageCacheTracer.NULL, batchImporterFactory, INSTANCE);
    TransactionId actual = migrator.extractTransactionIdInformation(neoStore, txId, databaseLayout, NULL);
    // then
    assertEquals(txId, actual.transactionId());
    assertEquals(TransactionIdStore.UNKNOWN_TX_CHECKSUM, actual.checksum());
    assertEquals(TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP, actual.commitTimestamp());
}
Also used : Path(java.nio.file.Path) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) Config(org.neo4j.configuration.Config) NullLogService(org.neo4j.logging.internal.NullLogService) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) LogService(org.neo4j.logging.internal.LogService) TransactionId(org.neo4j.storageengine.api.TransactionId) Test(org.junit.jupiter.api.Test)

Aggregations

LogService (org.neo4j.logging.internal.LogService)20 NullLogService (org.neo4j.logging.internal.NullLogService)15 Path (java.nio.file.Path)13 SimpleLogService (org.neo4j.logging.internal.SimpleLogService)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 MethodSource (org.junit.jupiter.params.provider.MethodSource)8 MigrationProgressMonitor (org.neo4j.storageengine.migration.MigrationProgressMonitor)8 Config (org.neo4j.configuration.Config)6 Log (org.neo4j.logging.Log)5 Test (org.junit.jupiter.api.Test)4 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)4 ScanOnOpenOverwritingIdGeneratorFactory (org.neo4j.internal.id.ScanOnOpenOverwritingIdGeneratorFactory)4 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)4 Test (org.junit.Test)3 ProgressReporter (org.neo4j.common.ProgressReporter)3 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)3 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 IOException (java.io.IOException)2 Optional (java.util.Optional)2 BoltGraphDatabaseManagementServiceSPI (org.neo4j.bolt.dbapi.BoltGraphDatabaseManagementServiceSPI)2