Mercurial > hg > monetdb-java
comparison tests/OnClientTester.java @ 581:5aef0ea654b1 onclient
Take null to mean the default charset
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Fri, 15 Oct 2021 10:10:52 +0200 (2021-10-15) |
parents | 13134a44dfc8 |
children | 718492fb8714 |
comparison
equal
deleted
inserted
replaced
580:13134a44dfc8 | 581:5aef0ea654b1 |
---|---|
355 // Exception closes the connection | 355 // Exception closes the connection |
356 assertEq("connection is closed", conn.isClosed(), true); | 356 assertEq("connection is closed", conn.isClosed(), true); |
357 } | 357 } |
358 | 358 |
359 public void test_FileTransferHandlerUploadUtf8() throws IOException, SQLException, Failure { | 359 public void test_FileTransferHandlerUploadUtf8() throws IOException, SQLException, Failure { |
360 testFileTransferHandlerUpload("UTF-8"); | 360 testFileTransferHandlerUpload(StandardCharsets.UTF_8, "UTF-8"); |
361 } | 361 } |
362 | 362 |
363 public void test_FileTransferHandlerUploadLatin1() throws IOException, SQLException, Failure { | 363 public void test_FileTransferHandlerUploadLatin1() throws IOException, SQLException, Failure { |
364 testFileTransferHandlerUpload("latin1"); | 364 testFileTransferHandlerUpload(Charset.forName("latin1"), "latin1"); |
365 } | 365 } |
366 | 366 |
367 public void testFileTransferHandlerUpload(String encoding) throws IOException, SQLException, Failure { | 367 public void test_FileTransferHandlerUploadNull() throws IOException, SQLException, Failure { |
368 testFileTransferHandlerUpload(null, Charset.defaultCharset().name()); | |
369 } | |
370 | |
371 public void testFileTransferHandlerUpload(Charset handlerEncoding, String fileEncoding) throws IOException, SQLException, Failure { | |
368 prepare(); | 372 prepare(); |
369 Path d = getTmpDir(currentTestName); | 373 Path d = getTmpDir(currentTestName); |
370 Path f = d.resolve("data.txt"); | 374 Path f = d.resolve("data.txt"); |
371 OutputStream s = Files.newOutputStream(f, CREATE_NEW); | 375 OutputStream s = Files.newOutputStream(f, CREATE_NEW); |
372 PrintStream ps = new PrintStream(s, false, encoding); | 376 PrintStream ps = new PrintStream(s, false, fileEncoding); |
373 ps.println("1|one"); | 377 ps.println("1|one"); |
374 ps.println("2|twø"); | 378 ps.println("2|twø"); |
375 ps.println("3|three"); | 379 ps.println("3|three"); |
376 ps.close(); | 380 ps.close(); |
377 conn.setUploadHandler(new FileTransferHandler(d, Charset.forName(encoding))); | 381 conn.setUploadHandler(new FileTransferHandler(d, handlerEncoding)); |
378 update("COPY INTO foo FROM 'data.txt' ON CLIENT"); | 382 update("COPY INTO foo FROM 'data.txt' ON CLIENT"); |
379 assertQueryInt("SELECT SUM(i) FROM foo", 6); | 383 assertQueryInt("SELECT SUM(i) FROM foo", 6); |
380 assertQueryString("SELECT t FROM foo WHERE i = 2", "twø"); | 384 assertQueryString("SELECT t FROM foo WHERE i = 2", "twø"); |
381 } | 385 } |
382 | 386 |
398 // connection is still alive | 402 // connection is still alive |
399 assertQueryInt("SELECT SUM(i) FROM foo", 0); | 403 assertQueryInt("SELECT SUM(i) FROM foo", 0); |
400 } | 404 } |
401 | 405 |
402 public void test_FileTransferHandlerDownloadUtf8() throws SQLException, Failure, IOException { | 406 public void test_FileTransferHandlerDownloadUtf8() throws SQLException, Failure, IOException { |
403 testFileTransferHandlerDownload(StandardCharsets.UTF_8); | 407 testFileTransferHandlerDownload(StandardCharsets.UTF_8, StandardCharsets.UTF_8); |
404 } | 408 } |
405 | 409 |
406 public void test_FileTransferHandlerDownloadLatin1() throws SQLException, Failure, IOException { | 410 public void test_FileTransferHandlerDownloadLatin1() throws SQLException, Failure, IOException { |
407 Charset latin1 = Charset.forName("latin1"); | 411 Charset latin1 = Charset.forName("latin1"); |
408 testFileTransferHandlerDownload(latin1); | 412 testFileTransferHandlerDownload(latin1, latin1); |
409 } | 413 } |
410 | 414 |
411 public void testFileTransferHandlerDownload(Charset encoding) throws SQLException, Failure, IOException { | 415 public void test_FileTransferHandlerDownloadNull() throws SQLException, Failure, IOException { |
416 testFileTransferHandlerDownload(null, Charset.defaultCharset()); | |
417 } | |
418 | |
419 public void testFileTransferHandlerDownload(Charset handlerEncoding, Charset fileEncoding) throws SQLException, Failure, IOException { | |
412 prepare(); | 420 prepare(); |
413 update("INSERT INTO foo VALUES (42, 'forty-twø')"); | 421 update("INSERT INTO foo VALUES (42, 'forty-twø')"); |
414 Path d = getTmpDir(currentTestName); | 422 Path d = getTmpDir(currentTestName); |
415 conn.setDownloadHandler(new FileTransferHandler(d, encoding)); | 423 conn.setDownloadHandler(new FileTransferHandler(d, handlerEncoding)); |
416 update("COPY SELECT * FROM foo INTO 'data.txt' ON CLIENT"); | 424 update("COPY SELECT * FROM foo INTO 'data.txt' ON CLIENT"); |
417 List<String> lines = Files.readAllLines(d.resolve("data.txt"), encoding); | 425 List<String> lines = Files.readAllLines(d.resolve("data.txt"), fileEncoding); |
418 assertEq("lines written", lines.size(), 1); | 426 assertEq("lines written", lines.size(), 1); |
419 assertEq("line content", lines.get(0), "42|\"forty-twø\""); | 427 assertEq("line content", lines.get(0), "42|\"forty-twø\""); |
420 // connection is still alive | 428 // connection is still alive |
421 assertQueryInt("SELECT SUM(i) FROM foo", 42); | 429 assertQueryInt("SELECT SUM(i) FROM foo", 42); |
422 } | 430 } |