Skip to content

Commit

Permalink
JBVFS-38, fixes for jar entries iteration corrupted on linux + fixed …
Browse files Browse the repository at this point in the history
…file locking issues
  • Loading branch information
Marko Strukelj committed Jun 29, 2008
1 parent 7c5e2a6 commit 114c63a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 30 deletions.
Expand Up @@ -39,17 +39,17 @@
* @author Scott.Stark@jboss.org
* @version $Revision:$
*/
public class HDScannerTestCase extends OSAwareVFSTest
public class HDScannerTestCase extends AbstractVFSTest
{

public HDScannerTestCase(String name, boolean forceCopy)
{
super(name, forceCopy, true);
super(name, forceCopy, false);
}

public HDScannerTestCase(String name)
{
super(name, true, true);
super(name, true, false);
}

public void testDeleteWhileScanning()
Expand Down Expand Up @@ -87,7 +87,8 @@ public void testDeleteWhileScanning()
archive.setLastModified(System.currentTimeMillis());
}
getLog().info("Trying to remove: "+archive.getAbsolutePath());
assertTrue(archive.delete());
assertTrue(archiveVF.delete());
assertFalse(archiveVF.exists());
getLog().info("Deleted deployed archive");
scanner.stop();
}
Expand Down
29 changes: 16 additions & 13 deletions src/test/java/org/jboss/test/virtual/test/JARCacheUnitTestCase.java
Expand Up @@ -39,16 +39,16 @@
* @author <a href="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
* @version $Revision$
*/
public class JARCacheUnitTestCase extends OSAwareVFSTest
public class JARCacheUnitTestCase extends AbstractVFSTest
{
public JARCacheUnitTestCase(String name)
{
super(name);
super(name, false, false);
}

protected JARCacheUnitTestCase(String name, boolean forceCopy)
{
super(name, forceCopy);
super(name, forceCopy, false);
}

public static Test suite()
Expand All @@ -69,20 +69,19 @@ public void testJarCache() throws Exception
out.flush();
out.close();
}

// Verify it via VFS
File root = new File(".");
VirtualFile vf = VFS.getVirtualFile(root.toURL(), "test.jar");
{
VirtualFile vf = VFS.getVirtualFile(root.toURL(), "test.jar");
// System.err.println("lastModified = " + vf.getLastModified());
VirtualFile manifestFile = vf.findChild("META-INF/MANIFEST.MF");
Manifest manifest = new Manifest(manifestFile.openStream());
String actual = manifest.getMainAttributes().getValue("test");
assertEquals("v1", actual);
}

// If we don't delete, VFS will give ZIP errors (related issue?)
assertTrue("test file deleted: " + testFile, testFile.delete() || isWindowsOS());
// If we don't delete, we get a corrupt zip entries iterator on linux
assertTrue("test file deleted: " + testFile, vf.delete());

// Create a new test.jar with manifest v2
{
Expand All @@ -104,11 +103,15 @@ public void testJarCache() throws Exception

// Verify the manifest the VFS way
{
VirtualFile vf = VFS.getVirtualFile(root.toURL(), "test.jar");
// Note that the modification date has not changed according to VFS
// System.err.println("lastModified = " + vf.getLastModified());
// System.err.println("modified = " + vf.hasBeenModified());

VirtualFile manifestFile = vf.findChild("META-INF/MANIFEST.MF");
Manifest manifest = new Manifest(manifestFile.openStream());
String actual = manifest.getMainAttributes().getValue("test");
assertEquals("VFS found the wrong manifest", "v2", actual);
}

// Verify again - through new context
{
vf = VFS.getVirtualFile(root.toURL(), "test.jar");
VirtualFile manifestFile = vf.findChild("META-INF/MANIFEST.MF");
Manifest manifest = new Manifest(manifestFile.openStream());
String actual = manifest.getMainAttributes().getValue("test");
Expand Down
Expand Up @@ -37,16 +37,16 @@
*
* @author Ales.Justin@jboss.org
*/
public class JAREntryTestCase extends OSAwareVFSTest
public class JAREntryTestCase extends AbstractVFSTest
{
public JAREntryTestCase(String name)
{
super(name);
super(name, false, false);
}

protected JAREntryTestCase(String name, boolean forceCopy)
{
super(name, forceCopy);
super(name, forceCopy, false);
}

public static Test suite()
Expand Down Expand Up @@ -78,6 +78,9 @@ public void testEntryModified() throws Exception
List<VirtualFile> children = metainf.getChildren();
assertEquals(1, children.size());

// delete zipFile before recreating it otherwise you get a corrupt entries iterator on linux
assertTrue(root.delete());

fos = new FileOutputStream(tmp);
jos = new JarOutputStream(fos, mf);
try
Expand Down
Expand Up @@ -37,7 +37,7 @@
* @author Scott.Stark@jboss.org
* @version $Revision$
*/
public class URLExistsUnitTestCase extends OSAwareVFSTest
public class URLExistsUnitTestCase extends AbstractVFSTest
{
public URLExistsUnitTestCase(String name)
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public void testFileURLs() throws Exception
{
in.close();
}
assertTrue(tmp.getAbsolutePath()+" deleted", tmp.delete() || isWindowsOS());
assertTrue(tmp.getAbsolutePath()+" deleted", tmp.delete());
conn = tmpURL.openConnection();
lastModified = conn.getLastModified();
System.out.println("lastModified after delete, "+lastModified);
Expand All @@ -94,14 +94,28 @@ public void testJarURLs() throws Exception

URL tmpURL = new URL("jar:"+tmp.toURL()+"!/");
URLConnection conn = tmpURL.openConnection();
conn.setUseCaches(false);

long lastModified = conn.getLastModified();

// the following ugly block of code is
// the only known way to force jar file lock release on Windows
// and it's not even 100% reliable
conn = null;
tmpURL = null;
System.gc();
Thread.sleep(500);
System.gc();

System.out.println("lastModified, "+lastModified);
assertNotSame("lastModified", 0, lastModified);
assertTrue(tmp.getAbsolutePath()+" deleted", tmp.delete() || isWindowsOS());
assertTrue(tmp.getAbsolutePath()+" deleted", tmp.delete());

tmpURL = new URL("jar:"+tmp.toURL()+"!/");
conn = tmpURL.openConnection();
lastModified = conn.getLastModified();
System.out.println("lastModified after delete, "+lastModified);
// TODO - fix back
assertTrue("lastModified", 0 == lastModified || isWindowsOS());
assertTrue("lastModified", 0 == lastModified);
}
}
Expand Up @@ -89,15 +89,11 @@ public void testRootExists() throws Exception
}
os.close();

// use noReaper so that the underlying file is not locked
// when we try to delete it
String jarUrl = tmpJar.toURL().toString() + "?noReaper=true";
ZipEntryContext context = new ZipEntryContext(new URL(jarUrl));
ZipEntryContext context = new ZipEntryContext(tmpJar.toURL());
assertTrue("context.getRoot().exists()", context.getRoot().exists());

boolean isDeleted = tmpJar.delete();
boolean isDeleted = context.getRoot().delete(1000);
assertTrue("delete tmp file: " + tmpJar, isDeleted);

assertFalse("context.getRoot().exists()", context.getRoot().exists());
}

Expand Down

0 comments on commit 114c63a

Please sign in to comment.