Skip to content

Commit

Permalink
Apply Checkstyle to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Dec 14, 2024
1 parent 374eb8b commit 32d2c06
Show file tree
Hide file tree
Showing 29 changed files with 626 additions and 645 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<configuration>
<configLocation>${basedir}/src/conf/checkstyle.xml</configLocation>
<enableRulesSummary>false</enableRulesSummary>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -346,6 +347,7 @@
<configuration>
<configLocation>${basedir}/src/conf/checkstyle.xml</configLocation>
<enableRulesSummary>false</enableRulesSummary>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ private void assertAndReset(final DelegatingConnection<?> con) {
con.setLastUsed(Instant.EPOCH);
}


/**
* Verifies that PreparedStatement executeXxx methods update lastUsed on the parent connection
*/
private void checkLastUsedPreparedStatement(final PreparedStatement ps, final DelegatingConnection<?> conn)
throws Exception {
private void checkLastUsedPreparedStatement(final PreparedStatement ps, final DelegatingConnection<?> conn) throws Exception {
ps.execute();
assertAndReset(conn);
try (ResultSet rs = ps.executeQuery()) {
Expand Down Expand Up @@ -103,7 +101,7 @@ private void checkLastUsedStatement(final Statement st, final DelegatingConnecti
assertAndReset(conn);
}

private void createStatement(final Connection conn) throws Exception{
private void createStatement(final Connection conn) throws Exception {
final PreparedStatement ps = conn.prepareStatement("");
Assertions.assertNotNull(ps);
}
Expand Down Expand Up @@ -152,8 +150,7 @@ public void testAbandonedClose() throws Exception {
// Verify that conn1 is closed
assertTrue(((DelegatingConnection<?>) conn1).getInnermostDelegate().isClosed());
// Verify that conn1 is aborted
final TesterConnection tCon = (TesterConnection) ((DelegatingConnection<?>) conn1)
.getInnermostDelegate();
final TesterConnection tCon = (TesterConnection) ((DelegatingConnection<?>) conn1).getInnermostDelegate();
assertTrue(tCon.isAborted());

}
Expand Down Expand Up @@ -229,8 +226,7 @@ public void testAbandonedStackTraces() throws Exception {
// Verify that conn1 is closed
assertTrue(((DelegatingConnection<?>) conn1).getInnermostDelegate().isClosed());
// Verify that conn1 is aborted
final TesterConnection tCon = (TesterConnection) ((DelegatingConnection<?>) conn1)
.getInnermostDelegate();
final TesterConnection tCon = (TesterConnection) ((DelegatingConnection<?>) conn1).getInnermostDelegate();
assertTrue(tCon.isAborted());

}
Expand All @@ -244,9 +240,7 @@ public void testAbandonedStackTraces() throws Exception {
}

/**
* DBCP-180 - verify that a GC can clean up an unused Statement when it is
* no longer referenced even when it is tracked via the AbandonedTrace
* mechanism.
* DBCP-180 - verify that a GC can clean up an unused Statement when it is no longer referenced even when it is tracked via the AbandonedTrace mechanism.
*/
@Test
public void testGarbageCollectorCleanUp01() throws Exception {
Expand All @@ -269,7 +263,7 @@ public void testGarbageCollectorCleanUp02() throws Exception {
final DelegatingConnection<?> conn = (DelegatingConnection<?>) ds.getConnection();
final PoolableConnection poolableConn = (PoolableConnection) conn.getDelegate();
final PoolingConnection poolingConn = (PoolingConnection) poolableConn.getDelegate();
final KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> gkop = poolingConn.getStatementPool();
final KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> gkop = poolingConn.getStatementPool();
Assertions.assertEquals(0, conn.getTrace().size());
Assertions.assertEquals(0, gkop.getNumActive());
createStatement(conn);
Expand All @@ -288,8 +282,7 @@ public void testGarbageCollectorCleanUp02() throws Exception {
}

/**
* Verify that lastUsed property is updated when a connection
* creates or prepares a statement
* Verify that lastUsed property is updated when a connection creates or prepares a statement
*/
@Test
public void testLastUsed() throws Exception {
Expand Down Expand Up @@ -321,8 +314,7 @@ public void testLastUsed() throws Exception {
}

/**
* DBCP-343 - verify that using a DelegatingStatement updates
* the lastUsed on the parent connection
* DBCP-343 - verify that using a DelegatingStatement updates the lastUsed on the parent connection
*/
@Test
public void testLastUsedLargePreparedStatementUse() throws Exception {
Expand Down Expand Up @@ -353,8 +345,7 @@ public void testLastUsedLargePreparedStatementUse() throws Exception {
}

/**
* Verify that lastUsed property is updated when a connection
* prepares a callable statement.
* Verify that lastUsed property is updated when a connection prepares a callable statement.
*/
@Test
public void testLastUsedPrepareCall() throws Exception {
Expand Down Expand Up @@ -386,15 +377,13 @@ public void testLastUsedPrepareCall() throws Exception {
}

/**
* DBCP-343 - verify that using a DelegatingStatement updates
* the lastUsed on the parent connection
* DBCP-343 - verify that using a DelegatingStatement updates the lastUsed on the parent connection
*/
@Test
public void testLastUsedPreparedStatementUse() throws Exception {
ds.setRemoveAbandonedTimeout(Duration.ofSeconds(1));
ds.setMaxTotal(2);
try (Connection conn1 = ds.getConnection();
Statement st = conn1.createStatement()) {
try (Connection conn1 = ds.getConnection(); Statement st = conn1.createStatement()) {
final String querySQL = "SELECT 1 FROM DUAL";
Thread.sleep(500);
Assertions.assertNotNull(st.executeQuery(querySQL)); // Should reset lastUsed
Expand All @@ -405,14 +394,15 @@ public void testLastUsedPreparedStatementUse() throws Exception {
Thread.sleep(500);
st.executeUpdate(""); // Should also reset
Thread.sleep(800);
try (Connection c = ds.getConnection()) {} // trigger abandoned cleanup again
try (Statement s = conn1.createStatement()) {} // Connection should still be good
try (Connection c = ds.getConnection()) {
} // trigger abandoned cleanup again
try (Statement s = conn1.createStatement()) {
} // Connection should still be good
}
}

/**
* DBCP-343 - verify additional operations reset lastUsed on
* the parent connection
* DBCP-343 - verify additional operations reset lastUsed on the parent connection
*/
@Test
public void testLastUsedUpdate() throws Exception {
Expand Down
Loading

0 comments on commit 32d2c06

Please sign in to comment.