annotate tests/OnClientTester.java @ 542:d462000fc410 onclient

Various changes suggested by Martin van Dinther
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Thu, 02 Sep 2021 15:13:46 +0200 (2021-09-02)
parents 31df6a12fd41
children c71ce17fa724
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
542
d462000fc410 Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 541
diff changeset
1 /*
d462000fc410 Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 541
diff changeset
2 * This Source Code Form is subject to the terms of the Mozilla Public
d462000fc410 Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 541
diff changeset
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
d462000fc410 Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 541
diff changeset
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
d462000fc410 Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 541
diff changeset
5 *
d462000fc410 Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 541
diff changeset
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
d462000fc410 Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 541
diff changeset
7 */
d462000fc410 Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 541
diff changeset
8
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
9 import org.monetdb.jdbc.MonetConnection;
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
10 import org.monetdb.jdbc.MonetConnection.UploadHandler;
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
11 import org.monetdb.jdbc.MonetConnection.DownloadHandler;
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
12
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
13 import java.io.*;
526
6060ca8c5c1a Add test for uploadFrom methods
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 525
diff changeset
14 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
15 import java.sql.SQLException;
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
16
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
17 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
18
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
19 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
20 super(jdbcUrl, verbosity, watchDogEnabled);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
21 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
22
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
23 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
24 String jdbcUrl = null;
525
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
25 String requiredPrefix = null;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
26 int verbosity = 0;
530
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
27 boolean watchDogEnabled = true;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
28
525
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
29 for (String arg : args) {
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
30 if (arg.equals("-v"))
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
31 verbosity++;
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
32 else if (arg.equals("-vv"))
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
33 verbosity += 2;
530
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
34 else if (arg.equals("-w"))
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
35 watchDogEnabled = false;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
36 else if (jdbcUrl == null)
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
37 jdbcUrl = arg;
525
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
38 else if (requiredPrefix == null)
70ff796c42f7 Run subset of tests based on prefix
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 524
diff changeset
39 requiredPrefix = arg;
524
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
40 else {
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
41 System.err.println("Unexpected argument " + arg);
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
42 System.exit(2);
71644dc873fe Manage verbosity
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 523
diff changeset
43 }
519
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
530
bf47aab3aeb7 Add flag to disable watchdog timer
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 529
diff changeset
46 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
47 int failures = tester.runTests(requiredPrefix);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
48
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
49 if (failures > 0)
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
50 System.exit(1);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
51 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
52
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
53 protected void prepare() throws SQLException {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
54 execute("DROP TABLE IF EXISTS foo");
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
55 execute("CREATE TABLE foo (i INT, t TEXT)");
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
56 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
57
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
58 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
59 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
60 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
61 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
62 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
63 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
64 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
65 }
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 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
68 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
69 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
70 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
71 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
72 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
73 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
74 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
75
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
76 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
77 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
78 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
79 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
80 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
81 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
82 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
83 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
84 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
85
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
86 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
87 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
88 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
89 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
90 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
91 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
92 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
93 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
94 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
95
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
96 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
97 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
98 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
99 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
100 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
101 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
102 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
103 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
104 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
105
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
106 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
107 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
108 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
109 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
110 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
111 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
112 // 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
113 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
114 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
115
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
116 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
117 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
118 MyDownloadHandler handler = new MyDownloadHandler();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
119 conn.setDownloadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
120 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
121 update(q, n);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
122 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
123 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
124 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
125 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
126
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
127 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
128 test_Download(100);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
129 }
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 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
132 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
133 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
134 conn.setDownloadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
135 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
136 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
137 // 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
138 expectError("SELECT 42 -- check if the connection still works", "Connection to server lost!");
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
139 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
140
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
141 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
142 watchDog.setDuration(25_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
143 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
144 int n = 4_000_000;
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
145 MyUploadHandler handler = new MyUploadHandler(n);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
146 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
147 handler.setChunkSize(1024 * 1024);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
148 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
149 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
150 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
151 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
152
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
153 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
154 watchDog.setDuration(25_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
155 test_Download(4_000_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
156 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
157
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
158 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
159 prepare();
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
160 UploadHandler handler = new UploadHandler() {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
161 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
162
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
163 @Override
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
164 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
165 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
166 handle.uploadFrom(s);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
167 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
168 };
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
169 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
170 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
171 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
172 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
173
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
174 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
175 prepare();
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
176 UploadHandler handler = new UploadHandler() {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
177 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
178
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
179 @Override
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
180 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
181 StringReader r = new StringReader(data);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
182 handle.uploadFrom(r);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
183 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
184 };
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
185 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
186 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
187 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
188 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
189
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
190 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
191 prepare();
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
192 UploadHandler handler = new UploadHandler() {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
193 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
194
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
195 @Override
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
196 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
197 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
198 handle.uploadFrom(r, offset);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
199 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
200 };
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
201 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
202 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
203 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
204 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
205
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
206 public void test_FailUploadLate() throws SQLException, Failure {
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
207 prepare();
533
b75464874130 Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 531
diff changeset
208 MyUploadHandler handler = new MyUploadHandler(100, 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
209 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
210 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
211 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
212 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
213 }
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 // 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
216 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
217 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
218 MyDownloadHandler handler = new MyDownloadHandler(200, "download refused");
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
219 conn.setDownloadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
220 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
221 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
222 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
223 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
224
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
225 static class MyUploadHandler implements UploadHandler {
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
226 private final int rows;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
227 private final int errorAt;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
228 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
229 private boolean encounteredWriteError;
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
230
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
231 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
232
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
233 MyUploadHandler(int rows, int errorAt, String errorMessage) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
234 this.rows = rows;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
235 this.errorAt = errorAt;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
236 this.errorMessage = errorMessage;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
237 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
238
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
239 MyUploadHandler(int rows) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
240 this(rows, -1, null);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
241 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
242
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
243 MyUploadHandler(String errorMessage) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
244 this(0, -1, errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
245 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
246
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
247 public void setChunkSize(int chunkSize) {
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
248 this.chunkSize = chunkSize;
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
249 }
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
250
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
251 @Override
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
252 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
253 int toSkip = offset > 0 ? offset - 1 : 0;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
254 if (errorAt == -1 && errorMessage != null) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
255 handle.sendError(errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
256 return;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
257 }
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
258 handle.setChunkSize(chunkSize);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
259 PrintStream stream = handle.getStream();
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
260 for (int i = toSkip; i < rows; i++) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
261 if (i == errorAt) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
262 throw new IOException(errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
263 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
264 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
265 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
266 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
267 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
268 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
269 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
270 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
271
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
272 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
273 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
274 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
275 }
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
276
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
277 static class MyDownloadHandler implements DownloadHandler {
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
278 private final int errorAtByte;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
279 private final String errorMessage;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
280 private int attempts = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
281 private int bytesSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
282 private int lineEndingsSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
283 private int startOfLine = 0;
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(int errorAtByte, String errorMessage) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
286 this.errorAtByte = errorAtByte;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
287 this.errorMessage = errorMessage;
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
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
290 MyDownloadHandler(String errorMessage) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
291 this(-1, errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
292 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
293
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
294 MyDownloadHandler() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
295 this(-1, null);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
296 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
297
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
298 @Override
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
299 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
300 attempts++;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
301 bytesSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
302 lineEndingsSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
303 startOfLine = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
304
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 handle.sendError(errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
307 return;
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
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
310 InputStream stream = handle.getStream();
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
311 byte[] buffer = new byte[1024];
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
312 while (true) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
313 int toRead = buffer.length;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
314 if (errorMessage != null && errorAtByte >= 0) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
315 if (bytesSeen == errorAtByte) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
316 throw new IOException(errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
317 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
318 toRead = Integer.min(toRead, errorAtByte - bytesSeen);
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 int nread = stream.read(buffer, 0, toRead);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
321 if (nread < 0)
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
322 break;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
323 for (int i = 0; i < nread; i++) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
324 if (buffer[i] == '\n') {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
325 lineEndingsSeen += 1;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
326 startOfLine = bytesSeen + i + 1;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
327 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
328 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
329 bytesSeen += nread;
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
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
333 public int countAttempts() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
334 return attempts;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
335 }
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
336
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
337 public int countBytes() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
338 return bytesSeen;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
339 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
340
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
341 public int lineCount() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
342 int lines = lineEndingsSeen;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
343 if (startOfLine != bytesSeen)
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
344 lines++;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
345 return lines;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
346 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
347 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
348
526
6060ca8c5c1a Add test for uploadFrom methods
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 525
diff changeset
349 }