Search in sources :

Example 81 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class TestExtension method dependenciesCanBeRetrieved.

/**
 * Check that dependencies can be accessed
 */
@Test
void dependenciesCanBeRetrieved() {
    GraphDatabaseAPI graphdb = graphDb();
    try {
        GlobalExtensions globalExtensions = graphdb.getDependencyResolver().resolveDependency(GlobalExtensions.class);
        assertNotNull(globalExtensions.resolveDependency(DummyExtension.class).getDependencies().getConfig());
        assertEquals(graphdb.getDependencyResolver().resolveDependency(DatabaseManager.class), globalExtensions.resolveDependency(DummyExtension.class).getDependencies().getDatabaseManager());
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManager(org.neo4j.dbms.database.DatabaseManager) GlobalExtensions(org.neo4j.kernel.extension.GlobalExtensions) Test(org.junit.jupiter.api.Test) ExtensionFactoryContractTest(org.neo4j.kernel.extension.ExtensionFactoryContractTest)

Example 82 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class CountsStoreRecoveryTest method flushNeoStoreOnly.

private void flushNeoStoreOnly() {
    NeoStores neoStores = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    MetaDataStore metaDataStore = neoStores.getMetaDataStore();
    metaDataStore.flush(NULL);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores)

Example 83 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI 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 84 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class JUnitRuleTestIT method contentOf.

private String contentOf(String file) throws IOException {
    GraphDatabaseAPI api = (GraphDatabaseAPI) neo4j.defaultDatabaseService();
    Config config = api.getDependencyResolver().resolveDependency(Config.class);
    Path homeDir = config.get(GraphDatabaseSettings.neo4j_home);
    return Files.readString(homeDir.resolve(file));
}
Also used : Path(java.nio.file.Path) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Config(org.neo4j.configuration.Config)

Example 85 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class BaseBootstrapperIT method shouldHaveSameLayoutAsEmbedded.

@Test
public void shouldHaveSameLayoutAsEmbedded() throws Exception {
    Path serverDir = testDirectory.directory("server-dir");
    NeoBootstrapper.start(bootstrapper, withConnectorsOnRandomPortsConfig("--home-dir", serverDir.toAbsolutePath().toString()));
    assertEventually("Server was not started", bootstrapper::isRunning, Conditions.TRUE, 1, TimeUnit.MINUTES);
    var databaseAPI = (GraphDatabaseAPI) bootstrapper.getDatabaseManagementService().database(DEFAULT_DATABASE_NAME);
    var serverLayout = databaseAPI.databaseLayout().getNeo4jLayout();
    bootstrapper.stop();
    Path embeddedDir = testDirectory.directory("embedded-dir");
    DatabaseManagementService dbms = newEmbeddedDbms(embeddedDir);
    Neo4jLayout embeddedLayout = ((GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME)).databaseLayout().getNeo4jLayout();
    dbms.shutdown();
    assertEquals(serverDir.relativize(serverLayout.homeDirectory()), embeddedDir.relativize(embeddedLayout.homeDirectory()));
    assertEquals(serverDir.relativize(serverLayout.databasesDirectory()), embeddedDir.relativize(embeddedLayout.databasesDirectory()));
    assertEquals(serverDir.relativize(serverLayout.transactionLogsRootDirectory()), embeddedDir.relativize(embeddedLayout.transactionLogsRootDirectory()));
}
Also used : Path(java.nio.file.Path) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Neo4jLayout(org.neo4j.io.layout.Neo4jLayout) Test(org.junit.Test)

Aggregations

GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)262 Test (org.junit.Test)91 Test (org.junit.jupiter.api.Test)88 Transaction (org.neo4j.graphdb.Transaction)87 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)61 Node (org.neo4j.graphdb.Node)38 Path (java.nio.file.Path)30 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)30 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)28 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)26 File (java.io.File)25 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)24 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)19 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)18 DependencyResolver (org.neo4j.graphdb.DependencyResolver)17 Label (org.neo4j.graphdb.Label)15 PageCache (org.neo4j.io.pagecache.PageCache)15 Config (org.neo4j.kernel.configuration.Config)15 DatabaseStateService (org.neo4j.dbms.DatabaseStateService)14 IOException (java.io.IOException)11