vvysotskyi commented on a change in pull request #1714: DRILL-7048: Implement 
JDBC Statement.setMaxRows() with System Option
URL: https://github.com/apache/drill/pull/1714#discussion_r269720216
 
 

 ##########
 File path: exec/jdbc/src/test/java/org/apache/drill/jdbc/StatementTest.java
 ##########
 @@ -239,4 +246,174 @@ public void testNonTriggeredQueryTimeout() throws 
SQLException {
     }
   }
 
+  ////////////////////////////////////////
+  // Query maxRows methods:
+
+  /**
+   * Test for reading of default max rows
+   */
+  @Test
+  public void   testDefaultGetMaxRows() throws SQLException {
+    try (Statement stmt = connection.createStatement()) {
+      int maxRowsValue = stmt.getMaxRows();
+      assertEquals(0, maxRowsValue);
+    }
+  }
+
+  /**
+   * Test Invalid parameter by giving negative maxRows value
+   */
+  @Test
+  public void testInvalidSetMaxRows() throws SQLException {
+    try (Statement stmt = connection.createStatement()) {
+      // Setting negative value
+      int valueToSet = -10;
+      try {
+        stmt.setMaxRows(valueToSet);
+      } catch ( final SQLException e) {
+        assertThat( e.getMessage(), containsString("VALIDATION ERROR: Option 
exec.query.max_rows must be between 0 and ") );
+      }
+    }
+  }
+
+  /**
+   * Test setting a valid maxRows value
+   */
+  @Test
+  public void testValidSetMaxRows() throws SQLException {
+    try (Statement stmt = connection.createStatement()) {
+      // Setting positive value
+      int valueToSet = RANDOMIZER.nextInt(59)+1;
+      stmt.setMaxRows(valueToSet);
+      assertEquals( valueToSet, stmt.getMaxRows() );
+    }
+  }
+
+  /**
+   * Test setting maxSize as zero (i.e. no Limit)
+   */
+  @Test
+  public void testSetMaxRowsAsZero() throws SQLException {
+    try (Statement stmt = connection.createStatement()) {
+      stmt.setMaxRows(0);
+      stmt.executeQuery(SYS_OPTIONS_SQL);
+      ResultSet rs = stmt.getResultSet();
+      int rowCount = 0;
+      while (rs.next()) {
+        rs.getBytes(1);
+        rowCount++;
+      }
+      rs.close();
+      assertTrue(rowCount > 0);
+    }
+  }
+
+  /**
+   * Test setting maxSize at a value lower than existing query limit
+   */
+  @Test
+  public void testSetMaxRowsLowerThanQueryLimit() throws SQLException {
+    try (Statement stmt = connection.createStatement()) {
+      int valueToSet = RANDOMIZER.nextInt(9)+1; // range:[1-9]
+      stmt.setMaxRows(valueToSet);
+      stmt.executeQuery(SYS_OPTIONS_SQL_LIMIT_10);
+      ResultSet rs = stmt.getResultSet();
+      int rowCount = 0;
+      while (rs.next()) {
+        rs.getBytes(1);
+        rowCount++;
+      }
+      rs.close();
+      assertEquals(valueToSet, rowCount);
+    }
+  }
+
+  /**
+   * Test setting maxSize at a value higher than existing query limit
+   */
+  @Test
+  public void testSetMaxRowsHigherThanQueryLimit() throws SQLException {
+    try (Statement stmt = connection.createStatement()) {
+      int valueToSet = RANDOMIZER.nextInt(10)+11; // range:[11-20]
 
 Review comment:
   ```suggestion
         int valueToSet = RANDOMIZER.nextInt(10) + 11; // range: [11-20]
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to