Repository: systemml Updated Branches: refs/heads/master 6bd2d8808 -> 723acfc09
[MINOR] Fix test resource leaks to address intermittent test failures Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/38162d23 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/38162d23 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/38162d23 Branch: refs/heads/master Commit: 38162d232e22aa189003428d0afbcc04712b608d Parents: 6bd2d88 Author: Matthias Boehm <[email protected]> Authored: Wed Nov 22 15:16:42 2017 -0800 Committer: Matthias Boehm <[email protected]> Committed: Wed Nov 22 20:32:04 2017 -0800 ---------------------------------------------------------------------- .../functions/jmlc/JMLCInputStreamReadTest.java | 2 ++ .../integration/mlcontext/MLContextTest.java | 20 +++++++++++--------- .../org/apache/sysml/test/utils/TestUtils.java | 8 +------- 3 files changed, 14 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/38162d23/src/test/java/org/apache/sysml/test/integration/functions/jmlc/JMLCInputStreamReadTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/jmlc/JMLCInputStreamReadTest.java b/src/test/java/org/apache/sysml/test/integration/functions/jmlc/JMLCInputStreamReadTest.java index 05ee456..6411410 100644 --- a/src/test/java/org/apache/sysml/test/integration/functions/jmlc/JMLCInputStreamReadTest.java +++ b/src/test/java/org/apache/sysml/test/integration/functions/jmlc/JMLCInputStreamReadTest.java @@ -142,6 +142,7 @@ public class JMLCInputStreamReadTest extends AutomatedTestBase //read matrix from input stream FileInputStream fis = new FileInputStream(output("X")); double[][] data2 = conn.convertToDoubleMatrix(fis, rows, cols, format); + fis.close(); //compare matrix result TestUtils.compareMatrices(data, data2, rows, cols, 0); @@ -164,6 +165,7 @@ public class JMLCInputStreamReadTest extends AutomatedTestBase //read frame from input stream FileInputStream fis = new FileInputStream(output("X")); String[][] fdata2 = conn.convertToStringFrame(fis, rows, cols, format); + fis.close(); //compare frame result TestUtils.compareFrames(fdata, fdata2, rows, cols); http://git-wip-us.apache.org/repos/asf/systemml/blob/38162d23/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java b/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java index 9e4cfac..6dc3053 100644 --- a/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java +++ b/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java @@ -33,7 +33,7 @@ import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; @@ -123,23 +123,25 @@ public class MLContextTest extends MLContextTestBase { } @Test - public void testCreateDMLScriptBasedOnInputStreamAndExecute() throws FileNotFoundException { + public void testCreateDMLScriptBasedOnInputStreamAndExecute() throws IOException { System.out.println("MLContextTest - create DML script based on InputStream and execute"); setExpectedStdOut("hello world"); File file = new File(baseDirectory + File.separator + "hello-world.dml"); - InputStream is = new FileInputStream(file); - Script script = dmlFromInputStream(is); - ml.execute(script); + try( InputStream is = new FileInputStream(file) ) { + Script script = dmlFromInputStream(is); + ml.execute(script); + } } @Test - public void testCreatePYDMLScriptBasedOnInputStreamAndExecute() throws FileNotFoundException { + public void testCreatePYDMLScriptBasedOnInputStreamAndExecute() throws IOException { System.out.println("MLContextTest - create PYDML script based on InputStream and execute"); setExpectedStdOut("hello world"); File file = new File(baseDirectory + File.separator + "hello-world.pydml"); - InputStream is = new FileInputStream(file); - Script script = pydmlFromInputStream(is); - ml.execute(script); + try( InputStream is = new FileInputStream(file) ) { + Script script = pydmlFromInputStream(is); + ml.execute(script); + } } @Test http://git-wip-us.apache.org/repos/asf/systemml/blob/38162d23/src/test/java/org/apache/sysml/test/utils/TestUtils.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/utils/TestUtils.java b/src/test/java/org/apache/sysml/test/utils/TestUtils.java index 0ea4489..aaaade23 100644 --- a/src/test/java/org/apache/sysml/test/utils/TestUtils.java +++ b/src/test/java/org/apache/sysml/test/utils/TestUtils.java @@ -570,12 +570,8 @@ public class TestUtils } else if ( count > 1 ) { File tmp = new File(csvFile+"_temp.csv"); - OutputStreamWriter out = null; - - try { - out = new OutputStreamWriter(new FileOutputStream(tmp), - "UTF-8"); + try( OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(tmp), "UTF-8") ) { // Directory listing may contain .crc files or may be in the // wrong order. Sanitize the list of names. ArrayList<String> partNames = new ArrayList<String>(); @@ -594,8 +590,6 @@ public class TestUtils "UTF-8"); out.append(fileContents); } - } finally { - IOUtilFunctions.closeSilently(out); } csvFile = tmp.getCanonicalPath();
