comparison tests/OnClientTester.java @ 522:279414178dc6 onclient

Also test larger up- and downloads
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Thu, 26 Aug 2021 12:08:06 +0200 (2021-08-26)
parents b4c7816e3592
children 3ff972d266cb
comparison
equal deleted inserted replaced
521:72007c4f8f8a 522:279414178dc6
205 static class MyUploadHandler implements MonetUploadHandler { 205 static class MyUploadHandler implements MonetUploadHandler {
206 206
207 private final int rows; 207 private final int rows;
208 private final int errorAt; 208 private final int errorAt;
209 private final String errorMessage; 209 private final String errorMessage;
210
211 private int chunkSize = 100; // small number to trigger more bugs
212
210 MyUploadHandler(int rows, int errorAt, String errorMessage) { 213 MyUploadHandler(int rows, int errorAt, String errorMessage) {
211 this.rows = rows; 214 this.rows = rows;
212 this.errorAt = errorAt; 215 this.errorAt = errorAt;
213 this.errorMessage = errorMessage; 216 this.errorMessage = errorMessage;
214 } 217 }
217 this(rows, -1, null); 220 this(rows, -1, null);
218 } 221 }
219 222
220 MyUploadHandler(String errorMessage) { 223 MyUploadHandler(String errorMessage) {
221 this(0, -1, errorMessage); 224 this(0, -1, errorMessage);
225 }
226
227 public void setChunkSize(int chunkSize) {
228 this.chunkSize = chunkSize;
222 } 229 }
223 230
224 @Override 231 @Override
225 public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, int offset) throws IOException { 232 public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, int offset) throws IOException {
226 int toSkip = offset > 0 ? offset - 1 : 0; 233 int toSkip = offset > 0 ? offset - 1 : 0;
227 if (errorAt == -1 && errorMessage != null) { 234 if (errorAt == -1 && errorMessage != null) {
228 handle.sendError(errorMessage); 235 handle.sendError(errorMessage);
229 return; 236 return;
230 } 237 }
238 handle.setChunkSize(chunkSize);
231 PrintStream stream = handle.getStream(); 239 PrintStream stream = handle.getStream();
232 for (int i = toSkip; i < rows; i++) { 240 for (int i = toSkip; i < rows; i++) {
233 if (i == errorAt) { 241 if (i == errorAt) {
234 throw new IOException(errorMessage); 242 throw new IOException(errorMessage);
235 } 243 }
366 update("COPY 10 RECORDS INTO foo FROM 'banana' ON CLIENT", 96); 374 update("COPY 10 RECORDS INTO foo FROM 'banana' ON CLIENT", 96);
367 // Server stopped reading after 10 rows. Will we stay in sync? 375 // Server stopped reading after 10 rows. Will we stay in sync?
368 queryInt("SELECT COUNT(i) FROM foo", 10); 376 queryInt("SELECT COUNT(i) FROM foo", 10);
369 } 377 }
370 378
371 private void test_Download() throws SQLException, Failure { 379 private void test_Download(int n) throws SQLException, Failure {
372 prepare(); 380 prepare();
373 MyDownloadHandler handler = new MyDownloadHandler(); 381 MyDownloadHandler handler = new MyDownloadHandler();
374 conn.setDownloadHandler(handler); 382 conn.setDownloadHandler(handler);
375 update("INSERT INTO foo SELECT value as i, 'number' || value AS t FROM sys.generate_series(0, 100)", 100); 383 String q = "INSERT INTO foo SELECT value as i, 'number' || value AS t FROM sys.generate_series(0, " + n + ")";
384 update(q, n);
376 update("COPY (SELECT * FROM foo) INTO 'banana' ON CLIENT", -1); 385 update("COPY (SELECT * FROM foo) INTO 'banana' ON CLIENT", -1);
377 assertEq("download attempts", 1, handler.countAttempts()); 386 assertEq("download attempts", 1, handler.countAttempts());
378 assertEq("lines downloaded", 100, handler.lineCount()); 387 assertEq("lines downloaded", n, handler.lineCount());
388 }
389
390 private void test_Download() throws SQLException, Failure {
391 test_Download(100);
379 } 392 }
380 393
381 private void test_CancelledDownload() throws SQLException, Failure { 394 private void test_CancelledDownload() throws SQLException, Failure {
382 prepare(); 395 prepare();
383 MyDownloadHandler handler = new MyDownloadHandler("download refused"); 396 MyDownloadHandler handler = new MyDownloadHandler("download refused");
386 expectError("COPY (SELECT * FROM foo) INTO 'banana' ON CLIENT", "download refused"); 399 expectError("COPY (SELECT * FROM foo) INTO 'banana' ON CLIENT", "download refused");
387 // check if the connection still works 400 // check if the connection still works
388 queryInt("SELECT 42", 42); 401 queryInt("SELECT 42", 42);
389 } 402 }
390 403
404 public void test_LargeUpload() throws SQLException, Failure {
405 prepare();
406 int n = 4_000_000;
407 MyUploadHandler handler = new MyUploadHandler(n);
408 conn.setUploadHandler(handler);
409 handler.setChunkSize(1024 * 1024);
410 update("COPY INTO foo FROM 'banana' ON CLIENT", n);
411 queryInt("SELECT COUNT(DISTINCT i) FROM foo", n);
412 }
413
414 private void test_LargeDownload() throws SQLException, Failure {
415 test_Download(4_000_000);
416 }
391 417
392 } 418 }