22
22
import java .util .List ;
23
23
import java .util .Map ;
24
24
import java .util .Properties ;
25
- import java .util .concurrent .CompletableFuture ;
26
25
import java .util .concurrent .ExecutionException ;
27
26
28
27
import org .apache .kafka .clients .admin .NewTopic ;
40
39
import org .springframework .kafka .core .DefaultKafkaProducerFactory ;
41
40
import org .springframework .kafka .core .KafkaTemplate ;
42
41
import org .springframework .kafka .core .ProducerFactory ;
42
+ import org .springframework .kafka .support .SendResult ;
43
43
import org .springframework .kafka .test .EmbeddedKafkaBroker ;
44
44
import org .springframework .kafka .test .context .EmbeddedKafka ;
45
45
import org .springframework .kafka .test .utils .KafkaTestUtils ;
46
46
import org .springframework .test .context .junit .jupiter .SpringExtension ;
47
+ import org .springframework .util .concurrent .ListenableFuture ;
47
48
48
49
import static org .hamcrest .MatcherAssert .assertThat ;
49
50
import static org .hamcrest .Matchers .containsInAnyOrder ;
@@ -142,12 +143,12 @@ void testValidation() {
142
143
@ Test
143
144
void testReadFromSinglePartition () throws ExecutionException , InterruptedException {
144
145
this .template .setDefaultTopic ("topic1" );
145
- var futures = new ArrayList <CompletableFuture <?> >();
146
+ List < ListenableFuture < SendResult < String , String >>> futures = new ArrayList <>();
146
147
futures .add (this .template .sendDefault ("val0" ));
147
148
futures .add (this .template .sendDefault ("val1" ));
148
149
futures .add (this .template .sendDefault ("val2" ));
149
150
futures .add (this .template .sendDefault ("val3" ));
150
- for (var future : futures ) {
151
+ for (ListenableFuture < SendResult < String , String >> future : futures ) {
151
152
future .get ();
152
153
}
153
154
@@ -176,12 +177,12 @@ void testReadFromSinglePartition() throws ExecutionException, InterruptedExcepti
176
177
@ Test
177
178
void testReadFromSinglePartitionFromCustomOffset () throws ExecutionException , InterruptedException {
178
179
this .template .setDefaultTopic ("topic5" );
179
- var futures = new ArrayList <CompletableFuture <?> >();
180
+ List < ListenableFuture < SendResult < String , String >>> futures = new ArrayList <>();
180
181
futures .add (this .template .sendDefault ("val0" )); // <-- offset 0
181
182
futures .add (this .template .sendDefault ("val1" )); // <-- offset 1
182
183
futures .add (this .template .sendDefault ("val2" )); // <-- offset 2
183
184
futures .add (this .template .sendDefault ("val3" )); // <-- offset 3
184
- for (var future : futures ) {
185
+ for (ListenableFuture < SendResult < String , String >> future : futures ) {
185
186
future .get ();
186
187
}
187
188
@@ -212,10 +213,10 @@ void testReadFromSinglePartitionFromTheOffsetStoredInKafka() throws Exception {
212
213
// first run: read a topic from the beginning
213
214
214
215
this .template .setDefaultTopic ("topic6" );
215
- var futures = new ArrayList <CompletableFuture <?> >();
216
+ List < ListenableFuture < SendResult < String , String >>> futures = new ArrayList <>();
216
217
futures .add (this .template .sendDefault ("val0" )); // <-- offset 0
217
218
futures .add (this .template .sendDefault ("val1" )); // <-- offset 1
218
- for (var future : futures ) {
219
+ for (ListenableFuture < SendResult < String , String >> future : futures ) {
219
220
future .get ();
220
221
}
221
222
this .reader = new KafkaItemReader <>(this .consumerProperties , "topic6" , 0 );
@@ -266,12 +267,12 @@ void testReadFromSinglePartitionFromTheOffsetStoredInKafka() throws Exception {
266
267
@ Test
267
268
void testReadFromMultiplePartitions () throws ExecutionException , InterruptedException {
268
269
this .template .setDefaultTopic ("topic2" );
269
- var futures = new ArrayList <CompletableFuture <?> >();
270
+ List < ListenableFuture < SendResult < String , String >>> futures = new ArrayList <>();
270
271
futures .add (this .template .sendDefault ("val0" ));
271
272
futures .add (this .template .sendDefault ("val1" ));
272
273
futures .add (this .template .sendDefault ("val2" ));
273
274
futures .add (this .template .sendDefault ("val3" ));
274
- for (var future : futures ) {
275
+ for (ListenableFuture < SendResult < String , String >> future : futures ) {
275
276
future .get ();
276
277
}
277
278
@@ -294,13 +295,13 @@ void testReadFromMultiplePartitions() throws ExecutionException, InterruptedExce
294
295
@ Test
295
296
void testReadFromSinglePartitionAfterRestart () throws ExecutionException , InterruptedException {
296
297
this .template .setDefaultTopic ("topic3" );
297
- var futures = new ArrayList <CompletableFuture <?> >();
298
+ List < ListenableFuture < SendResult < String , String >>> futures = new ArrayList <>();
298
299
futures .add (this .template .sendDefault ("val0" ));
299
300
futures .add (this .template .sendDefault ("val1" ));
300
301
futures .add (this .template .sendDefault ("val2" ));
301
302
futures .add (this .template .sendDefault ("val3" ));
302
303
futures .add (this .template .sendDefault ("val4" ));
303
- for (var future : futures ) {
304
+ for (ListenableFuture < SendResult < String , String >> future : futures ) {
304
305
future .get ();
305
306
}
306
307
ExecutionContext executionContext = new ExecutionContext ();
@@ -330,7 +331,7 @@ void testReadFromSinglePartitionAfterRestart() throws ExecutionException, Interr
330
331
331
332
@ Test
332
333
void testReadFromMultiplePartitionsAfterRestart () throws ExecutionException , InterruptedException {
333
- var futures = new ArrayList <CompletableFuture <?> >();
334
+ List < ListenableFuture < SendResult < String , String >>> futures = new ArrayList <>();
334
335
futures .add (this .template .send ("topic4" , 0 , null , "val0" ));
335
336
futures .add (this .template .send ("topic4" , 0 , null , "val2" ));
336
337
futures .add (this .template .send ("topic4" , 0 , null , "val4" ));
@@ -340,7 +341,7 @@ void testReadFromMultiplePartitionsAfterRestart() throws ExecutionException, Int
340
341
futures .add (this .template .send ("topic4" , 1 , null , "val5" ));
341
342
futures .add (this .template .send ("topic4" , 1 , null , "val7" ));
342
343
343
- for (var future : futures ) {
344
+ for (ListenableFuture <?> future : futures ) {
344
345
future .get ();
345
346
}
346
347
0 commit comments