Search in sources :

Example 1 with AgentWorkerStatusTracker

use of org.apache.kafka.trogdor.task.AgentWorkerStatusTracker in project kafka by apache.

the class ExternalCommandWorkerTest method testProcessWithNormalExit.

/**
 * Test running a process which exits successfully-- in this case, /bin/true.
 */
@Test
public void testProcessWithNormalExit() throws Exception {
    if (OperatingSystem.IS_WINDOWS)
        return;
    ExternalCommandWorker worker = new ExternalCommandWorkerBuilder("trueTask").command("true").build();
    KafkaFutureImpl<String> doneFuture = new KafkaFutureImpl<>();
    worker.start(null, new AgentWorkerStatusTracker(), doneFuture);
    assertEquals("", doneFuture.get());
    worker.stop(null);
}
Also used : AgentWorkerStatusTracker(org.apache.kafka.trogdor.task.AgentWorkerStatusTracker) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) Test(org.junit.jupiter.api.Test)

Example 2 with AgentWorkerStatusTracker

use of org.apache.kafka.trogdor.task.AgentWorkerStatusTracker in project kafka by apache.

the class ExternalCommandWorkerTest method testProcessNotFound.

/**
 * Test attempting to run an executable which doesn't exist.
 * We use a path which starts with /dev/null, since that should never be a
 * directory in UNIX.
 */
@Test
public void testProcessNotFound() throws Exception {
    ExternalCommandWorker worker = new ExternalCommandWorkerBuilder("notFoundTask").command("/dev/null/non/existent/script/path").build();
    KafkaFutureImpl<String> doneFuture = new KafkaFutureImpl<>();
    worker.start(null, new AgentWorkerStatusTracker(), doneFuture);
    String errorString = doneFuture.get();
    assertTrue(errorString.startsWith("Unable to start process"));
    worker.stop(null);
}
Also used : AgentWorkerStatusTracker(org.apache.kafka.trogdor.task.AgentWorkerStatusTracker) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) Test(org.junit.jupiter.api.Test)

Example 3 with AgentWorkerStatusTracker

use of org.apache.kafka.trogdor.task.AgentWorkerStatusTracker in project kafka by apache.

the class ExternalCommandWorkerTest method testProcessStop.

/**
 * Test running a process which times out.  We will send it a SIGTERM.
 */
@Test
public void testProcessStop() throws Exception {
    if (OperatingSystem.IS_WINDOWS)
        return;
    ExternalCommandWorker worker = new ExternalCommandWorkerBuilder("testStopTask").command("sleep", "3600000").build();
    KafkaFutureImpl<String> doneFuture = new KafkaFutureImpl<>();
    worker.start(null, new AgentWorkerStatusTracker(), doneFuture);
    worker.stop(null);
    // We don't check the numeric return code, since that will vary based on
    // platform.
    assertTrue(doneFuture.get().startsWith("exited with return code "));
}
Also used : AgentWorkerStatusTracker(org.apache.kafka.trogdor.task.AgentWorkerStatusTracker) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) Test(org.junit.jupiter.api.Test)

Example 4 with AgentWorkerStatusTracker

use of org.apache.kafka.trogdor.task.AgentWorkerStatusTracker in project kafka by apache.

the class ExternalCommandWorkerTest method testProcessWithFailedExit.

/**
 * Test running a process which exits unsuccessfully-- in this case, /bin/false.
 */
@Test
public void testProcessWithFailedExit() throws Exception {
    if (OperatingSystem.IS_WINDOWS)
        return;
    ExternalCommandWorker worker = new ExternalCommandWorkerBuilder("falseTask").command("false").build();
    KafkaFutureImpl<String> doneFuture = new KafkaFutureImpl<>();
    worker.start(null, new AgentWorkerStatusTracker(), doneFuture);
    assertEquals("exited with return code 1", doneFuture.get());
    worker.stop(null);
}
Also used : AgentWorkerStatusTracker(org.apache.kafka.trogdor.task.AgentWorkerStatusTracker) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) Test(org.junit.jupiter.api.Test)

Aggregations

KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)4 AgentWorkerStatusTracker (org.apache.kafka.trogdor.task.AgentWorkerStatusTracker)4 Test (org.junit.jupiter.api.Test)4