@@ -140,6 +140,40 @@ where
140
140
bootstrap. to_string_lossy ( ) . to_string ( )
141
141
}
142
142
143
+ /// Clear the cluster's error state for the given ApiKey.
144
+ pub fn clear_request_errors ( & self , api_key : RDKafkaApiKey ) {
145
+ unsafe { rdsys:: rd_kafka_mock_clear_request_errors ( self . mock_cluster , api_key. into ( ) ) }
146
+ }
147
+
148
+ /// Push errors onto the cluster's error stack for the given ApiKey.
149
+ ///
150
+ /// The protocol requests matching the given ApiKey will fail with the
151
+ /// provided error code and removed from the stack, starting with
152
+ /// the first error code, then the second, etc.
153
+ ///
154
+ /// Passing RD_KAFKA_RESP_ERR__TRANSPORT will make the mock broker
155
+ /// disconnect the client which can be useful to trigger a disconnect
156
+ /// on certain requests.
157
+ pub fn request_errors ( & self , api_key : RDKafkaApiKey , errors : & [ RDKafkaRespErr ] ) {
158
+ unsafe {
159
+ rdsys:: rd_kafka_mock_push_request_errors_array (
160
+ self . mock_cluster ,
161
+ api_key. into ( ) ,
162
+ errors. len ( ) ,
163
+ errors. as_ptr ( ) ,
164
+ )
165
+ }
166
+ }
167
+
168
+ /// Set the topic error to return in protocol requests.
169
+ ///
170
+ /// Currently only used for TopicMetadataRequest and AddPartitionsToTxnRequest.
171
+ pub fn topic_error ( & self , topic : & str , error : RDKafkaRespErr ) -> KafkaResult < ( ) > {
172
+ let topic_c = CString :: new ( topic) ?;
173
+ unsafe { rdsys:: rd_kafka_mock_topic_set_error ( self . mock_cluster , topic_c. as_ptr ( ) , error) }
174
+ Ok ( ( ) )
175
+ }
176
+
143
177
/// Create a topic
144
178
///
145
179
/// This is an alternative to automatic topic creation as performed by the client itself.
@@ -320,6 +354,31 @@ where
320
354
}
321
355
}
322
356
}
357
+
358
+ /// Set the allowed ApiVersion range for the given ApiKey.
359
+ ///
360
+ /// Set min_version and max_version to `None` to disable the API completely.
361
+ /// max_version MUST not exceed the maximum implemented value.
362
+ pub fn apiversion (
363
+ & self ,
364
+ api_key : RDKafkaApiKey ,
365
+ min_version : Option < i16 > ,
366
+ max_version : Option < i16 > ,
367
+ ) -> KafkaResult < ( ) > {
368
+ let min_version = min_version. unwrap_or ( -1 ) ;
369
+ let max_version = max_version. unwrap_or ( -1 ) ;
370
+
371
+ return_mock_op ! {
372
+ unsafe {
373
+ rdsys:: rd_kafka_mock_set_apiversion(
374
+ self . mock_cluster,
375
+ api_key. into( ) ,
376
+ min_version,
377
+ max_version,
378
+ )
379
+ }
380
+ }
381
+ }
323
382
}
324
383
325
384
impl < ' c , C > Drop for MockCluster < ' c , C >
0 commit comments