Skip to content

Commit 76584dc

Browse files
committed
tmp
1 parent a6d1522 commit 76584dc

File tree

1 file changed

+89
-1
lines changed

1 file changed

+89
-1
lines changed

src/test/java/org/apache/sysds/test/functions/jmlc/JMLConnectionTest.java

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.sysds.conf.CompilerConfig;
2828
import org.apache.sysds.conf.ConfigurationManager;
2929
import org.apache.sysds.parser.LanguageException;
30+
import org.apache.sysds.runtime.frame.data.FrameBlock;
3031
import org.apache.sysds.runtime.io.IOUtilFunctions;
3132
import org.apache.sysds.runtime.matrix.data.MatrixBlock;
3233
import org.apache.sysds.test.AutomatedTestBase;
@@ -105,13 +106,22 @@ public void testConnectionInvalidInName() throws DMLException {
105106

106107
@Test
107108
public void testConnectionParseLanguageException() {
109+
boolean oldStat = DMLScript.STATISTICS;
110+
boolean oldJMLCStat = DMLScript.JMLC_MEM_STATISTICS;
108111
try (Connection conn = new Connection()) {
112+
DMLScript.STATISTICS = true;
113+
conn.gatherMemStats(true);
114+
Assert.assertTrue(DMLScript.STATISTICS);
115+
109116
conn.prepareScript("printx('hello')", new String[]{}, new String[]{});
110117
throw new AssertionError("Test should have thrown a DMLException");
111118
} catch (DMLException e) {
112119
Throwable cause = e.getCause();
113120
Assert.assertTrue(cause.getMessage().startsWith("ERROR: [line 1:0] -> printx('hello') -- function printx is undefined in namespace .builtinNS"));
114-
}
121+
} finally {
122+
DMLScript.STATISTICS = oldStat;
123+
DMLScript.JMLC_MEM_STATISTICS = oldJMLCStat;
124+
}
115125
}
116126

117127
@Test
@@ -290,4 +300,82 @@ public void testConvertToMatrixInvalidFormat() {
290300
Assert.assertTrue(e.getMessage().startsWith("Invalid input format"));
291301
}
292302
}
303+
304+
@Test
305+
public void testReadFrame1() {
306+
try (Connection conn = new Connection()) {
307+
conn.readStringFrame("test.csv");
308+
} catch (IOException e) {
309+
Assert.assertEquals("IOException", e.getCause().getClass().getSimpleName());
310+
}
311+
}
312+
313+
@Test
314+
public void testReadFrame2() {
315+
try (Connection conn = new Connection()) {
316+
conn.readStringFrame("test.csv", Types.FileFormat.CSV, 1, 1);
317+
} catch (IOException e) {
318+
Assert.assertTrue(e.getCause().getMessage().startsWith("File test.csv does not exist on HDFS/LFS"));
319+
}
320+
}
321+
322+
@Test
323+
public void testConvertToStringFrame1() {
324+
try (Connection conn = new Connection()) {
325+
String[][] frame = conn.convertToStringFrame("Hello", META);
326+
Assert.assertEquals("Hello", frame[0][0]);
327+
} catch (IOException e) {
328+
throw new AssertionError(e);
329+
}
330+
}
331+
332+
@Test
333+
public void testConvertToStringFrameException1() {
334+
try (Connection conn = new Connection()) {
335+
conn.convertToFrame("Hello", "{" + META);
336+
} catch (IOException e) {
337+
Assert.assertEquals("NullPointerException", e.getCause().getClass().getSimpleName());
338+
}
339+
}
340+
341+
@Test
342+
public void testConvertToStringFrame2() {
343+
try (Connection conn = new Connection()) {
344+
String[][] frame = conn.convertToStringFrame("1 1 Hello", 1,1);
345+
Assert.assertEquals("Hello", frame[0][0]);
346+
} catch (IOException e) {
347+
throw new AssertionError(e);
348+
}
349+
}
350+
351+
@Test
352+
public void testConvertToStringFrame3() {
353+
try (Connection conn = new Connection()) {
354+
String[][] frame = conn.convertToStringFrame(IOUtilFunctions.toInputStream("Hello"), 1,1, "csv");
355+
Assert.assertEquals("Hello", frame[0][0]);
356+
} catch (IOException e) {
357+
throw new AssertionError(e);
358+
}
359+
}
360+
361+
@Test
362+
public void testConvertToStringFrame4() {
363+
try (Connection conn = new Connection()) {
364+
String[][] frame = conn.convertToStringFrame(IOUtilFunctions.toInputStream("%%MatrixMarket matrix coordinate real"+
365+
" general \n 1 1 1 \n 1 1 Hello"), 1,1, "mm");
366+
Assert.assertEquals("Hello", frame[0][0]);
367+
} catch (IOException e) {
368+
Assert.assertEquals("Failed to create frame reader for unknown format: mm", e.getCause().getMessage());
369+
}
370+
}
371+
372+
@Test
373+
public void testConvertToStringFrameException2() {
374+
try (Connection conn = new Connection()) {
375+
String[][] frame = conn.convertToStringFrame(IOUtilFunctions.toInputStream("Hi"), 1,1, "abc");
376+
Assert.assertEquals("Hello", frame[0][0]);
377+
} catch (IOException e) {
378+
Assert.assertTrue(e.getMessage().startsWith("Invalid input format"));
379+
}
380+
}
293381
}

0 commit comments

Comments
 (0)