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