Github user kkhatua commented on a diff in the pull request:
https://github.com/apache/drill/pull/1024#discussion_r149476820
--- Diff:
exec/jdbc/src/test/java/org/apache/drill/jdbc/PreparedStatementTest.java ---
@@ -237,6 +245,127 @@ public String toString() {
}
}
+ /**
+ * Test for reading of default query timeout
+ */
+ @Test
+ public void testDefaultGetQueryTimeout() throws SQLException {
+ PreparedStatement stmt = connection.prepareStatement(SYS_VERSION_SQL);
+ int timeoutValue = stmt.getQueryTimeout();
+ assert( 0 == timeoutValue );
+ }
+
+ /**
+ * Test Invalid parameter by giving negative timeout
+ */
+ @Test ( expected = InvalidParameterSqlException.class )
+ public void testInvalidSetQueryTimeout() throws SQLException {
+ PreparedStatement stmt = connection.prepareStatement(SYS_VERSION_SQL);
+ //Setting negative value
+ int valueToSet = -10;
+ if (0L == valueToSet) {
+ valueToSet--;
+ }
+ try {
+ stmt.setQueryTimeout(valueToSet);
+ } catch ( final Exception e) {
+ // TODO: handle exception
+ assertThat( e.getMessage(), containsString( "illegal timeout value")
);
+ //Converting this to match expected Exception
+ throw new InvalidParameterSqlException(e.getMessage());
+ }
+ }
+
+ /**
+ * Test setting a valid timeout
+ */
+ @Test
+ public void testValidSetQueryTimeout() throws SQLException {
+ PreparedStatement stmt = connection.prepareStatement(SYS_VERSION_SQL);
+ //Setting positive value
+ int valueToSet = new Random(System.currentTimeMillis()).nextInt(60);
+ if (0L == valueToSet) {
+ valueToSet++;
+ }
+ stmt.setQueryTimeout(valueToSet);
+ assert( valueToSet == stmt.getQueryTimeout() );
+ }
+
+ /**
+ * Test setting timeout as zero and executing
+ */
+ @Test
+ public void testSetQueryTimeoutAsZero() throws SQLException {
+ PreparedStatement stmt = connection.prepareStatement(SYS_RANDOM_SQL);
+ stmt.setQueryTimeout(0);
+ stmt.executeQuery();
+ ResultSet rs = stmt.getResultSet();
+ int rowCount = 0;
+ while (rs.next()) {
+ rs.getBytes(1);
+ rowCount++;
+ }
+ stmt.close();
+ assert( 3 == rowCount );
+ }
+
+ /**
+ * Test setting timeout for a query that actually times out
+ */
+ @Test ( expected = SQLTimeoutException.class )
+ public void testTriggeredQueryTimeout() throws SQLException {
+ PreparedStatement stmt = null;
+ //Setting to a very low value (3sec)
+ int timeoutDuration = 3;
+ int rowsCounted = 0;
+ try {
+ stmt = connection.prepareStatement(SYS_RANDOM_SQL);
+ stmt.setQueryTimeout(timeoutDuration);
+ System.out.println("Set a timeout of "+ stmt.getQueryTimeout() +"
seconds");
--- End diff --
I think I previously came across some unit tests that are using System.out
instead of logger, so i figured there wasn't any preference. Logger is probably
the cleaner way of doing things. +1
---