annotate tests/OnClientTester.java @ 533:b75464874130 onclient

Keep better track of whether the server has cancelled the upload IOExceptions are suppressed by PrintStreams print/println methods. This means the client may not realize the server cancelled and we must suppress all further attempts to write. Also, the end of upload handshake is different if a cancellation occurred.
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Fri, 27 Aug 2021 13:45:38 +0200 (2021-08-27)
parents 53dc4349ace9
children b437529144f1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
1 import org.monetdb.jdbc.MonetConnection;
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
2 import org.monetdb.jdbc.MonetDownloadHandler;
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
3 import org.monetdb.jdbc.MonetUploadHandler;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
4
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
5 import java.io.*;
526
6060ca8c5c1a Add test for uploadFrom methods
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 525
diff changeset
6 import java.nio.charset.StandardCharsets;
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
7 import java.sql.SQLException;
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
8
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
9 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
10
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
11 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
12 super(jdbcUrl, verbosity, watchDogEnabled);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
13 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
14
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
15 public static void main(String[] args) throws SQLException, NoSuchMethodException {
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
16 String jdbcUrl = null;
525
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
17 String requiredPrefix = null;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
18 int verbosity = 0;
530
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
19 boolean watchDogEnabled = true;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
20
525
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
21 for (String arg : args) {
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
22 if (arg.equals("-v"))
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
23 verbosity++;
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
24 else if (arg.equals("-vv"))
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
25 verbosity += 2;
530
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
26 else if (arg.equals("-w"))
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
27 watchDogEnabled = false;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
28 else if (jdbcUrl == null)
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
29 jdbcUrl = arg;
525
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
30 else if (requiredPrefix == null)
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
31 requiredPrefix = arg;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
32 else {
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
33 System.err.println("Unexpected argument " + arg);
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
34 System.exit(2);
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
35 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
36 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
37
530
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
38 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
39 int failures = tester.runTests(requiredPrefix);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
40
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
41 if (failures > 0)
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
42 System.exit(1);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
43 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
44
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
45 protected void prepare() throws SQLException {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
46 execute("DROP TABLE IF EXISTS foo");
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
47 execute("CREATE TABLE foo (i INT, t TEXT)");
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
48 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
49
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
50 public void test_Upload() throws Exception {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
51 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
52 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
53 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
54 update("COPY INTO foo FROM 'banana' ON CLIENT", 100);
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
55 assertEq("handler encountered write error", false, handler.encounteredWriteError());
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
56 queryInt("SELECT COUNT(*) FROM foo", 100);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
57 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
58
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
59 public void test_ClientRefusesUpload() throws Exception {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
60 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
61 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
62 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
63 expectError("COPY INTO foo FROM 'banana' ON CLIENT", "immediate error");
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
64 assertEq("handler encountered write error", false, handler.encounteredWriteError());
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
65 queryInt("SELECT COUNT(*) FROM foo", 0);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
66 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
67
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
68 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
69 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
70 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
71 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
72 update("COPY OFFSET 0 INTO foo FROM 'banana' ON CLIENT", 100);
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
73 assertEq("handler encountered write error", false, handler.encounteredWriteError());
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
74 queryInt("SELECT MIN(i) FROM foo", 1);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
75 queryInt("SELECT MAX(i) FROM foo", 100);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
76 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
77
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
78 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
79 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
80 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
81 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
82 update("COPY OFFSET 1 INTO foo FROM 'banana' ON CLIENT", 100);
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
83 assertEq("handler encountered write error", false, handler.encounteredWriteError());
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
84 queryInt("SELECT MIN(i) FROM foo", 1);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
85 queryInt("SELECT MAX(i) FROM foo", 100);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
86 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
87
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
88 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
89 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
90 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
91 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
92 update("COPY OFFSET 5 INTO foo FROM 'banana' ON CLIENT", 96);
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
93 assertEq("handler encountered write error", false, handler.encounteredWriteError());
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
94 queryInt("SELECT MIN(i) FROM foo", 5);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
95 queryInt("SELECT MAX(i) FROM foo", 100);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
96 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
97
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
98 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
99 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
100 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
101 conn.setUploadHandler(handler);
b75464874130 Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 531
diff changeset
102 update("COPY 10 RECORDS INTO foo FROM 'banana' ON CLIENT", 10);
b75464874130 Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 531
diff changeset
103 assertEq("handler encountered write error", true, handler.encounteredWriteError());
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
104 // Server stopped reading after 10 rows. Will we stay in sync?
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
105 queryInt("SELECT COUNT(i) FROM foo", 10);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
106 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
107
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
108 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
109 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
110 MyDownloadHandler handler = new MyDownloadHandler();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
111 conn.setDownloadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
112 String q = "INSERT INTO foo SELECT value as i, 'number' || value AS t FROM sys.generate_series(0, " + n + ")";
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
113 update(q, n);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
114 update("COPY (SELECT * FROM foo) INTO 'banana' ON CLIENT", -1);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
115 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
116 assertEq("lines downloaded", n, handler.lineCount());
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
117 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
118
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
119 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
120 test_Download(100);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
121 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
122
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
123 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
124 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
125 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
126 conn.setDownloadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
127 update("INSERT INTO foo SELECT value as i, 'number' || value AS t FROM sys.generate_series(0, 100)", 100);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
128 expectError("COPY (SELECT * FROM foo) INTO 'banana' ON CLIENT", "download refused");
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
129 queryInt("SELECT 42 -- check if the connection still works", 42);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
130 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
131
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
132 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
133 watchDog.setDuration(25_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
134 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
135 int n = 4_000_000;
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
136 MyUploadHandler handler = new MyUploadHandler(n);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
137 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
138 handler.setChunkSize(1024 * 1024);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
139 update("COPY INTO foo FROM 'banana' ON CLIENT", n);
533
b75464874130 Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 531
diff changeset
140 assertEq("handler encountered write error", false, handler.encounteredWriteError());
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
141 queryInt("SELECT COUNT(DISTINCT i) FROM foo", n);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
142 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
143
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
144 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
145 watchDog.setDuration(25_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
146 test_Download(4_000_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
147 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
148
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
149 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
150 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
151 MonetUploadHandler handler = new MonetUploadHandler() {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
152 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
153
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
154 @Override
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
155 public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, int offset) throws IOException {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
156 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
157 handle.uploadFrom(s);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
158 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
159 };
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
160 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
161 update("COPY INTO foo FROM 'banana' ON CLIENT", 3);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
162 queryInt("SELECT i FROM foo WHERE t = 'three'", 3);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
163 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
164
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
165 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
166 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
167 MonetUploadHandler handler = new MonetUploadHandler() {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
168 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
169
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
170 @Override
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
171 public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, int offset) throws IOException {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
172 StringReader r = new StringReader(data);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
173 handle.uploadFrom(r);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
174 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
175 };
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
176 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
177 update("COPY INTO foo FROM 'banana' ON CLIENT", 3);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
178 queryInt("SELECT i FROM foo WHERE t = 'three'", 3);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
179 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
180
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
181 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
182 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
183 MonetUploadHandler handler = new MonetUploadHandler() {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
184 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
185
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
186 @Override
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
187 public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, int offset) throws IOException {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
188 BufferedReader r = new BufferedReader(new StringReader(data));
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
189 handle.uploadFrom(r, offset);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
190 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
191 };
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
192 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
193 update("COPY OFFSET 2 INTO foo FROM 'banana' ON CLIENT", 2);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
194 queryInt("SELECT i FROM foo WHERE t = 'three'", 3);
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_FailUploadLate() 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, 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
200 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
201 expectError("COPY INTO foo FROM 'banana' ON CLIENT", "i don't like");
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
202 assertEq("handler encountered write error", false, handler.encounteredWriteError());
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
203 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
204 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
205
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
206 // Disabled because it hangs, triggering the watchdog timer
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
207 public void testx_FailDownloadLate() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
208 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
209 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
210 conn.setDownloadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
211 update("INSERT INTO foo SELECT value as i, 'number' || value AS t FROM sys.generate_series(0, 100)", 100);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
212 expectError("COPY (SELECT * FROM foo) INTO 'banana' ON CLIENT", "download refused");
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
213 queryInt("SELECT 42 -- check if the connection still works", 42);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
214 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
215
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
216 static class MyUploadHandler implements MonetUploadHandler {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
217 private final int rows;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
218 private final int errorAt;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
219 private final String errorMessage;
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
220 private boolean encounteredWriteError;
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
221
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
222 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
223
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
224 MyUploadHandler(int rows, int errorAt, String errorMessage) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
225 this.rows = rows;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
226 this.errorAt = errorAt;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
227 this.errorMessage = errorMessage;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
228 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
229
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
230 MyUploadHandler(int rows) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
231 this(rows, -1, null);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
232 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
233
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
234 MyUploadHandler(String errorMessage) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
235 this(0, -1, errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
236 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
237
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
238 public void setChunkSize(int chunkSize) {
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
239 this.chunkSize = chunkSize;
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
240 }
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
241
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
242 @Override
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
243 public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, int offset) throws IOException {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
244 int toSkip = offset > 0 ? offset - 1 : 0;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
245 if (errorAt == -1 && errorMessage != null) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
246 handle.sendError(errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
247 return;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
248 }
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
249 handle.setChunkSize(chunkSize);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
250 PrintStream stream = handle.getStream();
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
251 for (int i = toSkip; i < rows; i++) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
252 if (i == errorAt) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
253 throw new IOException(errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
254 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
255 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
256 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
257 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
258 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
259 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
260 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
261 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
262
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
263 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
264 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
265 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
266 }
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
267
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
268 static class MyDownloadHandler implements MonetDownloadHandler {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
269 private final int errorAtByte;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
270 private final String errorMessage;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
271 private int attempts = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
272 private int bytesSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
273 private int lineEndingsSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
274 private int startOfLine = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
275
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
276 MyDownloadHandler(int errorAtByte, String errorMessage) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
277 this.errorAtByte = errorAtByte;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
278 this.errorMessage = errorMessage;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
279 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
280
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
281 MyDownloadHandler(String errorMessage) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
282 this(-1, errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
283 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
284
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
285 MyDownloadHandler() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
286 this(-1, null);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
287 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
288
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
289 @Override
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
290 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
291 attempts++;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
292 bytesSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
293 lineEndingsSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
294 startOfLine = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
295
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
296 if (errorMessage != null && errorAtByte < 0) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
297 handle.sendError(errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
298 return;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
299 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
300
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
301 InputStream stream = handle.getStream();
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
302 byte[] buffer = new byte[1024];
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
303 while (true) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
304 int toRead = buffer.length;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
305 if (errorMessage != null && errorAtByte >= 0) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
306 if (bytesSeen == errorAtByte) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
307 throw new IOException(errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
308 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
309 toRead = Integer.min(toRead, errorAtByte - bytesSeen);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
310 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
311 int nread = stream.read(buffer, 0, toRead);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
312 if (nread < 0)
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
313 break;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
314 for (int i = 0; i < nread; i++) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
315 if (buffer[i] == '\n') {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
316 lineEndingsSeen += 1;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
317 startOfLine = bytesSeen + i + 1;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
318 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
319 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
320 bytesSeen += nread;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
321 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
322 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
323
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
324 public int countAttempts() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
325 return attempts;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
326 }
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
327
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
328 public int countBytes() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
329 return bytesSeen;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
330 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
331
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
332 public int lineCount() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
333 int lines = lineEndingsSeen;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
334 if (startOfLine != bytesSeen)
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
335 lines++;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
336 return lines;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
337 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
338 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
339
526
6060ca8c5c1a Add test for uploadFrom methods
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 525
diff changeset
340 }