This content has been marked as final.
Show 6 replies
-
1. Re: File last modified diff behavior
alesj Apr 13, 2009 4:56 PM (in response to alesj)"alesj" wrote:
While this work for me locally (winz machine), it fails for me remotely (linux machine).
The test is this one:
- http://anonsvn.jboss.org/repos/jbossas/projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java -
2. Re: File last modified diff behavior
jaikiran Apr 14, 2009 6:56 AM (in response to alesj)
File updateFile = new File(rootFile, "test.jsp");
assertTrue(updateFile.setLastModified(System.currentTimeMillis()));
As per the javadoc of java.io.File.setLastModified:All platforms support file-modification times to the nearest second, but some provide more precision. The argument will be truncated to fit the supported precision. If the operation succeeds and no intervening operations on the file take place, then the next invocation of the lastModified() method will return the (possibly truncated) time argument that was passed to this method.
So unless there is a difference of 1 second, there's no guarantee of that test case passing on all platforms. I guess the test case could be changed to add some delay before updating the last modified timestamp on the original file. -
3. Re: File last modified diff behavior
alesj Apr 14, 2009 7:27 AM (in response to alesj)I just added additional 1500ms.
Can you check (if you're on Linux :-))? -
4. Re: File last modified diff behavior
jaikiran Apr 14, 2009 7:42 AM (in response to alesj)Yep, i have Kubuntu system where this still fails:
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.425 sec <<< FAILURE! testWAR(org.jboss.test.deployers.vfs.structure.modified.test.SynchModificationTestCase) Time elapsed: 0.121 sec <<< FAILURE! junit.framework.AssertionFailedError: Last modified diff is not bigger then 0, diff: 0 at junit.framework.Assert.fail(Assert.java:47) at junit.framework.Assert.assertTrue(Assert.java:20) at org.jboss.test.deployers.vfs.structure.modified.test.SynchModificationTestCase.testWAR(SynchModificationTestCase.java:122)
I see that the testcase was changed to:assertTrue(updateFile.setLastModified(System.currentTimeMillis() + 1500l));
This probably won't introduce the "delay" that we are expecting.
Looking at this:long tempTimestamp = testJsp.getLastModified(); assertFalse(checker.hasStructureBeenModified(originalRoot)); long lastModified = testJsp.getLastModified();
I guess, internally its a file "copy" (original deployment to temp deployment) if the original file has changed. I am not really sure whether the "copy" copies over the last modified timestamp from the source. Maybe the copy just copies the file and updates the last modified time to current system timestamp?
The delay that we need, should be between the change of the original file and copying to temp file. Something like:long tempTimestamp = testJsp.getLastModified(); // Platform dependent precision for last modified. Let's wait a minimum of 1 sec Thread.sleep(1500); assertFalse(checker.hasStructureBeenModified(originalRoot)); long lastModified = testJsp.getLastModified();
-
5. Re: File last modified diff behavior
alesj Apr 14, 2009 7:54 AM (in response to alesj)"jaikiran" wrote:
Yep, i have Kubuntu system where this still fails:
Yeah, for me too."jaikiran" wrote:
The delay that we need, should be between the change of the original file and copying to temp file. Something like:long tempTimestamp = testJsp.getLastModified(); // Platform dependent precision for last modified. Let's wait a minimum of 1 sec Thread.sleep(1500); assertFalse(checker.hasStructureBeenModified(originalRoot)); long lastModified = testJsp.getLastModified();
Does this work for you?
Although, the temp should be compiled/copied to test-classes long before System.currentTimemillis - 1sec.
As mvn first creates all the files and only then runs the tests.
Checker then deletes and re-creates the temp file,
resulting in new last modified. -
6. Re: File last modified diff behavior
jaikiran Apr 14, 2009 8:04 AM (in response to alesj)"alesj" wrote:
long tempTimestamp = testJsp.getLastModified(); // Platform dependent precision for last modified. Let's wait a minimum of 1 sec Thread.sleep(1500); assertFalse(checker.hasStructureBeenModified(originalRoot)); long lastModified = testJsp.getLastModified();
Does this work for you?
Yes, it does:------------------------------------------------------------------------------- Test set: org.jboss.test.deployers.vfs.structure.modified.test.SynchModificationTestCase ------------------------------------------------------------------------------- Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.816 sec
"alesj" wrote:
Checker then deletes and re-creates the temp file,
resulting in new last modified.
Right, it's the checker which sets the last modified on the new temp to the current system time and should be atleast 1 second diff from the old temp file's last modified time. That delay, with Thread.sleep achieves this.