Search in sources :

Example 6 with Scheduler

use of org.apache.kafka.common.utils.Scheduler in project kafka by apache.

the class CoordinatorTest method testWorkersExitingAtDifferentTimes.

@Test
public void testWorkersExitingAtDifferentTimes() throws Exception {
    MockTime time = new MockTime(0, 0, 0);
    Scheduler scheduler = new MockScheduler(time);
    try (MiniTrogdorCluster cluster = new MiniTrogdorCluster.Builder().addCoordinator("node01").addAgent("node02").addAgent("node03").scheduler(scheduler).build()) {
        CoordinatorClient coordinatorClient = cluster.coordinatorClient();
        new ExpectedTasks().waitFor(coordinatorClient);
        HashMap<String, Long> nodeToExitMs = new HashMap<>();
        nodeToExitMs.put("node02", 10L);
        nodeToExitMs.put("node03", 20L);
        SampleTaskSpec fooSpec = new SampleTaskSpec(2, 100, nodeToExitMs, "");
        coordinatorClient.createTask(new CreateTaskRequest("foo", fooSpec));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskPending(fooSpec)).build()).waitFor(coordinatorClient);
        time.sleep(2);
        ObjectNode status1 = new ObjectNode(JsonNodeFactory.instance);
        status1.set("node02", new TextNode("active"));
        status1.set("node03", new TextNode("active"));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskRunning(fooSpec, 2, status1)).workerState(new WorkerRunning("foo", fooSpec, 2, new TextNode("active"))).build()).waitFor(coordinatorClient).waitFor(cluster.agentClient("node02")).waitFor(cluster.agentClient("node03"));
        time.sleep(10);
        ObjectNode status2 = new ObjectNode(JsonNodeFactory.instance);
        status2.set("node02", new TextNode("halted"));
        status2.set("node03", new TextNode("active"));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskRunning(fooSpec, 2, status2)).workerState(new WorkerRunning("foo", fooSpec, 2, new TextNode("active"))).build()).waitFor(coordinatorClient).waitFor(cluster.agentClient("node03"));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskRunning(fooSpec, 2, status2)).workerState(new WorkerDone("foo", fooSpec, 2, 12, new TextNode("halted"), "")).build()).waitFor(cluster.agentClient("node02"));
        time.sleep(10);
        ObjectNode status3 = new ObjectNode(JsonNodeFactory.instance);
        status3.set("node02", new TextNode("halted"));
        status3.set("node03", new TextNode("halted"));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskDone(fooSpec, 2, 22, "", false, status3)).build()).waitFor(coordinatorClient);
    }
}
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) HashMap(java.util.HashMap) MockScheduler(org.apache.kafka.common.utils.MockScheduler) Scheduler(org.apache.kafka.common.utils.Scheduler) TaskDone(org.apache.kafka.trogdor.rest.TaskDone) SampleTaskSpec(org.apache.kafka.trogdor.task.SampleTaskSpec) TextNode(com.fasterxml.jackson.databind.node.TextNode) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) 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) TaskRunning(org.apache.kafka.trogdor.rest.TaskRunning) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Example 7 with Scheduler

use of org.apache.kafka.common.utils.Scheduler in project kafka by apache.

the class CoordinatorTest method testTaskRequest.

@Test
public void testTaskRequest() throws Exception {
    MockTime time = new MockTime(0, 0, 0);
    Scheduler scheduler = new MockScheduler(time);
    try (MiniTrogdorCluster cluster = new MiniTrogdorCluster.Builder().addCoordinator("node01").addAgent("node02").scheduler(scheduler).build()) {
        CoordinatorClient coordinatorClient = cluster.coordinatorClient();
        NoOpTaskSpec fooSpec = new NoOpTaskSpec(1, 10);
        coordinatorClient.createTask(new CreateTaskRequest("foo", fooSpec));
        TaskState expectedState = new ExpectedTaskBuilder("foo").taskState(new TaskPending(fooSpec)).build().taskState();
        TaskState resp = coordinatorClient.task(new TaskRequest("foo"));
        assertEquals(expectedState, resp);
        time.sleep(2);
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskRunning(fooSpec, 2, new TextNode("active"))).workerState(new WorkerRunning("foo", fooSpec, 2, new TextNode("active"))).build()).waitFor(coordinatorClient).waitFor(cluster.agentClient("node02"));
        assertThrows(NotFoundException.class, () -> coordinatorClient.task(new TaskRequest("non-existent-foo")));
    }
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) MockScheduler(org.apache.kafka.common.utils.MockScheduler) Scheduler(org.apache.kafka.common.utils.Scheduler) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) TextNode(com.fasterxml.jackson.databind.node.TextNode) DestroyTaskRequest(org.apache.kafka.trogdor.rest.DestroyTaskRequest) StopTaskRequest(org.apache.kafka.trogdor.rest.StopTaskRequest) CreateTaskRequest(org.apache.kafka.trogdor.rest.CreateTaskRequest) TaskRequest(org.apache.kafka.trogdor.rest.TaskRequest) 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) TaskRunning(org.apache.kafka.trogdor.rest.TaskRunning) TaskState(org.apache.kafka.trogdor.rest.TaskState) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Example 8 with Scheduler

use of org.apache.kafka.common.utils.Scheduler in project kafka by apache.

the class CoordinatorTest method testNetworkPartitionFault.

@Test
public void testNetworkPartitionFault() throws Exception {
    CapturingCommandRunner runner = new CapturingCommandRunner();
    MockTime time = new MockTime(0, 0, 0);
    Scheduler scheduler = new MockScheduler(time);
    try (MiniTrogdorCluster cluster = new MiniTrogdorCluster.Builder().addCoordinator("node01").addAgent("node01").addAgent("node02").addAgent("node03").commandRunner(runner).scheduler(scheduler).build()) {
        CoordinatorClient coordinatorClient = cluster.coordinatorClient();
        NetworkPartitionFaultSpec spec = new NetworkPartitionFaultSpec(0, Long.MAX_VALUE, createPartitionLists(new String[][] { new String[] { "node01", "node02" }, new String[] { "node03" } }));
        coordinatorClient.createTask(new CreateTaskRequest("netpart", spec));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("netpart").taskSpec(spec).build()).waitFor(coordinatorClient);
        checkLines("-A", runner);
    }
    checkLines("-D", runner);
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) CreateTaskRequest(org.apache.kafka.trogdor.rest.CreateTaskRequest) MockScheduler(org.apache.kafka.common.utils.MockScheduler) Scheduler(org.apache.kafka.common.utils.Scheduler) MiniTrogdorCluster(org.apache.kafka.trogdor.common.MiniTrogdorCluster) NetworkPartitionFaultSpec(org.apache.kafka.trogdor.fault.NetworkPartitionFaultSpec) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) CapturingCommandRunner(org.apache.kafka.trogdor.common.CapturingCommandRunner) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Example 9 with Scheduler

use of org.apache.kafka.common.utils.Scheduler in project kafka by apache.

the class CoordinatorTest method testTaskCancellation.

@Test
public void testTaskCancellation() 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);
        ObjectNode status2 = new ObjectNode(JsonNodeFactory.instance);
        status2.set("node01", new TextNode("done"));
        status2.set("node02", new TextNode("done"));
        time.sleep(7);
        coordinatorClient.stopTask(new StopTaskRequest("foo"));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskDone(fooSpec, 11, 18, "", true, status2)).workerState(new WorkerDone("foo", fooSpec, 11, 18, new TextNode("done"), "")).build()).waitFor(coordinatorClient).waitFor(agentClient1).waitFor(agentClient2);
        coordinatorClient.destroyTask(new DestroyTaskRequest("foo"));
        new ExpectedTasks().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) StopTaskRequest(org.apache.kafka.trogdor.rest.StopTaskRequest) 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) DestroyTaskRequest(org.apache.kafka.trogdor.rest.DestroyTaskRequest) 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)

Example 10 with Scheduler

use of org.apache.kafka.common.utils.Scheduler in project apache-kafka-on-k8s by banzaicloud.

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, 2);
        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);
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskRunning(fooSpec, 11)).workerState(new WorkerRunning(fooSpec, 11, "")).build()).waitFor(coordinatorClient).waitFor(agentClient1).waitFor(agentClient2);
        time.sleep(2);
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskDone(fooSpec, 11, 13, "", false)).workerState(new WorkerDone(fooSpec, 11, 13, "", "")).build()).waitFor(coordinatorClient).waitFor(agentClient1).waitFor(agentClient2);
    }
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) 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) 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.Test)

Aggregations

MockScheduler (org.apache.kafka.common.utils.MockScheduler)15 MockTime (org.apache.kafka.common.utils.MockTime)15 Scheduler (org.apache.kafka.common.utils.Scheduler)15 MiniTrogdorCluster (org.apache.kafka.trogdor.common.MiniTrogdorCluster)15 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)14 CreateTaskRequest (org.apache.kafka.trogdor.rest.CreateTaskRequest)14 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)12 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)12 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)10 TextNode (com.fasterxml.jackson.databind.node.TextNode)9 TaskDone (org.apache.kafka.trogdor.rest.TaskDone)8 DestroyTaskRequest (org.apache.kafka.trogdor.rest.DestroyTaskRequest)6 StopTaskRequest (org.apache.kafka.trogdor.rest.StopTaskRequest)6 WorkerDone (org.apache.kafka.trogdor.rest.WorkerDone)6 AgentClient (org.apache.kafka.trogdor.agent.AgentClient)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 TaskRequest (org.apache.kafka.trogdor.rest.TaskRequest)4