|
27 | 27 | import org.apache.sysds.conf.CompilerConfig; |
28 | 28 | import org.apache.sysds.conf.ConfigurationManager; |
29 | 29 | import org.apache.sysds.parser.LanguageException; |
| 30 | +import org.apache.sysds.runtime.frame.data.FrameBlock; |
30 | 31 | import org.apache.sysds.runtime.io.IOUtilFunctions; |
31 | 32 | import org.apache.sysds.runtime.matrix.data.MatrixBlock; |
32 | 33 | import org.apache.sysds.test.AutomatedTestBase; |
@@ -105,13 +106,22 @@ public void testConnectionInvalidInName() throws DMLException { |
105 | 106 |
|
106 | 107 | @Test |
107 | 108 | public void testConnectionParseLanguageException() { |
| 109 | + boolean oldStat = DMLScript.STATISTICS; |
| 110 | + boolean oldJMLCStat = DMLScript.JMLC_MEM_STATISTICS; |
108 | 111 | try (Connection conn = new Connection()) { |
| 112 | + DMLScript.STATISTICS = true; |
| 113 | + conn.gatherMemStats(true); |
| 114 | + Assert.assertTrue(DMLScript.STATISTICS); |
| 115 | + |
109 | 116 | conn.prepareScript("printx('hello')", new String[]{}, new String[]{}); |
110 | 117 | throw new AssertionError("Test should have thrown a DMLException"); |
111 | 118 | } catch (DMLException e) { |
112 | 119 | Throwable cause = e.getCause(); |
113 | 120 | 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 | + } |
115 | 125 | } |
116 | 126 |
|
117 | 127 | @Test |
@@ -290,4 +300,82 @@ public void testConvertToMatrixInvalidFormat() { |
290 | 300 | Assert.assertTrue(e.getMessage().startsWith("Invalid input format")); |
291 | 301 | } |
292 | 302 | } |
| 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 | + } |
293 | 381 | } |
0 commit comments