@@ -99,7 +99,7 @@ public void testMetricsConnectionScope() throws IOException {
9999 }
100100
101101 @ Test
102- public void testMetricsWithMutiConnections () throws IOException {
102+ public void testMetricsWithMultiConnections () throws IOException {
103103 Configuration conf = new Configuration ();
104104 conf .setBoolean (MetricsConnection .CLIENT_SIDE_METRICS_ENABLED_KEY , true );
105105 conf .set (MetricsConnection .METRICS_SCOPE_KEY , "unit-test" );
@@ -178,7 +178,8 @@ public void testStaticMetrics() throws IOException {
178178 MutateRequest .newBuilder ()
179179 .setMutation (ProtobufUtil .toMutation (MutationType .PUT , new Put (foo ))).setRegion (region )
180180 .build (),
181- MetricsConnection .newCallStats (), null );
181+ MetricsConnection .newCallStats (),
182+ new CallTimeoutException ("test with CallTimeoutException" ));
182183 }
183184
184185 final String rpcCountPrefix = "rpcCount_" + ClientService .getDescriptor ().getName () + "_" ;
@@ -188,40 +189,58 @@ public void testStaticMetrics() throws IOException {
188189 long metricVal ;
189190 Counter counter ;
190191
191- for (String method : new String [] { "Get" , "Scan" , "Multi" , "Mutate" }) {
192+ for (String method : new String [] { "Get" , "Scan" , "Multi" }) {
192193 metricKey = rpcCountPrefix + method ;
193194 metricVal = METRICS .getRpcCounters ().get (metricKey ).getCount ();
194- assertTrue ("metric: " + metricKey + " val: " + metricVal , metricVal >= loop );
195+ assertEquals ("metric: " + metricKey + " val: " + metricVal , metricVal , loop );
195196
196197 metricKey = rpcFailureCountPrefix + method ;
197198 counter = METRICS .getRpcCounters ().get (metricKey );
198199 metricVal = (counter != null ) ? counter .getCount () : 0 ;
199- if (method .equals ("Get" ) || method . equals ( "Mutate" ) ) {
200+ if (method .equals ("Get" )) {
200201 // no failure
201- assertTrue ("metric: " + metricKey + " val: " + metricVal , metricVal == 0 );
202+ assertEquals ("metric: " + metricKey + " val: " + metricVal , 0 , metricVal );
202203 } else {
203204 // has failure
204- assertTrue ("metric: " + metricKey + " val: " + metricVal , metricVal == loop );
205+ assertEquals ("metric: " + metricKey + " val: " + metricVal , metricVal , loop );
206+ }
207+ }
208+
209+ String method = "Mutate" ;
210+ for (String mutationType : new String [] { "Append" , "Delete" , "Increment" , "Put" }) {
211+ metricKey = rpcCountPrefix + method + "(" + mutationType + ")" ;
212+ metricVal = METRICS .getRpcCounters ().get (metricKey ).getCount ();
213+ assertEquals ("metric: " + metricKey + " val: " + metricVal , metricVal , loop );
214+
215+ metricKey = rpcFailureCountPrefix + method + "(" + mutationType + ")" ;
216+ counter = METRICS .getRpcCounters ().get (metricKey );
217+ metricVal = (counter != null ) ? counter .getCount () : 0 ;
218+ if (mutationType .equals ("Put" )) {
219+ // has failure
220+ assertEquals ("metric: " + metricKey + " val: " + metricVal , metricVal , loop );
221+ } else {
222+ // no failure
223+ assertEquals ("metric: " + metricKey + " val: " + metricVal , 0 , metricVal );
205224 }
206225 }
207226
208227 // remote exception
209228 metricKey = "rpcRemoteExceptions_IOException" ;
210229 counter = METRICS .getRpcCounters ().get (metricKey );
211230 metricVal = (counter != null ) ? counter .getCount () : 0 ;
212- assertTrue ("metric: " + metricKey + " val: " + metricVal , metricVal == loop );
231+ assertEquals ("metric: " + metricKey + " val: " + metricVal , metricVal , loop );
213232
214233 // local exception
215234 metricKey = "rpcLocalExceptions_CallTimeoutException" ;
216235 counter = METRICS .getRpcCounters ().get (metricKey );
217236 metricVal = (counter != null ) ? counter .getCount () : 0 ;
218- assertTrue ("metric: " + metricKey + " val: " + metricVal , metricVal == loop );
237+ assertEquals ("metric: " + metricKey + " val: " + metricVal , metricVal , loop * 2 );
219238
220239 // total exception
221240 metricKey = "rpcTotalExceptions" ;
222241 counter = METRICS .getRpcCounters ().get (metricKey );
223242 metricVal = (counter != null ) ? counter .getCount () : 0 ;
224- assertTrue ("metric: " + metricKey + " val: " + metricVal , metricVal == loop * 2 );
243+ assertEquals ("metric: " + metricKey + " val: " + metricVal , metricVal , loop * 3 );
225244
226245 for (MetricsConnection .CallTracker t : new MetricsConnection .CallTracker [] {
227246 METRICS .getGetTracker (), METRICS .getScanTracker (), METRICS .getMultiTracker (),
0 commit comments