Search in sources :

Example 16 with MockScheduler

use of org.apache.kafka.common.utils.MockScheduler 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 17 with MockScheduler

use of org.apache.kafka.common.utils.MockScheduler 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 18 with MockScheduler

use of org.apache.kafka.common.utils.MockScheduler 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 19 with MockScheduler

use of org.apache.kafka.common.utils.MockScheduler 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);
    }
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) MockScheduler(org.apache.kafka.common.utils.MockScheduler) Scheduler(org.apache.kafka.common.utils.Scheduler) TaskDone(org.apache.kafka.trogdor.rest.TaskDone) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) NoOpTaskSpec(org.apache.kafka.trogdor.task.NoOpTaskSpec) TaskPending(org.apache.kafka.trogdor.rest.TaskPending) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) CreateTaskRequest(org.apache.kafka.trogdor.rest.CreateTaskRequest) MiniTrogdorCluster(org.apache.kafka.trogdor.common.MiniTrogdorCluster) AgentClient(org.apache.kafka.trogdor.agent.AgentClient) TaskRunning(org.apache.kafka.trogdor.rest.TaskRunning) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.Test)

Example 20 with MockScheduler

use of org.apache.kafka.common.utils.MockScheduler 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);
    }
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) StopTaskRequest(org.apache.kafka.trogdor.rest.StopTaskRequest) MockScheduler(org.apache.kafka.common.utils.MockScheduler) Scheduler(org.apache.kafka.common.utils.Scheduler) TaskDone(org.apache.kafka.trogdor.rest.TaskDone) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) NoOpTaskSpec(org.apache.kafka.trogdor.task.NoOpTaskSpec) TaskPending(org.apache.kafka.trogdor.rest.TaskPending) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) CreateTaskRequest(org.apache.kafka.trogdor.rest.CreateTaskRequest) MiniTrogdorCluster(org.apache.kafka.trogdor.common.MiniTrogdorCluster) AgentClient(org.apache.kafka.trogdor.agent.AgentClient) TaskRunning(org.apache.kafka.trogdor.rest.TaskRunning) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.Test)

Aggregations

MockScheduler (org.apache.kafka.common.utils.MockScheduler)31 MockTime (org.apache.kafka.common.utils.MockTime)31 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)24 Test (org.junit.jupiter.api.Test)24 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)22 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)19 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)18 Scheduler (org.apache.kafka.common.utils.Scheduler)15 MiniTrogdorCluster (org.apache.kafka.trogdor.common.MiniTrogdorCluster)15 TextNode (com.fasterxml.jackson.databind.node.TextNode)14 CreateTaskRequest (org.apache.kafka.trogdor.rest.CreateTaskRequest)14 WorkerDone (org.apache.kafka.trogdor.rest.WorkerDone)14 TaskPending (org.apache.kafka.trogdor.rest.TaskPending)12 TaskRunning (org.apache.kafka.trogdor.rest.TaskRunning)12 CreateWorkerRequest (org.apache.kafka.trogdor.rest.CreateWorkerRequest)10 TaskDone (org.apache.kafka.trogdor.rest.TaskDone)9 Test (org.junit.Test)7 DestroyTaskRequest (org.apache.kafka.trogdor.rest.DestroyTaskRequest)6 StopTaskRequest (org.apache.kafka.trogdor.rest.StopTaskRequest)6 Subject (javax.security.auth.Subject)5