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());
}
}
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());
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations