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