Source:
<code>public void testDeleteRuntimeFailureClosesConnections() throws Exception { String tableName = generateUniqueName(); String ddl = "create table " + tableName + " (i integer not null primary key, j integer) SALT_BUCKETS=256 "; Properties props = new Properties(); props.setProperty(QueryServices.ENABLE_SERVER_SIDE_DELETE_MUTATIONS, <START> String.valueOf(false)); <END> props.setProperty(CLIENT_CONNECTION_MAX_ALLOWED_CONNECTIONS,String.valueOf(10)); props.setProperty(INTERNAL_CONNECTION_MAX_ALLOWED_CONNECTIONS,String.valueOf(10)); String deleteStmt = "DELETE FROM " + tableName + " WHERE 20 = j"; assertEquals(0,GLOBAL_OPEN_PHOENIX_CONNECTIONS.getMetric().getValue()); assertEquals(0,GLOBAL_OPEN_INTERNAL_PHOENIX_CONNECTIONS.getMetric().getValue()); Connection conn = null; try{ conn = DriverManager.getConnection(getUniqueUrl(), props); try(Statement statement = conn.createStatement()) { statement.execute(ddl); } DelayedRegionServer.setDelayEnabled(true); try(Statement statement = conn.createStatement()) { statement.execute(deleteStmt); } fail(); } catch (SQLException e) { assertEquals(NEW_CONNECTION_THROTTLED.getErrorCode(),e.getErrorCode()); assertEquals(NEW_CONNECTION_THROTTLED.getSQLState(),e.getSQLState()); } finally { DelayedRegionServer.setDelayEnabled(false); if(conn != null) { conn.close(); } long connections = GLOBAL_OPEN_PHOENIX_CONNECTIONS.getMetric().getValue(); assertTrue(String.format("Found %d connections still open.",connections),2 >= connections); connections = GLOBAL_OPEN_INTERNAL_PHOENIX_CONNECTIONS.getMetric().getValue(); assertTrue(String.format("Found %d internal connections still open.",connections),2 >= connections); } }</code><technical_language>if server-side mutations enabled? If enabled, longer need rs.next read data server + generate delete mutations for them, is difference in behavior w.r.t. create cloned connections</technical_language>

Target:
public void testDeleteRuntimeFailureClosesConnections() throws Exception { String tableName = generateUniqueName(); String connectionUrl = getUniqueUrl(); String ddl = "create table " + tableName + " (i integer not null primary key, j integer) SALT_BUCKETS=256 "; Properties props = new Properties(); props.setProperty(CLIENT_CONNECTION_MAX_ALLOWED_CONNECTIONS,String.valueOf(10)); props.setProperty(INTERNAL_CONNECTION_MAX_ALLOWED_CONNECTIONS,String.valueOf(10)); props.setProperty(TASK_HANDLING_INTERVAL_MS_ATTRIB,String.valueOf(600000)); props.setProperty(TASK_HANDLING_INITIAL_DELAY_MS_ATTRIB,String.valueOf(600000)); String deleteStmt = "DELETE FROM " + tableName + " WHERE 20 = j"; try(Connection conn = DriverManager.getConnection(connectionUrl, props); Statement statement = conn.createStatement()) { statement.execute(ddl); } assertEquals(0, GLOBAL_OPEN_PHOENIX_CONNECTIONS.getMetric().getValue()); assertEquals(0, GLOBAL_OPEN_INTERNAL_PHOENIX_CONNECTIONS.getMetric().getValue()); Connection conn = null; try { conn = DriverManager.getConnection(connectionUrl, props); DelayedRegionServer.setDelayEnabled(true); try (Statement statement = conn.createStatement()) { statement.execute(deleteStmt); } fail(); } catch (SQLException e) { assertEquals(NEW_INTERNAL_CONNECTION_THROTTLED.getErrorCode(), e.getErrorCode()); assertEquals(NEW_INTERNAL_CONNECTION_THROTTLED.getSQLState(), e.getSQLState()); } finally { DelayedRegionServer.setDelayEnabled(false); if (conn != null) { conn.close(); } long connections = GLOBAL_OPEN_PHOENIX_CONNECTIONS.getMetric().getValue(); assertEquals(String.format("Found %d connections still open.", connections),0,connections); connections = GLOBAL_OPEN_INTERNAL_PHOENIX_CONNECTIONS.getMetric().getValue(); assertEquals(String.format("Found %d internal connections still open.", connections),0 ,connections); } }