Search in sources :

Example 1 with MiniTrogdorCluster

use of org.apache.kafka.trogdor.common.MiniTrogdorCluster in project apache-kafka-on-k8s by banzaicloud.

the class CoordinatorTest method testCreateTask.

@Test
public void testCreateTask() 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()) {
        new ExpectedTasks().waitFor(cluster.coordinatorClient());
        NoOpTaskSpec fooSpec = new NoOpTaskSpec(1, 2);
        cluster.coordinatorClient().createTask(new CreateTaskRequest("foo", fooSpec));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskPending(fooSpec)).build()).waitFor(cluster.coordinatorClient());
        time.sleep(2);
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskRunning(fooSpec, 2)).workerState(new WorkerRunning(fooSpec, 2, "")).build()).waitFor(cluster.coordinatorClient()).waitFor(cluster.agentClient("node02"));
        time.sleep(3);
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskDone(fooSpec, 2, 5, "", false)).build()).waitFor(cluster.coordinatorClient());
    }
}
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) 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) TaskRunning(org.apache.kafka.trogdor.rest.TaskRunning) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.Test)

Example 2 with MiniTrogdorCluster

use of org.apache.kafka.trogdor.common.MiniTrogdorCluster in project kafka by apache.

the class CoordinatorTest method testTasksRequest.

@Test
public void testTasksRequest() 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();
        new ExpectedTasks().waitFor(coordinatorClient);
        NoOpTaskSpec fooSpec = new NoOpTaskSpec(1, 10);
        NoOpTaskSpec barSpec = new NoOpTaskSpec(3, 1);
        coordinatorClient.createTask(new CreateTaskRequest("foo", fooSpec));
        coordinatorClient.createTask(new CreateTaskRequest("bar", barSpec));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskPending(fooSpec)).build()).addTask(new ExpectedTaskBuilder("bar").taskState(new TaskPending(barSpec)).build()).waitFor(coordinatorClient);
        assertEquals(0, coordinatorClient.tasks(new TasksRequest(null, 10, 0, 10, 0, Optional.empty())).tasks().size());
        TasksResponse resp1 = coordinatorClient.tasks(new TasksRequest(Arrays.asList("foo", "baz"), 0, 0, 0, 0, Optional.empty()));
        assertTrue(resp1.tasks().containsKey("foo"));
        assertFalse(resp1.tasks().containsKey("bar"));
        assertEquals(1, resp1.tasks().size());
        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()).addTask(new ExpectedTaskBuilder("bar").taskState(new TaskPending(barSpec)).build()).waitFor(coordinatorClient).waitFor(cluster.agentClient("node02"));
        TasksResponse resp2 = coordinatorClient.tasks(new TasksRequest(null, 1, 0, 0, 0, Optional.empty()));
        assertTrue(resp2.tasks().containsKey("foo"));
        assertFalse(resp2.tasks().containsKey("bar"));
        assertEquals(1, resp2.tasks().size());
        assertEquals(0, coordinatorClient.tasks(new TasksRequest(null, 3, 0, 0, 0, Optional.empty())).tasks().size());
    }
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) TasksResponse(org.apache.kafka.trogdor.rest.TasksResponse) 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) 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) TasksRequest(org.apache.kafka.trogdor.rest.TasksRequest) TaskRunning(org.apache.kafka.trogdor.rest.TaskRunning) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Example 3 with MiniTrogdorCluster

use of org.apache.kafka.trogdor.common.MiniTrogdorCluster in project kafka by apache.

the class CoordinatorTest method testTaskRequestWithOldStartMsGetsUpdated.

@Test
public void testTaskRequestWithOldStartMsGetsUpdated() 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()) {
        NoOpTaskSpec fooSpec = new NoOpTaskSpec(1, 500);
        time.sleep(552);
        CoordinatorClient coordinatorClient = cluster.coordinatorClient();
        NoOpTaskSpec updatedSpec = new NoOpTaskSpec(552, 500);
        coordinatorClient.createTask(new CreateTaskRequest("fooSpec", fooSpec));
        TaskState expectedState = new ExpectedTaskBuilder("fooSpec").taskState(new TaskRunning(updatedSpec, 552, new TextNode("receiving"))).build().taskState();
        TaskState resp = coordinatorClient.task(new TaskRequest("fooSpec"));
        assertEquals(expectedState, resp);
    }
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) 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) 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 4 with MiniTrogdorCluster

use of org.apache.kafka.trogdor.common.MiniTrogdorCluster in project kafka by apache.

the class CoordinatorTest method testTaskDestruction.

@Test
public void testTaskDestruction() 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(2, 12);
        coordinatorClient.destroyTask(new DestroyTaskRequest("foo"));
        coordinatorClient.createTask(new CreateTaskRequest("foo", fooSpec));
        NoOpTaskSpec barSpec = new NoOpTaskSpec(20, 20);
        coordinatorClient.createTask(new CreateTaskRequest("bar", barSpec));
        coordinatorClient.destroyTask(new DestroyTaskRequest("bar"));
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskPending(fooSpec)).build()).waitFor(coordinatorClient).waitFor(agentClient1).waitFor(agentClient2);
        time.sleep(10);
        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, 10, status1)).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) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MockScheduler(org.apache.kafka.common.utils.MockScheduler) Scheduler(org.apache.kafka.common.utils.Scheduler) 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 5 with MiniTrogdorCluster

use of org.apache.kafka.trogdor.common.MiniTrogdorCluster in project kafka by apache.

the class CoordinatorTest method testTaskRequestWithFutureStartMsDoesNotGetRun.

@Test
public void testTaskRequestWithFutureStartMsDoesNotGetRun() 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()) {
        NoOpTaskSpec fooSpec = new NoOpTaskSpec(1000, 500);
        time.sleep(999);
        CoordinatorClient coordinatorClient = cluster.coordinatorClient();
        coordinatorClient.createTask(new CreateTaskRequest("fooSpec", fooSpec));
        TaskState expectedState = new ExpectedTaskBuilder("fooSpec").taskState(new TaskPending(fooSpec)).build().taskState();
        TaskState resp = coordinatorClient.task(new TaskRequest("fooSpec"));
        assertEquals(expectedState, resp);
    }
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) TaskPending(org.apache.kafka.trogdor.rest.TaskPending) CreateTaskRequest(org.apache.kafka.trogdor.rest.CreateTaskRequest) MockScheduler(org.apache.kafka.common.utils.MockScheduler) Scheduler(org.apache.kafka.common.utils.Scheduler) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) MiniTrogdorCluster(org.apache.kafka.trogdor.common.MiniTrogdorCluster) 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) TaskState(org.apache.kafka.trogdor.rest.TaskState) MockTime(org.apache.kafka.common.utils.MockTime) NoOpTaskSpec(org.apache.kafka.trogdor.task.NoOpTaskSpec) Test(org.junit.jupiter.api.Test)

Aggregations

MiniTrogdorCluster (org.apache.kafka.trogdor.common.MiniTrogdorCluster)18 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)17 MockScheduler (org.apache.kafka.common.utils.MockScheduler)15 MockTime (org.apache.kafka.common.utils.MockTime)15 Scheduler (org.apache.kafka.common.utils.Scheduler)15 CreateTaskRequest (org.apache.kafka.trogdor.rest.CreateTaskRequest)15 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)13 Test (org.junit.jupiter.api.Test)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 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 Test (org.junit.Test)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4