Mercurial > hg > monetdb-java
comparison tests/OnClientTester.java @ 578:687034945b3f onclient
Pass expected encoding as a constructor parameter to FileTransferHandler
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Thu, 14 Oct 2021 15:25:31 +0200 (2021-10-14) |
parents | 08c9918177b2 |
children | 13134a44dfc8 |
comparison
equal
deleted
inserted
replaced
577:6ab9168ef8e1 | 578:687034945b3f |
---|---|
363 PrintStream ps = new PrintStream(s, false, "UTF-8"); | 363 PrintStream ps = new PrintStream(s, false, "UTF-8"); |
364 ps.println("1|one"); | 364 ps.println("1|one"); |
365 ps.println("2|two"); | 365 ps.println("2|two"); |
366 ps.println("3|three"); | 366 ps.println("3|three"); |
367 ps.close(); | 367 ps.close(); |
368 conn.setUploadHandler(new FileTransferHandler(d, true)); | 368 conn.setUploadHandler(new FileTransferHandler(d, StandardCharsets.UTF_8)); |
369 update("COPY INTO foo FROM 'data.txt' ON CLIENT"); | 369 update("COPY INTO foo FROM 'data.txt' ON CLIENT"); |
370 assertQueryInt("SELECT SUM(i) FROM foo", 6); | 370 assertQueryInt("SELECT SUM(i) FROM foo", 6); |
371 } | 371 } |
372 | 372 |
373 public void test_FileTransferHandlerUploadRefused() throws IOException, SQLException, Failure { | 373 public void test_FileTransferHandlerUploadRefused() throws IOException, SQLException, Failure { |
380 ps.println("2|two"); | 380 ps.println("2|two"); |
381 ps.println("3|three"); | 381 ps.println("3|three"); |
382 ps.close(); | 382 ps.close(); |
383 | 383 |
384 Path d2 = getTmpDir(currentTestName + "2"); | 384 Path d2 = getTmpDir(currentTestName + "2"); |
385 conn.setUploadHandler(new FileTransferHandler(d2, false)); | 385 conn.setUploadHandler(new FileTransferHandler(d2, StandardCharsets.UTF_8)); |
386 String quoted = f.toAbsolutePath().toString().replaceAll("'", "''"); | 386 String quoted = f.toAbsolutePath().toString().replaceAll("'", "''"); |
387 expectError("COPY INTO foo FROM R'"+ quoted + "' ON CLIENT", "not in upload directory"); | 387 expectError("COPY INTO foo FROM R'"+ quoted + "' ON CLIENT", "not in upload directory"); |
388 // connection is still alive | 388 // connection is still alive |
389 assertQueryInt("SELECT SUM(i) FROM foo", 0); | 389 assertQueryInt("SELECT SUM(i) FROM foo", 0); |
390 } | 390 } |
391 | 391 |
392 public void test_FileTransferHandlerDownload() throws SQLException, Failure, IOException { | 392 public void test_FileTransferHandlerDownload() throws SQLException, Failure, IOException { |
393 prepare(); | 393 prepare(); |
394 update("INSERT INTO foo VALUES (42, 'forty-two')"); | 394 update("INSERT INTO foo VALUES (42, 'forty-two')"); |
395 Path d = getTmpDir(currentTestName); | 395 Path d = getTmpDir(currentTestName); |
396 conn.setDownloadHandler(new FileTransferHandler(d, false)); | 396 conn.setDownloadHandler(new FileTransferHandler(d, StandardCharsets.UTF_8)); |
397 update("COPY SELECT * FROM foo INTO 'data.txt' ON CLIENT"); | 397 update("COPY SELECT * FROM foo INTO 'data.txt' ON CLIENT"); |
398 List<String> lines = Files.readAllLines(d.resolve("data.txt")); | 398 List<String> lines = Files.readAllLines(d.resolve("data.txt")); |
399 assertEq("lines written", lines.size(), 1); | 399 assertEq("lines written", lines.size(), 1); |
400 assertEq("line content", lines.get(0), "42|\"forty-two\""); | 400 assertEq("line content", lines.get(0), "42|\"forty-two\""); |
401 // connection is still alive | 401 // connection is still alive |
406 prepare(); | 406 prepare(); |
407 BugFixLevel level = getLevel(); | 407 BugFixLevel level = getLevel(); |
408 update("INSERT INTO foo VALUES (42, 'forty-two')"); | 408 update("INSERT INTO foo VALUES (42, 'forty-two')"); |
409 Path d = getTmpDir(currentTestName); | 409 Path d = getTmpDir(currentTestName); |
410 Path d2 = getTmpDir(currentTestName + "2"); | 410 Path d2 = getTmpDir(currentTestName + "2"); |
411 conn.setDownloadHandler(new FileTransferHandler(d2, false)); | 411 conn.setDownloadHandler(new FileTransferHandler(d2, StandardCharsets.UTF_8)); |
412 String quoted = d.resolve("data.txt").toAbsolutePath().toString().replaceAll("'", "''"); | 412 String quoted = d.resolve("data.txt").toAbsolutePath().toString().replaceAll("'", "''"); |
413 expectError("COPY SELECT * FROM foo INTO R'" + quoted + "' ON CLIENT", "not in download directory"); | 413 expectError("COPY SELECT * FROM foo INTO R'" + quoted + "' ON CLIENT", "not in download directory"); |
414 if (level.compareTo(BugFixLevel.CanRefuseDownload) >= 0) { | 414 if (level.compareTo(BugFixLevel.CanRefuseDownload) >= 0) { |
415 // connection is still alive | 415 // connection is still alive |
416 assertQueryInt("SELECT SUM(i) FROM foo", 42); | 416 assertQueryInt("SELECT SUM(i) FROM foo", 42); |