From 32dca8819c003ee6d815d1c9858dccb19f64b71d Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Tue, 14 Apr 2015 18:59:38 +0300 Subject: [PATCH] [JENKINS-10629] - Direct unit test for the issue This test also introduces additional round-trip tests for small files --- core/src/test/java/hudson/FilePathTest.java | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/core/src/test/java/hudson/FilePathTest.java b/core/src/test/java/hudson/FilePathTest.java index 999b3e792c..801e184906 100644 --- a/core/src/test/java/hudson/FilePathTest.java +++ b/core/src/test/java/hudson/FilePathTest.java @@ -35,6 +35,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.RandomAccessFile; import java.net.ConnectException; import java.net.HttpURLConnection; import java.net.URL; @@ -56,6 +57,8 @@ import org.apache.commons.io.output.NullOutputStream; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Chmod; import static org.junit.Assert.*; +import static org.junit.Assume.assumeTrue; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -325,6 +328,53 @@ public class FilePathTest { FileUtils.touch(building); return new FilePath(building); } + + /** + * Performs round-trip archiving for Tar handling methods. + * @throws Exception test failure + */ + @Test public void compressTarUntarRoundTrip() throws Exception { + checkTarUntarRoundTrip("compressTarUntarRoundTrip_zero", 0); + checkTarUntarRoundTrip("compressTarUntarRoundTrip_small", 100); + checkTarUntarRoundTrip("compressTarUntarRoundTrip_medium", 50000); + } + + /** + * Checks that big files (>8GB) can be archived and then unpacked. + * This test is disabled by default due the impact on RAM. + * The actual file size limit is 8589934591 bytes. + * @throws Exception test failure + */ + @Issue("JENKINS-10629") + @Ignore + @Test public void archiveBigFile() throws Exception { + final long largeFileSize = 9000000000L; // >8589934591 bytes + final String filePrefix = "JENKINS-10629"; + checkTarUntarRoundTrip(filePrefix, largeFileSize); + } + + private void checkTarUntarRoundTrip(String filePrefix, long fileSize) throws Exception { + final File tmpDir = temp.newFolder(filePrefix); + final File tempFile = new File(tmpDir, filePrefix + ".log"); + RandomAccessFile file = new RandomAccessFile(tempFile, "rw"); + final File tarFile = new File(tmpDir, filePrefix + ".tar"); + + file.setLength(fileSize); + assumeTrue(fileSize == file.length()); + file.close(); + + // Compress archive + final FilePath tmpDirPath = new FilePath(tmpDir); + int tar = tmpDirPath.tar(new FileOutputStream(tarFile), tempFile.getName()); + assertEquals("One file should have been compressed", 1, tar); + + // Decompress + FilePath outDir = new FilePath(temp.newFolder(filePrefix + "_out")); + final FilePath outFile = outDir.child(tempFile.getName()); + tmpDirPath.child( filePrefix + ".tar").untar(outDir, TarCompression.NONE); + assertEquals("Result file after the roundtrip differs from the initial file", + new FilePath(tempFile).digest(), outFile.digest()); + } @Test public void list() throws Exception { File baseDir = temp.getRoot(); -- GitLab