Skip to content
Permalink
Browse files

Check that JDBC Connections that are closed by the server do not repo…

…rt as valid (#1533)

Signed-off-by: Tim Ward <timothyjward@apache.org>
  • Loading branch information...
timothyjward authored and davecramer committed Aug 30, 2019
1 parent bda74d7 commit 56399efddd25281ccefd90c56e9db084c550d195
Showing with 36 additions and 0 deletions.
  1. +36 −0 pgjdbc/src/test/java/org/postgresql/test/jdbc4/IsValidTest.java
@@ -10,14 +10,17 @@
import static org.junit.Assert.assertTrue;

import org.postgresql.core.BaseConnection;
import org.postgresql.core.ServerVersion;
import org.postgresql.core.TransactionState;
import org.postgresql.test.TestUtil;
import org.postgresql.test.jdbc2.BaseTest4;

import org.junit.Test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class IsValidTest extends BaseTest4 {

@@ -67,4 +70,37 @@ public void testTransactionState() throws Exception {
}
}

@Test
public void testIsValidRemoteClose() throws Exception {

assumeMinimumServerVersion("Unable to use pg_terminate_backend before version 8.4", ServerVersion.v8_4);

Properties props = new Properties();
updateProperties(props);
Connection con2 = TestUtil.openPrivilegedDB();

try {

assertTrue("First Connection should be valid", con.isValid(0));

String pid;
Statement s = con.createStatement();

try {
s.execute("select pg_backend_pid()");
ResultSet rs = s.getResultSet();
rs.next();
pid = rs.getString(1);
} finally {
TestUtil.closeQuietly(s);
}

TestUtil.execute("select pg_terminate_backend(" + pid + ")", con2);

assertFalse("The Second connection should now be invalid", con.isValid(0));

} finally {
TestUtil.closeQuietly(con2);
}
}
}

0 comments on commit 56399ef

Please sign in to comment.
You can’t perform that action at this time.