chia7712 commented on code in PR #15946:
URL: https://github.com/apache/kafka/pull/15946#discussion_r1602875475
##########
core/src/test/java/kafka/test/junit/RaftClusterInvocationContext.java:
##########
@@ -284,24 +259,59 @@ public void startBroker(int brokerId) {
@Override
public void waitForReadyBrokers() throws InterruptedException {
try {
- clusterReference.get().waitForReadyBrokers();
+ clusterTestKit.waitForReadyBrokers();
} catch (ExecutionException e) {
throw new AssertionError("Failed while waiting for brokers to
become ready", e);
}
}
- private BrokerServer findBrokerOrThrow(int brokerId) {
- return
Optional.ofNullable(clusterReference.get().brokers().get(brokerId))
- .orElseThrow(() -> new IllegalArgumentException("Unknown
brokerId " + brokerId));
- }
-
public Stream<BrokerServer> brokers() {
- return clusterReference.get().brokers().values().stream();
+ return clusterTestKit.brokers().values().stream();
}
public Stream<ControllerServer> controllers() {
- return clusterReference.get().controllers().values().stream();
+ return clusterTestKit.controllers().values().stream();
+ }
+
+ public void format() throws Exception {
+ safeBuildCluster();
+ this.clusterTestKit.format();
}
+ private BrokerServer findBrokerOrThrow(int brokerId) {
+ return Optional.ofNullable(clusterTestKit.brokers().get(brokerId))
+ .orElseThrow(() -> new IllegalArgumentException("Unknown
brokerId " + brokerId));
+ }
+
+ private void safeBuildCluster() throws Exception {
+ if (this.clusterTestKit != null) {
+ return;
+ }
+ synchronized (this) {
Review Comment:
I don't think we need to sync, as it won't be called concurrent.
##########
core/src/test/java/kafka/test/junit/RaftClusterInvocationContext.java:
##########
@@ -284,24 +259,59 @@ public void startBroker(int brokerId) {
@Override
public void waitForReadyBrokers() throws InterruptedException {
try {
- clusterReference.get().waitForReadyBrokers();
+ clusterTestKit.waitForReadyBrokers();
} catch (ExecutionException e) {
throw new AssertionError("Failed while waiting for brokers to
become ready", e);
}
}
- private BrokerServer findBrokerOrThrow(int brokerId) {
- return
Optional.ofNullable(clusterReference.get().brokers().get(brokerId))
- .orElseThrow(() -> new IllegalArgumentException("Unknown
brokerId " + brokerId));
- }
-
public Stream<BrokerServer> brokers() {
- return clusterReference.get().brokers().values().stream();
+ return clusterTestKit.brokers().values().stream();
}
public Stream<ControllerServer> controllers() {
- return clusterReference.get().controllers().values().stream();
+ return clusterTestKit.controllers().values().stream();
+ }
+
+ public void format() throws Exception {
Review Comment:
This method is not idempotent, so user can re-format it if they call
`format` and then `start`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]