Search in sources :

Example 6 with FileWatcher

use of org.neo4j.io.fs.watcher.FileWatcher in project neo4j by neo4j.

the class FileWatchIT method notifyAboutStoreFileDeletion.

@Test(timeout = TEST_TIMEOUT)
public void notifyAboutStoreFileDeletion() throws Exception {
    assumeFalse(SystemUtils.IS_OS_WINDOWS);
    String fileName = MetaDataStore.DEFAULT_NAME;
    FileWatcher fileWatcher = getFileWatcher(database);
    CheckPointer checkpointer = getCheckpointer(database);
    DeletionLatchEventListener deletionListener = new DeletionLatchEventListener(fileName);
    fileWatcher.addFileWatchEventListener(deletionListener);
    do {
        createNode(database);
        forceCheckpoint(checkpointer);
    } while (!deletionListener.awaitModificationNotification());
    deleteFile(storeDir, fileName);
    deletionListener.awaitDeletionNotification();
    logProvider.assertContainsMessageContaining("'" + fileName + "' which belongs to the store was deleted while database was running.");
}
Also used : FileWatcher(org.neo4j.io.fs.watcher.FileWatcher) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 7 with FileWatcher

use of org.neo4j.io.fs.watcher.FileWatcher in project neo4j by neo4j.

the class FileWatchIT method notifyAboutLegacyIndexFolderRemoval.

@Test(timeout = TEST_TIMEOUT)
public void notifyAboutLegacyIndexFolderRemoval() throws InterruptedException, IOException {
    String monitoredDirectory = getLegacyIndexDirectory(storeDir);
    FileWatcher fileWatcher = getFileWatcher(database);
    CheckPointer checkPointer = getCheckpointer(database);
    DeletionLatchEventListener deletionListener = new DeletionLatchEventListener(monitoredDirectory);
    ModificationEventListener modificationEventListener = new ModificationEventListener(MetaDataStore.DEFAULT_NAME);
    fileWatcher.addFileWatchEventListener(deletionListener);
    fileWatcher.addFileWatchEventListener(modificationEventListener);
    do {
        createNode(database);
        forceCheckpoint(checkPointer);
    } while (!modificationEventListener.awaitModificationNotification());
    deleteStoreDirectory(storeDir, monitoredDirectory);
    deletionListener.awaitDeletionNotification();
    logProvider.assertContainsMessageContaining("'" + monitoredDirectory + "' which belongs to the store was deleted while database was running.");
}
Also used : FileWatcher(org.neo4j.io.fs.watcher.FileWatcher) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 FileWatcher (org.neo4j.io.fs.watcher.FileWatcher)7 Matchers.containsString (org.hamcrest.Matchers.containsString)5 CheckPointer (org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer)5 File (java.io.File)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1 Label (org.neo4j.graphdb.Label)1 SelectiveFileSystemAbstraction (org.neo4j.graphdb.mockfs.SelectiveFileSystemAbstraction)1 SilentFileWatcher (org.neo4j.io.fs.watcher.SilentFileWatcher)1 WatchedResource (org.neo4j.io.fs.watcher.resource.WatchedResource)1 DefaultFileDeletionEventListener (org.neo4j.kernel.impl.util.watcher.DefaultFileDeletionEventListener)1 FileWatcherLifecycleAdapter (org.neo4j.kernel.impl.util.watcher.FileWatcherLifecycleAdapter)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)1