Search in sources :

Example 6 with Database

use of org.neo4j.kernel.database.Database in project neo4j by neo4j.

the class DbmsDiagnosticsManagerTest method dumpDiagnosticsInConciseForm.

@Test
void dumpDiagnosticsInConciseForm() {
    Map<NamedDatabaseId, StandaloneDatabaseContext> databaseMap = new HashMap<>();
    int numberOfDatabases = 1000;
    for (int i = 0; i < numberOfDatabases; i++) {
        Database database = mock(Database.class);
        NamedDatabaseId namedDatabaseId = TestDatabaseIdRepository.randomNamedDatabaseId();
        when(database.getNamedDatabaseId()).thenReturn(namedDatabaseId);
        databaseMap.put(namedDatabaseId, new StandaloneDatabaseContext(database));
    }
    when(databaseManager.registeredDatabases()).thenReturn(new TreeMap<>(databaseMap));
    diagnosticsManager.dumpAll();
    var logAssertions = assertThat(logProvider);
    var databaseNames = databaseMap.keySet().stream().map(NamedDatabaseId::name).toArray(String[]::new);
    logAssertions.containsMessagesOnce(databaseNames);
}
Also used : HashMap(java.util.HashMap) Database(org.neo4j.kernel.database.Database) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) StandaloneDatabaseContext(org.neo4j.dbms.database.StandaloneDatabaseContext) Test(org.junit.jupiter.api.Test)

Example 7 with Database

use of org.neo4j.kernel.database.Database in project neo4j by neo4j.

the class DbmsDiagnosticsManagerTest method dumpDatabaseDiagnosticsNotInterleavedWithEachother.

@Test
void dumpDatabaseDiagnosticsNotInterleavedWithEachother() throws Throwable {
    Database secondDatabase = prepareDatabase(DatabaseIdFactory.from("second", UUID.randomUUID()));
    assertThat(logProvider).doesNotHaveAnyLogs();
    Race race = new Race();
    race.addContestant(() -> diagnosticsManager.dumpDatabaseDiagnostics(defaultDatabase));
    race.addContestant(() -> diagnosticsManager.dumpDatabaseDiagnostics(secondDatabase));
    race.go();
    // Assert that diagnostics messages from the two databases are not interleaved.
    // If they are the sequence of the diagnostics provider headers will not be ordered correctly.
    assertThat(logProvider.serialize()).containsSubsequence("Database: ", "Version", "Store files", "Transaction log", "Database: ", "Version", "Store files", "Transaction log");
}
Also used : Race(org.neo4j.test.Race) Database(org.neo4j.kernel.database.Database) Test(org.junit.jupiter.api.Test)

Example 8 with Database

use of org.neo4j.kernel.database.Database in project neo4j by neo4j.

the class DbmsDiagnosticsManagerTest method prepareDatabase.

private Database prepareDatabase(NamedDatabaseId databaseId) throws IOException {
    Database database = mock(Database.class);
    Dependencies databaseDependencies = new Dependencies();
    databaseDependencies.satisfyDependency(DbmsInfo.COMMUNITY);
    databaseDependencies.satisfyDependency(storageEngine);
    databaseDependencies.satisfyDependency(storageEngineFactory);
    databaseDependencies.satisfyDependency(new DefaultFileSystemAbstraction());
    databaseDependencies.satisfyDependency(logFilesBasedOnlyBuilder(directory.homePath(), directory.getFileSystem()).withLogEntryReader(mock(LogEntryReader.class)).build());
    when(database.getDependencyResolver()).thenReturn(databaseDependencies);
    when(database.getNamedDatabaseId()).thenReturn(databaseId);
    when(database.isStarted()).thenReturn(true);
    when(database.getDatabaseLayout()).thenReturn(DatabaseLayout.ofFlat(directory.homePath()));
    return database;
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Database(org.neo4j.kernel.database.Database) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) Dependencies(org.neo4j.collection.Dependencies)

Example 9 with Database

use of org.neo4j.kernel.database.Database in project neo4j by neo4j.

the class DatabaseFileListingTest method verifyLogFilesWithCustomPathListing.

private void verifyLogFilesWithCustomPathListing(Path path) throws IOException {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath("customDb")).setConfig(GraphDatabaseSettings.transaction_logs_root_path, path).build();
    GraphDatabaseAPI graphDatabase = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    Database database = graphDatabase.getDependencyResolver().resolveDependency(Database.class);
    LogFiles logFiles = graphDatabase.getDependencyResolver().resolveDependency(LogFiles.class);
    assertTrue(database.listStoreFiles(true).stream().anyMatch(metadata -> metadata.isLogFile() && logFiles.isLogFile(metadata.path())));
    assertEquals(path.getFileName().toString(), logFiles.logFilesDirectory().getParent().getFileName().toString());
    managementService.shutdown();
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) ResourceIterator(org.neo4j.graphdb.ResourceIterator) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) Resource(org.neo4j.graphdb.Resource) Mockito.spy(org.mockito.Mockito.spy) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ArrayList(java.util.ArrayList) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Inject(org.neo4j.test.extension.Inject) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Path(java.nio.file.Path) DEFAULT_FILENAME_FILTER(org.neo4j.kernel.impl.transaction.log.files.TransactionLogFiles.DEFAULT_FILENAME_FILTER) Files(java.nio.file.Files) Iterators(org.neo4j.internal.helpers.collection.Iterators) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Collection(java.util.Collection) Set(java.util.Set) TestDirectory(org.neo4j.test.rule.TestDirectory) IOException(java.io.IOException) DbmsExtension(org.neo4j.test.extension.DbmsExtension) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) File(java.io.File) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Database(org.neo4j.kernel.database.Database) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Mockito.mock(org.mockito.Mockito.mock) Iterators.asResourceIterator(org.neo4j.internal.helpers.collection.Iterators.asResourceIterator) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Database(org.neo4j.kernel.database.Database) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 10 with Database

use of org.neo4j.kernel.database.Database in project neo4j by neo4j.

the class GraphDatabaseFacadeTest method setUp.

@BeforeEach
void setUp() {
    queryService = mock(GraphDatabaseQueryService.class);
    Database database = mock(Database.class, RETURNS_MOCKS);
    Dependencies resolver = mock(Dependencies.class);
    kernel = mock(Kernel.class, RETURNS_MOCKS);
    when(database.getKernel()).thenReturn(kernel);
    when(database.getDependencyResolver()).thenReturn(resolver);
    when(resolver.resolveDependency(GraphDatabaseQueryService.class)).thenReturn(queryService);
    Config config = Config.defaults();
    when(resolver.resolveDependency(Config.class)).thenReturn(config);
    graphDatabaseFacade = new GraphDatabaseFacade(database, config, DbmsInfo.COMMUNITY, mock(DatabaseAvailabilityGuard.class));
}
Also used : GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Config(org.neo4j.configuration.Config) Database(org.neo4j.kernel.database.Database) Dependencies(org.neo4j.collection.Dependencies) Kernel(org.neo4j.kernel.api.Kernel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Database (org.neo4j.kernel.database.Database)15 Test (org.junit.jupiter.api.Test)9 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)5 Log (org.neo4j.logging.Log)5 Dependencies (org.neo4j.collection.Dependencies)4 DatabaseManagementException (org.neo4j.dbms.api.DatabaseManagementException)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.when (org.mockito.Mockito.when)2 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)2 File (java.io.File)1 UncheckedIOException (java.io.UncheckedIOException)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1