Search in sources :

Example 46 with GraphDatabaseAPI

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

the class IndexSamplingIntegrationTest method fetchIndexSamplingValues.

private DoubleLongRegister fetchIndexSamplingValues(GraphDatabaseService db) throws IndexNotFoundKernelException {
    try {
        // Then
        db = new TestGraphDatabaseFactory().newEmbeddedDatabase(testDirectory.graphDbDir());
        @SuppressWarnings("deprecation") GraphDatabaseAPI api = (GraphDatabaseAPI) db;
        CountsTracker countsTracker = api.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getCounts();
        IndexSampleKey key = CountsKeyFactory.indexSampleKey(indexId(api));
        return countsTracker.get(key, Registers.newDoubleLongRegister());
    } finally {
        if (db != null) {
            db.shutdown();
        }
    }
}
Also used : IndexSampleKey(org.neo4j.kernel.impl.store.counts.keys.IndexSampleKey) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker)

Example 47 with GraphDatabaseAPI

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

the class FileWatchIT method doNotNotifyAboutLuceneIndexFilesDeletion.

@Test(timeout = TEST_TIMEOUT)
public void doNotNotifyAboutLuceneIndexFilesDeletion() throws InterruptedException, IOException {
    DependencyResolver dependencyResolver = ((GraphDatabaseAPI) database).getDependencyResolver();
    FileWatcher fileWatcher = getFileWatcher(database);
    CheckPointer checkPointer = dependencyResolver.resolveDependency(CheckPointer.class);
    String propertyStoreName = MetaDataStore.DEFAULT_NAME + StoreFactory.PROPERTY_STORE_NAME;
    AccumulativeDeletionEventListener accumulativeListener = new AccumulativeDeletionEventListener();
    ModificationEventListener modificationListener = new ModificationEventListener(propertyStoreName);
    fileWatcher.addFileWatchEventListener(modificationListener);
    fileWatcher.addFileWatchEventListener(accumulativeListener);
    String labelName = "labelName";
    String propertyName = "propertyName";
    Label testLabel = Label.label(labelName);
    createIndexes(database, propertyName, testLabel);
    do {
        createNode(database, propertyName, testLabel);
        forceCheckpoint(checkPointer);
    } while (!modificationListener.awaitModificationNotification());
    fileWatcher.removeFileWatchEventListener(modificationListener);
    ModificationEventListener afterRemovalListener = new ModificationEventListener(propertyStoreName);
    fileWatcher.addFileWatchEventListener(afterRemovalListener);
    dropAllIndexes(database);
    do {
        createNode(database, propertyName, testLabel);
        forceCheckpoint(checkPointer);
    } while (!afterRemovalListener.awaitModificationNotification());
    accumulativeListener.assertDoesNotHaveAnyDeletions();
}
Also used : FileWatcher(org.neo4j.io.fs.watcher.FileWatcher) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) Label(org.neo4j.graphdb.Label) Matchers.containsString(org.hamcrest.Matchers.containsString) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Test(org.junit.Test)

Example 48 with GraphDatabaseAPI

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

the class TestRecoveryMultipleDataSources method main.

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        exit(1);
    }
    File storeDir = new File(args[0]);
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
    try (Transaction tx = db.beginTx()) {
        db.createNode().createRelationshipTo(db.createNode(), MyRelTypes.TEST);
        tx.success();
    }
    ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
    try (Transaction tx = db.beginTx()) {
        db.index().forNodes("index").add(db.createNode(), storeDir.getAbsolutePath(), db.createNode());
        tx.success();
    }
    exit(0);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) File(java.io.File)

Example 49 with GraphDatabaseAPI

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

the class IndexStatisticsTest method before.

@Before
public void before() {
    GraphDatabaseAPI graphDatabaseAPI = dbRule.getGraphDatabaseAPI();
    this.db = graphDatabaseAPI;
    DependencyResolver dependencyResolver = graphDatabaseAPI.getDependencyResolver();
    this.bridge = dependencyResolver.resolveDependency(ThreadToStatementContextBridge.class);
    graphDatabaseAPI.getDependencyResolver().resolveDependency(Monitors.class).addMonitorListener(indexOnlineMonitor);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Monitors(org.neo4j.kernel.monitoring.Monitors) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Before(org.junit.Before)

Example 50 with GraphDatabaseAPI

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

the class TestReferenceDangling method testPropertyStoreReferencesOnRead.

@Test
public void testPropertyStoreReferencesOnRead() throws Throwable {
    // Given
    GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
    // and Given the cache contains a LazyProperty
    long nId = ensurePropertyIsCachedLazyProperty(db, "some");
    // When
    restartNeoDataSource(db);
    // Then reading the property is still possible
    try (Transaction tx = db.beginTx()) {
        db.getNodeById(nId).getProperty("some");
        tx.success();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) 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