Search in sources :

Example 6 with CreateWorkerRequest

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());
    }
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) ArrayList(java.util.ArrayList) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) KiboshFilesUnreadableFaultSpec(org.apache.kafka.trogdor.fault.Kibosh.KiboshFilesUnreadableFaultSpec) Kibosh(org.apache.kafka.trogdor.fault.Kibosh) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) StopWorkerRequest(org.apache.kafka.trogdor.rest.StopWorkerRequest) KiboshControlFile(org.apache.kafka.trogdor.fault.Kibosh.KiboshControlFile) KiboshFilesUnreadableFaultSpec(org.apache.kafka.trogdor.fault.Kibosh.KiboshFilesUnreadableFaultSpec) FilesUnreadableFaultSpec(org.apache.kafka.trogdor.fault.FilesUnreadableFaultSpec) CreateWorkerRequest(org.apache.kafka.trogdor.rest.CreateWorkerRequest) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.Test)

Example 7 with CreateWorkerRequest

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();
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) StopWorkerRequest(org.apache.kafka.trogdor.rest.StopWorkerRequest) CreateWorkerRequest(org.apache.kafka.trogdor.rest.CreateWorkerRequest) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) MockTime(org.apache.kafka.common.utils.MockTime) NoOpTaskSpec(org.apache.kafka.trogdor.task.NoOpTaskSpec) Test(org.junit.Test)

Example 8 with CreateWorkerRequest

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();
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) AgentStatusResponse(org.apache.kafka.trogdor.rest.AgentStatusResponse) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) CreateWorkerRequest(org.apache.kafka.trogdor.rest.CreateWorkerRequest) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) MockTime(org.apache.kafka.common.utils.MockTime) NoOpTaskSpec(org.apache.kafka.trogdor.task.NoOpTaskSpec) CreateWorkerResponse(org.apache.kafka.trogdor.rest.CreateWorkerResponse) Test(org.junit.Test)

Example 9 with CreateWorkerRequest

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);
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) SampleTaskSpec(org.apache.kafka.trogdor.task.SampleTaskSpec) TextNode(com.fasterxml.jackson.databind.node.TextNode) CreateWorkerRequest(org.apache.kafka.trogdor.rest.CreateWorkerRequest) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Example 10 with CreateWorkerRequest

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);
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) TaskDone(org.apache.kafka.trogdor.rest.TaskDone) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) NoOpTaskSpec(org.apache.kafka.trogdor.task.NoOpTaskSpec) AgentStatusResponse(org.apache.kafka.trogdor.rest.AgentStatusResponse) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) CreateWorkerRequest(org.apache.kafka.trogdor.rest.CreateWorkerRequest) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Aggregations

CreateWorkerRequest (org.apache.kafka.trogdor.rest.CreateWorkerRequest)11 MockScheduler (org.apache.kafka.common.utils.MockScheduler)10 MockTime (org.apache.kafka.common.utils.MockTime)10 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)10 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)10 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)9 WorkerDone (org.apache.kafka.trogdor.rest.WorkerDone)8 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)6 Test (org.junit.jupiter.api.Test)6 TextNode (com.fasterxml.jackson.databind.node.TextNode)5 StopWorkerRequest (org.apache.kafka.trogdor.rest.StopWorkerRequest)5 AgentStatusResponse (org.apache.kafka.trogdor.rest.AgentStatusResponse)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 FilesUnreadableFaultSpec (org.apache.kafka.trogdor.fault.FilesUnreadableFaultSpec)2 KiboshControlFile (org.apache.kafka.trogdor.fault.Kibosh.KiboshControlFile)2 KiboshFilesUnreadableFaultSpec (org.apache.kafka.trogdor.fault.Kibosh.KiboshFilesUnreadableFaultSpec)2 DestroyWorkerRequest (org.apache.kafka.trogdor.rest.DestroyWorkerRequest)2 SampleTaskSpec (org.apache.kafka.trogdor.task.SampleTaskSpec)2 ZoneOffset (java.time.ZoneOffset)1