Search in sources :

Example 1 with WorkerState

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;
}
Also used : AgentStatusResponse(org.apache.kafka.trogdor.rest.AgentStatusResponse) HashMap(java.util.HashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) WorkerState(org.apache.kafka.trogdor.rest.WorkerState)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 AgentStatusResponse (org.apache.kafka.trogdor.rest.AgentStatusResponse)1 WorkerState (org.apache.kafka.trogdor.rest.WorkerState)1