@ -152,8 +152,7 @@ public class SenderTest {
@@ -152,8 +152,7 @@ public class SenderTest {
@Test
public void testSimple ( ) throws Exception {
long offset = 0 ;
Future < RecordMetadata > future = accumulator . append ( tp0 , 0L , "key" . getBytes ( ) , "value" . getBytes ( ) ,
null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future = appendToAccumulator ( tp0 , 0L , "key" , "value" ) ;
sender . runOnce ( ) ; // connect
sender . runOnce ( ) ; // send produce request
assertEquals ( "We should have a single produce request in flight." , 1 , client . inFlightRequestCount ( ) ) ;
@ -179,8 +178,7 @@ public class SenderTest {
@@ -179,8 +178,7 @@ public class SenderTest {
// start off support produce request v3
apiVersions . update ( "0" , NodeApiVersions . create ( ) ) ;
Future < RecordMetadata > future = accumulator . append ( tp0 , 0L , "key" . getBytes ( ) , "value" . getBytes ( ) ,
null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future = appendToAccumulator ( tp0 , 0L , "key" , "value" ) ;
// now the partition leader supports only v2
apiVersions . update ( "0" , NodeApiVersions . create ( ApiKeys . PRODUCE . id , ( short ) 0 , ( short ) 2 ) ) ;
@ -218,14 +216,12 @@ public class SenderTest {
@@ -218,14 +216,12 @@ public class SenderTest {
// start off support produce request v3
apiVersions . update ( "0" , NodeApiVersions . create ( ) ) ;
Future < RecordMetadata > future1 = accumulator . append ( tp0 , 0L , "key" . getBytes ( ) , "value" . getBytes ( ) ,
null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future1 = appendToAccumulator ( tp0 , 0L , "key" , "value" ) ;
// now the partition leader supports only v2
apiVersions . update ( "0" , NodeApiVersions . create ( ApiKeys . PRODUCE . id , ( short ) 0 , ( short ) 2 ) ) ;
Future < RecordMetadata > future2 = accumulator . append ( tp1 , 0L , "key" . getBytes ( ) , "value" . getBytes ( ) ,
null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future2 = appendToAccumulator ( tp1 , 0L , "key" , "value" ) ;
// start off support produce request v3
apiVersions . update ( "0" , NodeApiVersions . create ( ) ) ;
@ -320,7 +316,7 @@ public class SenderTest {
@@ -320,7 +316,7 @@ public class SenderTest {
1 , metricsRegistry , time , REQUEST_TIMEOUT , RETRY_BACKOFF_MS , null , apiVersions ) ;
// Append a message so that topic metrics are created
accumulator . append ( tp0 , 0L , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) ;
appendToA ccumulator ( tp0 , 0L , "key" , "value" ) ;
sender . runOnce ( ) ; // connect
sender . runOnce ( ) ; // send produce request
client . respond ( produceResponse ( tp0 , 0 , Errors . NONE , 0 ) ) ;
@ -347,7 +343,7 @@ public class SenderTest {
@@ -347,7 +343,7 @@ public class SenderTest {
Sender sender = new Sender ( logContext , client , metadata , this . accumulator , false , MAX_REQUEST_SIZE , ACKS_ALL ,
maxRetries , senderMetrics , time , REQUEST_TIMEOUT , RETRY_BACKOFF_MS , null , apiVersions ) ;
// do a successful retry
Future < RecordMetadata > future = accumulator . append ( tp0 , 0L , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future = appendToA ccumulator ( tp0 , 0L , "key" , "value" ) ;
sender . runOnce ( ) ; // connect
sender . runOnce ( ) ; // send produce request
String id = client . requests ( ) . peek ( ) . destination ( ) ;
@ -376,7 +372,7 @@ public class SenderTest {
@@ -376,7 +372,7 @@ public class SenderTest {
assertEquals ( 0 , sender . inFlightBatches ( tp0 ) . size ( ) ) ;
// do an unsuccessful retry
future = accumulator . append ( tp0 , 0L , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
future = appendToA ccumulator ( tp0 , 0L , "key" , "value" ) ;
sender . runOnce ( ) ; // send produce request
assertEquals ( 1 , sender . inFlightBatches ( tp0 ) . size ( ) ) ;
for ( int i = 0 ; i < maxRetries + 1 ; i + + ) {
@ -410,7 +406,7 @@ public class SenderTest {
@@ -410,7 +406,7 @@ public class SenderTest {
// Send the first message.
TopicPartition tp2 = new TopicPartition ( "test" , 1 ) ;
accumulator . append ( tp2 , 0L , "key1" . getBytes ( ) , "value1" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) ;
appendToA ccumulator ( tp2 , 0L , "key1" , "value1" ) ;
sender . runOnce ( ) ; // connect
sender . runOnce ( ) ; // send produce request
String id = client . requests ( ) . peek ( ) . destination ( ) ;
@ -423,7 +419,7 @@ public class SenderTest {
@@ -423,7 +419,7 @@ public class SenderTest {
time . sleep ( 900 ) ;
// Now send another message to tp2
accumulator . append ( tp2 , 0L , "key2" . getBytes ( ) , "value2" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) ;
appendToA ccumulator ( tp2 , 0L , "key2" , "value2" ) ;
// Update metadata before sender receives response from broker 0. Now partition 2 moves to broker 0
MetadataResponse metadataUpdate2 = TestUtils . metadataUpdateWith ( 1 , Collections . singletonMap ( "test" , 2 ) ) ;
@ -453,7 +449,7 @@ public class SenderTest {
@@ -453,7 +449,7 @@ public class SenderTest {
if ( exception instanceof TimeoutException ) {
expiryCallbackCount . incrementAndGet ( ) ;
try {
accumulator . append ( tp1 , 0L , key , value , Record . EMPTY_HEADERS , null , maxBlockTimeMs , false ) ;
accumulator . append ( tp1 , 0L , key , value , Record . EMPTY_HEADERS , null , maxBlockTimeMs , false , time . milliseconds ( ) ) ;
} catch ( InterruptedException e ) {
throw new RuntimeException ( "Unexpected interruption" , e ) ;
}
@ -462,8 +458,9 @@ public class SenderTest {
@@ -462,8 +458,9 @@ public class SenderTest {
}
} ;
final long nowMs = time . milliseconds ( ) ;
for ( int i = 0 ; i < messagesPerBatch ; i + + )
accumulator . append ( tp1 , 0L , key , value , null , callback , maxBlockTimeMs , false ) ;
accumulator . append ( tp1 , 0L , key , value , null , callback , maxBlockTimeMs , false , nowMs ) ;
// Advance the clock to expire the first batch.
time . sleep ( 10000 ) ;
@ -496,7 +493,7 @@ public class SenderTest {
@@ -496,7 +493,7 @@ public class SenderTest {
long offset = 0 ;
client . updateMetadata ( TestUtils . metadataUpdateWith ( 1 , Collections . singletonMap ( "test" , 2 ) ) ) ;
Future < RecordMetadata > future = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertTrue ( "Topic not added to metadata" , metadata . containsTopic ( tp0 . topic ( ) ) ) ;
client . updateMetadata ( TestUtils . metadataUpdateWith ( 1 , Collections . singletonMap ( "test" , 2 ) ) ) ;
@ -513,7 +510,7 @@ public class SenderTest {
@@ -513,7 +510,7 @@ public class SenderTest {
time . sleep ( ProducerMetadata . TOPIC_EXPIRY_MS ) ;
client . updateMetadata ( TestUtils . metadataUpdateWith ( 1 , Collections . singletonMap ( "test" , 2 ) ) ) ;
assertFalse ( "Unused topic has not been expired" , metadata . containsTopic ( tp0 . topic ( ) ) ) ;
future = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
future = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertTrue ( "Topic not added to metadata" , metadata . containsTopic ( tp0 . topic ( ) ) ) ;
client . updateMetadata ( TestUtils . metadataUpdateWith ( 1 , Collections . singletonMap ( "test" , 2 ) ) ) ;
@ -555,7 +552,7 @@ public class SenderTest {
@@ -555,7 +552,7 @@ public class SenderTest {
@Test
public void testCanRetryWithoutIdempotence ( ) throws Exception {
// do a successful retry
Future < RecordMetadata > future = accumulator . append ( tp0 , 0L , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future = appendToA ccumulator ( tp0 , 0L , "key" , "value" ) ;
sender . runOnce ( ) ; // connect
sender . runOnce ( ) ; // send produce request
String id = client . requests ( ) . peek ( ) . destination ( ) ;
@ -594,7 +591,7 @@ public class SenderTest {
@@ -594,7 +591,7 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
String nodeId = client . requests ( ) . peek ( ) . destination ( ) ;
Node node = new Node ( Integer . valueOf ( nodeId ) , "localhost" , 0 ) ;
@ -603,7 +600,7 @@ public class SenderTest {
@@ -603,7 +600,7 @@ public class SenderTest {
assertEquals ( OptionalInt . empty ( ) , transactionManager . lastAckedSequence ( tp0 ) ) ;
// Send second ProduceRequest
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 2 , client . inFlightRequestCount ( ) ) ;
assertEquals ( 2 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
@ -644,7 +641,7 @@ public class SenderTest {
@@ -644,7 +641,7 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
String nodeId = client . requests ( ) . peek ( ) . destination ( ) ;
Node node = new Node ( Integer . valueOf ( nodeId ) , "localhost" , 0 ) ;
@ -653,11 +650,11 @@ public class SenderTest {
@@ -653,11 +650,11 @@ public class SenderTest {
assertEquals ( OptionalInt . empty ( ) , transactionManager . lastAckedSequence ( tp0 ) ) ;
// Send second ProduceRequest
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
// Send third ProduceRequest
Future < RecordMetadata > request3 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request3 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 3 , client . inFlightRequestCount ( ) ) ;
@ -672,7 +669,7 @@ public class SenderTest {
@@ -672,7 +669,7 @@ public class SenderTest {
sender . runOnce ( ) ; // receive response 0
// Queue the fourth request, it shouldn't be sent until the first 3 complete.
Future < RecordMetadata > request4 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request4 = appendToAccumulator ( tp0 ) ;
assertEquals ( 2 , client . inFlightRequestCount ( ) ) ;
assertEquals ( OptionalInt . empty ( ) , transactionManager . lastAckedSequence ( tp0 ) ) ;
@ -744,7 +741,7 @@ public class SenderTest {
@@ -744,7 +741,7 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
String nodeId = client . requests ( ) . peek ( ) . destination ( ) ;
Node node = new Node ( Integer . valueOf ( nodeId ) , "localhost" , 0 ) ;
@ -753,7 +750,7 @@ public class SenderTest {
@@ -753,7 +750,7 @@ public class SenderTest {
assertEquals ( OptionalInt . empty ( ) , transactionManager . lastAckedSequence ( tp0 ) ) ;
// Send second ProduceRequest
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 2 , client . inFlightRequestCount ( ) ) ;
assertEquals ( 2 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
@ -803,8 +800,8 @@ public class SenderTest {
@@ -803,8 +800,8 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest with multiple messages.
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
String nodeId = client . requests ( ) . peek ( ) . destination ( ) ;
Node node = new Node ( Integer . valueOf ( nodeId ) , "localhost" , 0 ) ;
@ -818,7 +815,7 @@ public class SenderTest {
@@ -818,7 +815,7 @@ public class SenderTest {
sender . runOnce ( ) ;
// Send second ProduceRequest
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
assertEquals ( 3 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
@ -845,7 +842,7 @@ public class SenderTest {
@@ -845,7 +842,7 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
String nodeId = client . requests ( ) . peek ( ) . destination ( ) ;
Node node = new Node ( Integer . valueOf ( nodeId ) , "localhost" , 0 ) ;
@ -854,7 +851,7 @@ public class SenderTest {
@@ -854,7 +851,7 @@ public class SenderTest {
assertEquals ( OptionalInt . empty ( ) , transactionManager . lastAckedSequence ( tp0 ) ) ;
// Send second ProduceRequest
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 2 , client . inFlightRequestCount ( ) ) ;
assertEquals ( 2 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
@ -927,14 +924,14 @@ public class SenderTest {
@@ -927,14 +924,14 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
String nodeId = client . requests ( ) . peek ( ) . destination ( ) ;
Node node = new Node ( Integer . valueOf ( nodeId ) , "localhost" , 0 ) ;
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
// Send second ProduceRequest
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 2 , client . inFlightRequestCount ( ) ) ;
assertFalse ( request1 . isDone ( ) ) ;
@ -995,7 +992,7 @@ public class SenderTest {
@@ -995,7 +992,7 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , 0L , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToA ccumulator ( tp0 , 0L , "key" , "value" ) ;
Node node = metadata . fetch ( ) . nodes ( ) . get ( 0 ) ;
time . sleep ( 10000L ) ;
client . disconnect ( node . idString ( ) ) ;
@ -1017,13 +1014,13 @@ public class SenderTest {
@@ -1017,13 +1014,13 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ; // send request
// We separate the two appends by 1 second so that the two batches
// don't expire at the same time.
time . sleep ( 1000L ) ;
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ; // send request
assertEquals ( 2 , client . inFlightRequestCount ( ) ) ;
assertEquals ( 2 , sender . inFlightBatches ( tp0 ) . size ( ) ) ;
@ -1045,7 +1042,7 @@ public class SenderTest {
@@ -1045,7 +1042,7 @@ public class SenderTest {
assertEquals ( 0 , sender . inFlightBatches ( tp0 ) . size ( ) ) ;
// let's enqueue another batch, which should not be dequeued until the unresolved state is clear.
Future < RecordMetadata > request3 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request3 = appendToAccumulator ( tp0 ) ;
time . sleep ( 20 ) ;
assertFalse ( request2 . isDone ( ) ) ;
@ -1084,11 +1081,11 @@ public class SenderTest {
@@ -1084,11 +1081,11 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ; // send request
time . sleep ( 1000L ) ;
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ; // send request
assertEquals ( 2 , client . inFlightRequestCount ( ) ) ;
@ -1105,7 +1102,7 @@ public class SenderTest {
@@ -1105,7 +1102,7 @@ public class SenderTest {
assertFutureFailure ( request1 , TimeoutException . class ) ;
assertTrue ( transactionManager . hasUnresolvedSequence ( tp0 ) ) ;
// let's enqueue another batch, which should not be dequeued until the unresolved state is clear.
Future < RecordMetadata > request3 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request3 = appendToAccumulator ( tp0 ) ;
time . sleep ( 20 ) ;
assertFalse ( request2 . isDone ( ) ) ;
@ -1137,7 +1134,7 @@ public class SenderTest {
@@ -1137,7 +1134,7 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , 0L , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToA ccumulator ( tp0 , 0L , "key" , "value" ) ;
sender . runOnce ( ) ; // send request
sendIdempotentProducerResponse ( 0 , tp0 , Errors . NOT_LEADER_FOR_PARTITION , - 1 ) ;
@ -1176,10 +1173,8 @@ public class SenderTest {
@@ -1176,10 +1173,8 @@ public class SenderTest {
Sender sender = new Sender ( logContext , client , metadata , this . accumulator , true , MAX_REQUEST_SIZE , ACKS_ALL , maxRetries ,
senderMetrics , time , REQUEST_TIMEOUT , RETRY_BACKOFF_MS , transactionManager , apiVersions ) ;
Future < RecordMetadata > failedResponse = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) ,
"value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > successfulResponse = accumulator . append ( tp1 , time . milliseconds ( ) , "key" . getBytes ( ) ,
"value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > failedResponse = appendToAccumulator ( tp0 ) ;
Future < RecordMetadata > successfulResponse = appendToAccumulator ( tp1 ) ;
sender . runOnce ( ) ; // connect and send.
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
@ -1218,10 +1213,8 @@ public class SenderTest {
@@ -1218,10 +1213,8 @@ public class SenderTest {
Sender sender = new Sender ( logContext , client , metadata , this . accumulator , true , MAX_REQUEST_SIZE , ACKS_ALL , 10 ,
senderMetrics , time , REQUEST_TIMEOUT , RETRY_BACKOFF_MS , transactionManager , apiVersions ) ;
Future < RecordMetadata > failedResponse = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) ,
"value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > successfulResponse = accumulator . append ( tp1 , time . milliseconds ( ) , "key" . getBytes ( ) ,
"value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > failedResponse = appendToAccumulator ( tp0 ) ;
Future < RecordMetadata > successfulResponse = appendToAccumulator ( tp1 ) ;
sender . runOnce ( ) ; // connect and send.
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
@ -1257,10 +1250,8 @@ public class SenderTest {
@@ -1257,10 +1250,8 @@ public class SenderTest {
Sender sender = new Sender ( logContext , client , metadata , this . accumulator , true , MAX_REQUEST_SIZE , ACKS_ALL , 10 ,
senderMetrics , time , REQUEST_TIMEOUT , RETRY_BACKOFF_MS , transactionManager , apiVersions ) ;
Future < RecordMetadata > failedResponse = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) ,
"value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > successfulResponse = accumulator . append ( tp1 , time . milliseconds ( ) , "key" . getBytes ( ) ,
"value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > failedResponse = appendToAccumulator ( tp0 ) ;
Future < RecordMetadata > successfulResponse = appendToAccumulator ( tp1 ) ;
sender . runOnce ( ) ; // connect and send.
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
@ -1293,10 +1284,8 @@ public class SenderTest {
@@ -1293,10 +1284,8 @@ public class SenderTest {
Sender sender = new Sender ( logContext , client , metadata , this . accumulator , true , MAX_REQUEST_SIZE , ACKS_ALL , maxRetries ,
senderMetrics , time , REQUEST_TIMEOUT , RETRY_BACKOFF_MS , transactionManager , apiVersions ) ;
Future < RecordMetadata > failedResponse = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) ,
"value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > successfulResponse = accumulator . append ( tp1 , time . milliseconds ( ) , "key" . getBytes ( ) ,
"value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > failedResponse = appendToAccumulator ( tp0 ) ;
Future < RecordMetadata > successfulResponse = appendToAccumulator ( tp1 ) ;
sender . runOnce ( ) ; // connect.
sender . runOnce ( ) ; // send.
@ -1340,7 +1329,7 @@ public class SenderTest {
@@ -1340,7 +1329,7 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
String nodeId = client . requests ( ) . peek ( ) . destination ( ) ;
Node node = new Node ( Integer . valueOf ( nodeId ) , "localhost" , 0 ) ;
@ -1349,7 +1338,7 @@ public class SenderTest {
@@ -1349,7 +1338,7 @@ public class SenderTest {
assertEquals ( OptionalInt . empty ( ) , transactionManager . lastAckedSequence ( tp0 ) ) ;
// Send second ProduceRequest
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 2 , client . inFlightRequestCount ( ) ) ;
assertEquals ( 2 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
@ -1393,7 +1382,7 @@ public class SenderTest {
@@ -1393,7 +1382,7 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
@ -1410,8 +1399,8 @@ public class SenderTest {
@@ -1410,8 +1399,8 @@ public class SenderTest {
assertEquals ( OptionalLong . of ( 1000L ) , transactionManager . lastAckedOffset ( tp0 ) ) ;
// Send second ProduceRequest, a single batch with 2 records.
accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) ;
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
appendToAccumulator ( tp0 ) ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 3 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
assertEquals ( OptionalInt . of ( 0 ) , transactionManager . lastAckedSequence ( tp0 ) ) ;
@ -1451,7 +1440,7 @@ public class SenderTest {
@@ -1451,7 +1440,7 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
@ -1468,7 +1457,7 @@ public class SenderTest {
@@ -1468,7 +1457,7 @@ public class SenderTest {
assertEquals ( OptionalLong . of ( 1000L ) , transactionManager . lastAckedOffset ( tp0 ) ) ;
// Send second ProduceRequest
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 2 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
assertEquals ( OptionalInt . of ( 0 ) , transactionManager . lastAckedSequence ( tp0 ) ) ;
@ -1509,7 +1498,7 @@ public class SenderTest {
@@ -1509,7 +1498,7 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
@ -1526,14 +1515,14 @@ public class SenderTest {
@@ -1526,14 +1515,14 @@ public class SenderTest {
assertEquals ( OptionalLong . of ( 1000L ) , transactionManager . lastAckedOffset ( tp0 ) ) ;
// Send second ProduceRequest
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 2 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
assertEquals ( OptionalInt . of ( 0 ) , transactionManager . lastAckedSequence ( tp0 ) ) ;
// Send the third ProduceRequest, in parallel with the second. It should be retried even though the
// lastAckedOffset > logStartOffset when its UnknownProducerResponse comes back.
Future < RecordMetadata > request3 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request3 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 3 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
assertEquals ( OptionalInt . of ( 0 ) , transactionManager . lastAckedSequence ( tp0 ) ) ;
@ -1598,7 +1587,7 @@ public class SenderTest {
@@ -1598,7 +1587,7 @@ public class SenderTest {
assertEquals ( 0 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
@ -1615,7 +1604,7 @@ public class SenderTest {
@@ -1615,7 +1604,7 @@ public class SenderTest {
assertEquals ( OptionalLong . of ( 1000L ) , transactionManager . lastAckedOffset ( tp0 ) ) ;
// Send second ProduceRequest,
Future < RecordMetadata > request2 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertEquals ( 2 , transactionManager . sequenceNumber ( tp0 ) . longValue ( ) ) ;
assertEquals ( OptionalInt . of ( 0 ) , transactionManager . lastAckedSequence ( tp0 ) ) ;
@ -1658,8 +1647,7 @@ public class SenderTest {
@@ -1658,8 +1647,7 @@ public class SenderTest {
assertTrue ( transactionManager . hasProducerId ( ) ) ;
// cluster authorization is a fatal error for the producer
Future < RecordMetadata > future = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) ,
null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future = appendToAccumulator ( tp0 ) ;
client . prepareResponse ( new MockClient . RequestMatcher ( ) {
@Override
public boolean matches ( AbstractRequest body ) {
@ -1685,12 +1673,10 @@ public class SenderTest {
@@ -1685,12 +1673,10 @@ public class SenderTest {
assertTrue ( transactionManager . hasProducerId ( ) ) ;
// cluster authorization is a fatal error for the producer
Future < RecordMetadata > future1 = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) ,
null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
Future < RecordMetadata > future2 = accumulator . append ( tp1 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) ,
null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future2 = appendToAccumulator ( tp1 ) ;
sender . runOnce ( ) ;
client . respond ( new MockClient . RequestMatcher ( ) {
@ -1726,8 +1712,7 @@ public class SenderTest {
@@ -1726,8 +1712,7 @@ public class SenderTest {
prepareAndReceiveInitProducerId ( producerId , Errors . NONE ) ;
assertTrue ( transactionManager . hasProducerId ( ) ) ;
Future < RecordMetadata > future = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) ,
null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future = appendToAccumulator ( tp0 ) ;
client . prepareResponse ( new MockClient . RequestMatcher ( ) {
@Override
public boolean matches ( AbstractRequest body ) {
@ -1751,8 +1736,7 @@ public class SenderTest {
@@ -1751,8 +1736,7 @@ public class SenderTest {
prepareAndReceiveInitProducerId ( producerId , Errors . NONE ) ;
assertTrue ( transactionManager . hasProducerId ( ) ) ;
Future < RecordMetadata > future = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) ,
null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future = appendToAccumulator ( tp0 ) ;
client . prepareUnsupportedVersionResponse ( new MockClient . RequestMatcher ( ) {
@Override
public boolean matches ( AbstractRequest body ) {
@ -1782,7 +1766,7 @@ public class SenderTest {
@@ -1782,7 +1766,7 @@ public class SenderTest {
Sender sender = new Sender ( logContext , client , metadata , this . accumulator , true , MAX_REQUEST_SIZE , ACKS_ALL , maxRetries ,
senderMetrics , time , REQUEST_TIMEOUT , RETRY_BACKOFF_MS , transactionManager , apiVersions ) ;
Future < RecordMetadata > responseFuture = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > responseFuture = appendToAccumulator ( tp0 ) ;
client . prepareResponse ( new MockClient . RequestMatcher ( ) {
@Override
public boolean matches ( AbstractRequest body ) {
@ -1824,7 +1808,7 @@ public class SenderTest {
@@ -1824,7 +1808,7 @@ public class SenderTest {
Sender sender = new Sender ( logContext , client , metadata , this . accumulator , true , MAX_REQUEST_SIZE , ACKS_ALL , maxRetries ,
senderMetrics , time , REQUEST_TIMEOUT , RETRY_BACKOFF_MS , transactionManager , apiVersions ) ;
Future < RecordMetadata > responseFuture = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > responseFuture = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ; // connect.
sender . runOnce ( ) ; // send.
String id = client . requests ( ) . peek ( ) . destination ( ) ;
@ -1863,7 +1847,7 @@ public class SenderTest {
@@ -1863,7 +1847,7 @@ public class SenderTest {
Sender sender = new Sender ( logContext , client , metadata , this . accumulator , true , MAX_REQUEST_SIZE , ACKS_ALL , maxRetries ,
senderMetrics , time , REQUEST_TIMEOUT , RETRY_BACKOFF_MS , transactionManager , apiVersions ) ;
Future < RecordMetadata > responseFuture = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > responseFuture = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ; // connect.
sender . runOnce ( ) ; // send.
@ -1926,10 +1910,11 @@ public class SenderTest {
@@ -1926,10 +1910,11 @@ public class SenderTest {
MetadataResponse metadataUpdate1 = TestUtils . metadataUpdateWith ( 2 , Collections . singletonMap ( topic , 2 ) ) ;
client . prepareMetadataUpdate ( metadataUpdate1 ) ;
// Send the first message.
long nowMs = time . milliseconds ( ) ;
Future < RecordMetadata > f1 =
accumulator . append ( tp , 0L , "key1" . getBytes ( ) , new byte [ batchSize / 2 ] , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
accumulator . append ( tp , 0L , "key1" . getBytes ( ) , new byte [ batchSize / 2 ] , null , null , MAX_BLOCK_TIMEOUT , false , nowMs ) . future ;
Future < RecordMetadata > f2 =
accumulator . append ( tp , 0L , "key2" . getBytes ( ) , new byte [ batchSize / 2 ] , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
accumulator . append ( tp , 0L , "key2" . getBytes ( ) , new byte [ batchSize / 2 ] , null , null , MAX_BLOCK_TIMEOUT , false , nowMs ) . future ;
sender . runOnce ( ) ; // connect
sender . runOnce ( ) ; // send produce request
@ -1998,8 +1983,7 @@ public class SenderTest {
@@ -1998,8 +1983,7 @@ public class SenderTest {
setupWithTransactionState ( null , false , pool ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 =
accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ; // send request
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
assertEquals ( 1 , sender . inFlightBatches ( tp0 ) . size ( ) ) ;
@ -2024,7 +2008,7 @@ public class SenderTest {
@@ -2024,7 +2008,7 @@ public class SenderTest {
setupWithTransactionState ( null , true , null ) ;
// Send first ProduceRequest
Future < RecordMetadata > request = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ; // send request
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
assertEquals ( "Expect one in-flight batch in accumulator" , 1 , sender . inFlightBatches ( tp0 ) . size ( ) ) ;
@ -2050,7 +2034,7 @@ public class SenderTest {
@@ -2050,7 +2034,7 @@ public class SenderTest {
setupWithTransactionState ( null , true , null ) ;
// Send first ProduceRequest
accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) ;
appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ; // send request
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
assertEquals ( 1 , sender . inFlightBatches ( tp0 ) . size ( ) ) ;
@ -2058,7 +2042,7 @@ public class SenderTest {
@@ -2058,7 +2042,7 @@ public class SenderTest {
time . sleep ( deliveryTimeoutMs / 2 ) ;
// Send second ProduceRequest
accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) ;
appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ; // must not send request because the partition is muted
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
assertEquals ( 1 , sender . inFlightBatches ( tp0 ) . size ( ) ) ;
@ -2081,9 +2065,7 @@ public class SenderTest {
@@ -2081,9 +2065,7 @@ public class SenderTest {
setupWithTransactionState ( null , false , null ) ;
// Send first ProduceRequest
Future < RecordMetadata > request1 =
accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null ,
MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ; // send request
assertEquals ( 1 , client . inFlightRequestCount ( ) ) ;
time . sleep ( deliverTimeoutMs ) ;
@ -2110,12 +2092,8 @@ public class SenderTest {
@@ -2110,12 +2092,8 @@ public class SenderTest {
public void testExpiredBatchDoesNotSplitOnMessageTooLargeError ( ) throws Exception {
long deliverTimeoutMs = 1500L ;
// create a producer batch with more than one record so it is eligible for splitting
Future < RecordMetadata > request1 =
accumulator . append ( tp0 , time . milliseconds ( ) , "key1" . getBytes ( ) , "value1" . getBytes ( ) , null , null ,
MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 =
accumulator . append ( tp0 , time . milliseconds ( ) , "key2" . getBytes ( ) , "value2" . getBytes ( ) , null , null ,
MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 ) ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 ) ;
// send request
sender . runOnce ( ) ;
@ -2143,8 +2121,7 @@ public class SenderTest {
@@ -2143,8 +2121,7 @@ public class SenderTest {
setupWithTransactionState ( null ) ;
accumulator . append ( tp0 , 0L , "key" . getBytes ( ) , "value" . getBytes ( ) , null , null ,
MAX_BLOCK_TIMEOUT , false ) ;
appendToAccumulator ( tp0 , 0L , "key" , "value" ) ;
sender . runOnce ( ) ;
sender . runOnce ( ) ;
@ -2168,8 +2145,8 @@ public class SenderTest {
@@ -2168,8 +2145,8 @@ public class SenderTest {
setupWithTransactionState ( null , true , null ) ;
// Send multiple ProduceRequest across multiple partitions.
Future < RecordMetadata > request1 = accumulator . append ( tp0 , time . milliseconds ( ) , "k1" . getBytes ( ) , "v1" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 = accumulator . append ( tp1 , time . milliseconds ( ) , "k2" . getBytes ( ) , "v2" . getBytes ( ) , null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToA ccumulator ( tp0 , time . milliseconds ( ) , "k1" , "v1" ) ;
Future < RecordMetadata > request2 = appendToA ccumulator ( tp1 , time . milliseconds ( ) , "k2" , "v2" ) ;
// Send request.
sender . runOnce ( ) ;
@ -2327,12 +2304,8 @@ public class SenderTest {
@@ -2327,12 +2304,8 @@ public class SenderTest {
sender . runOnce ( ) ;
// create a producer batch with more than one record so it is eligible for splitting
Future < RecordMetadata > request1 =
accumulator . append ( tp0 , time . milliseconds ( ) , "key1" . getBytes ( ) , "value1" . getBytes ( ) , null , null ,
MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request2 =
accumulator . append ( tp0 , time . milliseconds ( ) , "key2" . getBytes ( ) , "value2" . getBytes ( ) , null , null ,
MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > request1 = appendToAccumulator ( tp0 , time . milliseconds ( ) , "key1" , "value1" ) ;
Future < RecordMetadata > request2 = appendToAccumulator ( tp0 , time . milliseconds ( ) , "key2" , "value2" ) ;
// send request
sender . runOnce ( ) ;
@ -2441,6 +2414,15 @@ public class SenderTest {
@@ -2441,6 +2414,15 @@ public class SenderTest {
}
}
private FutureRecordMetadata appendToAccumulator ( TopicPartition tp ) throws InterruptedException {
return appendToAccumulator ( tp , time . milliseconds ( ) , "key" , "value" ) ;
}
private FutureRecordMetadata appendToAccumulator ( TopicPartition tp , long timestamp , String key , String value ) throws InterruptedException {
return accumulator . append ( tp , timestamp , key . getBytes ( ) , value . getBytes ( ) , Record . EMPTY_HEADERS ,
null , MAX_BLOCK_TIMEOUT , false , time . milliseconds ( ) ) . future ;
}
private ProduceResponse produceResponse ( TopicPartition tp , long offset , Errors error , int throttleTimeMs , long logStartOffset ) {
ProduceResponse . PartitionResponse resp = new ProduceResponse . PartitionResponse ( error , offset , RecordBatch . NO_TIMESTAMP , logStartOffset ) ;
Map < TopicPartition , ProduceResponse . PartitionResponse > partResp = Collections . singletonMap ( tp , resp ) ;
@ -2479,13 +2461,12 @@ public class SenderTest {
@@ -2479,13 +2461,12 @@ public class SenderTest {
this . sender = new Sender ( logContext , this . client , this . metadata , this . accumulator , guaranteeOrder , MAX_REQUEST_SIZE , ACKS_ALL ,
Integer . MAX_VALUE , this . senderMetricsRegistry , this . time , REQUEST_TIMEOUT , RETRY_BACKOFF_MS , transactionManager , apiVersions ) ;
metadata . add ( "test" ) ;
metadata . add ( "test" , time . milliseconds ( ) ) ;
this . client . updateMetadata ( TestUtils . metadataUpdateWith ( 1 , Collections . singletonMap ( "test" , 2 ) ) ) ;
}
private void assertSendFailure ( Class < ? extends RuntimeException > expectedError ) throws Exception {
Future < RecordMetadata > future = accumulator . append ( tp0 , time . milliseconds ( ) , "key" . getBytes ( ) , "value" . getBytes ( ) ,
null , null , MAX_BLOCK_TIMEOUT , false ) . future ;
Future < RecordMetadata > future = appendToAccumulator ( tp0 ) ;
sender . runOnce ( ) ;
assertTrue ( future . isDone ( ) ) ;
try {