@@ -175,6 +175,7 @@ public class SenderTest {
175
175
@ BeforeEach
176
176
public void setup () {
177
177
setupWithTransactionState (null );
178
+ apiVersions .update ("0" , NodeApiVersions .create (ApiKeys .PRODUCE .id , (short ) 0 , (short ) 12 ));
178
179
}
179
180
180
181
@ AfterEach
@@ -582,8 +583,11 @@ public void testNodeLatencyStats() throws Exception {
582
583
new BufferPool (totalSize , batchSize , m , time , "producer-internal-metrics" ));
583
584
584
585
SenderMetricsRegistry senderMetrics = new SenderMetricsRegistry (m );
586
+ ApiVersions apiVersions1 = new ApiVersions ();
587
+ apiVersions1 .update ("0" , NodeApiVersions .create (ApiKeys .PRODUCE .id , (short ) 0 , (short ) 12 ));
588
+
585
589
Sender sender = new Sender (logContext , client , metadata , this .accumulator , false , MAX_REQUEST_SIZE , ACKS_ALL , 1 ,
586
- senderMetrics , time , REQUEST_TIMEOUT , 1000L , null , new ApiVersions () );
590
+ senderMetrics , time , REQUEST_TIMEOUT , 1000L , null , apiVersions1 );
587
591
588
592
// Produce and send batch.
589
593
long time1 = time .milliseconds ();
@@ -2407,6 +2411,7 @@ public void testTransactionalSplitBatchAndSend() throws Exception {
2407
2411
2408
2412
txnManager .beginTransaction ();
2409
2413
txnManager .maybeAddPartition (tp );
2414
+ apiVersions .update ("0" , NodeApiVersions .create (ApiKeys .PRODUCE .id , (short ) 0 , (short ) 12 ));
2410
2415
client .prepareResponse (buildAddPartitionsToTxnResponseData (0 , Collections .singletonMap (tp , Errors .NONE )));
2411
2416
sender .runOnce ();
2412
2417
@@ -2424,16 +2429,21 @@ private void testSplitBatchAndSend(TransactionManager txnManager,
2424
2429
String metricGrpName = "producer-metrics" ;
2425
2430
// Set a good compression ratio.
2426
2431
CompressionRatioEstimator .setEstimation (topic , CompressionType .GZIP , 0.2f );
2432
+ ApiVersions apiVersions = new ApiVersions ();
2427
2433
try (Metrics m = new Metrics ()) {
2428
2434
accumulator = new RecordAccumulator (logContext , batchSize , Compression .gzip ().build (),
2429
- 0 , 0L , 0L , deliveryTimeoutMs , m , metricGrpName , time , new ApiVersions () , txnManager ,
2435
+ 0 , 0L , 0L , deliveryTimeoutMs , m , metricGrpName , time , apiVersions , txnManager ,
2430
2436
new BufferPool (totalSize , batchSize , metrics , time , "producer-internal-metrics" ));
2431
2437
SenderMetricsRegistry senderMetrics = new SenderMetricsRegistry (m );
2432
2438
Sender sender = new Sender (logContext , client , metadata , this .accumulator , true , MAX_REQUEST_SIZE , ACKS_ALL , maxRetries ,
2433
- senderMetrics , time , REQUEST_TIMEOUT , 1000L , txnManager , new ApiVersions () );
2439
+ senderMetrics , time , REQUEST_TIMEOUT , 1000L , txnManager , apiVersions );
2434
2440
// Create a two broker cluster, with partition 0 on broker 0 and partition 1 on broker 1
2435
2441
MetadataResponse metadataUpdate1 = RequestTestUtils .metadataUpdateWith (2 , Collections .singletonMap (topic , 2 ));
2436
2442
client .prepareMetadataUpdate (metadataUpdate1 );
2443
+ metadataUpdate1 .brokers ().stream ().forEach (node ->
2444
+ apiVersions .update (node .idString (), NodeApiVersions .create (ApiKeys .PRODUCE .id , (short ) 0 , (short ) 12 ))
2445
+ );
2446
+
2437
2447
// Send the first message.
2438
2448
long nowMs = time .milliseconds ();
2439
2449
Cluster cluster = TestUtils .singletonCluster ();
@@ -3426,6 +3436,9 @@ public void testWhenProduceResponseReturnsWithALeaderShipChangeErrorAndNewLeader
3426
3436
}
3427
3437
}));
3428
3438
Cluster startingMetadataCluster = metadata .fetch ();
3439
+ startingMetadataCluster .nodes ().forEach (node ->
3440
+ apiVersions .update (node .idString (), NodeApiVersions .create (ApiKeys .PRODUCE .id , (short ) 0 , (short ) 12 ))
3441
+ );
3429
3442
3430
3443
// Produce to tp0/1/2, where NO_LEADER_OR_FOLLOWER with new leader info is returned for tp0/1, and tp2 is returned without errors.
3431
3444
Future <RecordMetadata > futureIsProducedTp0 = appendToAccumulator (tp0 , 0L , "key" , "value" );
@@ -3446,7 +3459,9 @@ public void testWhenProduceResponseReturnsWithALeaderShipChangeErrorAndNewLeader
3446
3459
responses .put (tp0 , new OffsetAndError (-1 , Errors .NOT_LEADER_OR_FOLLOWER ));
3447
3460
responses .put (tp1 , new OffsetAndError (-1 , Errors .NOT_LEADER_OR_FOLLOWER ));
3448
3461
responses .put (tp2 , new OffsetAndError (100 , Errors .NONE ));
3449
-
3462
+ newNodes .forEach (node ->
3463
+ apiVersions .update (node .idString (), NodeApiVersions .create (ApiKeys .PRODUCE .id , (short ) 0 , (short ) 12 ))
3464
+ );
3450
3465
Map <TopicPartition , ProduceResponseData .LeaderIdAndEpoch > partitionLeaderInfo = new HashMap <>();
3451
3466
ProduceResponseData .LeaderIdAndEpoch tp0LeaderInfo = new ProduceResponseData .LeaderIdAndEpoch ();
3452
3467
tp0LeaderInfo .setLeaderEpoch (tp0LeaderEpoch + 1 );
0 commit comments