Mercurial > hg > monetdb-java
annotate tests/OnClientTester.java @ 592:b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 18 Nov 2021 21:21:13 +0100 (2021-11-18) |
parents | b2cd3b828967 |
children | 613f94a13ad6 |
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 * |
d462000fc410
Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V. |
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.*; |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
15 import java.nio.charset.Charset; |
526
6060ca8c5c1a
Add test for uploadFrom methods
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
525
diff
changeset
|
16 import java.nio.charset.StandardCharsets; |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
17 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
|
18 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
|
19 import java.nio.file.Path; |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
20 import java.nio.file.SimpleFileVisitor; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
21 import java.nio.file.attribute.BasicFileAttributes; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
22 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
|
23 import java.sql.DriverManager; |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
24 import java.sql.ResultSet; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
25 import java.sql.ResultSetMetaData; |
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; |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
28 import java.util.List; |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
29 |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
30 import static java.nio.file.StandardOpenOption.CREATE_NEW; |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
31 |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
32 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
33 /** |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
34 * 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
|
35 * COPY ... INTO ... ON CLIENT |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
36 * commands. |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
37 * 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
|
38 * 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
|
39 * |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
40 * 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
|
41 * see {@link org.monetdb.jdbc.MonetConnection#setUploadHandler(UploadHandler)} |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
42 * see {@link org.monetdb.jdbc.MonetConnection#setUploadHandler(DownloadHandler)} |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
43 * 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
|
44 * |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
45 * 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
|
46 * {@link org.monetdb.util.FileTransferHandler} |
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 * @author JvR |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
49 * @version 0.1 |
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 public final class OnClientTester { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
52 public static final int VERBOSITY_NONE = 0; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
53 public static final int VERBOSITY_ON = 1; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
54 public static final int VERBOSITY_SHOW_ALL = 2; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
55 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
56 private final String jdbcUrl; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
57 private final int verbosity; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
58 private String currentTestName; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
59 private long startTime; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
60 private MonetConnection conn; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
61 private Statement stmt; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
62 private StringBuilder outBuffer; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
63 private Path tmpDir; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
64 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
65 public OnClientTester(String jdbcUrl, int verbosity) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
66 this.jdbcUrl = jdbcUrl; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
67 this.verbosity = verbosity; |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
68 } |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
69 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
70 public static void main(String[] args) { |
524
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
71 String jdbcUrl = null; |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
72 int verbosity = 0; |
545
79393647d7fb
Call Class.forName("...MonetDriver") from main() in OnClientTester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
544
diff
changeset
|
73 |
525
70ff796c42f7
Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
524
diff
changeset
|
74 for (String arg : args) { |
524
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
75 if (arg.equals("-v")) |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
76 verbosity++; |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
77 else if (arg.equals("-vv")) |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
78 verbosity += 2; |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
79 else if (jdbcUrl == null) |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
80 jdbcUrl = arg; |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
81 else { |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
82 System.err.println("Unexpected argument " + arg); |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
83 System.exit(2); |
71644dc873fe
Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
523
diff
changeset
|
84 } |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
85 } |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
86 if (jdbcUrl == null || jdbcUrl.isEmpty()) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
87 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
|
88 System.exit(1); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
89 } |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
90 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
91 OnClientTester tester = new OnClientTester(jdbcUrl, verbosity); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
92 int failures = tester.runTests(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
93 if (failures > 0) |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
94 System.exit(-1); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
95 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
96 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
97 public int runTests() { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
98 if (! openConnection()) |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
99 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
|
100 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
101 outBuffer = new StringBuilder(1024); |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
102 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
103 int failures = 0; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
104 try { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
105 // all test methods start with test_ and have no arguments |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
106 test_BugFixLevel(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
107 test_Upload(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
108 test_ClientRefusesUpload(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
109 test_Offset0(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
110 test_Offset1(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
111 test_Offset5(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
112 test_ServerStopsReading(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
113 test_Download(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
114 test_ClientRefusesDownload(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
115 test_LargeUpload(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
116 test_LargeDownload(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
117 test_UploadFromStream(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
118 test_UploadFromReader(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
119 test_UploadFromReaderOffset(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
120 test_FailUploadLate(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
121 test_FailUploadLate2(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
122 test_FailDownloadLate(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
123 test_FileTransferHandlerUploadUtf8(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
124 test_FileTransferHandlerUploadLatin1(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
125 test_FileTransferHandlerUploadNull(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
126 test_FileTransferHandlerUploadRefused(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
127 test_FileTransferHandlerDownloadUtf8(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
128 test_FileTransferHandlerDownloadLatin1(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
129 test_FileTransferHandlerDownloadNull(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
130 test_FileTransferHandlerDownloadRefused(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
131 } catch (Failure e) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
132 failures++; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
133 System.err.println(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
134 System.err.println("Test " + currentTestName + " failed"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
135 dumpOutput(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
136 } catch (Exception e) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
137 failures++; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
138 System.err.println(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
139 System.err.println("Test " + currentTestName + " failed:"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
140 e.printStackTrace(System.err); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
141 dumpOutput(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
142 // 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
|
143 Throwable t = e; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
144 while (t.getCause() != null) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
145 t = t.getCause(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
146 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
147 System.err.println("Innermost cause was " + t); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
148 if (t.getStackTrace().length > 0) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
149 System.err.println(" at " + t.getStackTrace()[0]); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
150 } |
592
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
151 } finally { |
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
152 try { |
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
153 // 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
|
154 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
|
155 } catch (SQLException e) { /* ignore */ } |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
156 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
157 closeConnection(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
158 return failures; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
159 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
160 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
161 private boolean openConnection() { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
162 try { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
163 // 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
|
164 final Connection genericConnection = DriverManager.getConnection(jdbcUrl); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
165 conn = genericConnection.unwrap(MonetConnection.class); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
166 stmt = conn.createStatement(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
167 return true; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
168 } catch (SQLException e) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
169 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
|
170 System.err.println(e); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
171 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
172 return false; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
173 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
174 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
175 private void closeConnection() { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
176 if (stmt != null) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
177 try { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
178 stmt.close(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
179 } catch (SQLException e) { /* ignore */ } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
180 stmt = null; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
181 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
182 if (conn != null) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
183 try { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
184 conn.close(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
185 } catch (Exception e) { /* ignore */ } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
186 conn = null; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
187 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
188 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
189 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
190 private void initTest(final String name) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
191 currentTestName = name; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
192 outBuffer.setLength(0); // clear the output log buffer |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
193 startTime = System.currentTimeMillis(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
194 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
195 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
196 private void exitTest() { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
197 if (verbosity > VERBOSITY_ON) |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
198 System.err.println(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
199 if (verbosity >= VERBOSITY_ON) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
200 final long duration = System.currentTimeMillis() - startTime; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
201 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
|
202 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
203 if (verbosity >= VERBOSITY_SHOW_ALL) |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
204 dumpOutput(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
205 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
206 if (conn.isClosed()) |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
207 openConnection(); // restore connection for next test |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
208 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
209 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
210 private void dumpOutput() { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
211 final String output = outBuffer.toString(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
212 if (output.isEmpty()) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
213 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
|
214 } else { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
215 System.err.println("------ Accumulated output for test " + currentTestName + ":"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
216 System.err.println(output); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
217 System.err.println("------ End of accumulated output"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
218 } |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
219 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
220 |
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
|
221 /// 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
|
222 /// 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
|
223 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
|
224 /// 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
|
225 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
|
226 |
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
|
227 /// 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
|
228 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
|
229 |
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
|
230 ; |
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
|
231 |
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
|
232 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
|
233 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
|
234 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
|
235 |
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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 } |
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
|
241 |
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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 } |
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
|
253 |
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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 |
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
|
261 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
|
262 } |
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
|
263 |
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
|
264 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
|
265 BugFixLevel lastValid = Baseline; |
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
|
266 for (BugFixLevel level: BugFixLevel.values()) { |
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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 } |
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
|
272 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
|
273 } |
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
|
274 } |
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
|
275 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
276 private void prepare() throws SQLException { |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
277 execute("DROP TABLE IF EXISTS foo"); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
278 execute("CREATE TABLE foo (i INT, t CLOB)"); |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
279 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
280 |
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 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
|
282 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
|
283 BugFixLevel level = BugFixLevel.forVersion(version); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
284 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
|
285 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
|
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 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
288 private void test_BugFixLevel() throws Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
289 initTest("test_BugFixLevel"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
290 |
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
|
291 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
|
292 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
|
293 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
|
294 |
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 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
|
296 |
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 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
|
298 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
|
299 |
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 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
|
301 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
|
302 |
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 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
|
304 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
|
305 |
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 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 |
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 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
|
315 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
|
316 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
317 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
|
318 } |
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 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
320 private void test_Upload() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
321 initTest("test_Upload"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 assertQueryInt("SELECT COUNT(*) FROM foo", 100); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
328 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
329 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
330 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
331 private void test_ClientRefusesUpload() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
332 initTest("test_ClientRefusesUpload"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
333 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
|
334 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
|
335 conn.setUploadHandler(handler); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
336 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
|
337 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
|
338 assertQueryInt("SELECT COUNT(*) FROM foo", 0); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
339 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
340 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
341 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
342 private void test_Offset0() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
343 initTest("test_Offset0"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 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
|
350 assertQueryInt("SELECT MAX(i) FROM foo", 100); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
351 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
352 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
353 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
354 private void test_Offset1() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
355 initTest("test_Offset1"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 assertQueryInt("SELECT MAX(i) FROM foo", 100); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
363 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
364 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
365 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
366 private void test_Offset5() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
367 initTest("test_Offset5"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 assertQueryInt("SELECT MAX(i) FROM foo", 100); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
375 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
376 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
377 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
378 private void test_ServerStopsReading() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
379 initTest("test_ServerStopsReading"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
380 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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 // 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
|
387 assertQueryInt("SELECT COUNT(i) FROM foo", 10); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
388 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
389 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
390 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
391 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
|
392 prepare(); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
393 MyDownloadHandler handler = new MyDownloadHandler(); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
394 conn.setDownloadHandler(handler); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
395 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
|
396 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
|
397 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
|
398 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
|
399 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
|
400 // 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
|
401 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
|
402 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
403 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
404 private void test_Download() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
405 initTest("test_Download"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
406 test_Download(100); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
407 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
408 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
409 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
410 private void test_ClientRefusesDownload() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
411 initTest("test_ClientRefusesDownload"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
412 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
|
413 BugFixLevel level = getLevel(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
414 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
|
415 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
|
416 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
|
417 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
|
418 // 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
|
419 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
|
420 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
|
421 // 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
|
422 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
|
423 } |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
424 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
425 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
426 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
427 private void test_LargeUpload() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
428 initTest("test_LargeUpload"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
429 prepare(); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
430 int n = 4_000_000; |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
431 MyUploadHandler handler = new MyUploadHandler(n); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
432 conn.setUploadHandler(handler); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
433 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
|
434 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
|
435 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
|
436 // 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
|
437 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
|
438 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
439 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
440 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
441 private void test_LargeDownload() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
442 initTest("test_LargeDownload"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
443 test_Download(4_000_000); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
444 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
445 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
446 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
447 private void test_UploadFromStream() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
448 initTest("test_UploadFromStream"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
449 prepare(); |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
534
diff
changeset
|
450 UploadHandler handler = new UploadHandler() { |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
451 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
|
452 |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
453 @Override |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
454 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
|
455 // 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
|
456 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
|
457 handle.uploadFrom(s); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
458 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
459 }; |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
460 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
|
461 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
|
462 // 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
|
463 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
|
464 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
465 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
466 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
467 private void test_UploadFromReader() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
468 initTest("test_UploadFromReader"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
469 prepare(); |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
534
diff
changeset
|
470 UploadHandler handler = new UploadHandler() { |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
471 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
|
472 |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
473 @Override |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
474 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
|
475 // 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
|
476 StringReader r = new StringReader(data); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
477 handle.uploadFrom(r); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
478 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
479 }; |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
480 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
|
481 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
|
482 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
|
483 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
484 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
485 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
486 private void test_UploadFromReaderOffset() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
487 initTest("test_UploadFromReaderOffset"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
488 prepare(); |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
534
diff
changeset
|
489 UploadHandler handler = new UploadHandler() { |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
490 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
|
491 |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
492 @Override |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
493 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
|
494 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
|
495 handle.uploadFrom(r, linesToSkip); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
496 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
497 }; |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
502 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
503 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
504 private void test_FailUploadLate() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
505 initTest("test_FailUploadLate"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
506 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
|
507 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
|
508 conn.setUploadHandler(handler); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
509 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
|
510 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
|
511 assertEq("connection is closed", true, conn.isClosed()); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
512 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
513 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
514 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
515 private void test_FailUploadLate2() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
516 initTest("test_FailUploadLate2"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
517 // 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
|
518 // 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
|
519 prepare(); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
520 UploadHandler handler = new UploadHandler() { |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
521 @Override |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
522 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
|
523 // 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
|
524 PrintStream stream = handle.getStream(); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
525 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
|
526 stream.println(); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
527 stream.flush(); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
528 throw new IOException("exception after all"); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
529 } |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
530 }; |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
531 conn.setUploadHandler(handler); |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
532 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
|
533 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
|
534 // 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
|
535 exitTest(); |
544
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
536 } |
c71ce17fa724
Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
537 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
538 private void test_FailDownloadLate() throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
539 initTest("test_FailDownloadLate"); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
540 prepare(); |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
541 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
|
542 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
|
543 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
|
544 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
|
545 // 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
|
546 assertEq("connection is closed", conn.isClosed(), true); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
547 exitTest(); |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
548 } |
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
549 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
550 private void test_FileTransferHandlerUploadUtf8() throws IOException, SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
551 initTest("test_FileTransferHandlerUploadUtf8"); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
552 testFileTransferHandlerUpload(StandardCharsets.UTF_8, "UTF-8"); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
553 exitTest(); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
554 } |
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
555 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
556 private void test_FileTransferHandlerUploadLatin1() throws IOException, SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
557 initTest("test_FileTransferHandlerUploadLatin1"); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
558 testFileTransferHandlerUpload(Charset.forName("latin1"), "latin1"); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
559 exitTest(); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
560 } |
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
561 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
562 private void test_FileTransferHandlerUploadNull() throws IOException, SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
563 initTest("test_FileTransferHandlerUploadNull"); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
564 testFileTransferHandlerUpload(null, Charset.defaultCharset().name()); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
565 exitTest(); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
566 } |
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
567 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
568 private void testFileTransferHandlerUpload(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
|
569 prepare(); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
570 Path d = getTmpDir(currentTestName); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
571 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
|
572 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
|
573 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
|
574 ps.println("1|one"); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
575 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
|
576 ps.println("3|three"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
577 ps.close(); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
578 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
|
579 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
|
580 assertQueryInt("SELECT SUM(i) FROM foo", 6); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
581 assertQueryString("SELECT t FROM foo WHERE i = 2", "tw??"); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
582 } |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
583 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
584 private void test_FileTransferHandlerUploadRefused() throws IOException, SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
585 initTest("test_FileTransferHandlerUploadRefused"); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
586 prepare(); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
587 Path d = getTmpDir(currentTestName); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
588 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
|
589 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
|
590 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
|
591 ps.println("1|one"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
592 ps.println("2|two"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
593 ps.println("3|three"); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
594 ps.close(); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
595 |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
596 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
|
597 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
|
598 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
|
599 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
|
600 // 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
|
601 assertQueryInt("SELECT SUM(i) FROM foo", 0); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
602 exitTest(); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
603 } |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
604 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
605 private void test_FileTransferHandlerDownloadUtf8() throws SQLException, Failure, IOException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
606 initTest("test_FileTransferHandlerDownloadUtf8"); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
607 testFileTransferHandlerDownload(StandardCharsets.UTF_8, StandardCharsets.UTF_8); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
608 exitTest(); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
609 } |
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
610 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
611 private void test_FileTransferHandlerDownloadLatin1() throws SQLException, Failure, IOException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
612 initTest("test_FileTransferHandlerDownloadLatin1"); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
613 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
|
614 testFileTransferHandlerDownload(latin1, latin1); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
615 exitTest(); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
616 } |
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
617 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
618 private void test_FileTransferHandlerDownloadNull() throws SQLException, Failure, IOException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
619 initTest("test_FileTransferHandlerDownloadNull"); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
620 testFileTransferHandlerDownload(null, Charset.defaultCharset()); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
621 exitTest(); |
581
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
622 } |
5aef0ea654b1
Take null to mean the default charset
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
580
diff
changeset
|
623 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
624 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
|
625 prepare(); |
580
13134a44dfc8
Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
578
diff
changeset
|
626 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
|
627 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
|
628 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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 // 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
|
634 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
|
635 } |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
636 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
637 private void test_FileTransferHandlerDownloadRefused() throws SQLException, Failure, IOException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
638 initTest("test_FileTransferHandlerDownloadRefused"); |
571
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
639 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
|
640 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
|
641 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
|
642 Path d = getTmpDir(currentTestName); |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
643 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
|
644 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
|
645 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
|
646 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
|
647 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
|
648 // 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
|
649 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
|
650 } |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
651 exitTest(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
652 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
653 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
654 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
655 /* utility methods */ |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
656 private void fail(String message) throws Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
657 outBuffer.append("FAILURE: ").append(message).append("\n"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
658 throw new Failure(message); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
659 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
660 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
661 private void checked(String quantity, Object actual) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
662 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
|
663 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
664 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
665 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
|
666 if (expected.equals(actual)) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
667 checked(quantity, actual); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
668 } else { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
669 fail("Expected <" + quantity + "> to be " + expected + " got " + actual); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
670 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
671 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
672 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
673 private boolean execute(String query) throws SQLException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
674 outBuffer.append("EXECUTE: ").append(query).append("\n"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
675 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
|
676 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
|
677 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
|
678 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
|
679 } |
592
b58f6f26fab0
Add removal of used table foo. Also eliminated duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
591
diff
changeset
|
680 outBuffer.append("\n"); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
681 return result; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
682 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
683 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
684 private void update(String query) throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
685 execute(query); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
686 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
687 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
688 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
|
689 try { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
690 execute(query); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
691 } catch (SQLException e) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
692 if (e.getMessage().contains(expectedError)) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
693 outBuffer.append(" GOT EXPECTED EXCEPTION: ").append(e.getMessage()).append("\n"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
694 } else { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
695 throw e; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
696 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
697 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
698 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
699 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
700 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
|
701 if (execute(query) == false) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
702 fail("Query does not return a result set"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
703 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
704 final ResultSet rs = stmt.getResultSet(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
705 final ResultSetMetaData metaData = rs.getMetaData(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
706 assertEq("column count", 1, metaData.getColumnCount()); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
707 if (!rs.next()) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
708 fail("Result set is empty"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
709 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
710 final int result = rs.getInt(1); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
711 if (rs.next()) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
712 fail("Result set has more than one row"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
713 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
714 rs.close(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
715 checked("row count", 1); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
716 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
|
717 } |
8a4e6c82815a
Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
718 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
719 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
|
720 final String result = queryString(query); |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
721 assertEq("query result", expected, result); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
722 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
723 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
724 private String queryString(String query) throws SQLException, Failure { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
725 if (execute(query) == false) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
726 fail("Query does not return a result set"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
727 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
728 final ResultSet rs = stmt.getResultSet(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
729 final ResultSetMetaData metaData = rs.getMetaData(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
730 assertEq("column count", 1, metaData.getColumnCount()); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
731 if (!rs.next()) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
732 fail("Result set is empty"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
733 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
734 final String result = rs.getString(1); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
735 if (rs.next()) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
736 fail("Result set has more than one row"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
737 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
738 rs.close(); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
739 checked("row count", 1); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
740 return result; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
741 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
742 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
743 private synchronized Path getTmpDir(String name) throws IOException { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
744 if (tmpDir == null) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
745 tmpDir = Files.createTempDirectory("testMonetDB"); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
746 Runtime.getRuntime().addShutdownHook(new Thread(() -> { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
747 try { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
748 Files.walkFileTree(tmpDir, new SimpleFileVisitor<Path>() { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
749 @Override |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
750 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
|
751 Files.delete(file); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
752 return FileVisitResult.CONTINUE; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
753 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
754 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
755 @Override |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
756 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
|
757 Files.delete(dir); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
758 return FileVisitResult.CONTINUE; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
759 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
760 }); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
761 } catch (IOException e) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
762 // we do this on a best effort basis |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
763 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
764 })); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
765 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
766 final Path p = tmpDir.resolve(name); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
767 Files.createDirectory(p); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
768 return p; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
769 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
770 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
771 /** |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
772 * Implementation of an UploadHandler |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
773 */ |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
534
diff
changeset
|
774 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
|
775 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
|
776 private final long errorAt; |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
777 private final String errorMessage; |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
778 private boolean encounteredWriteError = false; |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
779 private boolean cancelled = false; |
522
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
780 |
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
781 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
|
782 |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
783 MyUploadHandler(long rows, long errorAt, String errorMessage) { |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
784 this.rows = rows; |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
785 this.errorAt = errorAt; |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
786 this.errorMessage = errorMessage; |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
787 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
788 |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
789 MyUploadHandler(long rows) { |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
790 this(rows, -1, null); |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
791 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
792 |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
793 MyUploadHandler(String errorMessage) { |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
794 this(0, -1, errorMessage); |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
795 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
796 |
522
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
797 public void setChunkSize(int chunkSize) { |
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
798 this.chunkSize = chunkSize; |
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
799 } |
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
800 |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
801 @Override |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
802 public void uploadCancelled() { |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
803 cancelled = true; |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
804 } |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
805 |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
806 @Override |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
548
diff
changeset
|
807 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
|
808 if (errorAt == -1 && errorMessage != null) { |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
809 handle.sendError(errorMessage); |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
810 return; |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
811 } |
522
279414178dc6
Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
520
diff
changeset
|
812 handle.setChunkSize(chunkSize); |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
813 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
|
814 for (long i = linesToSkip; i < rows; i++) { |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
815 if (i == errorAt) { |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
816 throw new IOException(errorMessage); |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
817 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
818 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
|
819 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
|
820 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
|
821 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
|
822 } |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
823 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
824 } |
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
825 |
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
|
826 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
|
827 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
|
828 } |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
829 |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
830 public boolean isCancelled() { |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
831 return cancelled; |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
832 } |
519
04a72c5bde80
Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
833 } |
520
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
834 |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
835 /** |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
836 * Implementation of a DownloadHandler |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
837 */ |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
534
diff
changeset
|
838 static class MyDownloadHandler implements DownloadHandler { |
520
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
839 private final int errorAtByte; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
840 private final String errorMessage; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
841 private int attempts = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
842 private int bytesSeen = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
843 private int lineEndingsSeen = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
844 private int startOfLine = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
845 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
846 MyDownloadHandler(int errorAtByte, String errorMessage) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
847 this.errorAtByte = errorAtByte; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
848 this.errorMessage = errorMessage; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
849 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
850 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
851 MyDownloadHandler(String errorMessage) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
852 this(-1, errorMessage); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
853 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
854 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
855 MyDownloadHandler() { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
856 this(-1, null); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
857 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
858 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
859 @Override |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
860 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
|
861 attempts++; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
862 bytesSeen = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
863 lineEndingsSeen = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
864 startOfLine = 0; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
865 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
866 if (errorMessage != null && errorAtByte < 0) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
867 handle.sendError(errorMessage); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
868 return; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
869 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
870 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
871 InputStream stream = handle.getStream(); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
872 byte[] buffer = new byte[1024]; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
873 while (true) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
874 int toRead = buffer.length; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
875 if (errorMessage != null && errorAtByte >= 0) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
876 if (bytesSeen == errorAtByte) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
877 throw new IOException(errorMessage); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
878 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
879 toRead = Integer.min(toRead, errorAtByte - bytesSeen); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
880 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
881 int nread = stream.read(buffer, 0, toRead); |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
882 if (nread < 0) |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
883 break; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
884 for (int i = 0; i < nread; i++) { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
885 if (buffer[i] == '\n') { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
886 lineEndingsSeen += 1; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
887 startOfLine = bytesSeen + i + 1; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
888 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
889 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
890 bytesSeen += nread; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
891 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
892 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
893 |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
894 public int countAttempts() { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
895 return attempts; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
896 } |
531
53dc4349ace9
Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
530
diff
changeset
|
897 |
520
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
898 public int lineCount() { |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
899 int lines = lineEndingsSeen; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
900 if (startOfLine != bytesSeen) |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
901 lines++; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
902 return lines; |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
903 } |
b4c7816e3592
Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
519
diff
changeset
|
904 } |
591
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
905 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
906 static class Failure extends Exception { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
907 static final long serialVersionUID = 3387516993124229948L; |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
908 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
909 public Failure(String message) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
910 super(message); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
911 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
912 |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
913 public Failure(String message, Throwable cause) { |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
914 super(message, cause); |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
915 } |
b2cd3b828967
Simplify OnClientTester program.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
589
diff
changeset
|
916 } |
526
6060ca8c5c1a
Add test for uploadFrom methods
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
525
diff
changeset
|
917 } |