annotate tests/OnClientTester.java @ 580:13134a44dfc8 onclient

Test FileTransferHandler with multiple encodings
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Thu, 14 Oct 2021 16:26:36 +0200 (2021-10-14)
parents 687034945b3f
children 5aef0ea654b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
571
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
17 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
18 import java.nio.file.Path;
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
19 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
20 import java.util.List;
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
21
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
22 import static java.nio.file.StandardOpenOption.CREATE_NEW;
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
23
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
24 public final class OnClientTester extends TestRunner {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
25
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
26 public OnClientTester(String jdbcUrl, int verbosity, boolean watchDogEnabled) {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
27 super(jdbcUrl, verbosity, watchDogEnabled);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
28 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
29
545
79393647d7fb Call Class.forName("...MonetDriver") from main() in OnClientTester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 544
diff changeset
30 public static void main(String[] args) throws SQLException, NoSuchMethodException, ClassNotFoundException {
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
31 String jdbcUrl = null;
525
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
32 String requiredPrefix = null;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
33 int verbosity = 0;
530
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
34 boolean watchDogEnabled = true;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
35
545
79393647d7fb Call Class.forName("...MonetDriver") from main() in OnClientTester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 544
diff changeset
36 // Don't know why I need this all of a sudden.. is it only on my system?
79393647d7fb Call Class.forName("...MonetDriver") from main() in OnClientTester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 544
diff changeset
37 Class.forName("org.monetdb.jdbc.MonetDriver");
79393647d7fb Call Class.forName("...MonetDriver") from main() in OnClientTester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 544
diff changeset
38
525
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
39 for (String arg : args) {
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
40 if (arg.equals("-v"))
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
41 verbosity++;
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
42 else if (arg.equals("-vv"))
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
43 verbosity += 2;
530
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
44 else if (arg.equals("-w"))
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
45 watchDogEnabled = false;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
46 else if (jdbcUrl == null)
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
47 jdbcUrl = arg;
525
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
48 else if (requiredPrefix == null)
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
49 requiredPrefix = arg;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
50 else {
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
51 System.err.println("Unexpected argument " + arg);
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
52 System.exit(2);
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
53 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
54 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
55
530
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
56 OnClientTester tester = new OnClientTester(jdbcUrl, verbosity, watchDogEnabled);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
57 int failures = tester.runTests(requiredPrefix);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
58
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
59 if (failures > 0)
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
60 System.exit(1);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
61 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
62
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
63 /// 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
64 /// This Enum is used to indicate the possibilities.
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
65 public enum BugFixLevel {
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
66 /// 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
67 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
68
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
69 /// 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
70 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
71
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
72 ;
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
73
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
74 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
75 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
76 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
77
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
78 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
79 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
80 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
81 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
82 }
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
83
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
84 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
85 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
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94 }
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
95
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
96 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
97 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
98 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
99 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
100 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
101 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
102
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
103 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
104 }
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
105
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
106 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
107 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
108 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
109 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
110 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
111 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
112 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
113 }
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
114 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
115 }
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
116 }
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
117
556
87feb93330a6 Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 551
diff changeset
118 void prepare() throws SQLException {
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
119 execute("DROP TABLE IF EXISTS foo");
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
120 execute("CREATE TABLE foo (i INT, t TEXT)");
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
121 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
122
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
123 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
124 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
125 BugFixLevel level = BugFixLevel.forVersion(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
126 out.println(" NOTE: version " + version + " means level = " + 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
127 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
128 }
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
129
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
130 public void test_BugFixLevel() throws 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
131 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
132 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
133 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
134
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
135 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
136
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
137 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
138 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
139
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
140 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
141 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
142
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
143 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
144 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
145
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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153
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
154 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
155 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
156 }
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
157
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
158 public void test_Upload() throws SQLException, Failure {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
159 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
160 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
161 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
162 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
163 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
164 assertQueryInt("SELECT COUNT(*) FROM foo", 100);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
165 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
166
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
167 public void test_ClientRefusesUpload() throws SQLException, Failure {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
168 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
169 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
170 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
171 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
172 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
173 assertQueryInt("SELECT COUNT(*) FROM foo", 0);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
174 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
175
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
176 public void test_Offset0() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
177 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
178 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
179 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
180 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
181 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
182 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
183 assertQueryInt("SELECT MAX(i) FROM foo", 100);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
184 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
185
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
186 public void test_Offset1() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
187 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
188 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
189 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
190 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
191 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
192 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
193 assertQueryInt("SELECT MAX(i) FROM foo", 100);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
194 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
195
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
196 public void test_Offset5() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
197 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
198 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
199 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
200 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
201 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
202 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
203 assertQueryInt("SELECT MAX(i) FROM foo", 100);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
204 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
205
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
206 public void test_ServerStopsReading() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
207 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
208 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
209 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
210 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
211 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
212 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
213 // 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
214 assertQueryInt("SELECT COUNT(i) FROM foo", 10);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
215 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
216
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
217 public void test_Download(int n) throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
218 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
219 MyDownloadHandler handler = new MyDownloadHandler();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
220 conn.setDownloadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
221 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
222 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
223 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
224 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
225 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
226 // 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
227 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
228 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
229
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
230 public void test_Download() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
231 test_Download(100);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
232 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
233
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
234 public void test_ClientRefusesDownload() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
235 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
236 BugFixLevel level = getLevel();
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
237 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
238 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
239 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
240 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
241 // 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
242 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
243 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
244 // 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
245 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
246 }
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
247 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
248
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
249 public void test_LargeUpload() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
250 watchDog.setDuration(25_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
251 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
252 int n = 4_000_000;
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
253 MyUploadHandler handler = new MyUploadHandler(n);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
254 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
255 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
256 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
257 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
258 // 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
259 assertQueryInt("SELECT COUNT(DISTINCT i) FROM foo", n);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
260 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
261
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
262 public void test_LargeDownload() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
263 watchDog.setDuration(25_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
264 test_Download(4_000_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
265 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
266
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
267 public void test_UploadFromStream() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
268 prepare();
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
269 UploadHandler handler = new UploadHandler() {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
270 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
271
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
272 @Override
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
273 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
274 // 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
275 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
276 handle.uploadFrom(s);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
277 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
278 };
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
279 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
280 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
281 // 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
282 assertQueryInt("SELECT i FROM foo WHERE t = 'three'", 3);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
283 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
284
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
285 public void test_UploadFromReader() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
286 prepare();
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
287 UploadHandler handler = new UploadHandler() {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
288 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
289
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
290 @Override
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
291 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
292 // 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
293 StringReader r = new StringReader(data);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
294 handle.uploadFrom(r);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
295 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
296 };
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
297 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
298 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
299 assertQueryInt("SELECT i FROM foo WHERE t = 'three'", 3);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
300 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
301
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
302 public void test_UploadFromReaderOffset() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
303 prepare();
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
304 UploadHandler handler = new UploadHandler() {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
305 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
306
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
307 @Override
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
308 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
309 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
310 handle.uploadFrom(r, linesToSkip);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
311 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
312 };
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
313 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
314 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
315 assertQueryInt("SELECT i FROM foo WHERE t = 'three'", 3);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
316 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
317
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
318 public void test_FailUploadLate() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
319 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
320 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
321 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
322 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
323 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
324 assertEq("connection is closed", true, conn.isClosed());
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
325 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
326
544
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
327
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
328 public void test_FailUploadLate2() throws SQLException, Failure {
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
329 // Here we send empty lines only, to check if the server detects is properly instead
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
330 // 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
331 prepare();
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
332 UploadHandler handler = new UploadHandler() {
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
333 @Override
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
334 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
335 // 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
336 PrintStream stream = handle.getStream();
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
337 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
338 stream.println();
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
339 stream.flush();
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
340 throw new IOException("exception after all");
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
341 }
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
342 };
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
343 conn.setUploadHandler(handler);
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
344 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
345 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
346 // Cannot check the server log, but at the time I checked, it said "prematurely stopped client", which is fine.
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
347 }
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
348
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
349 public void test_FailDownloadLate() throws SQLException, Failure {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
350 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
351 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
352 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
353 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
354 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
355 // 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
356 assertEq("connection is closed", conn.isClosed(), true);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
357 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
358
580
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
359 public void test_FileTransferHandlerUploadUtf8() throws IOException, SQLException, Failure {
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
360 testFileTransferHandlerUpload("UTF-8");
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
361 }
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
362
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
363 public void test_FileTransferHandlerUploadLatin1() throws IOException, SQLException, Failure {
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
364 testFileTransferHandlerUpload("latin1");
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
365 }
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
366
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
367 public void testFileTransferHandlerUpload(String encoding) 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
368 prepare();
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
369 Path d = getTmpDir(currentTestName);
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
370 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
371 OutputStream s = Files.newOutputStream(f, CREATE_NEW);
580
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
372 PrintStream ps = new PrintStream(s, false, encoding);
571
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
373 ps.println("1|one");
580
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
374 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
375 ps.println("3|three");
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
376 ps.close();
580
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
377 conn.setUploadHandler(new FileTransferHandler(d, Charset.forName(encoding)));
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
378 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
379 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
380 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
381 }
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
382
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
383 public void test_FileTransferHandlerUploadRefused() throws IOException, SQLException, Failure {
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
384 prepare();
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
385 Path d = getTmpDir(currentTestName);
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
386 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
387 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
388 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
389 ps.println("1|one");
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
390 ps.println("2|two");
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
391 ps.println("3|three");
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
392 ps.close();
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
393
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
394 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
395 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
396 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
397 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
398 // 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
399 assertQueryInt("SELECT SUM(i) FROM foo", 0);
571
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
400 }
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
401
580
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
402 public void test_FileTransferHandlerDownloadUtf8() throws SQLException, Failure, IOException {
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
403 testFileTransferHandlerDownload(StandardCharsets.UTF_8);
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
404 }
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
405
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
406 public void test_FileTransferHandlerDownloadLatin1() throws SQLException, Failure, IOException {
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
407 Charset latin1 = Charset.forName("latin1");
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
408 testFileTransferHandlerDownload(latin1);
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
409 }
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
410
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
411 public void testFileTransferHandlerDownload(Charset encoding) 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
412 prepare();
580
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
413 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
414 Path d = getTmpDir(currentTestName);
580
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
415 conn.setDownloadHandler(new FileTransferHandler(d, encoding));
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("COPY SELECT * FROM foo INTO 'data.txt' ON CLIENT");
580
13134a44dfc8 Test FileTransferHandler with multiple encodings
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 578
diff changeset
417 List<String> lines = Files.readAllLines(d.resolve("data.txt"), encoding);
571
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
418 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
419 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
420 // 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
421 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
422 }
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
423
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
424 public void test_FileTransferHandlerDownloadRefused() throws SQLException, Failure, IOException {
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
425 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
426 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
427 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
428 Path d = getTmpDir(currentTestName);
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
429 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
430 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
431 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
432 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
433 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
434 // 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
435 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
436 }
571
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
437 }
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
438
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
439 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
440 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
441 private final long errorAt;
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
442 private final String errorMessage;
557
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
443 private boolean encounteredWriteError = false;
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
444 private boolean cancelled = false;
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
445
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
446 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
447
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
448 MyUploadHandler(long rows, long errorAt, String errorMessage) {
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
449 this.rows = rows;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
450 this.errorAt = errorAt;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
451 this.errorMessage = errorMessage;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
452 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
453
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
454 MyUploadHandler(long rows) {
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
455 this(rows, -1, null);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
456 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
457
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
458 MyUploadHandler(String errorMessage) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
459 this(0, -1, errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
460 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
461
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
462 public void setChunkSize(int chunkSize) {
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
463 this.chunkSize = chunkSize;
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
464 }
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
465
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
466 @Override
557
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
467 public void uploadCancelled() {
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
468 cancelled = true;
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
469 }
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
470
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
471 @Override
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
472 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
473 if (errorAt == -1 && errorMessage != null) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
474 handle.sendError(errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
475 return;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
476 }
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
477 handle.setChunkSize(chunkSize);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
478 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
479 for (long i = linesToSkip; i < rows; i++) {
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
480 if (i == errorAt) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
481 throw new IOException(errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
482 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
483 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
484 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
485 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
486 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
487 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
488 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
489 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
490
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
491 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
492 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
493 }
557
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
494
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
495 public boolean isCancelled() {
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
496 return cancelled;
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
497 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
498 }
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
499
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
500 static class MyDownloadHandler implements DownloadHandler {
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
501 private final int errorAtByte;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
502 private final String errorMessage;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
503 private int attempts = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
504 private int bytesSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
505 private int lineEndingsSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
506 private int startOfLine = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
507
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
508 MyDownloadHandler(int errorAtByte, String errorMessage) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
509 this.errorAtByte = errorAtByte;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
510 this.errorMessage = errorMessage;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
511 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
512
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
513 MyDownloadHandler(String errorMessage) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
514 this(-1, errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
515 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
516
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
517 MyDownloadHandler() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
518 this(-1, null);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
519 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
521 @Override
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
522 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
523 attempts++;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
524 bytesSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
525 lineEndingsSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
526 startOfLine = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
527
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
528 if (errorMessage != null && errorAtByte < 0) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
529 handle.sendError(errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
530 return;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
531 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
532
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
533 InputStream stream = handle.getStream();
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
534 byte[] buffer = new byte[1024];
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
535 while (true) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
536 int toRead = buffer.length;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
537 if (errorMessage != null && errorAtByte >= 0) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
538 if (bytesSeen == errorAtByte) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
539 throw new IOException(errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
540 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
541 toRead = Integer.min(toRead, errorAtByte - bytesSeen);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
542 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
543 int nread = stream.read(buffer, 0, toRead);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
544 if (nread < 0)
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
545 break;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
546 for (int i = 0; i < nread; i++) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
547 if (buffer[i] == '\n') {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
548 lineEndingsSeen += 1;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
549 startOfLine = bytesSeen + i + 1;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
550 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
551 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
552 bytesSeen += nread;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
553 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
554 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
555
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
556 public int countAttempts() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
557 return attempts;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
558 }
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
559
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
560 public int lineCount() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
561 int lines = lineEndingsSeen;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
562 if (startOfLine != bytesSeen)
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
563 lines++;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
564 return lines;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
565 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
566 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
567
526
6060ca8c5c1a Add test for uploadFrom methods
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 525
diff changeset
568 }