Mercurial > hg > monetdb-java
comparison tests/OnClientTester.java @ 594:613f94a13ad6
Show hexdumps in the File Transfer encoding tests
to track down elusive Windows problem
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Thu, 25 Nov 2021 14:58:22 +0100 (2021-11-25) |
parents | b58f6f26fab0 |
children | c2581dbd1dbf |
comparison
equal
deleted
inserted
replaced
593:f4181beae53d | 594:613f94a13ad6 |
---|---|
10 import org.monetdb.jdbc.MonetConnection.UploadHandler; | 10 import org.monetdb.jdbc.MonetConnection.UploadHandler; |
11 import org.monetdb.jdbc.MonetConnection.DownloadHandler; | 11 import org.monetdb.jdbc.MonetConnection.DownloadHandler; |
12 import org.monetdb.util.FileTransferHandler; | 12 import org.monetdb.util.FileTransferHandler; |
13 | 13 |
14 import java.io.*; | 14 import java.io.*; |
15 import java.lang.Character.UnicodeBlock; | |
15 import java.nio.charset.Charset; | 16 import java.nio.charset.Charset; |
16 import java.nio.charset.StandardCharsets; | 17 import java.nio.charset.StandardCharsets; |
17 import java.nio.file.FileVisitResult; | 18 import java.nio.file.FileVisitResult; |
18 import java.nio.file.Files; | 19 import java.nio.file.Files; |
19 import java.nio.file.Path; | 20 import java.nio.file.Path; |
261 return BugFixLevel.forVersion(major, minor, micro); | 262 return BugFixLevel.forVersion(major, minor, micro); |
262 } | 263 } |
263 | 264 |
264 static BugFixLevel forVersion(int major, int minor, int micro) { | 265 static BugFixLevel forVersion(int major, int minor, int micro) { |
265 BugFixLevel lastValid = Baseline; | 266 BugFixLevel lastValid = Baseline; |
266 for (BugFixLevel level: BugFixLevel.values()) { | 267 for (BugFixLevel level : BugFixLevel.values()) { |
267 if (level.includesVersion(major, minor, micro)) | 268 if (level.includesVersion(major, minor, micro)) |
268 lastValid = level; | 269 lastValid = level; |
269 else | 270 else |
270 break; | 271 break; |
271 } | 272 } |
561 | 562 |
562 private void test_FileTransferHandlerUploadNull() throws IOException, SQLException, Failure { | 563 private void test_FileTransferHandlerUploadNull() throws IOException, SQLException, Failure { |
563 initTest("test_FileTransferHandlerUploadNull"); | 564 initTest("test_FileTransferHandlerUploadNull"); |
564 testFileTransferHandlerUpload(null, Charset.defaultCharset().name()); | 565 testFileTransferHandlerUpload(null, Charset.defaultCharset().name()); |
565 exitTest(); | 566 exitTest(); |
567 } | |
568 | |
569 private String hexdump(String s) | |
570 { | |
571 StringBuilder buf = new StringBuilder(); | |
572 char[] chars = s.toCharArray(); | |
573 for (char c: chars) { | |
574 buf.append(' '); | |
575 buf.append((int)c); | |
576 | |
577 UnicodeBlock b = UnicodeBlock.of(c); | |
578 if (!Character.isISOControl(c) && b != null) { | |
579 if (b != UnicodeBlock.HIGH_SURROGATES && b != UnicodeBlock.LOW_SURROGATES && b != UnicodeBlock.SPECIALS) { | |
580 buf.append("='"); | |
581 buf.append(c); | |
582 buf.append("'"); | |
583 } | |
584 } | |
585 } | |
586 | |
587 return "<" + buf.toString().trim() + ">"; | |
566 } | 588 } |
567 | 589 |
568 private void testFileTransferHandlerUpload(Charset handlerEncoding, String fileEncoding) throws IOException, SQLException, Failure { | 590 private void testFileTransferHandlerUpload(Charset handlerEncoding, String fileEncoding) throws IOException, SQLException, Failure { |
569 prepare(); | 591 prepare(); |
570 Path d = getTmpDir(currentTestName); | 592 Path d = getTmpDir(currentTestName); |
576 ps.println("3|three"); | 598 ps.println("3|three"); |
577 ps.close(); | 599 ps.close(); |
578 conn.setUploadHandler(new FileTransferHandler(d, handlerEncoding)); | 600 conn.setUploadHandler(new FileTransferHandler(d, handlerEncoding)); |
579 update("COPY INTO foo FROM 'data.txt' ON CLIENT"); | 601 update("COPY INTO foo FROM 'data.txt' ON CLIENT"); |
580 assertQueryInt("SELECT SUM(i) FROM foo", 6); | 602 assertQueryInt("SELECT SUM(i) FROM foo", 6); |
581 assertQueryString("SELECT t FROM foo WHERE i = 2", "twø"); | 603 final String result = queryString("SELECT t FROM foo WHERE i = 2"); |
604 String two = "twø"; | |
605 // | |
606 String hexTwo = hexdump(two); | |
607 String hexResult = hexdump(result); | |
608 assertEq("query result hexdump", hexTwo, hexResult); | |
609 assertEq("query result", two, result); | |
582 } | 610 } |
583 | 611 |
584 private void test_FileTransferHandlerUploadRefused() throws IOException, SQLException, Failure { | 612 private void test_FileTransferHandlerUploadRefused() throws IOException, SQLException, Failure { |
585 initTest("test_FileTransferHandlerUploadRefused"); | 613 initTest("test_FileTransferHandlerUploadRefused"); |
586 prepare(); | 614 prepare(); |