Skip to content

Commit 92c0628

Browse files
mbooth101krosenvold
authored andcommitted
Test case that reproduces "too many open files" problem from #6.
1 parent 9da7141 commit 92c0628

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: src/test/java/org/codehaus/plexus/archiver/jar/JarArchiverTest.java

+30
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import org.codehaus.plexus.archiver.ArchiverException;
44

55
import java.io.File;
6+
import java.io.FileOutputStream;
67
import java.io.IOException;
8+
import java.util.Random;
79

810
import junit.framework.TestCase;
911

@@ -42,4 +44,32 @@ public void testNonCompressed()
4244
archiver.createArchive();
4345
}
4446

47+
public void testVeryLargeJar()
48+
throws IOException, ManifestException, ArchiverException
49+
{
50+
// Generate some number of random files that is likely to be
51+
// two or three times the number of available file handles
52+
File tmpDir = File.createTempFile( "veryLargeJar", null );
53+
tmpDir.delete();
54+
tmpDir.mkdirs();
55+
Random rand = new Random();
56+
for ( int i = 0; i < 15000; i++ )
57+
{
58+
File f = new File( tmpDir, "file" + i );
59+
f.deleteOnExit();
60+
FileOutputStream out = new FileOutputStream(f);
61+
byte[] data = new byte[10240]; // 10kb per file
62+
rand.nextBytes( data );
63+
out.write( data );
64+
out.flush();
65+
out.close();
66+
}
67+
68+
File jarFile = new File( "target/output/veryLargeJar.jar" );
69+
70+
JarArchiver archiver = new JarArchiver();
71+
archiver.setDestFile( jarFile );
72+
archiver.addDirectory( tmpDir );
73+
archiver.createArchive();
74+
}
4575
}

0 commit comments

Comments
 (0)