use of org.apache.samza.system.StreamSpec in project samza by apache.
the class TestWindowOperator method setup.
@Before
public void setup() throws Exception {
config = mock(Config.class);
taskContext = mock(TaskContext.class);
runner = mock(ApplicationRunner.class);
when(taskContext.getSystemStreamPartitions()).thenReturn(ImmutableSet.of(new SystemStreamPartition("kafka", "integers", new Partition(0))));
when(taskContext.getMetricsRegistry()).thenReturn(new MetricsRegistryMap());
when(runner.getStreamSpec("integers")).thenReturn(new StreamSpec("integers", "integers", "kafka"));
}
use of org.apache.samza.system.StreamSpec in project samza by apache.
the class TestAbstractApplicationRunner method testgetStreamPropertiesPassthrough.
// The properties in the config "streams.{streamId}.*" should be passed through to the spec.
@Test
public void testgetStreamPropertiesPassthrough() {
Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME, StreamConfig.SYSTEM(), TEST_SYSTEM, "systemProperty1", "systemValue1", "systemProperty2", "systemValue2", "systemProperty3", "systemValue3");
AbstractApplicationRunner runner = new TestAbstractApplicationRunnerImpl(config);
StreamSpec spec = runner.getStreamSpec(STREAM_ID);
Map<String, String> properties = spec.getConfig();
assertEquals(3, properties.size());
assertEquals("systemValue1", properties.get("systemProperty1"));
assertEquals("systemValue2", properties.get("systemProperty2"));
assertEquals("systemValue3", properties.get("systemProperty3"));
assertEquals("systemValue1", spec.get("systemProperty1"));
assertEquals("systemValue2", spec.get("systemProperty2"));
assertEquals("systemValue3", spec.get("systemProperty3"));
}
use of org.apache.samza.system.StreamSpec in project samza by apache.
the class TestAbstractApplicationRunner method testGetStreamSamzaPropertiesOmitted.
// The samza properties (which are invalid for the underlying system) should be filtered out.
@Test
public void testGetStreamSamzaPropertiesOmitted() {
Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME, StreamConfig.SYSTEM(), TEST_SYSTEM, "systemProperty1", "systemValue1", "systemProperty2", "systemValue2", "systemProperty3", "systemValue3");
AbstractApplicationRunner runner = new TestAbstractApplicationRunnerImpl(config);
StreamSpec spec = runner.getStreamSpec(STREAM_ID);
Map<String, String> properties = spec.getConfig();
assertEquals(3, properties.size());
assertNull(properties.get(String.format(StreamConfig.PHYSICAL_NAME_FOR_STREAM_ID(), STREAM_ID)));
assertNull(properties.get(String.format(StreamConfig.SYSTEM_FOR_STREAM_ID(), STREAM_ID)));
assertNull(spec.get(String.format(StreamConfig.PHYSICAL_NAME_FOR_STREAM_ID(), STREAM_ID)));
assertNull(spec.get(String.format(StreamConfig.SYSTEM_FOR_STREAM_ID(), STREAM_ID)));
}
use of org.apache.samza.system.StreamSpec in project samza by apache.
the class TestLocalApplicationRunner method testStreamCreation.
@Test
public void testStreamCreation() throws Exception {
Map<String, String> config = new HashMap<>();
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);
StreamManager streamManager = mock(StreamManager.class);
Field streamManagerField = runner.getClass().getSuperclass().getDeclaredField("streamManager");
streamManagerField.setAccessible(true);
streamManagerField.set(runner, streamManager);
ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
ExecutionPlan plan = new ExecutionPlan() {
@Override
public List<JobConfig> getJobConfigs() {
return Collections.emptyList();
}
@Override
public List<StreamSpec> getIntermediateStreams() {
return Collections.singletonList(new StreamSpec("test-stream", "test-stream", "test-system"));
}
@Override
public String getPlanAsJson() throws Exception {
return "";
}
};
when(planner.plan(anyObject())).thenReturn(plan);
LocalApplicationRunner spy = spy(runner);
try {
spy.run(app);
} catch (Throwable t) {
//no jobs exception
assertNotNull(t);
}
verify(streamManager).createStreams(captor.capture());
List<StreamSpec> streamSpecs = captor.getValue();
assertEquals(streamSpecs.size(), 1);
assertEquals(streamSpecs.get(0).getId(), "test-stream");
}
use of org.apache.samza.system.StreamSpec 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);
}
Aggregations