use of org.apache.kafka.trogdor.rest.CreateWorkerRequest in project apache-kafka-on-k8s by banzaicloud.
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()) {
Assert.assertEquals(KiboshControlFile.EMPTY, mockKibosh.read());
FilesUnreadableFaultSpec fooSpec = new FilesUnreadableFaultSpec(0, 900000, Collections.singleton("myAgent"), mockKibosh.tempDir.getPath().toString(), "/foo", 123);
client.createWorker(new CreateWorkerRequest("foo", fooSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning(fooSpec, 0, "")).build()).waitFor(client);
Assert.assertEquals(new KiboshControlFile(Collections.<Kibosh.KiboshFaultSpec>singletonList(new KiboshFilesUnreadableFaultSpec("/foo", 123))), mockKibosh.read());
FilesUnreadableFaultSpec barSpec = new FilesUnreadableFaultSpec(0, 900000, Collections.singleton("myAgent"), mockKibosh.tempDir.getPath().toString(), "/bar", 456);
client.createWorker(new CreateWorkerRequest("bar", barSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning(fooSpec, 0, "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning(barSpec, 0, "")).build()).waitFor(client);
Assert.assertEquals(new KiboshControlFile(new ArrayList<Kibosh.KiboshFaultSpec>() {
{
add(new KiboshFilesUnreadableFaultSpec("/foo", 123));
add(new KiboshFilesUnreadableFaultSpec("/bar", 456));
}
}), mockKibosh.read());
time.sleep(1);
client.stopWorker(new StopWorkerRequest("foo"));
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);
Assert.assertEquals(new KiboshControlFile(Collections.<Kibosh.KiboshFaultSpec>singletonList(new KiboshFilesUnreadableFaultSpec("/bar", 456))), mockKibosh.read());
}
}
use of org.apache.kafka.trogdor.rest.CreateWorkerRequest in project apache-kafka-on-k8s by banzaicloud.
the class AgentTest method testAgentFinishesTasks.
@Test
public void testAgentFinishesTasks() 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);
final NoOpTaskSpec fooSpec = new NoOpTaskSpec(10, 2);
client.createWorker(new CreateWorkerRequest("foo", fooSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning(fooSpec, 0, "")).build()).waitFor(client);
time.sleep(1);
final NoOpTaskSpec barSpec = new NoOpTaskSpec(2000, 900000);
client.createWorker(new CreateWorkerRequest("bar", barSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning(fooSpec, 0, "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning(barSpec, 1, "")).build()).waitFor(client);
time.sleep(1);
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone(fooSpec, 0, 2, "", "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning(barSpec, 1, "")).build()).waitFor(client);
time.sleep(5);
client.stopWorker(new StopWorkerRequest("bar"));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone(fooSpec, 0, 2, "", "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerDone(barSpec, 1, 7, "", "")).build()).waitFor(client);
agent.beginShutdown();
agent.waitForShutdown();
}
use of org.apache.kafka.trogdor.rest.CreateWorkerRequest in project apache-kafka-on-k8s by banzaicloud.
the class AgentTest method testAgentCreateWorkers.
@Test
public void testAgentCreateWorkers() 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();
AgentStatusResponse status = client.status();
assertEquals(Collections.emptyMap(), status.workers());
new ExpectedTasks().waitFor(client);
final NoOpTaskSpec fooSpec = new NoOpTaskSpec(1000, 600000);
CreateWorkerResponse response = client.createWorker(new CreateWorkerRequest("foo", fooSpec));
assertEquals(fooSpec.toString(), response.spec().toString());
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning(fooSpec, 0, "")).build()).waitFor(client);
final NoOpTaskSpec barSpec = new NoOpTaskSpec(2000, 900000);
client.createWorker(new CreateWorkerRequest("bar", barSpec));
client.createWorker(new CreateWorkerRequest("bar", barSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning(fooSpec, 0, "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning(barSpec, 0, "")).build()).waitFor(client);
final NoOpTaskSpec bazSpec = new NoOpTaskSpec(1, 450000);
client.createWorker(new CreateWorkerRequest("baz", bazSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning(fooSpec, 0, "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning(barSpec, 0, "")).build()).addTask(new ExpectedTaskBuilder("baz").workerState(new WorkerRunning(bazSpec, 0, "")).build()).waitFor(client);
agent.beginShutdown();
agent.waitForShutdown();
}
use of org.apache.kafka.trogdor.rest.CreateWorkerRequest in project kafka by apache.
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, Collections.singletonMap("node01", 1L), "");
client.createWorker(new CreateWorkerRequest(0, "foo", fooSpec));
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning("foo", fooSpec, 0, new TextNode("active"))).build()).waitFor(client);
SampleTaskSpec barSpec = new SampleTaskSpec(0, 900000, Collections.singletonMap("node01", 2L), "baz");
client.createWorker(new CreateWorkerRequest(1, "bar", barSpec));
time.sleep(1);
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone("foo", fooSpec, 0, 1, new TextNode("halted"), "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning("bar", barSpec, 0, new TextNode("active"))).build()).waitFor(client);
time.sleep(1);
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone("foo", fooSpec, 0, 1, new TextNode("halted"), "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerDone("bar", barSpec, 0, 2, new TextNode("halted"), "baz")).build()).waitFor(client);
}
use of org.apache.kafka.trogdor.rest.CreateWorkerRequest in project kafka by apache.
the class AgentTest method testCreateExpiredWorkerIsNotScheduled.
@Test
public void testCreateExpiredWorkerIsNotScheduled() throws Exception {
long initialTimeMs = 100;
long tickMs = 15;
final boolean[] toSleep = { true };
MockTime time = new MockTime(tickMs, initialTimeMs, 0) {
/**
* Modify sleep() to call super.sleep() every second call
* in order to avoid the endless loop in the tick() calls to the MockScheduler listener
*/
@Override
public void sleep(long ms) {
toSleep[0] = !toSleep[0];
if (toSleep[0])
super.sleep(ms);
}
};
MockScheduler scheduler = new MockScheduler(time);
Agent agent = createAgent(scheduler);
AgentClient client = new AgentClient.Builder().maxTries(10).target("localhost", agent.port()).build();
AgentStatusResponse status = client.status();
assertEquals(Collections.emptyMap(), status.workers());
new ExpectedTasks().waitFor(client);
final NoOpTaskSpec fooSpec = new NoOpTaskSpec(10, 10);
client.createWorker(new CreateWorkerRequest(0, "foo", fooSpec));
long actualStartTimeMs = initialTimeMs + tickMs;
long doneMs = actualStartTimeMs + 2 * tickMs;
new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone("foo", fooSpec, actualStartTimeMs, doneMs, null, "worker expired")).taskState(new TaskDone(fooSpec, actualStartTimeMs, doneMs, "worker expired", false, null)).build()).waitFor(client);
}
Aggregations