use of org.apache.samza.system.StreamSpec 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);
}
use of org.apache.samza.system.StreamSpec in project samza by apache.
the class TestStreamGraphImpl method testMultipleGetInputStream.
@Test(expected = IllegalStateException.class)
public void testMultipleGetInputStream() {
ApplicationRunner mockRunner = mock(ApplicationRunner.class);
Config mockConfig = mock(Config.class);
StreamSpec testStreamSpec1 = new StreamSpec("test-stream-1", "physical-stream-1", "test-system");
StreamSpec testStreamSpec2 = new StreamSpec("test-stream-2", "physical-stream-2", "test-system");
StreamSpec nonExistentStreamSpec = new StreamSpec("non-existent-stream", "physical-stream-1", "test-system");
when(mockRunner.getStreamSpec("test-stream-1")).thenReturn(testStreamSpec1);
when(mockRunner.getStreamSpec("test-stream-2")).thenReturn(testStreamSpec2);
StreamGraphImpl graph = new StreamGraphImpl(mockRunner, mockConfig);
BiFunction<String, MessageType, TestInputMessageEnvelope> xMsgBuilder = (k, v) -> new TestInputMessageEnvelope(k, v.getValue(), v.getEventTime(), "input-id-1");
//create 2 streams for the corresponding streamIds
MessageStream<TestInputMessageEnvelope> inputStream1 = graph.getInputStream("test-stream-1", xMsgBuilder);
MessageStream<TestInputMessageEnvelope> inputStream2 = graph.getInputStream("test-stream-2", xMsgBuilder);
//assert that the streamGraph contains only the above 2 streams
assertEquals(graph.getInputStreams().get(testStreamSpec1), inputStream1);
assertEquals(graph.getInputStreams().get(testStreamSpec2), inputStream2);
assertEquals(graph.getInputStreams().get(nonExistentStreamSpec), null);
assertEquals(graph.getInputStreams().size(), 2);
//should throw IllegalStateException
graph.getInputStream("test-stream-1", xMsgBuilder);
}
use of org.apache.samza.system.StreamSpec in project samza by apache.
the class TestAbstractApplicationRunner method testgetStreamWithPhysicalNameInConfig.
// The physical name should be pulled from the StreamConfig.PHYSICAL_NAME property value.
@Test
public void testgetStreamWithPhysicalNameInConfig() {
Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME, StreamConfig.SYSTEM(), TEST_SYSTEM);
AbstractApplicationRunner runner = new TestAbstractApplicationRunnerImpl(config);
StreamSpec spec = runner.getStreamSpec(STREAM_ID);
assertEquals(TEST_PHYSICAL_NAME, spec.getPhysicalName());
}
use of org.apache.samza.system.StreamSpec in project samza by apache.
the class TestAbstractApplicationRunner method testGetStreamPhysicalNameArgSpecialCharacters.
// Special characters are allowed for the physical name
@Test
public void testGetStreamPhysicalNameArgSpecialCharacters() {
Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME2, StreamConfig.SYSTEM(), TEST_SYSTEM);
AbstractApplicationRunner runner = new TestAbstractApplicationRunnerImpl(config);
StreamSpec spec = runner.getStreamSpec(STREAM_ID, TEST_PHYSICAL_NAME_SPECIAL_CHARS);
assertEquals(TEST_PHYSICAL_NAME_SPECIAL_CHARS, spec.getPhysicalName());
}
use of org.apache.samza.system.StreamSpec in project samza by apache.
the class TestAbstractApplicationRunner method testStreamConfigOverrides.
@Test
public void testStreamConfigOverrides() {
final String sysStreamPrefix = String.format("systems.%s.streams.%s.", TEST_SYSTEM, TEST_PHYSICAL_NAME);
Config config = addConfigs(buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME, StreamConfig.SYSTEM(), TEST_SYSTEM, "systemProperty1", "systemValue1", "systemProperty2", "systemValue2", "systemProperty3", "systemValue3"), sysStreamPrefix + "systemProperty4", "systemValue4", sysStreamPrefix + "systemProperty2", "systemValue8");
AbstractApplicationRunner env = new TestAbstractApplicationRunnerImpl(config);
StreamSpec spec = env.getStreamSpec(STREAM_ID);
Map<String, String> properties = spec.getConfig();
assertEquals(4, properties.size());
assertEquals("systemValue4", properties.get("systemProperty4"));
assertEquals("systemValue2", properties.get("systemProperty2"));
}
Aggregations