Skip to content

Commit

Permalink
test: Add a test for ResultSet.isAfterLast with different fetch sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexismeneses committed Apr 2, 2015
1 parent a6bd36f commit 2a4d01e
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions org/postgresql/test/jdbc2/CursorFetchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,58 @@ public void testMultiRowResultPositioning() throws Exception
}
}

public void testAnotherMultiRowResultPositioning() throws Exception
{
String msg;

int rowCount = 4;
createRows(rowCount);

int[] sizes = { 2, 3 };
for (int i = 0; i < sizes.length; ++i)
{
Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
stmt.setFetchSize(sizes[i]);

ResultSet rs = stmt.executeQuery("select * from test_fetch order by value");
msg = "before-first row positioning error with fetchsize=" + sizes[i];
assertTrue(msg, rs.isBeforeFirst());
assertTrue(msg, !rs.isAfterLast());
assertTrue(msg, !rs.isFirst());
assertTrue(msg, !rs.isLast());

for (int j = 0; j < rowCount; ++j)
{
msg = "row " + j + " positioning error with fetchsize=" + sizes[i];
assertTrue(msg, rs.next());
assertEquals(msg, j, rs.getInt(1));

assertTrue(msg, !rs.isBeforeFirst());
assertTrue(msg, !rs.isAfterLast());
if (j == 0)
assertTrue(msg, rs.isFirst());
else
assertTrue(msg, !rs.isFirst());

if (j == rowCount - 1)
assertTrue(msg, rs.isLast());
else
assertTrue(msg, !rs.isLast());
}

msg = "after-last row positioning error with fetchsize=" + sizes[i];
assertTrue(msg, !rs.next());

assertTrue(msg, !rs.isBeforeFirst());
assertTrue(msg, rs.isAfterLast());
assertTrue(msg, !rs.isFirst());
assertTrue(msg, !rs.isLast());

rs.close();
stmt.close();
}
}

// Test odd queries that should not be transformed into cursor-based fetches.
public void testInsert() throws Exception
{
Expand Down

0 comments on commit 2a4d01e

Please sign in to comment.