Changeset: d5e895c3c9ec for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/d5e895c3c9ec
Modified Files:
src/test/java/JDBC_API_Tester.java
src/test/java/org/monetdb/jdbc/ApiTests.java
Branch: default
Log Message:
Convert Test_Creplysize() -> ApiTests#testReplySize()
diffs (188 lines):
diff --git a/src/test/java/JDBC_API_Tester.java
b/src/test/java/JDBC_API_Tester.java
--- a/src/test/java/JDBC_API_Tester.java
+++ b/src/test/java/JDBC_API_Tester.java
@@ -175,111 +175,6 @@ public final class JDBC_API_Tester exten
}
@Test
- public void Test_Creplysize() {
- sb.setLength(0); // clear the output log buffer
-
- Statement stmt1 = null;
- ResultSet rs = null;
- try {
- con.setAutoCommit(false);
- // >> true: auto commit should be off by now
- sb.append("0.
true\t").append(con.getAutoCommit()).append("\n");
-
- stmt1 = con.createStatement();
- // test commit by checking if a change is visible in
another connection
- sb.append("1. create... ");
- stmt1.executeUpdate("CREATE TABLE table_Test_Creplysize
( id int )");
- sb.append("passed\n");
-
- sb.append("2. populating with 21 records... ");
- for (int i = 0; i < 21; i++)
- stmt1.executeUpdate("INSERT INTO
table_Test_Creplysize (id) values (" + (i + 1) + ")");
- sb.append("passed\n");
-
- sb.append("3. hinting the driver to use fetchsize 10...
");
- stmt1.setFetchSize(10);
- sb.append("passed\n");
-
- sb.append("4. selecting all values... ");
- rs = stmt1.executeQuery("SELECT * FROM
table_Test_Creplysize");
- int i = 0;
- while (rs.next())
- i++;
- rs.close();
- if (i == 21) {
- sb.append("passed");
- } else {
- sb.append("got ").append(i).append("
records!!!");
- }
- sb.append("\n");
-
- sb.append("5. resetting driver fetchsize hint... ");
- stmt1.setFetchSize(0);
- sb.append("passed\n");
-
- sb.append("6. instructing the driver to return at max
10 rows... ");
- stmt1.setMaxRows(10);
- sb.append("passed\n");
-
- sb.append("7. selecting all values... ");
- rs = stmt1.executeQuery("SELECT * FROM
table_Test_Creplysize");
- i = 0;
- while (rs.next())
- i++;
- rs.close();
- if (i == 10) {
- sb.append("passed");
- } else {
- sb.append("got ").append(i).append("
records!!!");
- }
- sb.append("\n");
-
- sb.append("8. hinting the driver to use fetchsize 5...
");
- stmt1.setFetchSize(5);
- sb.append("passed\n");
-
- sb.append("9. selecting all values... ");
- rs = stmt1.executeQuery("SELECT * FROM
table_Test_Creplysize");
- i = 0;
- while (rs.next())
- i++;
- rs.close();
- if (i == 10) {
- sb.append("passed");
- } else {
- sb.append("got ").append(i).append("
records!!!");
- }
- sb.append("\n");
-
- sb.append("10. drop... ");
- stmt1.executeUpdate("DROP TABLE table_Test_Creplysize");
- sb.append("passed\n");
-
- con.rollback();
-
- // restore auto commit mode
- con.setAutoCommit(true);
- } catch (SQLException e) {
- sb.append("FAILED:
").append(e.getMessage()).append("\n");
- }
-
- closeStmtResSet(stmt1, rs);
-
- compareExpectedOutput("Test_Creplysize",
- "0. true false\n" +
- "1. create... passed\n" +
- "2. populating with 21 records... passed\n" +
- "3. hinting the driver to use fetchsize 10... passed\n"
+
- "4. selecting all values... passed\n" +
- "5. resetting driver fetchsize hint... passed\n" +
- "6. instructing the driver to return at max 10 rows...
passed\n" +
- "7. selecting all values... passed\n" +
- "8. hinting the driver to use fetchsize 5... passed\n" +
- "9. selecting all values... passed\n" +
- "10. drop... passed\n");
- }
-
- @Test
public void Test_Csavepoints() {
sb.setLength(0); // clear the output log buffer
diff --git a/src/test/java/org/monetdb/jdbc/ApiTests.java
b/src/test/java/org/monetdb/jdbc/ApiTests.java
--- a/src/test/java/org/monetdb/jdbc/ApiTests.java
+++ b/src/test/java/org/monetdb/jdbc/ApiTests.java
@@ -89,6 +89,15 @@ public class ApiTests {
return DriverManager.getConnection(Config.getServerURL());
}
+ private int queryInt(String query) throws SQLException {
+ try (ResultSet rs = stmt.executeQuery(query)) {
+ assertTrue(rs.next(), query);
+ int result = rs.getInt(1);
+ assertFalse(rs.next(), query);
+ return result;
+ }
+ }
+
@Test
public void testAutocommit() throws SQLException {
stmt.executeUpdate("DROP TABLE IF EXISTS test_autocommit");
@@ -203,5 +212,53 @@ public class ApiTests {
}
}
}
+
+ @Test
+ public void testReplySize() throws SQLException {
+ int rowCount;
+ conn.setAutoCommit(false);
+
+ // Create table with 21 rows
+ stmt.executeUpdate("DROP TABLE IF EXISTS test_replysize");
+ stmt.executeUpdate("CREATE TABLE test_replysize(i INT)");
+ stmt.executeUpdate("INSERT INTO test_replysize SELECT * FROM
sys.generate_series(0, 21)");
+ assertEquals(21, queryInt("SELECT COUNT(*) FROM
test_replysize"));
+
+ rowCount = 0;
+ try (ResultSet rs = stmt.executeQuery("SELECT * FROM
test_replysize")) {
+ while (rs.next())
+ rowCount++;
+ }
+ assertEquals(21, rowCount);
+
+ // set fetchsize to 10
+ stmt.setFetchSize(10);
+ rowCount = 0;
+ try (ResultSet rs = stmt.executeQuery("SELECT * FROM
test_replysize")) {
+ while (rs.next())
+ rowCount++;
+ }
+ assertEquals(21, rowCount);
+
+ // maxrows and fetchsize + maxrows
+ stmt.setFetchSize(0);
+ stmt.setMaxRows(10);
+ rowCount = 0;
+ try (ResultSet rs = stmt.executeQuery("SELECT * FROM
test_replysize")) {
+ while (rs.next())
+ rowCount++;
+ }
+ assertEquals(10, rowCount);
+
+ stmt.setFetchSize(5);
+ rowCount = 0;
+ try (ResultSet rs = stmt.executeQuery("SELECT * FROM
test_replysize")) {
+ while (rs.next())
+ rowCount++;
+ }
+ assertEquals(10, rowCount);
+
+ conn.setAutoCommit(true);
+ }
}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]