Search in sources :

Example 1 with CreateWorkerResponse

use of org.apache.kafka.trogdor.rest.CreateWorkerResponse 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)

Aggregations

MockScheduler (org.apache.kafka.common.utils.MockScheduler)1 MockTime (org.apache.kafka.common.utils.MockTime)1 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)1 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)1 AgentStatusResponse (org.apache.kafka.trogdor.rest.AgentStatusResponse)1 CreateWorkerRequest (org.apache.kafka.trogdor.rest.CreateWorkerRequest)1 CreateWorkerResponse (org.apache.kafka.trogdor.rest.CreateWorkerResponse)1 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)1 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)1 Test (org.junit.Test)1