@@ -134,3 +134,57 @@ async def test_read_modify_write(self, target, temp_rows, handler, cluster_confi
134134 assert attempt .gfe_latency_ns > 0 and attempt .gfe_latency_ns < attempt .duration_ns
135135 assert attempt .application_blocking_time_ns == 0
136136 assert attempt .grpc_throttling_time_ns == 0 # TODO: confirm
137+
138+ @CrossSync .pytest
139+ async def test_check_and_mutate_row (self , target , temp_rows , handler , cluster_config ):
140+ from google .cloud .bigtable .data .mutations import SetCell
141+ from google .cloud .bigtable .data .row_filters import ValueRangeFilter
142+
143+ row_key = b"test-row-key"
144+ family = TEST_FAMILY
145+ qualifier = b"test-qualifier"
146+ await temp_rows .add_row (
147+ row_key , value = 1 , family = family , qualifier = qualifier
148+ )
149+
150+
151+ false_mutation_value = b"false-mutation-value"
152+ false_mutation = SetCell (
153+ family = TEST_FAMILY , qualifier = qualifier , new_value = false_mutation_value
154+ )
155+ true_mutation_value = b"true-mutation-value"
156+ true_mutation = SetCell (
157+ family = TEST_FAMILY , qualifier = qualifier , new_value = true_mutation_value
158+ )
159+ predicate = ValueRangeFilter (0 , 2 )
160+ await target .check_and_mutate_row (
161+ row_key ,
162+ predicate ,
163+ true_case_mutations = true_mutation ,
164+ false_case_mutations = false_mutation ,
165+ )
166+ # validate counts
167+ assert len (handler .completed_operations ) == 1
168+ assert len (handler .completed_attempts ) == 1
169+ assert len (handler .cancelled_operations ) == 0
170+ # validate operation
171+ operation = handler .completed_operations [0 ]
172+ assert isinstance (operation , CompletedOperationMetric )
173+ assert operation .final_status .value [0 ] == 0
174+ assert operation .is_streaming is False
175+ assert operation .op_type .value == "CheckAndMutateRow"
176+ assert len (operation .completed_attempts ) == 1
177+ assert operation .completed_attempts [0 ] == handler .completed_attempts [0 ]
178+ assert operation .cluster_id == next (iter (cluster_config .keys ()))
179+ assert operation .zone == cluster_config [operation .cluster_id ].location .split ("/" )[- 1 ]
180+ assert operation .duration_ns > 0 and operation .duration_ns < 1e9
181+ assert operation .first_response_latency_ns is None # populated for read_rows only
182+ assert operation .flow_throttling_time_ns == 0
183+ # validate attempt
184+ attempt = handler .completed_attempts [0 ]
185+ assert attempt .duration_ns > 0 and attempt .duration_ns < operation .duration_ns
186+ assert attempt .end_status .value [0 ] == 0
187+ assert attempt .backoff_before_attempt_ns == 0
188+ assert attempt .gfe_latency_ns > 0 and attempt .gfe_latency_ns < attempt .duration_ns
189+ assert attempt .application_blocking_time_ns == 0
190+ assert attempt .grpc_throttling_time_ns == 0 # TODO: confirm
0 commit comments