annotate tests/OnClientTester.java @ 575:08c9918177b2 onclient

Do not check the updated row count, it varies between server versions
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Wed, 06 Oct 2021 15:30:47 +0200 (2021-10-06)
parents 3370027aeb7f
children 687034945b3f
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.*;
526
6060ca8c5c1a Add test for uploadFrom methods
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 525
diff changeset
15 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
16 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
17 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
18 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
19 import java.util.List;
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
20
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
21 import static java.nio.file.StandardOpenOption.CREATE_NEW;
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
22
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
23 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
24
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
25 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
26 super(jdbcUrl, verbosity, watchDogEnabled);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
27 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
28
545
79393647d7fb Call Class.forName("...MonetDriver") from main() in OnClientTester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 544
diff changeset
29 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
30 String jdbcUrl = null;
525
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
31 String requiredPrefix = null;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
32 int verbosity = 0;
530
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
33 boolean watchDogEnabled = true;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
34
545
79393647d7fb Call Class.forName("...MonetDriver") from main() in OnClientTester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 544
diff changeset
35 // 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
36 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
37
525
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
38 for (String arg : args) {
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
39 if (arg.equals("-v"))
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
40 verbosity++;
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
41 else if (arg.equals("-vv"))
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
42 verbosity += 2;
530
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
43 else if (arg.equals("-w"))
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
44 watchDogEnabled = false;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
45 else if (jdbcUrl == null)
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
46 jdbcUrl = arg;
525
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
47 else if (requiredPrefix == null)
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
48 requiredPrefix = arg;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
49 else {
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
50 System.err.println("Unexpected argument " + arg);
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
51 System.exit(2);
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
52 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
53 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
54
530
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
55 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
56 int failures = tester.runTests(requiredPrefix);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
57
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
58 if (failures > 0)
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
59 System.exit(1);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
60 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
61
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
62 /// 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
63 /// 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
64 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
65 /// 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
66 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
67
3370027aeb7f 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 /// 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
69 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
70
3370027aeb7f 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 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
74 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
75 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
76
3370027aeb7f 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 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
78 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
79 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
80 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
81 }
3370027aeb7f 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 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
84 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
85 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
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 }
3370027aeb7f 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 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
96 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
97 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
98 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
99 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
100 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
101
3370027aeb7f 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 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
103 }
3370027aeb7f 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 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
106 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
107 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
108 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
109 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
110 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
111 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
112 }
3370027aeb7f 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 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
114 }
3370027aeb7f 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
556
87feb93330a6 Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 551
diff changeset
117 void prepare() throws SQLException {
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
118 execute("DROP TABLE IF EXISTS foo");
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
119 execute("CREATE TABLE foo (i INT, t TEXT)");
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
120 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
121
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
122 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
123 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
124 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
125 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
126 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
127 }
3370027aeb7f 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 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
130 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
131 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
132 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
133
3370027aeb7f 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 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
135
3370027aeb7f 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 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
137 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
138
3370027aeb7f 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 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
140 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
141
3370027aeb7f 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 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
143 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
144
3370027aeb7f 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 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
146 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
147 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
148 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
149 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
150 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
151 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
152
3370027aeb7f 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 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
154 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
155 }
3370027aeb7f 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 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
158 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
159 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
160 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
161 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
162 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
163 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
164 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
165
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
166 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
167 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
168 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
169 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
170 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
171 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
172 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
173 }
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 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
176 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
177 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
178 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
179 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
180 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
181 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
182 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
183 }
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 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
186 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
187 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
188 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
189 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
190 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
191 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
192 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
193 }
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 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
196 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
197 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
198 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
199 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
200 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
201 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
202 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
203 }
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 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
206 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
207 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
208 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
209 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
210 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
211 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
212 // 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
213 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
214 }
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 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
217 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
218 MyDownloadHandler handler = new MyDownloadHandler();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
219 conn.setDownloadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
220 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
221 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
222 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
223 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
224 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
225 // 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
226 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
227 }
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 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
230 test_Download(100);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
231 }
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 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
234 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
235 BugFixLevel level = getLevel();
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
236 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
237 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
238 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
239 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
240 // 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
241 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
242 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
243 // 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
244 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
245 }
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
246 }
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 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
249 watchDog.setDuration(25_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
250 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
251 int n = 4_000_000;
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
252 MyUploadHandler handler = new MyUploadHandler(n);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
253 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
254 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
255 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
256 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
257 // 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
258 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
259 }
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 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
262 watchDog.setDuration(25_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
263 test_Download(4_000_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
264 }
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 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
267 prepare();
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
268 UploadHandler handler = new UploadHandler() {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
269 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
270
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
271 @Override
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
272 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
273 // 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
274 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
275 handle.uploadFrom(s);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
276 }
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 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
279 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
280 // 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
281 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
282 }
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 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
285 prepare();
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
286 UploadHandler handler = new UploadHandler() {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
287 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
288
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
289 @Override
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
290 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
291 // 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
292 StringReader r = new StringReader(data);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
293 handle.uploadFrom(r);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
294 }
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 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
297 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
298 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
299 }
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 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
302 prepare();
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
303 UploadHandler handler = new UploadHandler() {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
304 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
305
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
306 @Override
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
307 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
308 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
309 handle.uploadFrom(r, linesToSkip);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
310 }
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 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
313 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
314 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
315 }
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 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
318 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
319 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
320 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
321 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
322 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
323 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
324 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
325
544
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
326
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
327 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
328 // 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
329 // 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
330 prepare();
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
331 UploadHandler handler = new UploadHandler() {
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
332 @Override
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
333 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
334 // 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
335 PrintStream stream = handle.getStream();
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
336 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
337 stream.println();
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
338 stream.flush();
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
339 throw new IOException("exception after all");
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
340 }
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 conn.setUploadHandler(handler);
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
343 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
344 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
345 // 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
346 }
c71ce17fa724 Add another error handling test
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 542
diff changeset
347
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
348 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
349 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
350 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
351 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
352 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
353 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
354 // 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
355 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
356 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
357
571
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
358 public void test_FileTransferHandlerUpload() throws IOException, SQLException, Failure {
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
359 prepare();
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
360 Path d = getTmpDir(currentTestName);
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
361 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
362 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
363 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
364 ps.println("1|one");
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
365 ps.println("2|two");
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
366 ps.println("3|three");
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
367 ps.close();
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
368 conn.setUploadHandler(new FileTransferHandler(d, true));
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
369 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
370 assertQueryInt("SELECT SUM(i) FROM foo", 6);
571
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
371 }
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
372
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
373 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
374 prepare();
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
375 Path d = getTmpDir(currentTestName);
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
376 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
377 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
378 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
379 ps.println("1|one");
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
380 ps.println("2|two");
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
381 ps.println("3|three");
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
382 ps.close();
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
383
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
384 Path d2 = getTmpDir(currentTestName + "2");
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
385 conn.setUploadHandler(new FileTransferHandler(d2, false));
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
386 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
387 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
388 // 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
389 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
390 }
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
391
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
392 public void test_FileTransferHandlerDownload() throws SQLException, Failure, IOException {
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
393 prepare();
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
394 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
395 Path d = getTmpDir(currentTestName);
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
396 conn.setDownloadHandler(new FileTransferHandler(d, false));
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
397 update("COPY SELECT * FROM foo INTO 'data.txt' ON CLIENT");
571
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
398 List<String> lines = Files.readAllLines(d.resolve("data.txt"));
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
399 assertEq("lines written", lines.size(), 1);
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
400 assertEq("line content", lines.get(0), "42|\"forty-two\"");
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
401 // 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
402 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
403 }
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
404
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
405 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
406 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
407 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
408 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
409 Path d = getTmpDir(currentTestName);
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
410 Path d2 = getTmpDir(currentTestName + "2");
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
411 conn.setDownloadHandler(new FileTransferHandler(d2, false));
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
412 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
413 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
414 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
415 // 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
416 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
417 }
571
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
418 }
8a4e6c82815a Fix problems with FileTransferHandler and add tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 557
diff changeset
419
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
420 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
421 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
422 private final long errorAt;
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
423 private final String errorMessage;
557
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
424 private boolean encounteredWriteError = false;
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
425 private boolean cancelled = false;
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
426
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
427 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
428
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
429 MyUploadHandler(long rows, long errorAt, String errorMessage) {
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
430 this.rows = rows;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
431 this.errorAt = errorAt;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
432 this.errorMessage = errorMessage;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
433 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
434
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
435 MyUploadHandler(long rows) {
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
436 this(rows, -1, null);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
437 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
438
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
439 MyUploadHandler(String errorMessage) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
440 this(0, -1, errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
441 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
442
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
443 public void setChunkSize(int chunkSize) {
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
444 this.chunkSize = chunkSize;
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
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
447 @Override
557
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
448 public void uploadCancelled() {
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
449 cancelled = true;
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
450 }
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
451
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
452 @Override
551
5ce6a942aff3 Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 548
diff changeset
453 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
454 if (errorAt == -1 && errorMessage != null) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
455 handle.sendError(errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
456 return;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
457 }
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
458 handle.setChunkSize(chunkSize);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
459 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
460 for (long i = linesToSkip; i < rows; i++) {
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
461 if (i == errorAt) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
462 throw new IOException(errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
463 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
464 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
465 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
466 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
467 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
468 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
469 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
470 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
471
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
472 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
473 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
474 }
557
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
475
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
476 public boolean isCancelled() {
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
477 return cancelled;
ce2b616ed22e Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 556
diff changeset
478 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
479 }
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
480
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
481 static class MyDownloadHandler implements DownloadHandler {
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
482 private final int errorAtByte;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
483 private final String errorMessage;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
484 private int attempts = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
485 private int bytesSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
486 private int lineEndingsSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
487 private int startOfLine = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
488
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
489 MyDownloadHandler(int errorAtByte, String errorMessage) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
490 this.errorAtByte = errorAtByte;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
491 this.errorMessage = errorMessage;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
492 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
493
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
494 MyDownloadHandler(String errorMessage) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
495 this(-1, errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
496 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
497
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
498 MyDownloadHandler() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
499 this(-1, null);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
500 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
501
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
502 @Override
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
503 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
504 attempts++;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
505 bytesSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
506 lineEndingsSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
507 startOfLine = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
508
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
509 if (errorMessage != null && errorAtByte < 0) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
510 handle.sendError(errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
511 return;
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
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
514 InputStream stream = handle.getStream();
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
515 byte[] buffer = new byte[1024];
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
516 while (true) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
517 int toRead = buffer.length;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
518 if (errorMessage != null && errorAtByte >= 0) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
519 if (bytesSeen == errorAtByte) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
520 throw new IOException(errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
521 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
522 toRead = Integer.min(toRead, errorAtByte - bytesSeen);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
523 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
524 int nread = stream.read(buffer, 0, toRead);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
525 if (nread < 0)
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
526 break;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
527 for (int i = 0; i < nread; i++) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
528 if (buffer[i] == '\n') {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
529 lineEndingsSeen += 1;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
530 startOfLine = bytesSeen + i + 1;
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 bytesSeen += nread;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
534 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
535 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
536
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
537 public int countAttempts() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
538 return attempts;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
539 }
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
540
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
541 public int lineCount() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
542 int lines = lineEndingsSeen;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
543 if (startOfLine != bytesSeen)
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
544 lines++;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
545 return lines;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
546 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
547 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
548
526
6060ca8c5c1a Add test for uploadFrom methods
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 525
diff changeset
549 }