Skip to content

Commit

Permalink
Minor Fixes in FileUtilitySuite
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikram Agrawal committed Aug 29, 2019
1 parent fcf2a86 commit fb86f0d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions core/src/test/java/org/apache/spark/io/FileUtilitySuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@
public class FileUtilitySuite {

protected File sourceFolder;
protected File destFile;
protected File destTarLoc;
protected File destFolder;

@Before
public void setUp() throws IOException {
sourceFolder = Utils.createTempDir(System.getProperty("java.io.tmpdir"),
"FileUtilTest" + RandomUtils.nextLong());
destTarLoc = File.createTempFile("dest-tar", ".tar");
destFile = File.createTempFile("dest-file", ".tmp");
String tmpDir = System.getProperty("java.io.tmpdir");
sourceFolder = Utils.createTempDir(tmpDir, "FileUtilTest-src-" + RandomUtils.nextLong());
destFolder = Utils.createTempDir(tmpDir, "FileUtilTest-dest-" + RandomUtils.nextLong());
destTarLoc= File.createTempFile("dest-tar", ".tar");
}

@After
public void tearDown() {
destTarLoc.delete();
destFile.delete();
}

@Test
Expand All @@ -66,14 +65,12 @@ public void testCreationAndExtraction() throws IllegalStateException, IOExceptio
Assert.assertTrue(destTarLoc.exists());

// Extract the tarball
String destFilePath = destFile.getAbsolutePath();
destFile.delete();
Assert.assertFalse(destFile.exists());
FileUtility.extractTarFile(destTarLoc.getAbsolutePath(), destFilePath);
Assert.assertEquals(destFolder.listFiles().length , 0);
FileUtility.extractTarFile(destTarLoc.getAbsolutePath(), destFolder.getAbsolutePath());

Assert.assertTrue(destFile.exists());
Assert.assertEquals(destFile.listFiles().length , 1);
Assert.assertArrayEquals(randomBytes, FileUtils.readFileToByteArray(destFile.listFiles()[0]));
Assert.assertTrue(destFolder.exists());
Assert.assertEquals(destFolder.listFiles().length , 1);
Assert.assertArrayEquals(randomBytes, FileUtils.readFileToByteArray(destFolder.listFiles()[0]));
}

}

0 comments on commit fb86f0d

Please sign in to comment.