use of org.apache.kafka.trogdor.rest.WorkerState in project kafka by apache.
the class ExpectedTasks method waitFor.
public ExpectedTasks waitFor(final AgentClient client) throws InterruptedException {
TestUtils.waitForCondition(() -> {
AgentStatusResponse status = null;
try {
status = client.status();
} catch (Exception e) {
log.info("Unable to get agent status", e);
throw new RuntimeException(e);
}
StringBuilder errors = new StringBuilder();
HashMap<String, WorkerState> taskIdToWorkerState = new HashMap<>();
for (WorkerState state : status.workers().values()) {
taskIdToWorkerState.put(state.taskId(), state);
}
for (Map.Entry<String, ExpectedTask> entry : expected.entrySet()) {
String id = entry.getKey();
ExpectedTask worker = entry.getValue();
String differences = worker.compare(taskIdToWorkerState.get(id));
if (differences != null) {
errors.append(differences);
}
}
String errorString = errors.toString();
if (!errorString.isEmpty()) {
log.info("EXPECTED WORKERS: {}", JsonUtil.toJsonString(expected));
log.info("ACTUAL WORKERS : {}", JsonUtil.toJsonString(status.workers()));
log.info(errorString);
return false;
}
return true;
}, "Timed out waiting for expected workers " + JsonUtil.toJsonString(expected));
return this;
}
Aggregations