use of org.apache.kafka.trogdor.rest.WorkerDone in project kafka by apache.
the class AgentTest method testKiboshFaults.
@Test
public void testKiboshFaults() throws Exception {
MockTime time = new MockTime(0, 0, 0);
MockScheduler scheduler = new MockScheduler(time);
Agent agent = createAgent(scheduler);
AgentClient client = new AgentClient.Builder().maxTries(10).target("localhost", agent.port()).build();
new ExpectedTasks().waitFor(client);
try (MockKibosh mockKibosh = new MockKibosh()) {
assertEquals(KiboshControlFile.EMPTY, mockKibosh.read());
FilesUnreadableFaultSpec fooSpec = new FilesUnreadableFaultSpec(0, 900000, Collections.singleton("myAgent"), mockKibosh.tempDir.getPath(), "/foo", 123);
client.createWorker(new CreateWorkerRequest(0, "foo", fooSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning("foo", fooSpec, 0, new TextNode("Added fault foo"))).build()).waitFor(client);
assertEquals(new KiboshControlFile(Collections.singletonList(new KiboshFilesUnreadableFaultSpec("/foo", 123))), mockKibosh.read());
FilesUnreadableFaultSpec barSpec = new FilesUnreadableFaultSpec(0, 900000, Collections.singleton("myAgent"), mockKibosh.tempDir.getPath(), "/bar", 456);
client.createWorker(new CreateWorkerRequest(1, "bar", barSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning("foo", fooSpec, 0, new TextNode("Added fault foo"))).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning("bar", barSpec, 0, new TextNode("Added fault bar"))).build()).waitFor(client);
assertEquals(new KiboshControlFile(asList(new KiboshFilesUnreadableFaultSpec("/foo", 123), new KiboshFilesUnreadableFaultSpec("/bar", 456))), mockKibosh.read());
time.sleep(1);
client.stopWorker(new StopWorkerRequest(0));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone("foo", fooSpec, 0, 1, new TextNode("Removed fault foo"), "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning("bar", barSpec, 0, new TextNode("Added fault bar"))).build()).waitFor(client);
assertEquals(new KiboshControlFile(Collections.singletonList(new KiboshFilesUnreadableFaultSpec("/bar", 456))), mockKibosh.read());
}
}
use of org.apache.kafka.trogdor.rest.WorkerDone in project kafka by apache.
the class AgentTest method testAgentFinishesTasks.
@Test
public void testAgentFinishesTasks() throws Exception {
long startTimeMs = 2000;
MockTime time = new MockTime(0, startTimeMs, 0);
MockScheduler scheduler = new MockScheduler(time);
Agent agent = createAgent(scheduler);
AgentClient client = new AgentClient.Builder().maxTries(10).target("localhost", agent.port()).build();
new ExpectedTasks().waitFor(client);
final NoOpTaskSpec fooSpec = new NoOpTaskSpec(startTimeMs, 2);
long fooSpecStartTimeMs = startTimeMs;
client.createWorker(new CreateWorkerRequest(0, "foo", fooSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning("foo", fooSpec, startTimeMs, new TextNode("active"))).build()).waitFor(client);
time.sleep(1);
long barSpecWorkerId = 1;
long barSpecStartTimeMs = startTimeMs + 1;
final NoOpTaskSpec barSpec = new NoOpTaskSpec(startTimeMs, 900000);
client.createWorker(new CreateWorkerRequest(barSpecWorkerId, "bar", barSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning("foo", fooSpec, fooSpecStartTimeMs, new TextNode("active"))).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning("bar", barSpec, barSpecStartTimeMs, new TextNode("active"))).build()).waitFor(client);
time.sleep(1);
// foo task expired
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone("foo", fooSpec, fooSpecStartTimeMs, fooSpecStartTimeMs + 2, new TextNode("done"), "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning("bar", barSpec, barSpecStartTimeMs, new TextNode("active"))).build()).waitFor(client);
time.sleep(5);
client.stopWorker(new StopWorkerRequest(barSpecWorkerId));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone("foo", fooSpec, fooSpecStartTimeMs, fooSpecStartTimeMs + 2, new TextNode("done"), "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerDone("bar", barSpec, barSpecStartTimeMs, startTimeMs + 7, new TextNode("done"), "")).build()).waitFor(client);
agent.beginShutdown();
agent.waitForShutdown();
}
use of org.apache.kafka.trogdor.rest.WorkerDone 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);
}
}
use of org.apache.kafka.trogdor.rest.WorkerDone 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);
}
}
use of org.apache.kafka.trogdor.rest.WorkerDone in project apache-kafka-on-k8s by banzaicloud.
the class AgentTest method testWorkerCompletions.
@Test
public void testWorkerCompletions() throws Exception {
MockTime time = new MockTime(0, 0, 0);
MockScheduler scheduler = new MockScheduler(time);
Agent agent = createAgent(scheduler);
AgentClient client = new AgentClient.Builder().maxTries(10).target("localhost", agent.port()).build();
new ExpectedTasks().waitFor(client);
SampleTaskSpec fooSpec = new SampleTaskSpec(0, 900000, 1, "");
client.createWorker(new CreateWorkerRequest("foo", fooSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning(fooSpec, 0, "")).build()).waitFor(client);
SampleTaskSpec barSpec = new SampleTaskSpec(0, 900000, 2, "baz");
client.createWorker(new CreateWorkerRequest("bar", barSpec));
time.sleep(1);
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone(fooSpec, 0, 1, "", "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning(barSpec, 0, "")).build()).waitFor(client);
time.sleep(1);
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone(fooSpec, 0, 1, "", "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerDone(barSpec, 0, 2, "", "baz")).build()).waitFor(client);
}
Aggregations