22
22
import java .util .List ;
23
23
import java .util .Map ;
24
24
import java .util .Properties ;
25
+ import java .util .concurrent .CompletableFuture ;
25
26
import java .util .concurrent .ExecutionException ;
26
27
27
28
import org .apache .kafka .clients .admin .NewTopic ;
38
39
import org .springframework .kafka .core .DefaultKafkaProducerFactory ;
39
40
import org .springframework .kafka .core .KafkaTemplate ;
40
41
import org .springframework .kafka .core .ProducerFactory ;
41
- import org .springframework .kafka .support .SendResult ;
42
42
import org .springframework .kafka .test .rule .EmbeddedKafkaRule ;
43
43
import org .springframework .kafka .test .utils .KafkaTestUtils ;
44
- import org .springframework .util .concurrent .ListenableFuture ;
45
44
46
45
import static org .hamcrest .MatcherAssert .assertThat ;
47
46
import static org .hamcrest .Matchers .containsInAnyOrder ;
@@ -187,12 +186,12 @@ public void testValidation() {
187
186
@ Test
188
187
public void testReadFromSinglePartition () throws ExecutionException , InterruptedException {
189
188
this .template .setDefaultTopic ("topic1" );
190
- List < ListenableFuture < SendResult < String , String >>> futures = new ArrayList <>();
189
+ var futures = new ArrayList <CompletableFuture <?> >();
191
190
futures .add (this .template .sendDefault ("val0" ));
192
191
futures .add (this .template .sendDefault ("val1" ));
193
192
futures .add (this .template .sendDefault ("val2" ));
194
193
futures .add (this .template .sendDefault ("val3" ));
195
- for (ListenableFuture < SendResult < String , String >> future : futures ) {
194
+ for (var future : futures ) {
196
195
future .get ();
197
196
}
198
197
@@ -221,12 +220,12 @@ public void testReadFromSinglePartition() throws ExecutionException, Interrupted
221
220
@ Test
222
221
public void testReadFromSinglePartitionFromCustomOffset () throws ExecutionException , InterruptedException {
223
222
this .template .setDefaultTopic ("topic5" );
224
- List < ListenableFuture < SendResult < String , String >>> futures = new ArrayList <>();
223
+ var futures = new ArrayList <CompletableFuture <?> >();
225
224
futures .add (this .template .sendDefault ("val0" )); // <-- offset 0
226
225
futures .add (this .template .sendDefault ("val1" )); // <-- offset 1
227
226
futures .add (this .template .sendDefault ("val2" )); // <-- offset 2
228
227
futures .add (this .template .sendDefault ("val3" )); // <-- offset 3
229
- for (ListenableFuture < SendResult < String , String >> future : futures ) {
228
+ for (var future : futures ) {
230
229
future .get ();
231
230
}
232
231
@@ -257,10 +256,10 @@ public void testReadFromSinglePartitionFromTheOffsetStoredInKafka() throws Excep
257
256
// first run: read a topic from the beginning
258
257
259
258
this .template .setDefaultTopic ("topic6" );
260
- List < ListenableFuture < SendResult < String , String >>> futures = new ArrayList <>();
259
+ var futures = new ArrayList <CompletableFuture <?> >();
261
260
futures .add (this .template .sendDefault ("val0" )); // <-- offset 0
262
261
futures .add (this .template .sendDefault ("val1" )); // <-- offset 1
263
- for (ListenableFuture < SendResult < String , String >> future : futures ) {
262
+ for (var future : futures ) {
264
263
future .get ();
265
264
}
266
265
this .reader = new KafkaItemReader <>(this .consumerProperties , "topic6" , 0 );
@@ -311,12 +310,12 @@ public void testReadFromSinglePartitionFromTheOffsetStoredInKafka() throws Excep
311
310
@ Test
312
311
public void testReadFromMultiplePartitions () throws ExecutionException , InterruptedException {
313
312
this .template .setDefaultTopic ("topic2" );
314
- List < ListenableFuture < SendResult < String , String >>> futures = new ArrayList <>();
313
+ var futures = new ArrayList <CompletableFuture <?> >();
315
314
futures .add (this .template .sendDefault ("val0" ));
316
315
futures .add (this .template .sendDefault ("val1" ));
317
316
futures .add (this .template .sendDefault ("val2" ));
318
317
futures .add (this .template .sendDefault ("val3" ));
319
- for (ListenableFuture < SendResult < String , String >> future : futures ) {
318
+ for (var future : futures ) {
320
319
future .get ();
321
320
}
322
321
@@ -339,13 +338,13 @@ public void testReadFromMultiplePartitions() throws ExecutionException, Interrup
339
338
@ Test
340
339
public void testReadFromSinglePartitionAfterRestart () throws ExecutionException , InterruptedException {
341
340
this .template .setDefaultTopic ("topic3" );
342
- List < ListenableFuture < SendResult < String , String >>> futures = new ArrayList <>();
341
+ var futures = new ArrayList <CompletableFuture <?> >();
343
342
futures .add (this .template .sendDefault ("val0" ));
344
343
futures .add (this .template .sendDefault ("val1" ));
345
344
futures .add (this .template .sendDefault ("val2" ));
346
345
futures .add (this .template .sendDefault ("val3" ));
347
346
futures .add (this .template .sendDefault ("val4" ));
348
- for (ListenableFuture < SendResult < String , String >> future : futures ) {
347
+ for (var future : futures ) {
349
348
future .get ();
350
349
}
351
350
ExecutionContext executionContext = new ExecutionContext ();
@@ -375,7 +374,7 @@ public void testReadFromSinglePartitionAfterRestart() throws ExecutionException,
375
374
376
375
@ Test
377
376
public void testReadFromMultiplePartitionsAfterRestart () throws ExecutionException , InterruptedException {
378
- List < ListenableFuture < SendResult < String , String >>> futures = new ArrayList <>();
377
+ var futures = new ArrayList <CompletableFuture <?> >();
379
378
futures .add (this .template .send ("topic4" , 0 , null , "val0" ));
380
379
futures .add (this .template .send ("topic4" , 0 , null , "val2" ));
381
380
futures .add (this .template .send ("topic4" , 0 , null , "val4" ));
@@ -385,7 +384,7 @@ public void testReadFromMultiplePartitionsAfterRestart() throws ExecutionExcepti
385
384
futures .add (this .template .send ("topic4" , 1 , null , "val5" ));
386
385
futures .add (this .template .send ("topic4" , 1 , null , "val7" ));
387
386
388
- for (ListenableFuture <?> future : futures ) {
387
+ for (var future : futures ) {
389
388
future .get ();
390
389
}
391
390
0 commit comments