From 2c5d31b11d6cb549c0ebfb34897d34ce5abd7c72 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Tue, 01 Sep 2026 08:53:57 +0000
Subject: [PATCH] [#872] Bound the connect of the JDBC pool and report a connect it cannot make (#876)
---
opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/TestCase.java | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/TestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/TestCase.java
index b650301..9d7cdac 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/TestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/TestCase.java
@@ -45,6 +45,7 @@
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
+import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -56,6 +57,7 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@@ -140,6 +142,40 @@
protected abstract String getJdbcUrl();
+ /**
+ * The second property bounding a login is a socket read timeout on mysql, oracle and sql
+ * server: in force for the whole life of the connection it would fail every statement slower
+ * than it - an import batch, the statistics of a freshly loaded table - so it has to be lifted
+ * as soon as the login is through (#872).
+ */
+ @Test(timeOut = 120000)
+ public void testLoginBoundDoesNotOutliveTheLogin() throws Exception {
+ final String url = createBackendCfg().getDBDirectory();
+ final CachedConnection.ConnectDialect dialect = CachedConnection.ConnectDialect.of(url);
+ assertNotNull(dialect, "the dialect of the container is one this backend bounds: " + CachedConnection.safeUrl(url));
+ System.setProperty(CachedConnection.CONNECT_TIMEOUT_PROPERTY, "2");
+ try {
+ // the bound this lifts has to be in force first, or the assertion below holds of a
+ // connection that never carried one: established here with the very properties the
+ // borrow uses, and read back off the socket of this driver
+ final Properties bounding = new Properties();
+ assertTrue(dialect.bound(url, bounding, 2),
+ "the read bound of the login is not set for this dialect, so there is nothing to lift");
+ try (final Connection bounded = DriverManager.getConnection(url, bounding)) {
+ assertEquals(bounded.getNetworkTimeout(), 2000,
+ "the property this dialect names does not bound the socket of its login");
+ }
+
+ // a pooled connection would be handed back without being established again
+ CachedConnection.cached.invalidate(url);
+ try (final Connection con = CachedConnection.getConnection(url)) {
+ assertEquals(con.getNetworkTimeout(), 0, "the read bound of the login is still in force");
+ }
+ } finally {
+ System.clearProperty(CachedConnection.CONNECT_TIMEOUT_PROPERTY);
+ }
+ }
+
private static ByteString key(int i) {
return ByteString.valueOfUtf8(String.format("key%02d", i));
}
--
Gitblit v1.10.0