use of org.apache.samza.processor.StreamProcessorLifecycleListener in project samza by apache.
the class TestLocalApplicationRunner method testRunFailure.
@Test
public void testRunFailure() throws Exception {
final Map<String, String> config = new HashMap<>();
config.put(ApplicationConfig.PROCESSOR_ID, "0");
LocalApplicationRunner runner = new LocalApplicationRunner(new MapConfig(config));
StreamApplication app = mock(StreamApplication.class);
doNothing().when(app).init(anyObject(), anyObject());
ExecutionPlanner planner = mock(ExecutionPlanner.class);
Field plannerField = runner.getClass().getSuperclass().getDeclaredField("planner");
plannerField.setAccessible(true);
plannerField.set(runner, planner);
ExecutionPlan plan = new ExecutionPlan() {
@Override
public List<JobConfig> getJobConfigs() {
return Collections.singletonList(new JobConfig(new MapConfig(config)));
}
@Override
public List<StreamSpec> getIntermediateStreams() {
return Collections.emptyList();
}
@Override
public String getPlanAsJson() throws Exception {
return "";
}
};
when(planner.plan(anyObject())).thenReturn(plan);
Throwable t = new Throwable("test failure");
StreamProcessor sp = mock(StreamProcessor.class);
ArgumentCaptor<StreamProcessorLifecycleListener> captor = ArgumentCaptor.forClass(StreamProcessorLifecycleListener.class);
doAnswer(i -> {
StreamProcessorLifecycleListener listener = captor.getValue();
listener.onFailure(t);
return null;
}).when(sp).start();
LocalApplicationRunner spy = spy(runner);
doReturn(sp).when(spy).createStreamProcessor(anyObject(), anyObject(), captor.capture());
try {
spy.run(app);
} catch (Throwable th) {
assertNotNull(th);
}
assertEquals(spy.status(app), ApplicationStatus.UnsuccessfulFinish);
}
use of org.apache.samza.processor.StreamProcessorLifecycleListener in project samza by apache.
the class TestLocalApplicationRunner method testRunComplete.
@Test
public void testRunComplete() throws Exception {
final Map<String, String> config = new HashMap<>();
config.put(ApplicationConfig.APP_PROCESSOR_ID_GENERATOR_CLASS, UUIDGenerator.class.getName());
LocalApplicationRunner runner = new LocalApplicationRunner(new MapConfig(config));
StreamApplication app = mock(StreamApplication.class);
doNothing().when(app).init(anyObject(), anyObject());
ExecutionPlanner planner = mock(ExecutionPlanner.class);
Field plannerField = runner.getClass().getSuperclass().getDeclaredField("planner");
plannerField.setAccessible(true);
plannerField.set(runner, planner);
ExecutionPlan plan = new ExecutionPlan() {
@Override
public List<JobConfig> getJobConfigs() {
return Collections.singletonList(new JobConfig(new MapConfig(config)));
}
@Override
public List<StreamSpec> getIntermediateStreams() {
return Collections.emptyList();
}
@Override
public String getPlanAsJson() throws Exception {
return "";
}
};
when(planner.plan(anyObject())).thenReturn(plan);
StreamProcessor sp = mock(StreamProcessor.class);
ArgumentCaptor<StreamProcessorLifecycleListener> captor = ArgumentCaptor.forClass(StreamProcessorLifecycleListener.class);
doAnswer(i -> {
StreamProcessorLifecycleListener listener = captor.getValue();
listener.onStart();
listener.onShutdown();
return null;
}).when(sp).start();
LocalApplicationRunner spy = spy(runner);
doReturn(sp).when(spy).createStreamProcessor(anyObject(), anyObject(), captor.capture());
spy.run(app);
assertEquals(spy.status(app), ApplicationStatus.SuccessfulFinish);
}
Aggregations