use of org.apache.kafka.trogdor.common.MiniTrogdorCluster in project apache-kafka-on-k8s by banzaicloud.
the class CoordinatorTest method testNetworkPartitionFault.
@Test
public void testNetworkPartitionFault() throws Exception {
CapturingCommandRunner runner = new CapturingCommandRunner();
try (MiniTrogdorCluster cluster = new MiniTrogdorCluster.Builder().addCoordinator("node01").addAgent("node01").addAgent("node02").addAgent("node03").commandRunner(runner).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);
}
use of org.apache.kafka.trogdor.common.MiniTrogdorCluster 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);
}
}
use of org.apache.kafka.trogdor.common.MiniTrogdorCluster in project apache-kafka-on-k8s by banzaicloud.
the class CoordinatorTest method testCoordinatorStatus.
@Test
public void testCoordinatorStatus() throws Exception {
try (MiniTrogdorCluster cluster = new MiniTrogdorCluster.Builder().addCoordinator("node01").build()) {
CoordinatorStatusResponse status = cluster.coordinatorClient().status();
assertEquals(cluster.coordinator().status(), status);
}
}
use of org.apache.kafka.trogdor.common.MiniTrogdorCluster in project apache-kafka-on-k8s by banzaicloud.
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, 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(1);
coordinatorClient.stopTask(new StopTaskRequest("foo"));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskDone(fooSpec, 11, 12, "", true)).workerState(new WorkerDone(fooSpec, 11, 12, "", "")).build()).waitFor(coordinatorClient).waitFor(agentClient1).waitFor(agentClient2);
}
}
use of org.apache.kafka.trogdor.common.MiniTrogdorCluster in project kafka by apache.
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());
// Re-creating a task with the same arguments is not an error.
cluster.coordinatorClient().createTask(new CreateTaskRequest("foo", fooSpec));
// Re-creating a task with different arguments gives a RequestConflictException.
NoOpTaskSpec barSpec = new NoOpTaskSpec(1000, 2000);
assertThrows(RequestConflictException.class, () -> cluster.coordinatorClient().createTask(new CreateTaskRequest("foo", barSpec)), "Recreating task with different task spec is not allowed");
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(cluster.coordinatorClient()).waitFor(cluster.agentClient("node02"));
time.sleep(3);
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskDone(fooSpec, 2, 5, "", false, new TextNode("done"))).build()).waitFor(cluster.coordinatorClient());
}
}
Aggregations