Search in sources :

Example 6 with AgentStatusResponse

use of org.apache.kafka.trogdor.rest.AgentStatusResponse in project apache-kafka-on-k8s by banzaicloud.

the class JsonSerializationTest method testDeserializationDoesNotProduceNulls.

@Test
public void testDeserializationDoesNotProduceNulls() throws Exception {
    verify(new FilesUnreadableFaultSpec(0, 0, null, null, null, 0));
    verify(new Kibosh.KiboshControlFile(null));
    verify(new NetworkPartitionFaultSpec(0, 0, null));
    verify(new ProcessStopFaultSpec(0, 0, null, null));
    verify(new AgentStatusResponse(0, null));
    verify(new TasksResponse(null));
    verify(new WorkerDone(null, 0, 0, null, null));
    verify(new WorkerRunning(null, 0, null));
    verify(new WorkerStopping(null, 0, null));
    verify(new ProduceBenchSpec(0, 0, null, null, 0, 0, null, null, null, 0, 0, "test-topic", 1, (short) 3));
    verify(new RoundTripWorkloadSpec(0, 0, null, null, 0, null, null, 0));
    verify(new SampleTaskSpec(0, 0, 0, null));
}
Also used : WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) WorkerStopping(org.apache.kafka.trogdor.rest.WorkerStopping) TasksResponse(org.apache.kafka.trogdor.rest.TasksResponse) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) NetworkPartitionFaultSpec(org.apache.kafka.trogdor.fault.NetworkPartitionFaultSpec) SampleTaskSpec(org.apache.kafka.trogdor.task.SampleTaskSpec) RoundTripWorkloadSpec(org.apache.kafka.trogdor.workload.RoundTripWorkloadSpec) Kibosh(org.apache.kafka.trogdor.fault.Kibosh) AgentStatusResponse(org.apache.kafka.trogdor.rest.AgentStatusResponse) ProcessStopFaultSpec(org.apache.kafka.trogdor.fault.ProcessStopFaultSpec) ProduceBenchSpec(org.apache.kafka.trogdor.workload.ProduceBenchSpec) FilesUnreadableFaultSpec(org.apache.kafka.trogdor.fault.FilesUnreadableFaultSpec) Test(org.junit.Test)

Example 7 with AgentStatusResponse

use of org.apache.kafka.trogdor.rest.AgentStatusResponse in project kafka by apache.

the class AgentTest method testCreateExpiredWorkerIsNotScheduled.

@Test
public void testCreateExpiredWorkerIsNotScheduled() throws Exception {
    long initialTimeMs = 100;
    long tickMs = 15;
    final boolean[] toSleep = { true };
    MockTime time = new MockTime(tickMs, initialTimeMs, 0) {

        /**
         * Modify sleep() to call super.sleep() every second call
         * in order to avoid the endless loop in the tick() calls to the MockScheduler listener
         */
        @Override
        public void sleep(long ms) {
            toSleep[0] = !toSleep[0];
            if (toSleep[0])
                super.sleep(ms);
        }
    };
    MockScheduler scheduler = new MockScheduler(time);
    Agent agent = createAgent(scheduler);
    AgentClient client = new AgentClient.Builder().maxTries(10).target("localhost", agent.port()).build();
    AgentStatusResponse status = client.status();
    assertEquals(Collections.emptyMap(), status.workers());
    new ExpectedTasks().waitFor(client);
    final NoOpTaskSpec fooSpec = new NoOpTaskSpec(10, 10);
    client.createWorker(new CreateWorkerRequest(0, "foo", fooSpec));
    long actualStartTimeMs = initialTimeMs + tickMs;
    long doneMs = actualStartTimeMs + 2 * tickMs;
    new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone("foo", fooSpec, actualStartTimeMs, doneMs, null, "worker expired")).taskState(new TaskDone(fooSpec, actualStartTimeMs, doneMs, "worker expired", false, null)).build()).waitFor(client);
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) TaskDone(org.apache.kafka.trogdor.rest.TaskDone) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) NoOpTaskSpec(org.apache.kafka.trogdor.task.NoOpTaskSpec) AgentStatusResponse(org.apache.kafka.trogdor.rest.AgentStatusResponse) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) CreateWorkerRequest(org.apache.kafka.trogdor.rest.CreateWorkerRequest) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Example 8 with AgentStatusResponse

use of org.apache.kafka.trogdor.rest.AgentStatusResponse in project kafka by apache.

the class JsonSerializationTest method testDeserializationDoesNotProduceNulls.

@Test
public void testDeserializationDoesNotProduceNulls() throws Exception {
    verify(new FilesUnreadableFaultSpec(0, 0, null, null, null, 0));
    verify(new Kibosh.KiboshControlFile(null));
    verify(new NetworkPartitionFaultSpec(0, 0, null));
    verify(new ProcessStopFaultSpec(0, 0, null, null));
    verify(new AgentStatusResponse(0, null));
    verify(new TasksResponse(null));
    verify(new WorkerDone(null, null, 0, 0, null, null));
    verify(new WorkerRunning(null, null, 0, null));
    verify(new WorkerStopping(null, null, 0, null));
    verify(new ProduceBenchSpec(0, 0, null, null, 0, 0, null, null, Optional.empty(), null, null, null, null, null, false, false));
    verify(new RoundTripWorkloadSpec(0, 0, null, null, null, null, null, null, 0, null, null, 0));
    verify(new TopicsSpec());
    verify(new PartitionsSpec(0, (short) 0, null, null));
    Map<Integer, List<Integer>> partitionAssignments = new HashMap<Integer, List<Integer>>();
    partitionAssignments.put(0, Arrays.asList(1, 2, 3));
    partitionAssignments.put(1, Arrays.asList(1, 2, 3));
    verify(new PartitionsSpec(0, (short) 0, partitionAssignments, null));
    verify(new PartitionsSpec(0, (short) 0, null, null));
}
Also used : WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) WorkerStopping(org.apache.kafka.trogdor.rest.WorkerStopping) TasksResponse(org.apache.kafka.trogdor.rest.TasksResponse) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) HashMap(java.util.HashMap) NetworkPartitionFaultSpec(org.apache.kafka.trogdor.fault.NetworkPartitionFaultSpec) RoundTripWorkloadSpec(org.apache.kafka.trogdor.workload.RoundTripWorkloadSpec) Kibosh(org.apache.kafka.trogdor.fault.Kibosh) AgentStatusResponse(org.apache.kafka.trogdor.rest.AgentStatusResponse) ProcessStopFaultSpec(org.apache.kafka.trogdor.fault.ProcessStopFaultSpec) ProduceBenchSpec(org.apache.kafka.trogdor.workload.ProduceBenchSpec) PartitionsSpec(org.apache.kafka.trogdor.workload.PartitionsSpec) FilesUnreadableFaultSpec(org.apache.kafka.trogdor.fault.FilesUnreadableFaultSpec) List(java.util.List) TopicsSpec(org.apache.kafka.trogdor.workload.TopicsSpec) Test(org.junit.jupiter.api.Test)

Example 9 with AgentStatusResponse

use of org.apache.kafka.trogdor.rest.AgentStatusResponse 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

AgentStatusResponse (org.apache.kafka.trogdor.rest.AgentStatusResponse)9 CreateWorkerRequest (org.apache.kafka.trogdor.rest.CreateWorkerRequest)4 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)4 Test (org.junit.jupiter.api.Test)4 MockScheduler (org.apache.kafka.common.utils.MockScheduler)3 MockTime (org.apache.kafka.common.utils.MockTime)3 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)3 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)3 WorkerDone (org.apache.kafka.trogdor.rest.WorkerDone)3 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 List (java.util.List)2 FilesUnreadableFaultSpec (org.apache.kafka.trogdor.fault.FilesUnreadableFaultSpec)2 Kibosh (org.apache.kafka.trogdor.fault.Kibosh)2 NetworkPartitionFaultSpec (org.apache.kafka.trogdor.fault.NetworkPartitionFaultSpec)2 ProcessStopFaultSpec (org.apache.kafka.trogdor.fault.ProcessStopFaultSpec)2 TasksResponse (org.apache.kafka.trogdor.rest.TasksResponse)2 WorkerStopping (org.apache.kafka.trogdor.rest.WorkerStopping)2 ProduceBenchSpec (org.apache.kafka.trogdor.workload.ProduceBenchSpec)2