Search in sources :

Example 76 with AssertableLogProvider

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

the class RecoveryLogIT method transactionsRecoveryLogContainsTimeSpent.

@Test
void transactionsRecoveryLogContainsTimeSpent() throws IOException {
    // Create database with forced recovery
    Path tmpLogDir = testDirectory.directory("logs");
    managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).build();
    GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    StorageEngineFactory storageEngineFactory = db.getDependencyResolver().resolveDependency(StorageEngineFactory.class);
    try (Transaction tx = db.beginTx()) {
        Node node1 = tx.createNode();
        Node node2 = tx.createNode();
        node1.createRelationshipTo(node2, RelationshipType.withName("likes"));
        tx.commit();
    }
    Path[] txLogs = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseLayout.getTransactionLogsDirectory(), fileSystem).withCommandReaderFactory(storageEngineFactory.commandReaderFactory()).build().logFiles();
    for (Path file : txLogs) {
        fileSystem.copyToDirectory(file, tmpLogDir);
    }
    managementService.shutdown();
    for (Path txLog : fileSystem.listFiles(databaseLayout.getTransactionLogsDirectory())) {
        fileSystem.deleteFile(txLog);
    }
    for (Path file : LogFilesBuilder.logFilesBasedOnlyBuilder(tmpLogDir, fileSystem).withCommandReaderFactory(storageEngineFactory.commandReaderFactory()).build().logFiles()) {
        fileSystem.moveToDirectory(file, databaseLayout.getTransactionLogsDirectory());
    }
    AssertableLogProvider provider = new AssertableLogProvider();
    managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setInternalLogProvider(provider).build();
    managementService.database(DEFAULT_DATABASE_NAME);
    assertThat(provider).containsMessages("Recovery completed", "time spent");
}
Also used : Path(java.nio.file.Path) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) Node(org.neo4j.graphdb.Node) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 77 with AssertableLogProvider

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

the class IndexPopulationIT method setUp.

@BeforeEach
void setUp() {
    logProvider = new AssertableLogProvider(true);
    managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).setInternalLogProvider(logProvider).build();
    database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    executorService = Executors.newCachedThreadPool();
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 78 with AssertableLogProvider

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

the class IndexPopulationIT method shutdownDatabaseDuringIndexPopulations.

@Test
void shutdownDatabaseDuringIndexPopulations() {
    AssertableLogProvider assertableLogProvider = new AssertableLogProvider(true);
    Path storeDir = directory.directory("shutdownDbTest");
    Label testLabel = Label.label("testLabel");
    String propertyName = "testProperty";
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDir).setInternalLogProvider(assertableLogProvider).build();
    GraphDatabaseService shutDownDb = managementService.database(DEFAULT_DATABASE_NAME);
    prePopulateDatabase(shutDownDb, testLabel, propertyName);
    try (Transaction transaction = shutDownDb.beginTx()) {
        transaction.schema().indexFor(testLabel).on(propertyName).create();
        transaction.commit();
    }
    managementService.shutdown();
    assertThat(assertableLogProvider).forClass(IndexPopulationJob.class).forLevel(ERROR).doesNotHaveAnyLogs();
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) Label(org.neo4j.graphdb.Label) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 79 with AssertableLogProvider

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

the class GenericConfigExtractorTest method shouldLogFailureToExtractIndexConfigFromGenericBecauseOfMissingFile.

@Test
void shouldLogFailureToExtractIndexConfigFromGenericBecauseOfMissingFile() throws IOException {
    // given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log myLog = logProvider.getLog(getClass());
    Path genericFile = directory.file("genericFile");
    assertFalse(fs.fileExists(genericFile));
    // when
    GenericConfigExtractor.indexConfigFromGenericFile(fs, pageCache, genericFile, NULL, myLog, DEFAULT_DATABASE_NAME);
    // then
    String reason = "Index file does not exists.";
    assertContainsLogEntry(logProvider, genericFile, 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 80 with AssertableLogProvider

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

the class VisibleMigrationProgressMonitorTest method shouldIncludeDurationInCompletionMessage.

@Test
void shouldIncludeDurationInCompletionMessage() {
    // given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log log = logProvider.getLog(getClass());
    FakeClock clock = new FakeClock();
    VisibleMigrationProgressMonitor monitor = new VisibleMigrationProgressMonitor(log, clock);
    // when
    monitor.started(1);
    clock.forward(1500, TimeUnit.MILLISECONDS);
    monitor.completed();
    // then
    assertThat(logProvider).containsMessages("took 1s 500ms");
}
Also used : Log(org.neo4j.logging.Log) FakeClock(org.neo4j.time.FakeClock) 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