1717import uuid
1818
1919from google .cloud .bigtable .data ._metrics .handlers ._base import MetricsHandler
20- from google .cloud .bigtable .data ._metrics .data_model import CompletedOperationMetric
20+ from google .cloud .bigtable .data ._metrics .data_model import CompletedOperationMetric , CompletedAttemptMetric
2121
2222from google .cloud .bigtable .data ._cross_sync import CrossSync
2323
@@ -43,11 +43,8 @@ def on_operation_complete(self, op):
4343 def on_operation_cancelled (self , op ):
4444 self .cancelled_operations .append (op )
4545
46- def on_attempt_complete (self , attempt , op ):
47- self .completed_attempts .append ((attempt , op ))
48-
49- def total (self ):
50- return len (self .completed_operations ) + len (self ._ancelled_operations ) + len (self .completed_attempts )
46+ def on_attempt_complete (self , attempt , _ ):
47+ self .completed_attempts .append (attempt )
5148
5249 def clear (self ):
5350 self .cancelled_operations .clear ()
@@ -101,7 +98,7 @@ async def target(self, client, table_id, instance_id, handler):
10198 yield table
10299
103100 @CrossSync .pytest
104- async def test_read_modify_write (self , target , temp_rows , handler ):
101+ async def test_read_modify_write (self , target , temp_rows , handler , cluster_config ):
105102 from google .cloud .bigtable .data .read_modify_write_rules import IncrementRule
106103
107104 row_key = b"test-row-key"
@@ -112,11 +109,28 @@ async def test_read_modify_write(self, target, temp_rows, handler):
112109 )
113110 rule = IncrementRule (family , qualifier , 1 )
114111 await target .read_modify_write_row (row_key , rule )
115- breakpoint ()
116- assert handler .total () == 1
112+ # validate counts
117113 assert len (handler .completed_operations ) == 1
118114 assert len (handler .completed_attempts ) == 1
119115 assert len (handler .cancelled_operations ) == 0
116+ # validate operation
120117 operation = handler .completed_operations [0 ]
118+ assert isinstance (operation , CompletedOperationMetric )
121119 assert operation .final_status .value [0 ] == 0
122- assert operation .final_status .value [0 ] == 0
120+ assert operation .is_streaming is False
121+ assert operation .op_type .value == "ReadModifyWriteRow"
122+ assert len (operation .completed_attempts ) == 1
123+ assert operation .completed_attempts [0 ] == handler .completed_attempts [0 ]
124+ assert operation .cluster_id == next (iter (cluster_config .keys ()))
125+ assert operation .zone == cluster_config [operation .cluster_id ].location .split ("/" )[- 1 ]
126+ assert operation .duration_ns > 0 and operation .duration_ns < 1e9
127+ assert operation .first_response_latency_ns is None # populated for read_rows only
128+ assert operation .flow_throttling_time_ns == 0
129+ # validate attempt
130+ attempt = handler .completed_attempts [0 ]
131+ assert attempt .duration_ns > 0 and attempt .duration_ns < operation .duration_ns
132+ assert attempt .end_status .value [0 ] == 0
133+ assert attempt .backoff_before_attempt_ns == 0
134+ assert attempt .gfe_latency_ns > 0 and attempt .gfe_latency_ns < attempt .duration_ns
135+ assert attempt .application_blocking_time_ns == 0
136+ assert attempt .grpc_throttling_time_ns == 0 # TODO: confirm
0 commit comments