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