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