# HG changeset patch # User Vladimir Kvashin # Date 1413977283 -14400 # Node ID 6ce1e0ad3bd4de68f17a0dd8ba154f923342c75c # Parent 3d2bc609462a1f9046d1350a0dd054e8d7558bb1 atest that shows that apart from fixed #248074 (No event on remote plain file modification) there is one more slight difference in events in local and remote modes (in event.getSource()) diff -r 3d2bc609462a -r 6ce1e0ad3bd4 dlight.remote.impl/test/unit/src/org/netbeans/modules/remote/impl/fs/ListenersParityTestCase.java --- a/dlight.remote.impl/test/unit/src/org/netbeans/modules/remote/impl/fs/ListenersParityTestCase.java Wed Oct 22 15:16:01 2014 +0400 +++ b/dlight.remote.impl/test/unit/src/org/netbeans/modules/remote/impl/fs/ListenersParityTestCase.java Wed Oct 22 15:28:03 2014 +0400 @@ -46,6 +46,7 @@ import java.io.PrintStream; import junit.framework.Test; import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; +import org.netbeans.modules.nativeexecution.api.util.ProcessUtils; import org.netbeans.modules.nativeexecution.test.ForAllEnvironments; import org.netbeans.modules.nativeexecution.test.RcFile.FormatException; import org.netbeans.modules.remote.spi.FileSystemProvider; @@ -198,7 +199,76 @@ } } } - + + private void doTestListenersChange1(boolean externalChange) throws Throwable { + File localTmpDir = createTempFile(getClass().getSimpleName(), ".tmp", true); + String remoteBaseDir = null; + try { + remoteBaseDir = mkTempAndRefreshParent(true); + FileObject remoteBaseDirFO = getFileObject(remoteBaseDir); + FileObject localBaseDirFO = FileUtil.toFileObject(FileUtil.normalizeFile(localTmpDir)); + File workDir = getWorkDir(); + File remoteLog = new File(workDir, "remote.dat"); + File localLog = new File(workDir, "local.dat"); + doTestListenersChange2(remoteBaseDirFO, remoteLog, externalChange); + doTestListenersChange2(localBaseDirFO, localLog, externalChange); + printFile(localLog, "LOCAL ", System.out); + printFile(remoteLog, "REMOTE", System.out); + File diff = new File(workDir, "diff.diff"); + try { + assertFile("Remote and local events differ, see diff " + remoteLog.getAbsolutePath() + " " + localLog.getAbsolutePath(), remoteLog, localLog, diff); + } catch (Throwable ex) { + if (diff.exists()) { + printFile(diff, null, System.err); + } + throw ex; + } + } finally { + removeRemoteDirIfNotNull(remoteBaseDir); + if (localTmpDir != null && localTmpDir.exists()) { + removeDirectory(localTmpDir); + } + } + } + + private void doTestListenersChange2(FileObject baseDirFO, File log, boolean externalChange) throws Exception { + PrintStream out = new PrintStream(log); + try { + String prefix = baseDirFO.getPath(); + FileObject subdirFO = baseDirFO.createFolder("child_folder"); + FileObject childFO = subdirFO.createData("child_file_1"); + subdirFO.addFileChangeListener(new DumpingFileChangeListener("Dir listener", prefix, out, true)); + childFO.addFileChangeListener(new DumpingFileChangeListener("File listener", prefix, out, true)); + if (externalChange) { + ExecutionEnvironment env = FileSystemProvider.getExecutionEnvironment(childFO); + ProcessUtils.ExitStatus rc = ProcessUtils.execute(env, "/bin/sh", "-c", "echo new_content > " + childFO.getPath()); + assertTrue("external modification command failed", rc.exitCode == 0); + if (env.isLocal()) { + FileUtil.refreshAll(); + File[] files = new File[] {FileUtil.toFile(subdirFO), FileUtil.toFile(childFO) }; + FileUtil.refreshFor(files); + sleep(5000); + } + subdirFO.refresh(); + } else { + writeFile(childFO, "new file content\n"); + } + } finally { + out.close(); + } + } + + @ForAllEnvironments + public void testListenersInternalChange() throws Throwable { + doTestListenersChange1(false); + } + +// For an external change I wasn't able to make masterfs to fire file change event +// @ForAllEnvironments +// public void testListenersExternalChange() throws Throwable { +// doTestListenersChange1(true); +// } + @ForAllEnvironments public void testListenersRename() throws Throwable { doTestListenersRename1(false);