annotate tests/OnClientTester.java @ 541:31df6a12fd41 onclient

Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection And rename them to UploadHandler and DownloadHandler
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Thu, 02 Sep 2021 14:27:20 +0200 (2021-09-02)
parents b437529144f1
children d462000fc410
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;
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
2 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
3 import org.monetdb.jdbc.MonetConnection.DownloadHandler;
519
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");
534
b437529144f1 Learn to live with server closing connection if client refuses
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 533
diff changeset
129 // 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
130 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
131 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
132
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
133 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
134 watchDog.setDuration(25_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
135 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
136 int n = 4_000_000;
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
137 MyUploadHandler handler = new MyUploadHandler(n);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
138 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
139 handler.setChunkSize(1024 * 1024);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
140 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
141 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
142 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
143 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
144
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
145 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
146 watchDog.setDuration(25_000);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
147 test_Download(4_000_000);
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
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
150 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
151 prepare();
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
152 UploadHandler handler = new UploadHandler() {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
153 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
154
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
155 @Override
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
156 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
157 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
158 handle.uploadFrom(s);
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 };
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
161 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
162 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
163 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
164 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
165
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
166 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
167 prepare();
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
168 UploadHandler handler = new UploadHandler() {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
169 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
170
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
171 @Override
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
172 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
173 StringReader r = new StringReader(data);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
174 handle.uploadFrom(r);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
175 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
176 };
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
177 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
178 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
179 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
180 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
181
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
182 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
183 prepare();
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
184 UploadHandler handler = new UploadHandler() {
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
185 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
186
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
187 @Override
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
188 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
189 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
190 handle.uploadFrom(r, offset);
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 };
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
193 conn.setUploadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
194 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
195 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
196 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
197
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
198 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
199 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
200 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
201 conn.setUploadHandler(handler);
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
202 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
203 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
204 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
205 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
206
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
207 // 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
208 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
209 prepare();
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
210 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
211 conn.setDownloadHandler(handler);
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
212 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
213 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
214 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
215 }
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
216
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
217 static class MyUploadHandler implements UploadHandler {
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
218 private final int rows;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
219 private final int errorAt;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
220 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
221 private boolean encounteredWriteError;
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
222
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
223 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
224
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
225 MyUploadHandler(int rows, int errorAt, String errorMessage) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
226 this.rows = rows;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
227 this.errorAt = errorAt;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
228 this.errorMessage = errorMessage;
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
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
231 MyUploadHandler(int rows) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
232 this(rows, -1, null);
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
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
235 MyUploadHandler(String errorMessage) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
236 this(0, -1, 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
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
239 public void setChunkSize(int chunkSize) {
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
240 this.chunkSize = chunkSize;
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
241 }
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
242
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
243 @Override
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
244 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
245 int toSkip = offset > 0 ? offset - 1 : 0;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
246 if (errorAt == -1 && errorMessage != null) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
247 handle.sendError(errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
248 return;
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
249 }
522
279414178dc6 Also test larger up- and downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 520
diff changeset
250 handle.setChunkSize(chunkSize);
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
251 PrintStream stream = handle.getStream();
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
252 for (int i = toSkip; i < rows; i++) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
253 if (i == errorAt) {
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
254 throw new IOException(errorMessage);
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
255 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
256 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
257 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
258 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
259 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
260 }
519
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 }
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
263
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
264 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
265 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
266 }
519
04a72c5bde80 Add OnclientTester.java
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
267 }
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
268
541
31df6a12fd41 Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 534
diff changeset
269 static class MyDownloadHandler implements DownloadHandler {
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
270 private final int errorAtByte;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
271 private final String errorMessage;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
272 private int attempts = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
273 private int bytesSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
274 private int lineEndingsSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
275 private int startOfLine = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
276
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
277 MyDownloadHandler(int errorAtByte, String errorMessage) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
278 this.errorAtByte = errorAtByte;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
279 this.errorMessage = errorMessage;
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
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
282 MyDownloadHandler(String errorMessage) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
283 this(-1, errorMessage);
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
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
286 MyDownloadHandler() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
287 this(-1, null);
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 @Override
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
291 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
292 attempts++;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
293 bytesSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
294 lineEndingsSeen = 0;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
295 startOfLine = 0;
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 if (errorMessage != null && errorAtByte < 0) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
298 handle.sendError(errorMessage);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
299 return;
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
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
302 InputStream stream = handle.getStream();
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
303 byte[] buffer = new byte[1024];
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
304 while (true) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
305 int toRead = buffer.length;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
306 if (errorMessage != null && errorAtByte >= 0) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
307 if (bytesSeen == errorAtByte) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
308 throw new IOException(errorMessage);
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 toRead = Integer.min(toRead, errorAtByte - bytesSeen);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
311 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
312 int nread = stream.read(buffer, 0, toRead);
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
313 if (nread < 0)
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
314 break;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
315 for (int i = 0; i < nread; i++) {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
316 if (buffer[i] == '\n') {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
317 lineEndingsSeen += 1;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
318 startOfLine = bytesSeen + i + 1;
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 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
321 bytesSeen += nread;
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
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
325 public int countAttempts() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
326 return attempts;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
327 }
531
53dc4349ace9 Extract OnClientTester infrastructure into separate class
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 530
diff changeset
328
520
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
329 public int countBytes() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
330 return bytesSeen;
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 lineCount() {
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
334 int lines = lineEndingsSeen;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
335 if (startOfLine != bytesSeen)
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
336 lines++;
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
337 return lines;
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 }
b4c7816e3592 Add more tests
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 519
diff changeset
340
526
6060ca8c5c1a Add test for uploadFrom methods
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 525
diff changeset
341 }