Skip to content

Commit

Permalink
Making the CONNECTION_MANAGER_MAP private
Browse files Browse the repository at this point in the history
  • Loading branch information
ashetkar committed Jul 12, 2024
1 parent 9df8e7f commit f208fef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class LoadBalanceProperties {
load-balance 'simple' to be used as KEY and for targeted topologies,
<placements> value specified will be used as key
*/
public static final Map<String, LoadBalancer> CONNECTION_MANAGER_MAP =
private static final Map<String, LoadBalancer> CONNECTION_MANAGER_MAP =
new HashMap<>();

private static Map<LoadBalancerKey, LoadBalanceProperties> loadBalancePropertiesMap =
Expand All @@ -74,6 +74,16 @@ public class LoadBalanceProperties {
private int failedHostReconnectDelaySecs = -1;
private boolean failedHostReconnectDelaySpecified;

/**
* FOR TEST PURPOSE ONLY
*/
static void clearConnectionManagerMap() {
LOGGER.warning("Clearing CONNECTION_MANAGER_MAP for testing purposes");
synchronized (CONNECTION_MANAGER_MAP) {
CONNECTION_MANAGER_MAP.clear();
}
}

public static LoadBalanceProperties getLoadBalanceProperties(String url, Properties properties) {
LoadBalancerKey key = new LoadBalancerKey(url, properties);
LoadBalanceProperties lbp = loadBalancePropertiesMap.get(key);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.yugabyte.ysql;

import static com.yugabyte.ysql.LoadBalanceProperties.CONNECTION_MANAGER_MAP;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -67,7 +65,7 @@ private static void checkBasicBehavior() throws SQLException {
createConnectionsAndVerify(baseUrl, "aws.us-west.us-west-2a:1,aws.us-west.us-west-2b:-2,aws" + ".us-west.us-west-2c:3", null);
createConnectionsAndVerify(baseUrl, "aws.us-west.us-west-2a:1,aws.us-west.us-west-2b:2,aws" + ".us-west.us-west-2c:", null);
} finally {
CONNECTION_MANAGER_MAP.clear();
LoadBalanceProperties.clearConnectionManagerMap();
LoadBalanceService.clear();
executeCmd(path + "/bin/yb-ctl destroy", "Stop YugabyteDB cluster", 10);
}
Expand Down Expand Up @@ -104,7 +102,7 @@ private static void checkNodeDownBehavior() throws SQLException {
createConnectionsAndVerify("jdbc:yugabytedb://127.0.0.4:5433/yugabyte?load-balance=true&fallback-to-topology-keys-only=true&topology-keys=",
"aws.us-west.us-west-1a", expectedInput(-1, -1, -1, 12+1, 0, 0));
} finally {
CONNECTION_MANAGER_MAP.clear();
LoadBalanceProperties.clearConnectionManagerMap();
LoadBalanceService.clear();
executeCmd(path + "/bin/yb-ctl destroy", "Stop YugabyteDB cluster", 10);
}
Expand Down Expand Up @@ -159,7 +157,7 @@ private static void checkNodeDownBehaviorMultiFallback() throws SQLException {
createConnectionsAndVerify(url, tk, expectedInput(-1, 12, -1, -1, -1, +1, -1, -1, -1));

} finally {
CONNECTION_MANAGER_MAP.clear();
LoadBalanceProperties.clearConnectionManagerMap();
LoadBalanceService.clear();
executeCmd(path + "/bin/yb-ctl destroy", "Stop YugabyteDB cluster", 10);
}
Expand Down
3 changes: 1 addition & 2 deletions pgjdbc/src/test/java/com/yugabyte/ysql/LoadBalanceTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.yugabyte.ysql;

import static com.yugabyte.ysql.FallbackOptionsLBTest.*;
import static com.yugabyte.ysql.LoadBalanceProperties.CONNECTION_MANAGER_MAP;

import java.sql.Connection;
import java.sql.DriverManager;
Expand Down Expand Up @@ -103,7 +102,7 @@ private static void testConcurrentConnectionCreations(String url,

} finally {
waitForSignal = true;
CONNECTION_MANAGER_MAP.clear();
LoadBalanceProperties.clearConnectionManagerMap();
executeCmd(path + "/bin/yb-ctl destroy", "Stop YugabyteDB cluster", 15);
}
}
Expand Down

0 comments on commit f208fef

Please sign in to comment.