dbwong commented on code in PR #1459:
URL: https://github.com/apache/phoenix/pull/1459#discussion_r916204416


##########
phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java:
##########
@@ -1099,6 +1100,53 @@ public void testGetConnectionsThrottledForSameUrl() 
throws Exception {
         assertEquals(maxConnections, connections.size());
     }
 
+    @Test
+    public void testGetConnectionsFailedCounter() throws Exception {
+        int attemptedPhoenixConnections = 7;
+        //3 Failed connections and 1 throttled connection
+        int maxConnections = attemptedPhoenixConnections - 4;
+        List<Connection> connections = Lists.newArrayList();
+        String zkQuorum = "localhost:" + 
getUtility().getZkCluster().getClientPort();
+        String url = PhoenixRuntime.JDBC_PROTOCOL + 
PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum +
+                ':' +  CUSTOM_URL_STRING + '=' + "FailedCounterTest";
+        Properties props = new Properties();
+        
props.setProperty(QueryServices.CLIENT_CONNECTION_MAX_ALLOWED_CONNECTIONS, 
Integer.toString(maxConnections));
+        Properties props1 = new Properties(props);
+        props1.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, 
Integer.toString(-1));
+
+        GLOBAL_QUERY_SERVICES_COUNTER.getMetric().reset();
+        GLOBAL_PHOENIX_CONNECTIONS_ATTEMPTED_COUNTER.getMetric().reset();
+        GLOBAL_PHOENIX_CONNECTIONS_THROTTLED_COUNTER.getMetric().reset();
+        GLOBAL_FAILED_PHOENIX_CONNECTIONS.getMetric().reset();
+        try {
+            for (int i = 0; i < attemptedPhoenixConnections; i++) {
+                try {
+                    if (i % 3 == 0) {
+                        connections.add(DriverManager.getConnection(url, 
props1));
+                    } else {
+                        connections.add(DriverManager.getConnection(url, 
props));
+                    }
+                } catch (SQLException se) {
+                    if (i % 3 == 0) {
+                        
assertEquals(SQLExceptionCode.INVALID_SCN.getErrorCode(), se.getErrorCode());
+                    } else {
+                        
assertEquals(SQLExceptionCode.NEW_CONNECTION_THROTTLED.getErrorCode(), 
se.getErrorCode());
+                    }
+                }
+            }
+        } finally {
+            for (Connection c : connections) {
+                c.close();
+            }
+        }
+        assertEquals(1, GLOBAL_QUERY_SERVICES_COUNTER.getMetric().getValue());
+        assertEquals(1, 
GLOBAL_PHOENIX_CONNECTIONS_THROTTLED_COUNTER.getMetric().getValue());
+        assertEquals(3, 
GLOBAL_FAILED_PHOENIX_CONNECTIONS.getMetric().getValue());
+        assertTrue("Not all connections were attempted!",
+                attemptedPhoenixConnections <= 
GLOBAL_PHOENIX_CONNECTIONS_ATTEMPTED_COUNTER.getMetric().getValue());

Review Comment:
   nit: Can we add a comment to the same?



-- 
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