@Test public void testDifferentEvents() throws Exception { IFilelistenerWriteTrx trx = new FilelistenerWriteTrx(mHolder.getSession().beginBucketWtx(), mHolder.getSession()); File tmp = Files.createTempDir(); String relativePath = File.separator + "file.txt"; File file = new File(tmp.getAbsolutePath() + File.separator + "file.txt"); byte[] bytes = new byte[1024 * 8]; Random rand = new Random(42); rand.nextBytes(bytes); Files.write(bytes, file); List<FilesystemNotification> notifications = new ArrayList<FilesystemNotification>(); notifications.add(new FilesystemNotification(file, relativePath, tmp.getAbsolutePath(), ENTRY_CREATE, trx)); notifications.add(new FilesystemNotification(file, relativePath, tmp.getAbsolutePath(), ENTRY_MODIFY, trx)); notifications.add(new FilesystemNotification(file, relativePath, tmp.getAbsolutePath(), ENTRY_DELETE, trx)); for (FilesystemNotification s : notifications) { s.call(); } }
@Override public Void call() throws Exception { mTimeTaken = System.currentTimeMillis(); if (this.getEvtType() == ENTRY_CREATE) { mWtx.addEmptyFile(this.getRelativePath()); } else if (this.getEvtType() == ENTRY_MODIFY) { mWtx.removeFile(this.getRelativePath()); if (this.getFile().exists()) { mWtx.addFile(this.getFile(), this.getRelativePath()); if (this.mObservers.size() > 0) { mWtx.commitBlocked(); } else { mWtx.commit(); } } } else if (this.getEvtType() == ENTRY_DELETE) { mWtx.removeFile(this.getRelativePath()); } mFinished = true; mTimeTaken = System.currentTimeMillis() - mTimeTaken; this.notifyObservers(); return null; }
FilesystemNotification implements Callable<Void> { @Override public Void call() throws Exception { mTimeTaken = System.currentTimeMillis(); if (this.getEvtType() == ENTRY_CREATE) { mWtx.addEmptyFile(this.getRelativePath()); } else if (this.getEvtType() == ENTRY_MODIFY) { mWtx.removeFile(this.getRelativePath()); if (this.getFile().exists()) { mWtx.addFile(this.getFile(), this.getRelativePath()); if (this.mObservers.size() > 0) { mWtx.commitBlocked(); } else { mWtx.commit(); } } } else if (this.getEvtType() == ENTRY_DELETE) { mWtx.removeFile(this.getRelativePath()); } mFinished = true; mTimeTaken = System.currentTimeMillis() - mTimeTaken; this.notifyObservers(); return null; } }
FilesystemNotification implements Callable<Void> { @Override public Void call() throws Exception { mTimeTaken = System.currentTimeMillis(); if (this.getEvtType() == ENTRY_CREATE) { mWtx.addEmptyFile(this.getRelativePath()); } else if (this.getEvtType() == ENTRY_MODIFY) { mWtx.removeFile(this.getRelativePath()); if (this.getFile().exists()) { mWtx.addFile(this.getFile(), this.getRelativePath()); if (this.mObservers.size() > 0) { mWtx.commitBlocked(); } else { mWtx.commit(); } } } else if (this.getEvtType() == ENTRY_DELETE) { mWtx.removeFile(this.getRelativePath()); } mFinished = true; mTimeTaken = System.currentTimeMillis() - mTimeTaken; this.notifyObservers(); return null; } FilesystemNotification(File pFile, String pRelativePath, String pRootPath,
        WatchEvent.Kind<?> pEvtType, IFilelistenerWriteTrx pWtx); }
FilesystemNotification implements Callable<Void> { @Override public Void call() throws Exception { mTimeTaken = System.currentTimeMillis(); if (this.getEvtType() == ENTRY_CREATE) { mWtx.addEmptyFile(this.getRelativePath()); } else if (this.getEvtType() == ENTRY_MODIFY) { mWtx.removeFile(this.getRelativePath()); if (this.getFile().exists()) { mWtx.addFile(this.getFile(), this.getRelativePath()); if (this.mObservers.size() > 0) { mWtx.commitBlocked(); } else { mWtx.commit(); } } } else if (this.getEvtType() == ENTRY_DELETE) { mWtx.removeFile(this.getRelativePath()); } mFinished = true; mTimeTaken = System.currentTimeMillis() - mTimeTaken; this.notifyObservers(); return null; } FilesystemNotification(File pFile, String pRelativePath, String pRootPath,
        WatchEvent.Kind<?> pEvtType, IFilelistenerWriteTrx pWtx); File getFile(); String getRelativePath(); String getRootPath(); void setEvtType(WatchEvent.Kind<?> pEvtType); WatchEvent.Kind<?> getEvtType(); boolean isFinished(); @Override int hashCode(); @Override boolean equals(Object o); @Override Void call(); long getTime(); int getBucketAmount(); void notifyObservers(); void addObserver(FilesystemNotificationObserver observer); }
FilesystemNotification implements Callable<Void> { @Override public Void call() throws Exception { mTimeTaken = System.currentTimeMillis(); if (this.getEvtType() == ENTRY_CREATE) { mWtx.addEmptyFile(this.getRelativePath()); } else if (this.getEvtType() == ENTRY_MODIFY) { mWtx.removeFile(this.getRelativePath()); if (this.getFile().exists()) { mWtx.addFile(this.getFile(), this.getRelativePath()); if (this.mObservers.size() > 0) { mWtx.commitBlocked(); } else { mWtx.commit(); } } } else if (this.getEvtType() == ENTRY_DELETE) { mWtx.removeFile(this.getRelativePath()); } mFinished = true; mTimeTaken = System.currentTimeMillis() - mTimeTaken; this.notifyObservers(); return null; } FilesystemNotification(File pFile, String pRelativePath, String pRootPath,
        WatchEvent.Kind<?> pEvtType, IFilelistenerWriteTrx pWtx); File getFile(); String getRelativePath(); String getRootPath(); void setEvtType(WatchEvent.Kind<?> pEvtType); WatchEvent.Kind<?> getEvtType(); boolean isFinished(); @Override int hashCode(); @Override boolean equals(Object o); @Override Void call(); long getTime(); int getBucketAmount(); void notifyObservers(); void addObserver(FilesystemNotificationObserver observer);  }