57
57
58
58
import java .util .AbstractMap ;
59
59
import java .util .ArrayList ;
60
- import java .util .Arrays ;
61
60
import java .util .HashMap ;
62
61
import java .util .HashSet ;
63
62
import java .util .LinkedHashMap ;
@@ -110,35 +109,35 @@ public class AssignmentsManagerTest {
110
109
delta .replay (new PartitionRecord ().
111
110
setPartitionId (0 ).
112
111
setTopicId (TOPIC_1 ).
113
- setReplicas (Arrays . asList (0 , 1 , 2 )).
114
- setIsr (Arrays . asList (0 , 1 , 2 )).
112
+ setReplicas (List . of (0 , 1 , 2 )).
113
+ setIsr (List . of (0 , 1 , 2 )).
115
114
setLeader (1 ));
116
115
delta .replay (new PartitionRecord ().
117
116
setPartitionId (1 ).
118
117
setTopicId (TOPIC_1 ).
119
- setReplicas (Arrays . asList (1 , 2 , 3 )).
120
- setIsr (Arrays . asList (1 , 2 , 3 )).
118
+ setReplicas (List . of (1 , 2 , 3 )).
119
+ setIsr (List . of (1 , 2 , 3 )).
121
120
setLeader (1 ));
122
121
delta .replay (new TopicRecord ().
123
122
setName ("bar" ).
124
123
setTopicId (TOPIC_2 ));
125
124
delta .replay (new PartitionRecord ().
126
125
setPartitionId (0 ).
127
126
setTopicId (TOPIC_2 ).
128
- setReplicas (Arrays . asList (0 , 3 , 2 )).
129
- setIsr (Arrays . asList (0 , 3 , 2 )).
127
+ setReplicas (List . of (0 , 3 , 2 )).
128
+ setIsr (List . of (0 , 3 , 2 )).
130
129
setLeader (1 ));
131
130
delta .replay (new PartitionRecord ().
132
131
setPartitionId (1 ).
133
132
setTopicId (TOPIC_2 ).
134
- setReplicas (Arrays . asList (1 , 2 , 3 )).
135
- setIsr (Arrays . asList (2 )).
133
+ setReplicas (List . of (1 , 2 , 3 )).
134
+ setIsr (List . of (2 )).
136
135
setLeader (2 ));
137
136
delta .replay (new PartitionRecord ().
138
137
setPartitionId (2 ).
139
138
setTopicId (TOPIC_2 ).
140
- setReplicas (Arrays . asList (3 , 2 , 1 )).
141
- setIsr (Arrays . asList (3 , 2 , 1 )).
139
+ setReplicas (List . of (3 , 2 , 1 )).
140
+ setIsr (List . of (3 , 2 , 1 )).
142
141
setLeader (3 ));
143
142
TEST_IMAGE = delta .apply (MetadataProvenance .EMPTY );
144
143
}
@@ -199,7 +198,7 @@ static class TestEnv implements AutoCloseable {
199
198
this .channelManager = new MockNodeToControllerChannelManager ();
200
199
this .assignmentsManager = new AssignmentsManager (
201
200
backoff , Time .SYSTEM , channelManager , 1 , () -> TEST_IMAGE ,
202
- t -> t . toString () , metricsRegistry );
201
+ Uuid :: toString , metricsRegistry );
203
202
this .successes = new HashMap <>();
204
203
}
205
204
@@ -225,11 +224,11 @@ void successfullyCompleteCallbackOfRequestAssigningTopic1ToDir1() throws Excepti
225
224
assertEquals (TOPIC_1 , topicData .topicId ());
226
225
assertEquals (0 , topicData .partitions ().get (0 ).partitionIndex ());
227
226
return mockClientResponse (new AssignReplicasToDirsResponseData ().
228
- setDirectories (Arrays . asList (new AssignReplicasToDirsResponseData .DirectoryData ().
227
+ setDirectories (List . of (new AssignReplicasToDirsResponseData .DirectoryData ().
229
228
setId (DIR_1 ).
230
- setTopics (Arrays . asList (new AssignReplicasToDirsResponseData .TopicData ().
229
+ setTopics (List . of (new AssignReplicasToDirsResponseData .TopicData ().
231
230
setTopicId (TOPIC_1 ).
232
- setPartitions (Arrays . asList (new AssignReplicasToDirsResponseData .PartitionData ().
231
+ setPartitions (List . of (new AssignReplicasToDirsResponseData .PartitionData ().
233
232
setPartitionIndex (0 ).
234
233
setErrorCode ((short ) 0 ))))))));
235
234
});
@@ -273,8 +272,7 @@ static Optional<ClientResponse> mockClientResponse(AssignReplicasToDirsResponseD
273
272
274
273
@ Test
275
274
public void testStartAndShutdown () throws Exception {
276
- try (TestEnv testEnv = new TestEnv ()) {
277
- }
275
+ new TestEnv ().close ();
278
276
}
279
277
280
278
@ Test
@@ -303,14 +301,10 @@ public void testSuccessfulAssignment() throws Exception {
303
301
public void testUnSuccessfulRequestCausesRetransmission (String failureType ) throws Exception {
304
302
try (TestEnv testEnv = new TestEnv ()) {
305
303
testEnv .onAssignment (new TopicIdPartition (TOPIC_1 , 0 ), DIR_1 );
306
- TestUtils .retryOnExceptionWithTimeout (60_000 , () -> {
307
- assertEquals (1 , testEnv .assignmentsManager .numPending ());
308
- });
304
+ TestUtils .retryOnExceptionWithTimeout (60_000 , () -> assertEquals (1 , testEnv .assignmentsManager .numPending ()));
309
305
if (failureType .equals ("invalidRequest" )) {
310
- testEnv .channelManager .completeCallback (req -> {
311
- return mockClientResponse (new AssignReplicasToDirsResponseData ().
312
- setErrorCode (Errors .INVALID_REQUEST .code ()));
313
- });
306
+ testEnv .channelManager .completeCallback (req -> mockClientResponse (new AssignReplicasToDirsResponseData ()
307
+ .setErrorCode (Errors .INVALID_REQUEST .code ())));
314
308
} else if (failureType .equals ("timeout" )) {
315
309
testEnv .channelManager .completeCallback (req -> Optional .empty ());
316
310
}
@@ -332,16 +326,12 @@ public void testUnSuccessfulRequestCausesRetransmission(String failureType) thro
332
326
@ ValueSource (strings = {"missingTopic" , "missingPartition" , "notReplica" })
333
327
public void testMismatchedInputDoesNotTriggerCompletion (String mismatchType ) throws Exception {
334
328
try (TestEnv testEnv = new TestEnv ()) {
335
- TopicIdPartition target ;
336
- if (mismatchType .equals ("missingTopic" )) {
337
- target = new TopicIdPartition (TOPIC_3 , 0 );
338
- } else if (mismatchType .equals ("missingPartition" )) {
339
- target = new TopicIdPartition (TOPIC_1 , 2 );
340
- } else if (mismatchType .equals ("notReplica" )) {
341
- target = new TopicIdPartition (TOPIC_2 , 0 );
342
- } else {
343
- throw new RuntimeException ("invalid mismatchType argument." );
344
- }
329
+ TopicIdPartition target = switch (mismatchType ) {
330
+ case "missingTopic" -> new TopicIdPartition (TOPIC_3 , 0 );
331
+ case "missingPartition" -> new TopicIdPartition (TOPIC_1 , 2 );
332
+ case "notReplica" -> new TopicIdPartition (TOPIC_2 , 0 );
333
+ default -> throw new RuntimeException ("invalid mismatchType argument." );
334
+ };
345
335
testEnv .onAssignment (target , DIR_1 );
346
336
TestUtils .retryOnExceptionWithTimeout (60_000 , () -> {
347
337
assertEquals (0 , testEnv .assignmentsManager .numPending ());
@@ -386,9 +376,9 @@ public void testOneAssignmentFailsOneSucceeds(String failureType) throws Excepti
386
376
}
387
377
}
388
378
return mockClientResponse (new AssignReplicasToDirsResponseData ().
389
- setDirectories (Arrays . asList (new AssignReplicasToDirsResponseData .DirectoryData ().
379
+ setDirectories (List . of (new AssignReplicasToDirsResponseData .DirectoryData ().
390
380
setId (DIR_1 ).
391
- setTopics (Arrays . asList (new AssignReplicasToDirsResponseData .TopicData ().
381
+ setTopics (List . of (new AssignReplicasToDirsResponseData .TopicData ().
392
382
setTopicId (TOPIC_1 ).
393
383
setPartitions (partitions ))))));
394
384
});
@@ -476,17 +466,16 @@ void testBuildRequestData() {
476
466
assignments .put (new TopicIdPartition (TOPIC_1 , 4 ), DIR_1 );
477
467
assignments .put (new TopicIdPartition (TOPIC_2 , 5 ), DIR_2 );
478
468
Map <TopicIdPartition , Assignment > targetAssignments = new LinkedHashMap <>();
479
- assignments .entrySet ().forEach (e -> targetAssignments .put (e .getKey (),
480
- new Assignment (e .getKey (), e .getValue (), 0 , () -> { })));
469
+ assignments .forEach ((key , value ) -> targetAssignments .put (key , new Assignment (key , value , 0 , () -> { })));
481
470
AssignReplicasToDirsRequestData built =
482
471
AssignmentsManager .buildRequestData (8 , 100L , targetAssignments );
483
472
AssignReplicasToDirsRequestData expected = new AssignReplicasToDirsRequestData ().
484
473
setBrokerId (8 ).
485
474
setBrokerEpoch (100L ).
486
- setDirectories (Arrays . asList (
475
+ setDirectories (List . of (
487
476
new AssignReplicasToDirsRequestData .DirectoryData ().
488
477
setId (DIR_2 ).
489
- setTopics (Arrays . asList (
478
+ setTopics (List . of (
490
479
new AssignReplicasToDirsRequestData .TopicData ().
491
480
setTopicId (TOPIC_1 ).
492
481
setPartitions (List .of (
@@ -510,7 +499,7 @@ void testBuildRequestData() {
510
499
setTopics (List .of (
511
500
new AssignReplicasToDirsRequestData .TopicData ().
512
501
setTopicId (TOPIC_1 ).
513
- setPartitions (Arrays . asList (
502
+ setPartitions (List . of (
514
503
new AssignReplicasToDirsRequestData .PartitionData ().
515
504
setPartitionIndex (1 ),
516
505
new AssignReplicasToDirsRequestData .PartitionData ().
0 commit comments