Skip to content

Commit 0202721

Browse files
authored
MINOR: Cleanups in jmh-benchmarks module (#20374)
This PR aims at cleaning up the `jmh-benchmarks` module further by getting rid of some extra code which can be replaced by record Reviewers: Ken Huang <[email protected]>, Chia-Ping Tsai <[email protected]>
1 parent a056672 commit 0202721

File tree

2 files changed

+4
-31
lines changed

2 files changed

+4
-31
lines changed

jmh-benchmarks/src/main/java/org/apache/kafka/jmh/assignor/StreamsStickyAssignorBenchmark.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.openjdk.jmh.annotations.Warmup;
4545
import org.openjdk.jmh.infra.Blackhole;
4646

47-
import java.util.Collections;
4847
import java.util.HashMap;
4948
import java.util.List;
5049
import java.util.Map;
@@ -107,7 +106,7 @@ public void setup() {
107106
taskAssignor = new StickyTaskAssignor();
108107

109108
Map<String, StreamsGroupMember> members = createMembers();
110-
this.assignmentConfigs = Collections.singletonMap(
109+
this.assignmentConfigs = Map.of(
111110
"num.standby.replicas",
112111
Integer.toString(standbyReplicas)
113112
);
@@ -138,7 +137,7 @@ private void simulateIncrementalRebalance() {
138137
for (Map.Entry<String, AssignmentMemberSpec> member : groupSpec.members().entrySet()) {
139138
MemberAssignment memberAssignment = members.getOrDefault(
140139
member.getKey(),
141-
new MemberAssignment(Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap())
140+
new MemberAssignment(Map.of(), Map.of(), Map.of())
142141
);
143142

144143
updatedMemberSpec.put(member.getKey(), new AssignmentMemberSpec(

jmh-benchmarks/src/main/java/org/apache/kafka/jmh/core/TestPurgatoryPerformance.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.ArrayList;
3131
import java.util.Comparator;
3232
import java.util.List;
33-
import java.util.Objects;
3433
import java.util.Optional;
3534
import java.util.Random;
3635
import java.util.concurrent.CountDownLatch;
@@ -405,12 +404,7 @@ public void shutdown() throws InterruptedException {
405404

406405
}
407406

408-
private static class Scheduled implements Delayed {
409-
final FakeOperation operation;
410-
411-
public Scheduled(FakeOperation operation) {
412-
this.operation = operation;
413-
}
407+
private record Scheduled(FakeOperation operation) implements Delayed {
414408

415409
@Override
416410
public long getDelay(TimeUnit unit) {
@@ -429,30 +423,11 @@ else if (operation.completesAt > other.operation.completesAt)
429423
}
430424
}
431425

432-
private static class FakeOperationKey implements DelayedOperationKey {
433-
private final String key;
434-
435-
public FakeOperationKey(String key) {
436-
this.key = key;
437-
}
438-
426+
private record FakeOperationKey(String key) implements DelayedOperationKey {
439427
@Override
440428
public String keyLabel() {
441429
return key;
442430
}
443-
444-
@Override
445-
public boolean equals(Object o) {
446-
if (this == o) return true;
447-
if (o == null || getClass() != o.getClass()) return false;
448-
FakeOperationKey that = (FakeOperationKey) o;
449-
return Objects.equals(key, that.key);
450-
}
451-
452-
@Override
453-
public int hashCode() {
454-
return Objects.hash(key);
455-
}
456431
}
457432

458433
private static class FakeOperation extends DelayedOperation {
@@ -469,7 +444,6 @@ public FakeOperation(long delayMs, long latencyMs, CountDownLatch latch) {
469444

470445
@Override
471446
public void onExpiration() {
472-
473447
}
474448

475449
@Override

0 commit comments

Comments
 (0)