Mercurial > hg > monetdb-java
annotate tests/OnClientTester.java @ 716:aeb268156580
Updated Copyright year.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 05 Jan 2023 12:03:22 +0100 (2023-01-05) |
parents | 3442d331cad0 |
children | 8bd314491d3e |
rev | line source |
---|---|
542
d462000fc410
Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
1 /* |
d462000fc410
Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
d462000fc410
Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
d462000fc410
Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
d462000fc410
Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
5 * |
716
aeb268156580
Updated Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
693
diff
changeset
|
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2023 MonetDB B.V. |
542
d462000fc410
Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
7 */ |
d462000fc410
Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
8 |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
9 import org.monetdb.jdbc.MonetConnection; |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
534
diff
changeset
|
10 import org.monetdb.jdbc.MonetConnection.UploadHandler; |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
534
diff
changeset
|
11 import org.monetdb.jdbc.MonetConnection.DownloadHandler; |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
12 import org.monetdb.util.FileTransferHandler; |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
13 |
520
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
14 import java.io.*; |
594
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
15 import java.lang.Character.UnicodeBlock; |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
16 import java.nio.charset.Charset; |
526
6060ca8c5c1a
Add test for uploadFrom methods
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
525
diff
changeset
|
17 import java.nio.charset.StandardCharsets; |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
18 import java.nio.file.FileVisitResult; |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
19 import java.nio.file.Files; |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
20 import java.nio.file.Path; |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
21 import java.nio.file.SimpleFileVisitor; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
22 import java.nio.file.attribute.BasicFileAttributes; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
23 import java.sql.Connection; |
589
718492fb8714
Answer to question. Please test if it works for your system.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
581
diff
changeset
|
24 import java.sql.DriverManager; |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
25 import java.sql.ResultSet; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
26 import java.sql.Statement; |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
27 import java.sql.SQLException; |
601
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
28 import java.util.ArrayList; |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
29 import java.util.List; |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
30 import java.util.Random; |
604
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
31 import java.util.zip.GZIPOutputStream; |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
32 |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
33 import static java.nio.file.StandardOpenOption.CREATE_NEW; |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
34 |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
35 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
36 /** |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
37 * Program to test MonetDB JDBC Driver in combination with SQL: |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
38 * COPY ... INTO ... ON CLIENT |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
39 * commands. |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
40 * This allows Java programmers to locally (so ON CLIENT) stream csv data |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
41 * to and from the MonetDB server for fast bulk data import / export. |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
42 * |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
43 * Specifically it tests the MonetDB specific extensions to register upload and download handlers |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
44 * see {@link org.monetdb.jdbc.MonetConnection#setUploadHandler(UploadHandler)} |
615
34a15cd8cfc2
Fix doc link
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
614
diff
changeset
|
45 * see {@link org.monetdb.jdbc.MonetConnection#setDownloadHandler(DownloadHandler)} |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
46 * and streaming of csv data to and from the MonetDB server using MAPI protocol. |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
47 * |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
48 * It also tests reading / writing data from / to a local file using |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
49 * {@link org.monetdb.util.FileTransferHandler} |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
50 * |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
51 * @author JvR |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
52 * @version 0.1 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
53 */ |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
54 public final class OnClientTester { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
55 public static final int VERBOSITY_NONE = 0; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
56 public static final int VERBOSITY_ON = 1; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
57 public static final int VERBOSITY_SHOW_ALL = 2; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
58 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
59 private final String jdbcUrl; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
60 private final int verbosity; |
601
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
61 private final ArrayList<String> selectedTests; |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
62 private String currentTestName; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
63 private long startTime; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
64 private MonetConnection conn; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
65 private Statement stmt; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
66 private StringBuilder outBuffer; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
67 private Path tmpDir; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
68 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
69 public OnClientTester(String jdbcUrl, int verbosity) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
70 this.jdbcUrl = jdbcUrl; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
71 this.verbosity = verbosity; |
601
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
72 this.selectedTests = null; |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
73 } |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
74 |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
75 public OnClientTester(String jdbcUrl, int verbosity, ArrayList<String> selectedTests) { |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
76 this.jdbcUrl = jdbcUrl; |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
77 this.verbosity = verbosity; |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
78 this.selectedTests = selectedTests; |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
79 } |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
80 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
81 public static void main(String[] args) { |
524
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
82 String jdbcUrl = null; |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
83 int verbosity = 0; |
622
61877c1f19f6
Optimizations
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
621
diff
changeset
|
84 ArrayList<String> selectedTests = new ArrayList<String>(); |
545
79393647d7fb
Call Class.forName("...MonetDriver") from main() in OnClientTester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
544
diff
changeset
|
85 |
525
70ff796c42f7
Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
524
diff
changeset
|
86 for (String arg : args) { |
524
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
87 if (arg.equals("-v")) |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
88 verbosity++; |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
89 else if (arg.equals("-vv")) |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
90 verbosity += 2; |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
91 else if (jdbcUrl == null) |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
92 jdbcUrl = arg; |
601
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
93 else if (arg.startsWith("-")){ |
524
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
94 System.err.println("Unexpected argument " + arg); |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
95 System.exit(2); |
601
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
96 } else { |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
97 selectedTests.add(arg); |
524
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
98 } |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
99 } |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
100 if (jdbcUrl == null || jdbcUrl.isEmpty()) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
101 System.err.println("Missing required startup argument: JDBC_connection_URL"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
102 System.exit(1); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
103 } |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
104 |
601
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
105 OnClientTester tester = new OnClientTester(jdbcUrl, verbosity, selectedTests); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
106 int failures = tester.runTests(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
107 if (failures > 0) |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
108 System.exit(-1); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
109 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
110 |
601
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
111 boolean isSelected(String name) { |
602
662e8de9b002
Fix selection criterium
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
601
diff
changeset
|
112 return selectedTests == null || selectedTests.isEmpty() || selectedTests.contains(name); |
601
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
113 } |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
114 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
115 public int runTests() { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
116 if (! openConnection()) |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
117 return 1; // failed to open JDBC connection to MonetDB |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
118 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
119 outBuffer = new StringBuilder(1024); |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
120 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
121 int failures = 0; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
122 try { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
123 // all test methods start with test_ and have no arguments |
601
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
124 if (isSelected("BugFixLevel")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
125 test_BugFixLevel(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
126 if (isSelected("Upload")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
127 test_Upload(); |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
128 if (isSelected("UploadCrLf")) |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
129 test_UploadCrLf(); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
130 if (isSelected("NormalizeCrLf")) |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
131 test_NormalizeCrLf(); |
601
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
132 if (isSelected("ClientRefusesUpload")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
133 test_ClientRefusesUpload(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
134 if (isSelected("Offset0")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
135 test_Offset0(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
136 if (isSelected("Offset1")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
137 test_Offset1(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
138 if (isSelected("Offset5")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
139 test_Offset5(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
140 if (isSelected("ServerStopsReading")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
141 test_ServerStopsReading(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
142 if (isSelected("Download")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
143 test_Download(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
144 if (isSelected("ClientRefusesDownload")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
145 test_ClientRefusesDownload(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
146 if (isSelected("LargeUpload")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
147 test_LargeUpload(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
148 if (isSelected("LargeDownload")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
149 test_LargeDownload(); |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
150 if (isSelected("DownloadCrLf")) |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
151 test_DownloadCrLf(); |
601
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
152 if (isSelected("UploadFromStream")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
153 test_UploadFromStream(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
154 if (isSelected("UploadFromReader")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
155 test_UploadFromReader(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
156 if (isSelected("UploadFromReaderOffset")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
157 test_UploadFromReaderOffset(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
158 if (isSelected("FailUploadLate")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
159 test_FailUploadLate(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
160 if (isSelected("FailUploadLate2")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
161 test_FailUploadLate2(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
162 if (isSelected("FailDownloadLate")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
163 test_FailDownloadLate(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
164 if (isSelected("FileTransferHandlerUploadUtf8")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
165 test_FileTransferHandlerUploadUtf8(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
166 if (isSelected("FileTransferHandlerUploadLatin1")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
167 test_FileTransferHandlerUploadLatin1(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
168 if (isSelected("FileTransferHandlerUploadNull")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
169 test_FileTransferHandlerUploadNull(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
170 if (isSelected("FileTransferHandlerUploadRefused")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
171 test_FileTransferHandlerUploadRefused(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
172 if (isSelected("FileTransferHandlerDownloadUtf8")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
173 test_FileTransferHandlerDownloadUtf8(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
174 if (isSelected("FileTransferHandlerDownloadLatin1")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
175 test_FileTransferHandlerDownloadLatin1(); |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
176 if (isSelected("FileTransferHandlerDownloadNull")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
177 test_FileTransferHandlerDownloadNull(); |
604
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
178 if (isSelected("test_FileTransferHandlerUploadNotCompressed")) |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
179 test_FileTransferHandlerUploadNotCompressed(); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
180 if (isSelected("test_FileTransferHandlerUploadNotCompressedSkip")) |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
181 test_FileTransferHandlerUploadNotCompressedSkip(); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
182 if (isSelected("test_FileTransferHandlerUploadCompressed")) |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
183 test_FileTransferHandlerUploadCompressed(); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
184 if (isSelected("test_FileTransferHandlerUploadCompressedSkip")) |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
185 test_FileTransferHandlerUploadCompressedSkip(); |
601
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
186 if (isSelected("FileTransferHandlerDownloadRefused")) |
2b5516ed0d92
Allow to select specific OnClient tests from command line
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
600
diff
changeset
|
187 test_FileTransferHandlerDownloadRefused(); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
188 } catch (Failure e) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
189 failures++; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
190 System.err.println(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
191 System.err.println("Test " + currentTestName + " failed"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
192 dumpOutput(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
193 } catch (Exception e) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
194 failures++; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
195 System.err.println(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
196 System.err.println("Test " + currentTestName + " failed:"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
197 e.printStackTrace(System.err); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
198 dumpOutput(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
199 // Show the inner bits of the exception again, they may have scrolled off screen |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
200 Throwable t = e; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
201 while (t.getCause() != null) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
202 t = t.getCause(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
203 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
204 System.err.println("Innermost cause was " + t); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
205 if (t.getStackTrace().length > 0) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
206 System.err.println(" at " + t.getStackTrace()[0]); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
207 } |
592
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
208 } finally { |
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
209 try { |
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
210 // cleanup created test table |
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
211 execute("DROP TABLE IF EXISTS foo"); |
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
212 } catch (SQLException e) { /* ignore */ } |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
213 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
214 closeConnection(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
215 return failures; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
216 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
217 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
218 private boolean openConnection() { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
219 try { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
220 // make a connection to MonetDB, its reused for all tests |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
221 final Connection genericConnection = DriverManager.getConnection(jdbcUrl); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
222 conn = genericConnection.unwrap(MonetConnection.class); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
223 stmt = conn.createStatement(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
224 return true; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
225 } catch (SQLException e) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
226 System.err.println("Failed to connect using JDBC URL: " + jdbcUrl); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
227 System.err.println(e); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
228 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
229 return false; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
230 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
231 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
232 private void closeConnection() { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
233 if (stmt != null) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
234 try { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
235 stmt.close(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
236 } catch (SQLException e) { /* ignore */ } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
237 stmt = null; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
238 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
239 if (conn != null) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
240 try { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
241 conn.close(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
242 } catch (Exception e) { /* ignore */ } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
243 conn = null; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
244 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
245 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
246 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
247 private void initTest(final String name) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
248 currentTestName = name; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
249 outBuffer.setLength(0); // clear the output log buffer |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
250 startTime = System.currentTimeMillis(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
251 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
252 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
253 private void exitTest() { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
254 if (verbosity > VERBOSITY_ON) |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
255 System.err.println(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
256 if (verbosity >= VERBOSITY_ON) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
257 final long duration = System.currentTimeMillis() - startTime; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
258 System.err.println("Test " + currentTestName + " succeeded in " + duration + "ms"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
259 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
260 if (verbosity >= VERBOSITY_SHOW_ALL) |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
261 dumpOutput(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
262 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
263 if (conn.isClosed()) |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
264 openConnection(); // restore connection for next test |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
265 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
266 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
267 private void dumpOutput() { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
268 final String output = outBuffer.toString(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
269 if (output.isEmpty()) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
270 System.err.println("(Test " + currentTestName + " did not produce any output)"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
271 } else { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
272 System.err.println("------ Accumulated output for test " + currentTestName + ":"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
273 System.err.println(output); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
274 System.err.println("------ End of accumulated output"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
275 } |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
276 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
277 |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
278 /// Some tests have to work limitations of the protocol or bugs in the server. |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
279 /// This Enum is used to indicate the possibilities. |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
280 private enum BugFixLevel { |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
281 /// Only those tests that work with older MonetDB versions |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
282 Baseline(0, 0, 0), |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
283 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
284 /// Connection keeps working after download request has been refused by client |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
285 CanRefuseDownload(11, 41, 12), |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
286 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
287 ; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
288 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
289 private final int major; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
290 private final int minor; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
291 private final int micro; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
292 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
293 BugFixLevel(int major, int minor, int micro) { |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
294 this.major = major; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
295 this.minor = minor; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
296 this.micro = micro; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
297 } |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
298 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
299 boolean includesVersion(int major, int minor, int micro) { |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
300 if (major > this.major) |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
301 return true; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
302 if (major < this.major) |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
303 return false; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
304 if (minor > this.minor) |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
305 return true; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
306 if (minor < this.minor) |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
307 return false; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
308 return micro >= this.micro; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
309 } |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
310 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
311 static BugFixLevel forVersion(String version) { |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
312 String[] parts = version.split("[.]", 3); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
313 assert parts.length == 3; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
314 int major = Integer.parseInt(parts[0]); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
315 int minor = Integer.parseInt(parts[1]); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
316 int micro = Integer.parseInt(parts[2]); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
317 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
318 return BugFixLevel.forVersion(major, minor, micro); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
319 } |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
320 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
321 static BugFixLevel forVersion(int major, int minor, int micro) { |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
322 BugFixLevel lastValid = Baseline; |
594
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
323 for (BugFixLevel level : BugFixLevel.values()) { |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
324 if (level.includesVersion(major, minor, micro)) |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
325 lastValid = level; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
326 else |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
327 break; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
328 } |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
329 return lastValid; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
330 } |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
331 } |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
332 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
333 private void prepare() throws SQLException { |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
334 execute("DROP TABLE IF EXISTS foo"); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
335 execute("CREATE TABLE foo (i INT, t CLOB)"); |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
336 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
337 |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
338 private BugFixLevel getLevel() throws SQLException, Failure { |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
339 String version = queryString("SELECT value FROM environment WHERE name = 'monet_version'"); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
340 BugFixLevel level = BugFixLevel.forVersion(version); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
341 outBuffer.append(" NOTE: version ").append(version).append(" means level = ").append(level).append("\n"); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
342 return level; |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
343 } |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
344 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
345 private void test_BugFixLevel() throws Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
346 initTest("test_BugFixLevel"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
347 |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
348 assertEq("Baseline includes 0.0.0", true, BugFixLevel.Baseline.includesVersion(0, 0, 0)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
349 assertEq("Baseline includes 11.41.11", true, BugFixLevel.Baseline.includesVersion(11, 41, 11)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
350 assertEq("Baseline includes 11.41.12", true, BugFixLevel.Baseline.includesVersion(11, 41, 12)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
351 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
352 assertEq("CanRefuseDownload includes 0.0.0", false, BugFixLevel.CanRefuseDownload.includesVersion(0, 0, 0)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
353 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
354 assertEq("CanRefuseDownload includes 11.0.0", false, BugFixLevel.CanRefuseDownload.includesVersion(11, 0, 0)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
355 assertEq("CanRefuseDownload includes 12.0.0", true, BugFixLevel.CanRefuseDownload.includesVersion(12, 0, 0)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
356 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
357 assertEq("CanRefuseDownload includes 11.41.0", false, BugFixLevel.CanRefuseDownload.includesVersion(11, 41, 0)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
358 assertEq("CanRefuseDownload includes 11.42.0", true, BugFixLevel.CanRefuseDownload.includesVersion(11, 42, 0)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
359 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
360 assertEq("CanRefuseDownload includes 11.41.11", false, BugFixLevel.CanRefuseDownload.includesVersion(11, 41, 11)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
361 assertEq("CanRefuseDownload includes 11.41.12", true, BugFixLevel.CanRefuseDownload.includesVersion(11, 41, 12)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
362 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
363 assertEq("Level for 0.0.0", BugFixLevel.Baseline, BugFixLevel.forVersion(0, 0, 0)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
364 assertEq("Level for 11.0.0", BugFixLevel.Baseline, BugFixLevel.forVersion(11, 0, 0)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
365 assertEq("Level for 11.41.0", BugFixLevel.Baseline, BugFixLevel.forVersion(11, 41, 0)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
366 assertEq("Level for 11.41.11", BugFixLevel.Baseline, BugFixLevel.forVersion(11, 41, 11)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
367 assertEq("Level for 11.41.12", BugFixLevel.CanRefuseDownload, BugFixLevel.forVersion(11, 41, 12)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
368 assertEq("Level for 11.42.0", BugFixLevel.CanRefuseDownload, BugFixLevel.forVersion(11, 42, 0)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
369 assertEq("Level for 12.0.0", BugFixLevel.CanRefuseDownload, BugFixLevel.forVersion(12, 0, 0)); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
370 |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
371 assertEq("Level for \"11.41.11\"", BugFixLevel.Baseline, BugFixLevel.forVersion("11.41.11")); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
372 assertEq("Level for \"11.41.12\"", BugFixLevel.CanRefuseDownload, BugFixLevel.forVersion("11.41.12")); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
373 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
374 exitTest(); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
375 } |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
376 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
377 private void test_Upload() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
378 initTest("test_Upload"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
379 prepare(); |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
380 MyUploadHandler handler = new MyUploadHandler(100); |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
381 conn.setUploadHandler(handler); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
382 update("COPY INTO foo FROM 'banana' ON CLIENT"); |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
383 assertEq("cancellation callback called", false, handler.isCancelled()); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
384 assertQueryInt("SELECT COUNT(*) FROM foo", 100); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
385 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
386 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
387 |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
388 private void test_UploadCrLf() throws SQLException, Failure { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
389 initTest("test_UploadCrLf"); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
390 prepare(); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
391 MonetConnection.UploadHandler handler = new MonetConnection.UploadHandler() { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
392 @Override |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
393 public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, long linesToSkip) throws IOException { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
394 String contentText = "100|foo\r\n10|bar\r\n1|baz\r\n"; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
395 byte[] contentBytes = contentText.getBytes(StandardCharsets.UTF_8); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
396 ByteArrayInputStream contentStream = new ByteArrayInputStream(contentBytes); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
397 handle.uploadFrom(contentStream); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
398 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
399 }; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
400 conn.setUploadHandler(handler); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
401 update("COPY INTO foo FROM 'banana' ON CLIENT"); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
402 assertQueryInt("SELECT SUM(i * LENGTH(t)) FROM foo", 333); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
403 exitTest(); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
404 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
405 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
406 private void test_NormalizeCrLf() throws Failure, IOException { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
407 initTest("test_NormalizeCrLf"); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
408 String[] fragments = { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
409 /* does not end in pending cr */ "\r\naaa\n\n\r\n", |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
410 /* ends in pending cr */ "\n\r\naaa\r", |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
411 /* clears it */ "\n", |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
412 /* means call the single-argument write(), cr now pending */ "13", |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
413 /* again, should flush the pending one and remain pending */ "13", |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
414 /* now the pending cr should be dropped */ "10", |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
415 /* same as above, but with arrays */ "\r", "\r", "\n", |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
416 /* empty write should not clear the pending */ "\r", "", "\n", |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
417 /* trailing \r */ "\r", |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
418 }; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
419 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
420 ByteArrayOutputStream out0 = new ByteArrayOutputStream(); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
421 MonetConnection.StripCrLfStream out = new MonetConnection.StripCrLfStream(out0); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
422 ByteArrayOutputStream ref = new ByteArrayOutputStream(); |
621
5e09597054d6
Resolve javac -Xlint warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
618
diff
changeset
|
423 ArrayList<Integer> fragmentPositions = new ArrayList<Integer>(); |
5e09597054d6
Resolve javac -Xlint warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
618
diff
changeset
|
424 ArrayList<Boolean> wasPending = new ArrayList<Boolean>(); |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
425 for (String f : fragments) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
426 int pos = out0.toByteArray().length; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
427 boolean pending = out.pending(); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
428 fragmentPositions.add(pos); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
429 wasPending.add(pending); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
430 if (!f.isEmpty() && Character.isDigit(f.charAt(0))) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
431 int n = Integer.parseInt(f); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
432 ref.write(n); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
433 out.write(n); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
434 } else { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
435 byte[] bytes = f.getBytes(StandardCharsets.UTF_8); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
436 ref.write(bytes); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
437 out.write(bytes); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
438 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
439 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
440 out.close(); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
441 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
442 String data = new String(out0.toByteArray()); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
443 String refData = new String(ref.toByteArray()).replaceAll("\r\n", "\n"); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
444 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
445 outBuffer.append("GOT\t\tEXPECTED\n"); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
446 int fragNo = 0; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
447 boolean different = false; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
448 for (int i = 0; i < data.length() || i < refData.length(); i++) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
449 while (fragNo < fragmentPositions.size() && i == fragmentPositions.get(fragNo)) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
450 outBuffer.append("(Start of fragment "); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
451 outBuffer.append(fragNo); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
452 if (wasPending.get(fragNo)) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
453 outBuffer.append(", cr pending"); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
454 } else { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
455 outBuffer.append(", cr not pending"); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
456 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
457 outBuffer.append(':'); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
458 String frag = fragments[fragNo]; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
459 if (!frag.isEmpty() && Character.isDigit(frag.charAt(0))) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
460 outBuffer.append(Integer.parseInt(frag)); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
461 } else { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
462 for (int k = 0; k < frag.length(); k++) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
463 int c = frag.charAt(k); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
464 outBuffer.append(' '); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
465 outBuffer.append(c); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
466 if (c == '\n' && k != frag.length() - 1) |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
467 outBuffer.append(" "); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
468 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
469 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
470 outBuffer.append(")\n"); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
471 fragNo++; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
472 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
473 int left = i < data.length() ? data.charAt(i) : 0; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
474 int right = i < refData.length() ? refData.charAt(i) : 0; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
475 outBuffer.append(left); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
476 outBuffer.append("\t\t"); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
477 outBuffer.append(right); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
478 if (!different && left != right) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
479 outBuffer.append("\t\t <---------------------- first difference found!"); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
480 different = true; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
481 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
482 outBuffer.append('\n'); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
483 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
484 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
485 if (different) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
486 fail("Normalized text is different than expected"); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
487 } |
614
2eb21a7167f9
Add missing call to exitTest
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
488 exitTest(); |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
489 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
490 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
491 private void test_ClientRefusesUpload() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
492 initTest("test_ClientRefusesUpload"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
493 prepare(); |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
494 MyUploadHandler handler = new MyUploadHandler("immediate error"); |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
495 conn.setUploadHandler(handler); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
496 expectError("COPY INTO foo FROM 'banana' ON CLIENT", "immediate error"); |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
497 assertEq("cancellation callback called", false, handler.isCancelled()); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
498 assertQueryInt("SELECT COUNT(*) FROM foo", 0); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
499 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
500 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
501 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
502 private void test_Offset0() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
503 initTest("test_Offset0"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
504 prepare(); |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
505 MyUploadHandler handler = new MyUploadHandler(100); |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
506 conn.setUploadHandler(handler); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
507 update("COPY OFFSET 0 INTO foo FROM 'banana' ON CLIENT"); |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
508 assertEq("cancellation callback called", false, handler.isCancelled()); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
509 assertQueryInt("SELECT MIN(i) FROM foo", 1); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
510 assertQueryInt("SELECT MAX(i) FROM foo", 100); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
511 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
512 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
513 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
514 private void test_Offset1() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
515 initTest("test_Offset1"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
516 prepare(); |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
517 MyUploadHandler handler = new MyUploadHandler(100); |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
518 conn.setUploadHandler(handler); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
519 update("COPY OFFSET 1 INTO foo FROM 'banana' ON CLIENT"); |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
520 assertEq("cancellation callback called", false, handler.isCancelled()); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
521 assertQueryInt("SELECT MIN(i) FROM foo", 1); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
522 assertQueryInt("SELECT MAX(i) FROM foo", 100); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
523 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
524 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
525 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
526 private void test_Offset5() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
527 initTest("test_Offset5"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
528 prepare(); |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
529 MyUploadHandler handler = new MyUploadHandler(100); |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
530 conn.setUploadHandler(handler); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
531 update("COPY OFFSET 5 INTO foo FROM 'banana' ON CLIENT"); |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
532 assertEq("cancellation callback called", false, handler.isCancelled()); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
533 assertQueryInt("SELECT MIN(i) FROM foo", 5); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
534 assertQueryInt("SELECT MAX(i) FROM foo", 100); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
535 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
536 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
537 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
538 private void test_ServerStopsReading() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
539 initTest("test_ServerStopsReading"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
540 prepare(); |
693
3442d331cad0
In test_ServerStopsReading, wait longer for the server to cancel the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
622
diff
changeset
|
541 long n = 2 * 1024 * 1024 / 10; |
3442d331cad0
In test_ServerStopsReading, wait longer for the server to cancel the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
622
diff
changeset
|
542 MyUploadHandler handler = new MyUploadHandler(n); |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
543 conn.setUploadHandler(handler); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
544 update("COPY 10 RECORDS INTO foo FROM 'banana' ON CLIENT"); |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
545 assertEq("cancellation callback called", true, handler.isCancelled()); |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
546 assertEq("handler encountered write error", true, handler.encounteredWriteError()); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
547 // connection is still alive |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
548 assertQueryInt("SELECT COUNT(i) FROM foo", 10); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
549 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
550 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
551 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
552 private void test_Download(int n) throws SQLException, Failure { |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
553 prepare(); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
554 MyDownloadHandler handler = new MyDownloadHandler(); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
555 conn.setDownloadHandler(handler); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
556 String q = "INSERT INTO foo SELECT value as i, 'number' || value AS t FROM sys.generate_series(0, " + n + ")"; |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
557 update(q); |
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
558 update("COPY (SELECT * FROM foo) INTO 'banana' ON CLIENT"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
559 assertEq("download attempts", 1, handler.countAttempts()); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
560 assertEq("lines downloaded", n, handler.lineCount()); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
561 // connection is still alive |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
562 assertQueryInt("SELECT COUNT(*) FROM foo", n); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
563 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
564 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
565 private void test_Download() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
566 initTest("test_Download"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
567 test_Download(100); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
568 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
569 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
570 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
571 private void test_ClientRefusesDownload() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
572 initTest("test_ClientRefusesDownload"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
573 prepare(); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
574 BugFixLevel level = getLevel(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
575 MyDownloadHandler handler = new MyDownloadHandler("download refused"); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
576 conn.setDownloadHandler(handler); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
577 update("INSERT INTO foo SELECT value as i, 'number' || value AS t FROM sys.generate_series(0, 100)"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
578 expectError("COPY (SELECT * FROM foo) INTO 'banana' ON CLIENT", "download refused"); |
534
b437529144f1
Learn to live with server closing connection if client refuses
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
579 // Wish it were different but the server closes the connection |
b437529144f1
Learn to live with server closing connection if client refuses
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
580 expectError("SELECT 42 -- check if the connection still works", "Connection to server lost!"); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
581 if (level.compareTo(BugFixLevel.CanRefuseDownload) >= 0) { |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
582 // connection is still alive |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
583 assertQueryInt("SELECT COUNT(*) FROM foo", 100); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
584 } |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
585 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
586 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
587 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
588 private void test_LargeUpload() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
589 initTest("test_LargeUpload"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
590 prepare(); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
591 int n = 4_000_000; |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
592 MyUploadHandler handler = new MyUploadHandler(n); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
593 conn.setUploadHandler(handler); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
594 handler.setChunkSize(1024 * 1024); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
595 update("COPY INTO foo FROM 'banana' ON CLIENT"); |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
596 assertEq("cancellation callback called", false, handler.isCancelled()); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
597 // connection is still alive |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
598 assertQueryInt("SELECT COUNT(DISTINCT i) FROM foo", n); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
599 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
600 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
601 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
602 private void test_LargeDownload() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
603 initTest("test_LargeDownload"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
604 test_Download(4_000_000); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
605 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
606 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
607 |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
608 private void test_DownloadCrLf() throws SQLException, Failure, IOException { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
609 |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
610 // This tests forces line ending conversion and reads in small batches, hoping to trigger corner cases |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
611 |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
612 initTest("test_DownloadCrLf"); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
613 prepare(); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
614 update("ALTER TABLE foo DROP COLUMN t"); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
615 update("ALTER TABLE foo ADD COLUMN j INT"); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
616 update("INSERT INTO foo SELECT rand() % CASE WHEN value % 10 = 0 THEN 1000 ELSE 10 END AS i, 0 AS j FROM generate_series(0, 500000)"); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
617 ByteArrayOutputStream target = new ByteArrayOutputStream(); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
618 Random rng = new Random(42); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
619 DownloadHandler handler = (handle, name, textMode) -> { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
620 handle.setLineSeparator("\r\n"); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
621 InputStream s = handle.getStream(); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
622 byte[] buf = new byte[10]; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
623 boolean expectEof = false; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
624 for (;;) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
625 int n = rng.nextInt(buf.length - 1) + 1; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
626 int nread = s.read(buf, 0, n); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
627 if (nread < 0) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
628 break; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
629 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
630 target.write(buf, 0, nread); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
631 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
632 |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
633 }; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
634 conn.setDownloadHandler(handler); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
635 update("COPY SELECT * FROM foo INTO 'banana' ON CLIENT"); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
636 // go to String instead of byte[] because Strings have handy replace methods. |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
637 String result = new String(target.toByteArray(), StandardCharsets.UTF_8); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
638 |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
639 // It should contain only \r\n's, no lonely \r's or \n's. |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
640 String replaced = result.replaceAll("\r\n", "XX"); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
641 |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
642 assertEq("Index of first lonely \\r", -1, replaced.indexOf('\r')); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
643 assertEq("Index of first lonely \\n", -1, replaced.indexOf('\n')); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
644 |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
645 String withoutData = result.replaceAll("[0-9]", ""); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
646 assertEq("Length after dropping data, modulo 3", 0, withoutData.length() % 3); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
647 for (int i = 0; i < withoutData.length(); i += 3) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
648 String sub = withoutData.substring(i, i+3); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
649 if (!sub.equals("|\r\n")) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
650 fail(String.format( |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
651 "At index %d out of %d in the skeleton (=digits removed) we find <%02x %02x %02x> instead of <7c 0d 0a>", |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
652 i, withoutData.length(), |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
653 (int)sub.charAt(0), (int)sub.charAt(1), (int)sub.charAt(2))); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
654 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
655 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
656 // only to show some succesful output if the above succeeds |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
657 assertEq("Every 3-byte normalized chunk", "|\\r\\n", "|\\r\\n"); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
658 |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
659 exitTest(); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
660 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
661 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
662 private void test_UploadFromStream() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
663 initTest("test_UploadFromStream"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
664 prepare(); |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
534
diff
changeset
|
665 UploadHandler handler = new UploadHandler() { |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
666 final String data = "1|one\n2|two\n3|three\n"; |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
667 |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
668 @Override |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
669 public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, long linesToSkip) throws IOException { |
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
670 // ignoring linesToSkip as it's not used in this test |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
671 ByteArrayInputStream s = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
672 handle.uploadFrom(s); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
673 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
674 }; |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
675 conn.setUploadHandler(handler); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
676 update("COPY INTO foo FROM 'banana' ON CLIENT"); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
677 // connection is still alive |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
678 assertQueryInt("SELECT i FROM foo WHERE t = 'three'", 3); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
679 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
680 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
681 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
682 private void test_UploadFromReader() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
683 initTest("test_UploadFromReader"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
684 prepare(); |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
534
diff
changeset
|
685 UploadHandler handler = new UploadHandler() { |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
686 final String data = "1|one\n2|two\n3|three\n"; |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
687 |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
688 @Override |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
689 public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, long linesToSkip) throws IOException { |
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
690 // ignoring linesToSkip as it's not used in this test |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
691 StringReader r = new StringReader(data); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
692 handle.uploadFrom(r); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
693 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
694 }; |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
695 conn.setUploadHandler(handler); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
696 update("COPY INTO foo FROM 'banana' ON CLIENT"); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
697 assertQueryInt("SELECT i FROM foo WHERE t = 'three'", 3); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
698 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
699 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
700 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
701 private void test_UploadFromReaderOffset() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
702 initTest("test_UploadFromReaderOffset"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
703 prepare(); |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
534
diff
changeset
|
704 UploadHandler handler = new UploadHandler() { |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
705 final String data = "1|one\n2|two\n3|three\n"; |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
706 |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
707 @Override |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
708 public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, long linesToSkip) throws IOException { |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
709 BufferedReader r = new BufferedReader(new StringReader(data)); |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
710 handle.uploadFrom(r, linesToSkip); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
711 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
712 }; |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
713 conn.setUploadHandler(handler); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
714 update("COPY OFFSET 2 INTO foo FROM 'banana' ON CLIENT"); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
715 assertQueryInt("SELECT i FROM foo WHERE t = 'three'", 3); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
716 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
717 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
718 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
719 private void test_FailUploadLate() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
720 initTest("test_FailUploadLate"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
721 prepare(); |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
722 MyUploadHandler handler = new MyUploadHandler(100, 50, "i don't like line 50"); |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
723 conn.setUploadHandler(handler); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
724 expectError("COPY INTO foo FROM 'banana' ON CLIENT", "i don't like"); |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
725 assertEq("cancellation callback called", false, handler.isCancelled()); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
726 assertEq("connection is closed", true, conn.isClosed()); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
727 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
728 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
729 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
730 private void test_FailUploadLate2() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
731 initTest("test_FailUploadLate2"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
732 // Here we send empty lines only, to check if the server detects it properly instead |
544
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
733 // of simply complaining about an incomplete file. |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
734 prepare(); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
735 UploadHandler handler = new UploadHandler() { |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
736 @Override |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
737 public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, long linesToSkip) throws IOException { |
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
738 // ignoring linesToSkip as it's not used in this test |
544
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
739 PrintStream stream = handle.getStream(); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
740 for (int i = 1; i <= 20_000; i++) |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
741 stream.println(); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
742 stream.flush(); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
743 throw new IOException("exception after all"); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
744 } |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
745 }; |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
746 conn.setUploadHandler(handler); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
747 expectError("COPY INTO foo(t) FROM 'banana'(t) ON CLIENT", "after all"); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
748 assertEq("connection is closed", true, conn.isClosed()); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
749 // Cannot check the server log, but at the time I checked, it said "prematurely stopped client", which is fine. |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
750 exitTest(); |
544
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
751 } |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
752 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
753 private void test_FailDownloadLate() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
754 initTest("test_FailDownloadLate"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
755 prepare(); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
756 MyDownloadHandler handler = new MyDownloadHandler(200, "download refused"); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
757 conn.setDownloadHandler(handler); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
758 update("INSERT INTO foo SELECT value as i, 'number' || value AS t FROM sys.generate_series(0, 100)"); |
548
d1f6678f92c5
Test that throwing an IO Exception in the download handler invalidates the connection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
545
diff
changeset
|
759 expectError("COPY (SELECT * FROM sys.generate_series(0,200)) INTO 'banana' ON CLIENT", "download refused"); |
d1f6678f92c5
Test that throwing an IO Exception in the download handler invalidates the connection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
545
diff
changeset
|
760 // Exception closes the connection |
d1f6678f92c5
Test that throwing an IO Exception in the download handler invalidates the connection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
545
diff
changeset
|
761 assertEq("connection is closed", conn.isClosed(), true); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
762 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
763 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
764 |
604
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
765 private void test_FileTransferHandlerUploadNotCompressed() throws IOException, SQLException, Failure { |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
766 initTest("FileTransferHandlerUploadNotCompressed"); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
767 testFileTransferHandlerUploadCompressed(StandardCharsets.UTF_8, false, 0); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
768 exitTest(); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
769 } |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
770 |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
771 private void test_FileTransferHandlerUploadNotCompressedSkip() throws IOException, SQLException, Failure { |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
772 initTest("FileTransferHandlerUploadNotCompressedSkip"); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
773 testFileTransferHandlerUploadCompressed(StandardCharsets.UTF_8, false, 2); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
774 exitTest(); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
775 } |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
776 |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
777 private void test_FileTransferHandlerUploadCompressed() throws IOException, SQLException, Failure { |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
778 initTest("FileTransferHandlerUploadCompressed"); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
779 testFileTransferHandlerUploadCompressed(StandardCharsets.UTF_8, true, 0); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
780 exitTest(); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
781 } |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
782 |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
783 private void test_FileTransferHandlerUploadCompressedSkip() throws IOException, SQLException, Failure { |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
784 initTest("FileTransferHandlerUploadCompressedSkip"); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
785 testFileTransferHandlerUploadCompressed(StandardCharsets.UTF_8, true, 2); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
786 exitTest(); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
787 } |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
788 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
789 private void test_FileTransferHandlerUploadUtf8() throws IOException, SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
790 initTest("test_FileTransferHandlerUploadUtf8"); |
604
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
791 testFileTransferHandlerUploadEncoding(StandardCharsets.UTF_8, "UTF-8"); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
792 exitTest(); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
793 } |
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
794 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
795 private void test_FileTransferHandlerUploadLatin1() throws IOException, SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
796 initTest("test_FileTransferHandlerUploadLatin1"); |
604
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
797 testFileTransferHandlerUploadEncoding(Charset.forName("latin1"), "latin1"); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
798 exitTest(); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
799 } |
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
800 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
801 private void test_FileTransferHandlerUploadNull() throws IOException, SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
802 initTest("test_FileTransferHandlerUploadNull"); |
604
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
803 testFileTransferHandlerUploadEncoding(null, Charset.defaultCharset().name()); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
804 exitTest(); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
805 } |
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
806 |
594
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
807 private String hexdump(String s) |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
808 { |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
809 StringBuilder buf = new StringBuilder(); |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
810 char[] chars = s.toCharArray(); |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
811 for (char c: chars) { |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
812 buf.append(' '); |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
813 buf.append((int)c); |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
814 |
600
c2581dbd1dbf
Change test output to make it more informative on Windows
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
594
diff
changeset
|
815 // UnicodeBlock b = UnicodeBlock.of(c); |
c2581dbd1dbf
Change test output to make it more informative on Windows
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
594
diff
changeset
|
816 // if (!Character.isISOControl(c) && b != null) { |
c2581dbd1dbf
Change test output to make it more informative on Windows
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
594
diff
changeset
|
817 // if (b != UnicodeBlock.HIGH_SURROGATES && b != UnicodeBlock.LOW_SURROGATES && b != UnicodeBlock.SPECIALS) { |
c2581dbd1dbf
Change test output to make it more informative on Windows
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
594
diff
changeset
|
818 // buf.append("='"); |
c2581dbd1dbf
Change test output to make it more informative on Windows
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
594
diff
changeset
|
819 // buf.append(c); |
c2581dbd1dbf
Change test output to make it more informative on Windows
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
594
diff
changeset
|
820 // buf.append("'"); |
c2581dbd1dbf
Change test output to make it more informative on Windows
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
594
diff
changeset
|
821 // } |
c2581dbd1dbf
Change test output to make it more informative on Windows
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
594
diff
changeset
|
822 // } |
594
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
823 } |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
824 |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
825 return "<" + buf.toString().trim() + ">"; |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
826 } |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
827 |
604
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
828 private void testFileTransferHandlerUploadEncoding(Charset handlerEncoding, String fileEncoding) throws IOException, SQLException, Failure { |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
829 prepare(); |
600
c2581dbd1dbf
Change test output to make it more informative on Windows
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
594
diff
changeset
|
830 outBuffer.append("Default encoding is " + Charset.defaultCharset().displayName() + "\n"); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
831 Path d = getTmpDir(currentTestName); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
832 Path f = d.resolve("data.txt"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
833 OutputStream s = Files.newOutputStream(f, CREATE_NEW); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
834 PrintStream ps = new PrintStream(s, false, fileEncoding); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
835 ps.println("1|one"); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
836 ps.println("2|tw??"); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
837 ps.println("3|three"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
838 ps.close(); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
839 conn.setUploadHandler(new FileTransferHandler(d, handlerEncoding)); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
840 update("COPY INTO foo FROM 'data.txt' ON CLIENT"); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
841 assertQueryInt("SELECT SUM(i) FROM foo", 6); |
594
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
842 final String result = queryString("SELECT t FROM foo WHERE i = 2"); |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
843 String two = "tw??"; |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
844 // |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
845 String hexTwo = hexdump(two); |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
846 String hexResult = hexdump(result); |
613f94a13ad6
Show hexdumps in the File Transfer encoding tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
592
diff
changeset
|
847 assertEq("query result hexdump", hexTwo, hexResult); |
600
c2581dbd1dbf
Change test output to make it more informative on Windows
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
594
diff
changeset
|
848 // assertEq("query result", two, result); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
849 } |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
850 |
604
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
851 private void testFileTransferHandlerUploadCompressed(Charset encoding, boolean compressed, int skipLines) throws IOException, SQLException, Failure { |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
852 prepare(); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
853 Path d = getTmpDir(currentTestName); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
854 String fileName = "data.txt"; |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
855 if (compressed) |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
856 fileName += ".gz"; |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
857 Path f = d.resolve(fileName); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
858 OutputStream s = Files.newOutputStream(f, CREATE_NEW); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
859 if (compressed) { |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
860 s = new GZIPOutputStream(s); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
861 } |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
862 Writer w = new OutputStreamWriter(s, encoding); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
863 PrintWriter ps = new PrintWriter(w); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
864 String[] words = { "one", "tw??", "three" }; |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
865 int i = 0; |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
866 int expectedSum = 0; |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
867 for (String word: words) { |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
868 int n = i + 1; |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
869 ps.println("" + n + "|" + word); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
870 if (i >= skipLines) { |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
871 expectedSum += n; |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
872 } |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
873 i += 1; |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
874 } |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
875 ps.close(); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
876 conn.setUploadHandler(new FileTransferHandler(d, encoding)); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
877 String query = "COPY OFFSET " + (skipLines + 1) + " INTO foo FROM '" + fileName + "' ON CLIENT"; |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
878 update(query); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
879 assertQueryInt("SELECT SUM(i) FROM foo", expectedSum); |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
880 } |
8e5dbe2ebe7d
Test uploading compressed files in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
602
diff
changeset
|
881 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
882 private void test_FileTransferHandlerUploadRefused() throws IOException, SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
883 initTest("test_FileTransferHandlerUploadRefused"); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
884 prepare(); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
885 Path d = getTmpDir(currentTestName); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
886 Path f = d.resolve("data.txt"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
887 OutputStream s = Files.newOutputStream(f, CREATE_NEW); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
888 PrintStream ps = new PrintStream(s, false, "UTF-8"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
889 ps.println("1|one"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
890 ps.println("2|two"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
891 ps.println("3|three"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
892 ps.close(); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
893 |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
894 Path d2 = getTmpDir(currentTestName + "2"); |
578
687034945b3f
Pass expected encoding as a constructor parameter to FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
575
diff
changeset
|
895 conn.setUploadHandler(new FileTransferHandler(d2, StandardCharsets.UTF_8)); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
896 String quoted = f.toAbsolutePath().toString().replaceAll("'", "''"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
897 expectError("COPY INTO foo FROM R'"+ quoted + "' ON CLIENT", "not in upload directory"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
898 // connection is still alive |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
899 assertQueryInt("SELECT SUM(i) FROM foo", 0); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
900 exitTest(); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
901 } |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
902 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
903 private void test_FileTransferHandlerDownloadUtf8() throws SQLException, Failure, IOException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
904 initTest("test_FileTransferHandlerDownloadUtf8"); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
905 testFileTransferHandlerDownload(StandardCharsets.UTF_8, StandardCharsets.UTF_8); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
906 exitTest(); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
907 } |
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
908 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
909 private void test_FileTransferHandlerDownloadLatin1() throws SQLException, Failure, IOException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
910 initTest("test_FileTransferHandlerDownloadLatin1"); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
911 Charset latin1 = Charset.forName("latin1"); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
912 testFileTransferHandlerDownload(latin1, latin1); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
913 exitTest(); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
914 } |
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
915 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
916 private void test_FileTransferHandlerDownloadNull() throws SQLException, Failure, IOException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
917 initTest("test_FileTransferHandlerDownloadNull"); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
918 testFileTransferHandlerDownload(null, Charset.defaultCharset()); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
919 exitTest(); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
920 } |
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
921 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
922 private void testFileTransferHandlerDownload(Charset handlerEncoding, Charset fileEncoding) throws SQLException, Failure, IOException { |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
923 prepare(); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
924 update("INSERT INTO foo VALUES (42, 'forty-tw??')"); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
925 Path d = getTmpDir(currentTestName); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
926 conn.setDownloadHandler(new FileTransferHandler(d, handlerEncoding)); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
927 update("COPY SELECT * FROM foo INTO 'data.txt' ON CLIENT"); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
928 List<String> lines = Files.readAllLines(d.resolve("data.txt"), fileEncoding); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
929 assertEq("lines written", lines.size(), 1); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
930 assertEq("line content", lines.get(0), "42|\"forty-tw??\""); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
931 // connection is still alive |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
932 assertQueryInt("SELECT SUM(i) FROM foo", 42); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
933 } |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
934 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
935 private void test_FileTransferHandlerDownloadRefused() throws SQLException, Failure, IOException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
936 initTest("test_FileTransferHandlerDownloadRefused"); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
937 prepare(); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
938 BugFixLevel level = getLevel(); |
575
08c9918177b2
Do not check the updated row count, it varies between server versions
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
574
diff
changeset
|
939 update("INSERT INTO foo VALUES (42, 'forty-two')"); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
940 Path d = getTmpDir(currentTestName); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
941 Path d2 = getTmpDir(currentTestName + "2"); |
578
687034945b3f
Pass expected encoding as a constructor parameter to FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
575
diff
changeset
|
942 conn.setDownloadHandler(new FileTransferHandler(d2, StandardCharsets.UTF_8)); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
943 String quoted = d.resolve("data.txt").toAbsolutePath().toString().replaceAll("'", "''"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
944 expectError("COPY SELECT * FROM foo INTO R'" + quoted + "' ON CLIENT", "not in download directory"); |
574
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
945 if (level.compareTo(BugFixLevel.CanRefuseDownload) >= 0) { |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
946 // connection is still alive |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
947 assertQueryInt("SELECT SUM(i) FROM foo", 42); |
3370027aeb7f
Test more systematically that the connection is still alive after file transfer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
571
diff
changeset
|
948 } |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
949 exitTest(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
950 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
951 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
952 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
953 /* utility methods */ |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
954 private void say(String message) throws Failure { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
955 outBuffer.append(message).append("\n"); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
956 throw new Failure(message); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
957 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
615
diff
changeset
|
958 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
959 private void fail(String message) throws Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
960 outBuffer.append("FAILURE: ").append(message).append("\n"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
961 throw new Failure(message); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
962 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
963 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
964 private void checked(String quantity, Object actual) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
965 outBuffer.append(" CHECKED: <").append(quantity).append("> is ").append(actual).append(" as expected").append("\n"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
966 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
967 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
968 private void assertEq(String quantity, Object expected, Object actual) throws Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
969 if (expected.equals(actual)) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
970 checked(quantity, actual); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
971 } else { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
972 fail("Expected <" + quantity + "> to be " + expected + " got " + actual); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
973 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
974 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
975 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
976 private boolean execute(String query) throws SQLException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
977 outBuffer.append("EXECUTE: ").append(query).append("\n"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
978 final boolean result = stmt.execute(query); |
592
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
979 outBuffer.append(" OK"); |
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
980 if (!result) { |
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
981 outBuffer.append(", updated ").append(stmt.getUpdateCount()).append(" rows"); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
982 } |
592
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
983 outBuffer.append("\n"); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
984 return result; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
985 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
986 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
987 private void update(String query) throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
988 execute(query); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
989 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
990 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
991 private void expectError(String query, String expectedError) throws SQLException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
992 try { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
993 execute(query); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
994 } catch (SQLException e) { |
622
61877c1f19f6
Optimizations
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
621
diff
changeset
|
995 String msg = e.getMessage(); |
61877c1f19f6
Optimizations
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
621
diff
changeset
|
996 if (msg.contains(expectedError)) { |
61877c1f19f6
Optimizations
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
621
diff
changeset
|
997 outBuffer.append(" GOT EXPECTED EXCEPTION: ").append(msg).append("\n"); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
998 } else { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
999 throw e; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1000 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1001 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1002 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1003 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1004 private void assertQueryInt(String query, int expected) throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1005 if (execute(query) == false) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1006 fail("Query does not return a result set"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1007 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1008 final ResultSet rs = stmt.getResultSet(); |
622
61877c1f19f6
Optimizations
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
621
diff
changeset
|
1009 assertEq("column count", 1, rs.getMetaData().getColumnCount()); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1010 if (!rs.next()) { |
607
69b0bcf5f62d
On failure do not forget to close the resultset resource first.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
604
diff
changeset
|
1011 rs.close(); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1012 fail("Result set is empty"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1013 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1014 final int result = rs.getInt(1); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1015 if (rs.next()) { |
607
69b0bcf5f62d
On failure do not forget to close the resultset resource first.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
604
diff
changeset
|
1016 rs.close(); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1017 fail("Result set has more than one row"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1018 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1019 rs.close(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1020 checked("row count", 1); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1021 assertEq("query result", expected, result); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
1022 } |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
1023 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1024 private void assertQueryString(String query, String expected) throws SQLException, Failure { |
592
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
1025 final String result = queryString(query); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1026 assertEq("query result", expected, result); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1027 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1028 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1029 private String queryString(String query) throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1030 if (execute(query) == false) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1031 fail("Query does not return a result set"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1032 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1033 final ResultSet rs = stmt.getResultSet(); |
622
61877c1f19f6
Optimizations
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
621
diff
changeset
|
1034 assertEq("column count", 1, rs.getMetaData().getColumnCount()); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1035 if (!rs.next()) { |
607
69b0bcf5f62d
On failure do not forget to close the resultset resource first.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
604
diff
changeset
|
1036 rs.close(); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1037 fail("Result set is empty"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1038 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1039 final String result = rs.getString(1); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1040 if (rs.next()) { |
607
69b0bcf5f62d
On failure do not forget to close the resultset resource first.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
604
diff
changeset
|
1041 rs.close(); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1042 fail("Result set has more than one row"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1043 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1044 rs.close(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1045 checked("row count", 1); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1046 return result; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1047 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1048 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1049 private synchronized Path getTmpDir(String name) throws IOException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1050 if (tmpDir == null) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1051 tmpDir = Files.createTempDirectory("testMonetDB"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1052 Runtime.getRuntime().addShutdownHook(new Thread(() -> { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1053 try { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1054 Files.walkFileTree(tmpDir, new SimpleFileVisitor<Path>() { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1055 @Override |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1056 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1057 Files.delete(file); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1058 return FileVisitResult.CONTINUE; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1059 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1060 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1061 @Override |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1062 public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1063 Files.delete(dir); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1064 return FileVisitResult.CONTINUE; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1065 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1066 }); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1067 } catch (IOException e) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1068 // we do this on a best effort basis |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1069 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1070 })); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1071 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1072 final Path p = tmpDir.resolve(name); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1073 Files.createDirectory(p); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1074 return p; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1075 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1076 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1077 /** |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1078 * Implementation of an UploadHandler |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1079 */ |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
534
diff
changeset
|
1080 static class MyUploadHandler implements UploadHandler { |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
1081 private final long rows; |
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
1082 private final long errorAt; |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1083 private final String errorMessage; |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1084 private boolean encounteredWriteError = false; |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1085 private boolean cancelled = false; |
522
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
1086 |
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
1087 private int chunkSize = 100; // small number to trigger more bugs |
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
1088 |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
1089 MyUploadHandler(long rows, long errorAt, String errorMessage) { |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1090 this.rows = rows; |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1091 this.errorAt = errorAt; |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1092 this.errorMessage = errorMessage; |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1093 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1094 |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
1095 MyUploadHandler(long rows) { |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1096 this(rows, -1, null); |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1097 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1098 |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1099 MyUploadHandler(String errorMessage) { |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1100 this(0, -1, errorMessage); |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1101 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1102 |
522
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
1103 public void setChunkSize(int chunkSize) { |
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
1104 this.chunkSize = chunkSize; |
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
1105 } |
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
1106 |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1107 @Override |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1108 public void uploadCancelled() { |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1109 cancelled = true; |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1110 } |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1111 |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1112 @Override |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
1113 public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, long linesToSkip) throws IOException { |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1114 if (errorAt == -1 && errorMessage != null) { |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1115 handle.sendError(errorMessage); |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1116 return; |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1117 } |
522
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
1118 handle.setChunkSize(chunkSize); |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1119 PrintStream stream = handle.getStream(); |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
1120 for (long i = linesToSkip; i < rows; i++) { |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1121 if (i == errorAt) { |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1122 throw new IOException(errorMessage); |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1123 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1124 stream.printf("%d|%d%n", i + 1, i + 1); |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
1125 if (i % 25 == 0 && stream.checkError()) { |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
1126 encounteredWriteError = true; |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
1127 break; |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
1128 } |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1129 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1130 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1131 |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
1132 public Object encounteredWriteError() { |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
1133 return encounteredWriteError; |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
531
diff
changeset
|
1134 } |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1135 |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1136 public boolean isCancelled() { |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1137 return cancelled; |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1138 } |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
1139 } |
520
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1140 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1141 /** |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1142 * Implementation of a DownloadHandler |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1143 */ |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
534
diff
changeset
|
1144 static class MyDownloadHandler implements DownloadHandler { |
520
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1145 private final int errorAtByte; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1146 private final String errorMessage; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1147 private int attempts = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1148 private int bytesSeen = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1149 private int lineEndingsSeen = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1150 private int startOfLine = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1151 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1152 MyDownloadHandler(int errorAtByte, String errorMessage) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1153 this.errorAtByte = errorAtByte; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1154 this.errorMessage = errorMessage; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1155 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1156 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1157 MyDownloadHandler(String errorMessage) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1158 this(-1, errorMessage); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1159 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1160 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1161 MyDownloadHandler() { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1162 this(-1, null); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1163 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1164 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1165 @Override |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1166 public void handleDownload(MonetConnection.Download handle, String name, boolean textMode) throws IOException { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1167 attempts++; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1168 bytesSeen = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1169 lineEndingsSeen = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1170 startOfLine = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1171 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1172 if (errorMessage != null && errorAtByte < 0) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1173 handle.sendError(errorMessage); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1174 return; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1175 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1176 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1177 InputStream stream = handle.getStream(); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1178 byte[] buffer = new byte[1024]; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1179 while (true) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1180 int toRead = buffer.length; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1181 if (errorMessage != null && errorAtByte >= 0) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1182 if (bytesSeen == errorAtByte) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1183 throw new IOException(errorMessage); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1184 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1185 toRead = Integer.min(toRead, errorAtByte - bytesSeen); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1186 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1187 int nread = stream.read(buffer, 0, toRead); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1188 if (nread < 0) |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1189 break; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1190 for (int i = 0; i < nread; i++) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1191 if (buffer[i] == '\n') { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1192 lineEndingsSeen += 1; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1193 startOfLine = bytesSeen + i + 1; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1194 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1195 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1196 bytesSeen += nread; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1197 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1198 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1199 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1200 public int countAttempts() { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1201 return attempts; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1202 } |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
1203 |
520
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1204 public int lineCount() { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1205 int lines = lineEndingsSeen; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1206 if (startOfLine != bytesSeen) |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1207 lines++; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1208 return lines; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1209 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
1210 } |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1211 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1212 static class Failure extends Exception { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1213 static final long serialVersionUID = 3387516993124229948L; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1214 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1215 public Failure(String message) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1216 super(message); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1217 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1218 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1219 public Failure(String message, Throwable cause) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1220 super(message, cause); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1221 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
1222 } |
526
6060ca8c5c1a
Add test for uploadFrom methods
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
525
diff
changeset
|
1223 } |