use of io.cdap.cdap.internal.app.runtime.AbstractProgramController in project cdap by caskdata.
the class DelayedProgramControllerTest method testListener.
@Test
public void testListener() throws InterruptedException {
ProgramRunId programRunId = new ProgramRunId("ns", "app", ProgramType.SPARK, "program", RunIds.generate().getId());
DelayedProgramController controller = new DelayedProgramController(programRunId);
CountDownLatch aliveLatch = new CountDownLatch(1);
CountDownLatch killedLatch = new CountDownLatch(1);
controller.addListener(new AbstractListener() {
@Override
public void init(ProgramController.State currentState, @Nullable Throwable cause) {
if (currentState == ProgramController.State.ALIVE) {
alive();
} else if (currentState == ProgramController.State.KILLED) {
completed();
}
}
@Override
public void alive() {
aliveLatch.countDown();
}
@Override
public void killed() {
killedLatch.countDown();
}
}, Threads.SAME_THREAD_EXECUTOR);
// Perform state change on the delegate
ProgramController delegate = new AbstractProgramController(programRunId) {
{
started();
}
@Override
protected void doSuspend() {
// no-op
}
@Override
protected void doResume() {
// no-op
}
@Override
protected void doStop() {
// no-op
}
@Override
protected void doCommand(String name, Object value) {
// no-op
}
};
controller.setProgramController(delegate);
Assert.assertTrue(aliveLatch.await(5, TimeUnit.SECONDS));
controller.stop();
Assert.assertTrue(killedLatch.await(5, TimeUnit.SECONDS));
}
use of io.cdap.cdap.internal.app.runtime.AbstractProgramController in project cdap by cdapio.
the class DelayedProgramControllerTest method testListener.
@Test
public void testListener() throws InterruptedException {
ProgramRunId programRunId = new ProgramRunId("ns", "app", ProgramType.SPARK, "program", RunIds.generate().getId());
DelayedProgramController controller = new DelayedProgramController(programRunId);
CountDownLatch aliveLatch = new CountDownLatch(1);
CountDownLatch killedLatch = new CountDownLatch(1);
controller.addListener(new AbstractListener() {
@Override
public void init(ProgramController.State currentState, @Nullable Throwable cause) {
if (currentState == ProgramController.State.ALIVE) {
alive();
} else if (currentState == ProgramController.State.KILLED) {
completed();
}
}
@Override
public void alive() {
aliveLatch.countDown();
}
@Override
public void killed() {
killedLatch.countDown();
}
}, Threads.SAME_THREAD_EXECUTOR);
// Perform state change on the delegate
ProgramController delegate = new AbstractProgramController(programRunId) {
{
started();
}
@Override
protected void doSuspend() {
// no-op
}
@Override
protected void doResume() {
// no-op
}
@Override
protected void doStop() {
// no-op
}
@Override
protected void doCommand(String name, Object value) {
// no-op
}
};
controller.setProgramController(delegate);
Assert.assertTrue(aliveLatch.await(5, TimeUnit.SECONDS));
controller.stop();
Assert.assertTrue(killedLatch.await(5, TimeUnit.SECONDS));
}
Aggregations