Search in sources :

Example 1 with FileWatcher

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

the class SelectiveFileSystemAbstractionTest method provideSelectiveWatcher.

@Test
public void provideSelectiveWatcher() throws IOException {
    File specialFile = new File("special");
    File otherFile = new File("other");
    FileSystemAbstraction normal = mock(FileSystemAbstraction.class);
    FileSystemAbstraction special = mock(FileSystemAbstraction.class);
    FileWatcher specialWatcher = mock(FileWatcher.class);
    FileWatcher normalWatcher = mock(FileWatcher.class);
    WatchedResource specialResource = mock(WatchedResource.class);
    WatchedResource normalResource = mock(WatchedResource.class);
    when(special.fileWatcher()).thenReturn(specialWatcher);
    when(normal.fileWatcher()).thenReturn(normalWatcher);
    when(specialWatcher.watch(specialFile)).thenReturn(specialResource);
    when(normalWatcher.watch(otherFile)).thenReturn(normalResource);
    try (SelectiveFileSystemAbstraction fs = new SelectiveFileSystemAbstraction(specialFile, special, normal)) {
        FileWatcher fileWatcher = fs.fileWatcher();
        assertSame(specialResource, fileWatcher.watch(specialFile));
        assertSame(normalResource, fileWatcher.watch(otherFile));
    }
}
Also used : SelectiveFileSystemAbstraction(org.neo4j.graphdb.mockfs.SelectiveFileSystemAbstraction) FileWatcher(org.neo4j.io.fs.watcher.FileWatcher) SelectiveFileSystemAbstraction(org.neo4j.graphdb.mockfs.SelectiveFileSystemAbstraction) WatchedResource(org.neo4j.io.fs.watcher.resource.WatchedResource) File(java.io.File) Test(org.junit.Test)

Example 2 with FileWatcher

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

the class FileWatcherLifecycleAdapterTest method startMonitoringWhenLifecycleStarting.

@Test
public void startMonitoringWhenLifecycleStarting() throws Throwable {
    CountDownLatch latch = new CountDownLatch(1);
    FileWatcher watcher = new TestFileWatcher(latch);
    FileWatcherLifecycleAdapter watcherAdapter = new FileWatcherLifecycleAdapter(jobScheduler, watcher);
    watcherAdapter.init();
    watcherAdapter.start();
    latch.await();
}
Also used : SilentFileWatcher(org.neo4j.io.fs.watcher.SilentFileWatcher) FileWatcher(org.neo4j.io.fs.watcher.FileWatcher) CountDownLatch(java.util.concurrent.CountDownLatch) FileWatcherLifecycleAdapter(org.neo4j.kernel.impl.util.watcher.FileWatcherLifecycleAdapter) Test(org.junit.Test)

Example 3 with FileWatcher

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

the class FileWatchIT method doNotMonitorTransactionLogFiles.

@Test(timeout = TEST_TIMEOUT)
public void doNotMonitorTransactionLogFiles() throws InterruptedException, IOException {
    assumeFalse(SystemUtils.IS_OS_WINDOWS);
    FileWatcher fileWatcher = getFileWatcher(database);
    CheckPointer checkpointer = getCheckpointer(database);
    ModificationEventListener modificationEventListener = new ModificationEventListener(MetaDataStore.DEFAULT_NAME);
    fileWatcher.addFileWatchEventListener(modificationEventListener);
    do {
        createNode(database);
        forceCheckpoint(checkpointer);
    } while (!modificationEventListener.awaitModificationNotification());
    String fileName = PhysicalLogFile.DEFAULT_NAME + ".0";
    DeletionLatchEventListener deletionListener = new DeletionLatchEventListener(fileName);
    fileWatcher.addFileWatchEventListener(deletionListener);
    deleteFile(storeDir, fileName);
    deletionListener.awaitDeletionNotification();
    AssertableLogProvider.LogMatcher logMatcher = AssertableLogProvider.inLog(DefaultFileDeletionEventListener.class).info(containsString(fileName));
    logProvider.assertNone(logMatcher);
}
Also used : DefaultFileDeletionEventListener(org.neo4j.kernel.impl.util.watcher.DefaultFileDeletionEventListener) FileWatcher(org.neo4j.io.fs.watcher.FileWatcher) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) Matchers.containsString(org.hamcrest.Matchers.containsString) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 4 with FileWatcher

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

the class FileWatchIT method notifyWhenWholeStoreDirectoryRemoved.

@Test(timeout = TEST_TIMEOUT)
public void notifyWhenWholeStoreDirectoryRemoved() throws IOException, InterruptedException {
    assumeFalse(SystemUtils.IS_OS_WINDOWS);
    String fileName = MetaDataStore.DEFAULT_NAME;
    FileWatcher fileWatcher = getFileWatcher(database);
    CheckPointer checkpointer = getCheckpointer(database);
    ModificationEventListener modificationListener = new ModificationEventListener(fileName);
    fileWatcher.addFileWatchEventListener(modificationListener);
    do {
        createNode(database);
        forceCheckpoint(checkpointer);
    } while (!modificationListener.awaitModificationNotification());
    fileWatcher.removeFileWatchEventListener(modificationListener);
    String storeDirectoryName = TestDirectory.DATABASE_DIRECTORY;
    DeletionLatchEventListener eventListener = new DeletionLatchEventListener(storeDirectoryName);
    fileWatcher.addFileWatchEventListener(eventListener);
    FileUtils.deleteRecursively(storeDir);
    eventListener.awaitDeletionNotification();
    logProvider.assertContainsMessageContaining("'" + storeDirectoryName + "' 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 5 with FileWatcher

use of org.neo4j.io.fs.watcher.FileWatcher 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)

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