Search in sources :

Example 16 with CreateTaskRequest

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

the class CoordinatorTest method testTaskDistribution.

@Test
public void testTaskDistribution() throws Exception {
    MockTime time = new MockTime(0, 0, 0);
    Scheduler scheduler = new MockScheduler(time);
    try (MiniTrogdorCluster cluster = new MiniTrogdorCluster.Builder().addCoordinator("node01").addAgent("node01").addAgent("node02").scheduler(scheduler).build()) {
        CoordinatorClient coordinatorClient = cluster.coordinatorClient();
        AgentClient agentClient1 = cluster.agentClient("node01");
        AgentClient agentClient2 = cluster.agentClient("node02");
        new ExpectedTasks().waitFor(coordinatorClient).waitFor(agentClient1).waitFor(agentClient2);
        NoOpTaskSpec fooSpec = new NoOpTaskSpec(5, 7);
        coordinatorClient.createTask(new CreateTaskRequest("foo", fooSpec));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskPending(fooSpec)).build()).waitFor(coordinatorClient).waitFor(agentClient1).waitFor(agentClient2);
        time.sleep(11);
        ObjectNode status1 = new ObjectNode(JsonNodeFactory.instance);
        status1.set("node01", new TextNode("active"));
        status1.set("node02", new TextNode("active"));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskRunning(fooSpec, 11, status1)).workerState(new WorkerRunning("foo", fooSpec, 11, new TextNode("active"))).build()).waitFor(coordinatorClient).waitFor(agentClient1).waitFor(agentClient2);
        time.sleep(7);
        ObjectNode status2 = new ObjectNode(JsonNodeFactory.instance);
        status2.set("node01", new TextNode("done"));
        status2.set("node02", new TextNode("done"));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskDone(fooSpec, 11, 18, "", false, status2)).workerState(new WorkerDone("foo", fooSpec, 11, 18, new TextNode("done"), "")).build()).waitFor(coordinatorClient).waitFor(agentClient1).waitFor(agentClient2);
    }
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) MockScheduler(org.apache.kafka.common.utils.MockScheduler) Scheduler(org.apache.kafka.common.utils.Scheduler) TaskDone(org.apache.kafka.trogdor.rest.TaskDone) TextNode(com.fasterxml.jackson.databind.node.TextNode) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) NoOpTaskSpec(org.apache.kafka.trogdor.task.NoOpTaskSpec) TaskPending(org.apache.kafka.trogdor.rest.TaskPending) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) CreateTaskRequest(org.apache.kafka.trogdor.rest.CreateTaskRequest) MiniTrogdorCluster(org.apache.kafka.trogdor.common.MiniTrogdorCluster) AgentClient(org.apache.kafka.trogdor.agent.AgentClient) TaskRunning(org.apache.kafka.trogdor.rest.TaskRunning) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Aggregations

CreateTaskRequest (org.apache.kafka.trogdor.rest.CreateTaskRequest)16 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)15 MiniTrogdorCluster (org.apache.kafka.trogdor.common.MiniTrogdorCluster)15 MockScheduler (org.apache.kafka.common.utils.MockScheduler)14 MockTime (org.apache.kafka.common.utils.MockTime)14 Scheduler (org.apache.kafka.common.utils.Scheduler)14 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)13 TaskPending (org.apache.kafka.trogdor.rest.TaskPending)12 TaskRunning (org.apache.kafka.trogdor.rest.TaskRunning)12 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)12 Test (org.junit.jupiter.api.Test)11 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)10 TextNode (com.fasterxml.jackson.databind.node.TextNode)9 TaskDone (org.apache.kafka.trogdor.rest.TaskDone)9 DestroyTaskRequest (org.apache.kafka.trogdor.rest.DestroyTaskRequest)7 StopTaskRequest (org.apache.kafka.trogdor.rest.StopTaskRequest)7 WorkerDone (org.apache.kafka.trogdor.rest.WorkerDone)6 AgentClient (org.apache.kafka.trogdor.agent.AgentClient)5 TaskRequest (org.apache.kafka.trogdor.rest.TaskRequest)5 TaskState (org.apache.kafka.trogdor.rest.TaskState)5