Copilot commented on code in PR #2508:
URL: https://github.com/apache/phoenix/pull/2508#discussion_r3789338053


##########
phoenix-core-client/src/main/java/org/apache/phoenix/util/ReadOnlyProps.java:
##########
@@ -58,7 +58,7 @@ public ReadOnlyProps(Iterator<Entry<String, String>> 
iterator) {
     this(EMPTY_PROPS, iterator);
   }
 
-  private ReadOnlyProps() {
+  public ReadOnlyProps() {

Review Comment:
   This exposes a new production API solely for the test utility, although 
`ReadOnlyProps.EMPTY_PROPS` already represents the same immutable empty value. 
Use that constant in `HBaseTestingUtilityPair` and keep this constructor 
private to avoid an unnecessary public API change.



##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/CbrtFunctionEnd2EndIT.java:
##########
@@ -48,7 +50,8 @@ public void initTable() throws Exception {
     Connection conn = null;
     PreparedStatement stmt = null;
     try {
-      conn = DriverManager.getConnection(getUrl());
+      System.out.println("get url " + getUrl());
+      conn = DriverManager.getConnection(getUrl(), 
PropertiesUtil.deepCopy(TEST_PROPERTIES));

Review Comment:
   This unconditional console print is leftover diagnostic output and calls 
`getUrl()` a second time for every setup. Remove it and let the configured test 
logging capture any needed URL diagnostics.



##########
phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java:
##########
@@ -381,6 +411,48 @@ protected static String setUpTestCluster(@Nonnull 
Configuration conf, ReadOnlyPr
     }
   }
 
+  /**
+   * Set up HA cluster for testing in single-cluster mode.
+   * This mode tests HA connection code paths (FailoverPhoenixConnection) 
without the
+   * resource overhead of running two physical HBase clusters.
+   * Both ACTIVE and STANDBY URLs point to the same physical cluster.
+   */
+  public static void setUpTestClusterForHA(ReadOnlyProps serverProps, 
ReadOnlyProps clientProps)
+    throws Exception {
+    CLUSTERS = new 
HighAvailabilityTestingUtility.HBaseTestingUtilityPair(serverProps);
+    CLUSTERS.start(true);  // true = single-cluster mode (only starts cluster1)
+    driver = newTestDriver(clientProps);
+    DriverManager.registerDriver(driver);
+    haGroupName = TEST_PROPERTIES.getProperty(PHOENIX_HA_GROUP_ATTR);
+    // Use single-cluster initialization (only cluster1 is running)
+    CLUSTERS.initClusterRoleRecordFor1Cluster(haGroupName, 
HighAvailabilityPolicy.FAILOVER);
+    clusterInitialized = true;
+    Properties haGroupProps = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+    for (Entry<String, String> entry : clientProps) {
+      haGroupProps.setProperty(entry.getKey(), entry.getValue());
+    }
+    haGroup = getHighAvailibilityGroup(CLUSTERS.getJdbcHAUrl(), haGroupProps);
+    LOGGER.info("Initialized HA group {} with URL {}", haGroup, 
CLUSTERS.getJdbcHAUrl());
+  }
+
+  /**
+   * Tear down HA cluster resources.
+   * Should be called in @AfterClass when using HA mode.
+   */
+  public static void tearDownForHA() throws Exception {
+    if (Boolean.parseBoolean(System.getProperty("phoenix.ha.profile.active"))) 
{
+      try {
+        DriverManager.deregisterDriver(PhoenixDriver.INSTANCE);

Review Comment:
   This deregisters the production `PhoenixDriver` but leaves the 
`PhoenixTestDriver` registered by `setUpTestClusterForHA`. The 
`ParallelStatsDisabledTest` execution reuses forks, so after the first subclass 
tears down, the next subclass initializes its role record through non-test JDBC 
URLs with no production driver registered, while stale test drivers accumulate. 
Keep the production driver available for the reused fork and explicitly 
close/deregister `driver` (and reset the shared HA state), or move HA 
setup/teardown to a fork-scoped lifecycle.



##########
phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityGroup.java:
##########
@@ -763,7 +763,7 @@ public ClusterRoleRecord getRoleRecord() {
    * lifecycle management is confined to this class because an HA group is a 
shared resource.
    * Someone calling close on this would make it unusable, since the state 
would become closed.
    */
-  void close() {
+  public void close() {

Review Comment:
   Making this method public contradicts its own lifecycle contract: instances 
are shared through the static `GROUPS` cache, so any application caller can now 
close the cached group and break unrelated connections. This is also 
unnecessary for the test change because 
`HighAvailabilityTestingUtility.closeHighAvailabilityGroup` already provides a 
test-only bridge. Keep `close()` package-private and use that helper from 
`BaseTest`.



##########
phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java:
##########
@@ -148,8 +149,14 @@
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.hbase.index.util.IndexManagementUtil;
+import org.apache.phoenix.jdbc.HighAvailabilityGroup;
+import org.apache.phoenix.jdbc.HighAvailabilityPolicy;
+import org.apache.phoenix.jdbc.HighAvailabilityTestingUtility;
+import static 
org.apache.phoenix.jdbc.HighAvailabilityTestingUtility.getHighAvailibilityGroup;

Review Comment:
   Static imports are consistently grouped at the top of this file (for 
example, lines 26–30), but this new static import is interleaved with regular 
imports. Move it into the static-import block; otherwise the 
formatting/import-order check will reject the file.



##########
phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java:
##########
@@ -148,8 +149,14 @@
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.hbase.index.util.IndexManagementUtil;
+import org.apache.phoenix.jdbc.HighAvailabilityGroup;
+import org.apache.phoenix.jdbc.HighAvailabilityPolicy;
+import org.apache.phoenix.jdbc.HighAvailabilityTestingUtility;
+import static 
org.apache.phoenix.jdbc.HighAvailabilityTestingUtility.getHighAvailibilityGroup;
 import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.jdbc.PhoenixMonitoredConnection;

Review Comment:
   `PhoenixMonitoredConnection` is not referenced anywhere in this file. Remove 
the unused import so the source passes the repository's import checks.



##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java:
##########
@@ -53,12 +53,25 @@ public static synchronized void doSetup() throws Exception {
     
props.put(BaseScannerRegionObserverConstants.PHOENIX_MAX_LOOKBACK_AGE_CONF_KEY,
       Integer.toString(60 * 60)); // An hour
     props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, 
Boolean.toString(false));
-    setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+
+    // Check if HA profile is enabled
+    if (Boolean.parseBoolean(System.getProperty("phoenix.ha.profile.active"))) 
{
+      // Set up HA cluster in single-cluster mode
+      setUpTestClusterForHA(new ReadOnlyProps(props.entrySet().iterator()),
+        new ReadOnlyProps(props.entrySet().iterator()));

Review Comment:
   Putting the HA setup in this shared base switches every 
`ParallelStatsDisabledIT` subclass to an HA URL, but only 
`CbrtFunctionEnd2EndIT` was converted to pass `TEST_PROPERTIES`. Existing 
subclasses such as `ArrayAppendFunctionIT` (lines 74 and 138) still call 
`DriverManager.getConnection(getUrl())`; an HA URL requires 
`phoenix.ha.group.name`, so a full `-Pha-enabled` run fails with invalid HA 
properties. Either scope this setup to the proof-of-concept test or update the 
shared connection mechanism/all affected tests to supply the HA properties.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to