Changeset: b2cd3b828967 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/b2cd3b828967
Modified Files:
tests/JDBC_API_Tester.java
tests/OnClientTester.java
tests/build.xml
Branch: default
Log Message:
Simplify OnClientTester program.
It no longer uses reflection and method naming conventions to find out which
tests to run, but just executes them sequentially.
This is much easier to read, understand and maintain.
The TestRunner superclass has also been merged into OnClientTester, so only one
file is now needed.
TestRunner.java file will be removed later, after all has proven to work well
in testweb.
diffs (truncated from 747 to 300 lines):
diff --git a/tests/JDBC_API_Tester.java b/tests/JDBC_API_Tester.java
--- a/tests/JDBC_API_Tester.java
+++ b/tests/JDBC_API_Tester.java
@@ -105,8 +105,8 @@ final public class JDBC_API_Tester {
if (jt.foundDifferences)
System.exit(-1);
- OnClientTester oct = new OnClientTester(con_URL, 0, true);
- int failures = oct.runTests("");
+ OnClientTester oct = new OnClientTester(con_URL, 0);
+ int failures = oct.runTests();
if (failures > 0)
System.exit(-1);
}
diff --git a/tests/OnClientTester.java b/tests/OnClientTester.java
--- a/tests/OnClientTester.java
+++ b/tests/OnClientTester.java
@@ -14,56 +14,208 @@ import org.monetdb.util.FileTransferHand
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.sql.Connection;
import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
import java.sql.SQLException;
import java.util.List;
import static java.nio.file.StandardOpenOption.CREATE_NEW;
-public final class OnClientTester extends TestRunner {
- public OnClientTester(String jdbcUrl, int verbosity, boolean
watchDogEnabled) {
- super(jdbcUrl, verbosity, watchDogEnabled);
+/**
+ * Program to test MonetDB JDBC Driver in combination with SQL:
+ * COPY ... INTO ... ON CLIENT
+ * commands.
+ * This allows Java programmers to locally (so ON CLIENT) stream csv data
+ * to and from the MonetDB server for fast bulk data import / export.
+ *
+ * Specifically it tests the MonetDB specific extensions to register upload
and download handlers
+ * see {@link org.monetdb.jdbc.MonetConnection#setUploadHandler(UploadHandler)}
+ * see {@link
org.monetdb.jdbc.MonetConnection#setUploadHandler(DownloadHandler)}
+ * and streaming of csv data to and from the MonetDB server using MAPI
protocol.
+ *
+ * It also tests reading / writing data from / to a local file using
+ * {@link org.monetdb.util.FileTransferHandler}
+ *
+ * @author JvR
+ * @version 0.1
+ */
+public final class OnClientTester {
+ public static final int VERBOSITY_NONE = 0;
+ public static final int VERBOSITY_ON = 1;
+ public static final int VERBOSITY_SHOW_ALL = 2;
+
+ private final String jdbcUrl;
+ private final int verbosity;
+ private String currentTestName;
+ private long startTime;
+ private MonetConnection conn;
+ private Statement stmt;
+ private StringBuilder outBuffer;
+ private Path tmpDir;
+
+ public OnClientTester(String jdbcUrl, int verbosity) {
+ this.jdbcUrl = jdbcUrl;
+ this.verbosity = verbosity;
}
- public static void main(String[] args) throws SQLException,
NoSuchMethodException, ClassNotFoundException {
+ public static void main(String[] args) {
String jdbcUrl = null;
- String requiredPrefix = null;
int verbosity = 0;
- boolean watchDogEnabled = true;
-
- // Don't know why I need this all of a sudden.. is it only on
my system?
- // Class.forName("org.monetdb.jdbc.MonetDriver"); //
should not be needed if you add: import java.sql.DriverManager;
for (String arg : args) {
if (arg.equals("-v"))
verbosity++;
else if (arg.equals("-vv"))
verbosity += 2;
- else if (arg.equals("-w"))
- watchDogEnabled = false;
else if (jdbcUrl == null)
jdbcUrl = arg;
- else if (requiredPrefix == null)
- requiredPrefix = arg;
else {
System.err.println("Unexpected argument " +
arg);
System.exit(2);
}
}
+ if (jdbcUrl == null || jdbcUrl.isEmpty()) {
+ System.err.println("Missing required startup argument:
JDBC_connection_URL");
+ System.exit(1);
+ }
- OnClientTester tester = new OnClientTester(jdbcUrl, verbosity,
watchDogEnabled);
- int failures = tester.runTests(requiredPrefix);
+ OnClientTester tester = new OnClientTester(jdbcUrl, verbosity);
+ int failures = tester.runTests();
+ if (failures > 0)
+ System.exit(-1);
+ }
+
+ public int runTests() {
+ if (! openConnection())
+ return 1; // failed to open JDBC connection to
MonetDB
+
+ outBuffer = new StringBuilder(1024);
- if (failures > 0)
- System.exit(1);
+ int failures = 0;
+ try {
+ // all test methods start with test_ and have no
arguments
+ test_BugFixLevel();
+ test_Upload();
+ test_ClientRefusesUpload();
+ test_Offset0();
+ test_Offset1();
+ test_Offset5();
+ test_ServerStopsReading();
+ test_Download();
+ test_ClientRefusesDownload();
+ test_LargeUpload();
+ test_LargeDownload();
+ test_UploadFromStream();
+ test_UploadFromReader();
+ test_UploadFromReaderOffset();
+ test_FailUploadLate();
+ test_FailUploadLate2();
+ test_FailDownloadLate();
+ test_FileTransferHandlerUploadUtf8();
+ test_FileTransferHandlerUploadLatin1();
+ test_FileTransferHandlerUploadNull();
+ test_FileTransferHandlerUploadRefused();
+ test_FileTransferHandlerDownloadUtf8();
+ test_FileTransferHandlerDownloadLatin1();
+ test_FileTransferHandlerDownloadNull();
+ test_FileTransferHandlerDownloadRefused();
+ } catch (Failure e) {
+ failures++;
+ System.err.println();
+ System.err.println("Test " + currentTestName + "
failed");
+ dumpOutput();
+ } catch (Exception e) {
+ failures++;
+ System.err.println();
+ System.err.println("Test " + currentTestName + "
failed:");
+ e.printStackTrace(System.err);
+ dumpOutput();
+ // Show the inner bits of the exception again, they may
have scrolled off screen
+ Throwable t = e;
+ while (t.getCause() != null) {
+ t = t.getCause();
+ }
+ System.err.println("Innermost cause was " + t);
+ if (t.getStackTrace().length > 0) {
+ System.err.println(" at " +
t.getStackTrace()[0]);
+ }
+ }
+ closeConnection();
+ return failures;
+ }
+
+ private boolean openConnection() {
+ try {
+ // make a connection to MonetDB, its reused for all
tests
+ final Connection genericConnection =
DriverManager.getConnection(jdbcUrl);
+ conn = genericConnection.unwrap(MonetConnection.class);
+ stmt = conn.createStatement();
+ return true;
+ } catch (SQLException e) {
+ System.err.println("Failed to connect using JDBC URL: "
+ jdbcUrl);
+ System.err.println(e);
+ }
+ return false;
+ }
+
+ private void closeConnection() {
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (SQLException e) { /* ignore */ }
+ stmt = null;
+ }
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (Exception e) { /* ignore */ }
+ conn = null;
+ }
+ }
+
+ private void initTest(final String name) {
+ currentTestName = name;
+ outBuffer.setLength(0); // clear the output log buffer
+ startTime = System.currentTimeMillis();
+ }
+
+ private void exitTest() {
+ if (verbosity > VERBOSITY_ON)
+ System.err.println();
+ if (verbosity >= VERBOSITY_ON) {
+ final long duration = System.currentTimeMillis() -
startTime;
+ System.err.println("Test " + currentTestName + "
succeeded in " + duration + "ms");
+ }
+ if (verbosity >= VERBOSITY_SHOW_ALL)
+ dumpOutput();
+
+ if (conn.isClosed())
+ openConnection(); // restore connection for next
test
+ }
+
+ private void dumpOutput() {
+ final String output = outBuffer.toString();
+ if (output.isEmpty()) {
+ System.err.println("(Test " + currentTestName + " did
not produce any output)");
+ } else {
+ System.err.println("------ Accumulated output for test
" + currentTestName + ":");
+ System.err.println(output);
+ System.err.println("------ End of accumulated output");
+ }
}
/// Some tests have to work limitations of the protocol or bugs in the
server.
/// This Enum is used to indicate the possibilities.
- public enum BugFixLevel {
+ private enum BugFixLevel {
/// Only those tests that work with older MonetDB versions
Baseline(0, 0, 0),
@@ -116,19 +268,21 @@ public final class OnClientTester extend
}
}
- void prepare() throws SQLException {
+ private void prepare() throws SQLException {
execute("DROP TABLE IF EXISTS foo");
- execute("CREATE TABLE foo (i INT, t TEXT)");
+ execute("CREATE TABLE foo (i INT, t CLOB)");
}
private BugFixLevel getLevel() throws SQLException, Failure {
String version = queryString("SELECT value FROM environment
WHERE name = 'monet_version'");
BugFixLevel level = BugFixLevel.forVersion(version);
- out.println(" NOTE: version " + version + " means level = " +
level);
+ outBuffer.append(" NOTE: version ").append(version).append("
means level = ").append(level).append("\n");
return level;
}
- public void test_BugFixLevel() throws Failure {
+ private void test_BugFixLevel() throws Failure {
+ initTest("test_BugFixLevel");
+
assertEq("Baseline includes 0.0.0", true,
BugFixLevel.Baseline.includesVersion(0, 0, 0));
assertEq("Baseline includes 11.41.11", true,
BugFixLevel.Baseline.includesVersion(11, 41, 11));
assertEq("Baseline includes 11.41.12", true,
BugFixLevel.Baseline.includesVersion(11, 41, 12));
@@ -154,27 +308,34 @@ public final class OnClientTester extend
assertEq("Level for \"11.41.11\"", BugFixLevel.Baseline,
BugFixLevel.forVersion("11.41.11"));
assertEq("Level for \"11.41.12\"",
BugFixLevel.CanRefuseDownload, BugFixLevel.forVersion("11.41.12"));
+
+ exitTest();
}
- public void test_Upload() throws SQLException, Failure {
+ private void test_Upload() throws SQLException, Failure {
+ initTest("test_Upload");
prepare();
MyUploadHandler handler = new MyUploadHandler(100);
conn.setUploadHandler(handler);
update("COPY INTO foo FROM 'banana' ON CLIENT");
assertEq("cancellation callback called", false,
handler.isCancelled());
assertQueryInt("SELECT COUNT(*) FROM foo", 100);
+ exitTest();
}
- public void test_ClientRefusesUpload() throws SQLException, Failure {
+ private void test_ClientRefusesUpload() throws SQLException, Failure {
+ initTest("test_ClientRefusesUpload");
prepare();
MyUploadHandler handler = new MyUploadHandler("immediate
error");
conn.setUploadHandler(handler);
expectError("COPY INTO foo FROM 'banana' ON CLIENT", "immediate
error");
assertEq("cancellation callback called", false,
handler.isCancelled());
assertQueryInt("SELECT COUNT(*) FROM foo", 0);
+ exitTest();
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list