Skip to content

Commit

Permalink
feat: pass JDBCSampler.maxRows to Statement.setMaxRows so the driver …
Browse files Browse the repository at this point in the history
…does not fetch extra rows from the database
  • Loading branch information
vlsi committed Dec 30, 2023
1 parent 05c8659 commit 24473c3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti
if (SELECT.equals(currentQueryType)) {
try (Statement stmt = conn.createStatement()) {
setQueryTimeout(stmt, getIntegerQueryTimeout());
configureMaxRows(stmt);
ResultSet rs = null;
try {
rs = stmt.executeQuery(getQuery());
Expand Down Expand Up @@ -198,6 +199,7 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti
} else if (PREPARED_SELECT.equals(currentQueryType)) {
try (PreparedStatement pstmt = getPreparedStatement(conn)) {
setArguments(pstmt);
configureMaxRows(pstmt);
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
Expand Down Expand Up @@ -236,7 +238,15 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti
}
}

private void configureMaxRows(Statement stmt) throws SQLException {
int maxRows = getIntegerResultSetMaxRows();
if (maxRows >= 0) {
stmt.setMaxRows(maxRows);
}
}

private String resultSetsToString(PreparedStatement pstmt, boolean result, int[] out) throws SQLException, UnsupportedEncodingException {
configureMaxRows(pstmt);
StringBuilder sb = new StringBuilder();
int updateCount = 0;
boolean currentResult = result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ public SampleResult sample(Entry e) {
Connection conn = null;

try {
if (JOrphanUtils.isBlank(getDataSource())) {
String dataSource = getDataSource();
if (JOrphanUtils.isBlank(dataSource)) {
throw new IllegalArgumentException("Name for DataSoure must not be empty in " + getName());
}

try {
conn = DataSourceElement.getConnection(getDataSource());
conn = DataSourceElement.getConnection(dataSource);
} finally {
res.connectEnd();
}
res.setResponseHeaders(DataSourceElement.getConnectionInfo(getDataSource()));
res.setResponseHeaders(DataSourceElement.getConnectionInfo(dataSource));
res.setResponseData(execute(conn, res));
} catch (SQLException ex) {
final String errCode = Integer.toString(ex.getErrorCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class JDBCSamplerTest {
val stmt = mockk<Statement> {
every { executeQuery(any()) } returns rs
justRun { queryTimeout = any() }
justRun { maxRows = any() }
justRun { close() }
}
val conn = mockk<Connection> {
Expand All @@ -90,11 +91,13 @@ class JDBCSamplerTest {
}

sut.query = "SELECT"
sut.resultSetMaxRows = "10"
val response = sut.executeForTest(conn, sample)

verifyOrder {
conn.createStatement()
stmt.queryTimeout = 0
stmt.maxRows = 10
stmt.executeQuery(any())
sample.latencyEnd()
// getStringFromResultSet
Expand Down
1 change: 1 addition & 0 deletions xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Summary
<li><issue>6165</issue><pr>6192</pr>The Constant Throughput Timer is throwing a NullPointerException when using variables (vars.get) in "Target Throughput"-field</li>
<li><issue>6162</issue>The Constant Timer is throwing a NullPointerException when using variables (vars.get) in "delay"-field</li>
<li><pr>6193</pr>Log errors happening while JMeter starts the test (previously, errors from TestStateListener.testStarted were not logged)</li>
<li><pr>6216</pr>Pass JDBCSampler.maxRows to Statement.setMaxRows so the driver does not fetch extra rows from the database</li>
</ul>

<ch_section>Non-functional changes</ch_section>
Expand Down

0 comments on commit 24473c3

Please sign in to comment.