You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by tc...@apache.org on 2007/01/21 19:16:14 UTC
svn commit: r498421 - in /jakarta/commons/sandbox/jci/trunk:
core/src/main/java/org/apache/commons/jci/listeners/ fam/
fam/src/main/java/org/apache/commons/jci/listeners/
fam/src/main/java/org/apache/commons/jci/monitor/
fam/src/test/java/org/apache/co...
Author: tcurdt
Date: Sun Jan 21 10:16:11 2007
New Revision: 498421
URL: http://svn.apache.org/viewvc?view=rev&rev=498421
Log:
moved tests to the sub project,
moved fam related listeners into the fam sub project,
no static instances,
added an abstract FAM listener
Added:
jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/
jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotificationListener.java (with props)
jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotifyingListener.java (with props)
jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/AbstractFilesystemAlterationListener.java (with props)
Removed:
jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/NotificationListener.java
jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/NotifyingListener.java
Modified:
jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java
jakarta/commons/sandbox/jci/trunk/fam/pom.xml
jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationListener.java
jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
jakarta/commons/sandbox/jci/trunk/fam/src/test/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java
Modified: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java?view=diff&rev=498421&r1=498420&r2=498421
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java (original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java Sun Jan 21 10:16:11 2007
@@ -45,7 +45,7 @@
public CompilingListener( final File pRepository ) {
this(pRepository,
- JavaCompilerFactory.getInstance().createCompiler("eclipse"),
+ new JavaCompilerFactory().createCompiler("eclipse"),
new TransactionalResourceStore(new MemoryResourceStore())
);
}
Modified: jakarta/commons/sandbox/jci/trunk/fam/pom.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/fam/pom.xml?view=diff&rev=498421&r1=498420&r2=498421
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/fam/pom.xml (original)
+++ jakarta/commons/sandbox/jci/trunk/fam/pom.xml Sun Jan 21 10:16:11 2007
@@ -33,13 +33,20 @@
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
- <version>1.0.4</version>
+ <version>1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.2</version>
+ <scope>test</scope>
</dependency>
</dependencies>
Added: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotificationListener.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotificationListener.java?view=auto&rev=498421
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotificationListener.java (added)
+++ jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotificationListener.java Sun Jan 21 10:16:11 2007
@@ -0,0 +1,6 @@
+package org.apache.commons.jci.listeners;
+
+
+public interface NotificationListener {
+ void handleNotification();
+}
Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotificationListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotificationListener.java
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotificationListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotifyingListener.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotifyingListener.java?view=auto&rev=498421
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotifyingListener.java (added)
+++ jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotifyingListener.java Sun Jan 21 10:16:11 2007
@@ -0,0 +1,112 @@
+package org.apache.commons.jci.listeners;
+
+import java.io.File;
+import org.apache.commons.jci.monitor.FilesystemAlterationListener;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+public abstract class NotifyingListener implements FilesystemAlterationListener {
+
+ private final Log log = LogFactory.getLog(NotifyingListener.class);
+
+ public final static class Signal {
+ public boolean triggered;
+ }
+
+ protected final File repository;
+ protected NotificationListener notificationListener;
+ private final Signal notificationSignal = new Signal();
+ private final Signal checkSignal = new Signal();
+
+ public NotifyingListener(final File pRepository) {
+ repository = pRepository;
+ }
+
+ public File getRepository() {
+ return repository;
+ }
+
+ public void setNotificationListener(final NotificationListener pNotificationListener) {
+ notificationListener = pNotificationListener;
+ }
+
+ protected void checked( final boolean pNotify ) {
+ if (pNotify) {
+ if (notificationListener != null) {
+ notificationListener.handleNotification();
+ }
+ synchronized(notificationSignal) {
+ notificationSignal.triggered = true;
+ notificationSignal.notifyAll();
+ }
+ }
+ synchronized(checkSignal) {
+ checkSignal.triggered = true;
+ checkSignal.notifyAll();
+ }
+ }
+
+
+ public void waitForNotification() throws Exception {
+ synchronized(notificationSignal) {
+ notificationSignal.triggered = false;
+ }
+ log.debug("waiting for reload signal");
+ if (!waitForSignal(notificationSignal, 10)) {
+ throw new Exception("timeout");
+ }
+ }
+
+ /*
+ * we don't reset the signal
+ * so if there was a check it is
+ * already true and exit immediatly
+ * otherwise it will behave just
+ * like waitForCheck()
+ */
+ public void waitForFirstCheck() throws Exception {
+ log.debug("waiting for first signal");
+ if (!waitForSignal(checkSignal, 10)) {
+ throw new Exception("timeout");
+ }
+ }
+
+ public void waitForCheck() throws Exception {
+ synchronized(checkSignal) {
+ checkSignal.triggered = false;
+ }
+ log.debug("waiting for check signal");
+ if (!waitForSignal(checkSignal, 10)) {
+ throw new Exception("timeout");
+ }
+ }
+
+ private boolean waitForSignal(final Signal pSignal, final int pSecondsTimeout) {
+ int i = 0;
+ while(true) {
+ synchronized(pSignal) {
+ //log.debug("loop");
+ if (!pSignal.triggered) {
+ try {
+ //log.debug("waiting");
+ pSignal.wait(1000);
+ } catch (InterruptedException e) {
+ ;
+ }
+ if (++i > pSecondsTimeout) {
+ log.error("timeout after " + pSecondsTimeout + "s");
+ return false;
+ }
+ } else {
+ pSignal.triggered = false;
+ break;
+ }
+ }
+ }
+
+ log.debug("caught signal");
+ return true;
+ }
+
+}
Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotifyingListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotifyingListener.java
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/NotifyingListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/AbstractFilesystemAlterationListener.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/AbstractFilesystemAlterationListener.java?view=auto&rev=498421
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/AbstractFilesystemAlterationListener.java (added)
+++ jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/AbstractFilesystemAlterationListener.java Sun Jan 21 10:16:11 2007
@@ -0,0 +1,162 @@
+package org.apache.commons.jci.monitor;
+
+import java.io.File;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public abstract class AbstractFilesystemAlterationListener implements FilesystemAlterationListener {
+
+ private final Log log = LogFactory.getLog(AbstractFilesystemAlterationListener.class);
+
+ private final static class Signal {
+ public boolean triggered;
+ }
+
+ private final Signal eventSignal = new Signal();
+ private final Signal checkSignal = new Signal();
+
+ private int createdFiles;
+ private int createdDirectories;
+ private int changedFiles;
+ private int changedDirectories;
+ private int deletedFiles;
+ private int deletedDirectories;
+
+
+
+
+ public void onChangeDirectory( final File pDir ) {
+ changedDirectories++;
+ }
+
+ public void onChangeFile( final File pFile ) {
+ changedFiles++;
+ }
+
+ public void onCreateDirectory( final File pDir ) {
+ createdDirectories++;
+ }
+
+ public void onCreateFile( final File pFile) {
+ createdFiles++;
+ }
+
+ public void onDeleteDirectory( final File pDir ) {
+ deletedDirectories++;
+ }
+
+ public void onDeleteFile( final File pfile ) {
+ deletedFiles++;
+ }
+
+ public void onStart() {
+ createdFiles = 0;
+ createdDirectories = 0;
+ changedFiles = 0;
+ changedDirectories = 0;
+ deletedFiles = 0;
+ deletedDirectories = 0;
+ }
+
+ public void onStop() {
+ if (createdFiles > 0 || createdDirectories > 0 ||
+ changedFiles > 0 || changedDirectories > 0 ||
+ deletedFiles > 0 || deletedDirectories >0) {
+
+ synchronized(eventSignal) {
+ eventSignal.triggered = true;
+ eventSignal.notifyAll();
+ }
+ }
+
+ synchronized(checkSignal) {
+ checkSignal.triggered = true;
+ checkSignal.notifyAll();
+ }
+ }
+
+
+ public int getChangedDirectories() {
+ return changedDirectories;
+ }
+
+ public int getChangedFiles() {
+ return changedFiles;
+ }
+
+ public int getCreatedDirectories() {
+ return createdDirectories;
+ }
+
+ public int getCreatedFiles() {
+ return createdFiles;
+ }
+
+ public int getDeletedDirectories() {
+ return deletedDirectories;
+ }
+
+ public int getDeletedFiles() {
+ return deletedFiles;
+ }
+
+ public void waitForEvent() throws Exception {
+ synchronized(eventSignal) {
+ eventSignal.triggered = false;
+ }
+ log.debug("waiting for change");
+ if (!waitForSignal(eventSignal, 10)) {
+ throw new Exception("timeout");
+ }
+ }
+
+ /*
+ * we don't reset the signal
+ * so if there was a check it is
+ * already true and exit immediatly
+ * otherwise it will behave just
+ * like waitForCheck()
+ */
+ public void waitForFirstCheck() throws Exception {
+ log.debug("waiting for first check");
+ if (!waitForSignal(checkSignal, 10)) {
+ throw new Exception("timeout");
+ }
+ }
+
+ public void waitForCheck() throws Exception {
+ synchronized(checkSignal) {
+ checkSignal.triggered = false;
+ }
+ log.debug("waiting for check");
+ if (!waitForSignal(checkSignal, 10)) {
+ throw new Exception("timeout");
+ }
+ }
+
+ private boolean waitForSignal(final Signal pSignal, final int pSecondsTimeout) {
+ int i = 0;
+ while(true) {
+ synchronized(pSignal) {
+ if (!pSignal.triggered) {
+ try {
+ pSignal.wait(1000);
+ } catch (InterruptedException e) {
+ }
+
+ if (++i > pSecondsTimeout) {
+ log.error("timeout after " + pSecondsTimeout + "s");
+ return false;
+ }
+
+ } else {
+ pSignal.triggered = false;
+ break;
+ }
+ }
+ }
+ return true;
+ }
+
+}
Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/AbstractFilesystemAlterationListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/AbstractFilesystemAlterationListener.java
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/AbstractFilesystemAlterationListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationListener.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationListener.java?view=diff&rev=498421&r1=498420&r2=498421
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationListener.java (original)
+++ jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationListener.java Sun Jan 21 10:16:11 2007
@@ -22,10 +22,13 @@
* @author tcurdt
*/
public interface FilesystemAlterationListener {
+
/**
* @deprecated
*/
File getRepository();
+
+
void onStart();
void onCreateFile( final File file );
void onChangeFile( final File file );
Modified: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java?view=diff&rev=498421&r1=498420&r2=498421
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java (original)
+++ jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java Sun Jan 21 10:16:11 2007
@@ -33,7 +33,7 @@
*/
public final class FilesystemAlterationMonitor implements Runnable {
- private final static Log log = LogFactory.getLog(FilesystemAlterationMonitor.class);
+ private final Log log = LogFactory.getLog(FilesystemAlterationMonitor.class);
public class Entry {
Modified: jakarta/commons/sandbox/jci/trunk/fam/src/test/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/fam/src/test/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java?view=diff&rev=498421&r1=498420&r2=498421
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/fam/src/test/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java (original)
+++ jakarta/commons/sandbox/jci/trunk/fam/src/test/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java Sun Jan 21 10:16:11 2007
@@ -17,115 +17,132 @@
package org.apache.commons.jci.monitor;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
import org.apache.commons.io.FileUtils;
-import org.apache.commons.jci.AbstractTestCase;
-import org.apache.commons.jci.listeners.NotifyingListener;
-import org.apache.commons.jci.stores.ResourceStore;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-public final class FilesystemAlterationMonitorTestCase extends AbstractTestCase {
+public final class FilesystemAlterationMonitorTestCase extends TestCase {
- private final static Log log = LogFactory.getLog(FilesystemAlterationMonitorTestCase.class);
+ private final Log log = LogFactory.getLog(FilesystemAlterationMonitorTestCase.class);
private FilesystemAlterationMonitor fam;
private MyFilesystemAlterationListener listener;
- private class MyFilesystemAlterationListener extends NotifyingListener {
- private int started;
- private int stopped;
- private int createdFiles;
- private int changedFiles;
- private int deletedFiles;
- private int createdDirs;
- private int changedDirs;
- private int deletedDirs;
- private boolean changed;
-
- public MyFilesystemAlterationListener(final File pRepository) {
- super(pRepository);
+ protected File directory;
+
+
+ protected void setUp() throws Exception {
+ directory = createTempDirectory();
+ assertTrue(directory.exists());
+ assertTrue(directory.isDirectory());
+ }
+
+ protected void tearDown() throws Exception {
+ FileUtils.deleteDirectory(directory);
+ }
+
+
+ protected File createDirectory( final String pName ) throws Exception {
+ final File newDirectory = new File(directory, pName);
+ assertTrue(newDirectory.mkdir());
+ assertTrue(newDirectory.exists());
+ assertTrue(newDirectory.isDirectory());
+ return newDirectory;
+ }
+
+ protected File writeFile( final String pName, final byte[] pData ) throws Exception {
+ final File file = new File(directory, pName);
+ final File parent = file.getParentFile();
+ if (!parent.exists()) {
+ if (!parent.mkdirs()) {
+ throw new IOException("could not create" + parent);
+ }
}
- public ResourceStore getStore() {
- return null;
- }
+ log.debug("writing file " + pName + " (" + pData.length + " bytes)");
+
+ final FileOutputStream os = new FileOutputStream(file);
+ os.write(pData);
+ os.close();
+
+ assertTrue(file.exists());
+ assertTrue(file.isFile());
+
+ return file;
+ }
- public int getChangedDirs() {
- return changedDirs;
- }
- public int getChangedFiles() {
- return changedFiles;
+ protected File writeFile( final String pName, final String pText ) throws Exception {
+ final File file = new File(directory, pName);
+ final File parent = file.getParentFile();
+ if (!parent.exists()) {
+ if (!parent.mkdirs()) {
+ throw new IOException("could not create" + parent);
+ }
}
- public int getCreatedDirs() {
- return createdDirs;
- }
- public int getCreatedFiles() {
- return createdFiles;
- }
- public int getDeletedDirs() {
- return deletedDirs;
- }
- public int getDeletedFiles() {
- return deletedFiles;
- }
- public int getStarted() {
- return started;
- }
- public int getStopped() {
- return stopped;
- }
-
- public void onStart() {
- changed = false;
- ++started;
- log.debug("onStart");
- }
- public void onStop() {
- ++stopped;
- log.debug("onStop");
-
- checked(changed);
- }
- public void onCreateFile( final File file ) {
- ++createdFiles;
- changed = true;
- log.debug("onCreateFile " + file);
- }
- public void onChangeFile( final File file ) {
- ++changedFiles;
- changed = true;
- log.debug("onChangeFile " + file);
- }
- public void onDeleteFile( final File file ) {
- ++deletedFiles;
- changed = true;
- log.debug("onDeleteFile " + file);
- }
- public void onCreateDirectory( final File file ) {
- ++createdDirs;
- changed = true;
- log.debug("onCreateDirectory " + file);
+ log.debug("writing " + file);
+ final FileWriter writer = new FileWriter(file);
+ writer.write(pText);
+ writer.close();
+
+ assertTrue(file.exists());
+ assertTrue(file.isFile());
+
+ return file;
+ }
+
+ protected File createTempDirectory() throws IOException {
+ final File tempFile = File.createTempFile("jci", null);
+
+ if (!tempFile.delete()) {
+ throw new IOException();
}
- public void onChangeDirectory( final File file ) {
- ++changedDirs;
- changed = true;
- log.debug("onChangeDirectory " + file);
+
+ if (!tempFile.mkdir()) {
+ throw new IOException();
}
- public void onDeleteDirectory( final File file ) {
- ++deletedDirs;
- changed = true;
- log.debug("onDeleteDirectory " + file);
+
+ return tempFile;
+ }
+
+
+ protected void delay() {
+ try {
+ Thread.sleep(1500);
+ } catch (final InterruptedException e) {
}
}
+
+
+ private static class MyFilesystemAlterationListener extends AbstractFilesystemAlterationListener {
+
+ final File directory;
+
+ public MyFilesystemAlterationListener( final File pDirectory ) {
+ directory = pDirectory;
+ }
+
+ public File getRepository() {
+ return directory;
+ }
+
+ }
+
private void start() throws Exception {
fam = new FilesystemAlterationMonitor();
listener = new MyFilesystemAlterationListener(directory);
fam.addListener(listener);
fam.start();
listener.waitForFirstCheck();
+ delay(); // FIXME: really required?
}
private void stop() {
@@ -137,11 +154,9 @@
listener = new MyFilesystemAlterationListener(directory);
fam.addListener(listener);
- log.debug(fam);
assertTrue(fam.getListeners().size() == 1);
fam.addListener(listener);
- log.debug(fam);
assertTrue(fam.getListeners().size() == 1);
}
@@ -149,32 +164,20 @@
fam = new FilesystemAlterationMonitor();
fam.addListener(new MyFilesystemAlterationListener(directory));
- log.debug(fam);
assertTrue(fam.getListenersFor(directory).size() == 1);
fam.addListener(new MyFilesystemAlterationListener(directory));
- log.debug(fam);
assertTrue(fam.getListenersFor(directory).size() == 2);
}
- public void testListener() throws Exception {
- start();
- log.debug(fam);
- fam.removeListener(listener);
- log.debug(fam);
- stop();
- }
-
public void testCreateFileDetection() throws Exception {
start();
- delay();
-
writeFile("file", "file");
- listener.waitForNotification();
+ listener.waitForEvent();
- assertTrue(listener.createdFiles == 1);
+ assertTrue(listener.getCreatedFiles() == 1);
stop();
}
@@ -182,13 +185,11 @@
public void testCreateDirectoryDetection() throws Exception {
start();
- delay();
-
createDirectory("dir");
- listener.waitForNotification();
+ listener.waitForEvent();
- assertTrue(listener.createdDirs == 1);
+ assertTrue(listener.getCreatedDirectories() == 1);
stop();
}
@@ -196,20 +197,18 @@
public void testDeleteFileDetection() throws Exception {
start();
- delay();
-
final File file = writeFile("file", "file");
- listener.waitForNotification();
+ listener.waitForEvent();
- assertTrue(listener.createdFiles == 1);
+ assertTrue(listener.getCreatedFiles() == 1);
file.delete();
assertTrue(!file.exists());
- listener.waitForNotification();
+ listener.waitForEvent();
- assertTrue(listener.deletedFiles == 1);
+ assertTrue(listener.getDeletedFiles() == 1);
stop();
}
@@ -217,23 +216,21 @@
public void testDeleteDirectoryDetection() throws Exception {
start();
- delay();
-
final File dir = createDirectory("dir");
createDirectory("dir/sub");
- listener.waitForNotification();
+ listener.waitForEvent();
- assertTrue(listener.createdDirs == 2);
+ assertTrue(listener.getCreatedDirectories() == 2);
delay();
FileUtils.deleteDirectory(dir);
assertTrue(!dir.exists());
- listener.waitForNotification();
+ listener.waitForEvent();
- assertTrue(listener.deletedDirs == 2);
+ assertTrue(listener.getDeletedDirectories() == 2);
stop();
}
@@ -241,21 +238,19 @@
public void testModifyFileDetection() throws Exception {
start();
- delay();
-
writeFile("file", "file");
- listener.waitForNotification();
+ listener.waitForEvent();
- assertTrue(listener.createdFiles == 1);
+ assertTrue(listener.getCreatedFiles() == 1);
delay();
writeFile("file", "changed file");
- listener.waitForNotification();
+ listener.waitForEvent();
- assertTrue(listener.changedFiles == 1);
+ assertTrue(listener.getChangedFiles() == 1);
stop();
}
@@ -266,6 +261,8 @@
delay();
createDirectory("directory");
+
+ delay();
assertTrue(directory.lastModified() != modified);
}
@@ -274,9 +271,11 @@
final long modified = directory.lastModified();
delay();
-
+
writeFile("file", "file");
+ delay();
+
assertTrue(directory.lastModified() != modified);
}
@@ -305,8 +304,23 @@
}
public void testInterval() throws Exception {
+
+ final long interval = 100;
+
start();
- fam.setInterval(100);
+ fam.setInterval(interval);
+
+ listener.waitForCheck();
+ long t1 = System.currentTimeMillis();
+
+ listener.waitForCheck();
+ long t2 = System.currentTimeMillis();
+
+ long diff = t2-t1;
+
+ // interval should be at around the same interval
+ assertTrue( (diff > (interval-20)) && (diff < (interval+20)) );
+
stop();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org