use of org.apache.heron.eco.definition.EcoTopologyDefinition in project heron by twitter.
the class StormSpoutBuilderTest method testBuildSpouts_AllGood_BehavesAsExpected.
@Test
public void testBuildSpouts_AllGood_BehavesAsExpected() throws ClassNotFoundException, InvocationTargetException, NoSuchFieldException, InstantiationException, IllegalAccessException {
EcoTopologyDefinition topologyDefinition = new EcoTopologyDefinition();
SpoutDefinition spoutDefinition = new SpoutDefinition();
final String id = "id";
final int parallelism = 2;
spoutDefinition.setId(id);
spoutDefinition.setParallelism(parallelism);
SpoutDefinition spoutDefinition1 = new SpoutDefinition();
final String id1 = "id1";
final int parallelism1 = 3;
spoutDefinition1.setId(id1);
spoutDefinition1.setParallelism(parallelism1);
List<SpoutDefinition> spoutDefinitions = new ArrayList<>();
spoutDefinitions.add(spoutDefinition);
spoutDefinitions.add(spoutDefinition1);
topologyDefinition.setSpouts(spoutDefinitions);
MockSpout mockSpout = new MockSpout();
MockSpout mockSpout1 = new MockSpout();
when(mockObjectBuilder.buildObject(eq(spoutDefinition), eq(mockContext))).thenReturn(mockSpout);
when(mockObjectBuilder.buildObject(eq(spoutDefinition1), eq(mockContext))).thenReturn(mockSpout1);
when(mockContext.getTopologyDefinition()).thenReturn(topologyDefinition);
subject.buildSpouts(mockContext, mockTopologyBuilder, mockObjectBuilder);
verify(mockContext).getTopologyDefinition();
verify(mockObjectBuilder).buildObject(same(spoutDefinition), same(mockContext));
verify(mockObjectBuilder).buildObject(same(spoutDefinition1), same(mockContext));
verify(mockTopologyBuilder).setSpout(eq(id), eq(mockSpout), eq(parallelism));
verify(mockTopologyBuilder).setSpout(eq(id1), eq(mockSpout1), eq(parallelism1));
verify(mockContext).addSpout(eq(id), anyObject());
verify(mockContext).addSpout(eq(id1), anyObject());
}
use of org.apache.heron.eco.definition.EcoTopologyDefinition in project heron by twitter.
the class EcoParserTest method testPartFromInputStream_NoConfigSpecified_ConfigMapIsEmpty.
@Test
public void testPartFromInputStream_NoConfigSpecified_ConfigMapIsEmpty() throws Exception {
InputStream inputStream = new ByteArrayInputStream(YAML_NO_CONFIG_STR.getBytes());
FileInputStream mockPropsStream = PowerMockito.mock(FileInputStream.class);
EcoTopologyDefinition topologyDefinition = subject.parseFromInputStream(inputStream, mockPropsStream, false);
assertNotNull(topologyDefinition.getConfig());
assertEquals(0, topologyDefinition.getConfig().size());
}
use of org.apache.heron.eco.definition.EcoTopologyDefinition in project heron by twitter.
the class EcoParserTest method testParseFromInputStream_StreamIsNull_ExceptionThrown.
@Test(expected = Exception.class)
public void testParseFromInputStream_StreamIsNull_ExceptionThrown() throws Exception {
InputStream inputStream = null;
EcoTopologyDefinition ecoTopologyDefinition = null;
FileInputStream mockPropsStream = PowerMockito.mock(FileInputStream.class);
try {
ecoTopologyDefinition = subject.parseFromInputStream(inputStream, mockPropsStream, false);
} finally {
assertNull(ecoTopologyDefinition);
}
}
use of org.apache.heron.eco.definition.EcoTopologyDefinition in project heron by twitter.
the class EcoParserTest method testParseFromInputStream_VerifyAllButComponents_MapsAsExpected.
@Test
public void testParseFromInputStream_VerifyAllButComponents_MapsAsExpected() throws Exception {
InputStream inputStream = new ByteArrayInputStream(YAML_STR.getBytes());
FileInputStream mockPropsStream = PowerMockito.mock(FileInputStream.class);
EcoTopologyDefinition topologyDefinition = subject.parseFromInputStream(inputStream, mockPropsStream, false);
assertEquals("yaml-topology", topologyDefinition.getName());
assertEquals(1, topologyDefinition.getConfig().size());
assertEquals(1, topologyDefinition.getConfig().get("topology.workers"));
BoltDefinition bolt1 = topologyDefinition.getBolt(BOLT_1);
assertNotNull(bolt1);
assertEquals(2, bolt1.getParallelism());
assertEquals("org.apache.heron.sample.TestWordCounter", bolt1.getClassName());
assertEquals(BOLT_1, bolt1.getId());
BoltDefinition bolt2 = topologyDefinition.getBolt(BOLT_2);
assertEquals(1, bolt2.getParallelism());
assertEquals("org.apache.heron.sample.LogInfoBolt", bolt2.getClassName());
assertEquals(BOLT_2, bolt2.getId());
List<StreamDefinition> streamDefinitions = topologyDefinition.getStreams();
StreamDefinition streamDefinitionOne = streamDefinitions.get(0);
GroupingDefinition groupingDefinitionOne = streamDefinitionOne.getGrouping();
StreamDefinition streamDefinitionTwo = streamDefinitions.get(1);
GroupingDefinition groupingDefinitionTwo = streamDefinitionTwo.getGrouping();
assertEquals(2, streamDefinitions.size());
assertEquals(BOLT_1, streamDefinitionOne.getTo());
assertEquals("spout-1", streamDefinitionOne.getFrom());
assertEquals(GroupingDefinition.Type.FIELDS, groupingDefinitionOne.getType());
assertEquals(1, groupingDefinitionOne.getArgs().size());
assertEquals("word", groupingDefinitionOne.getArgs().get(0));
assertEquals("connection-1", streamDefinitionOne.getId());
assertEquals(BOLT_2, streamDefinitionTwo.getTo());
assertEquals("bolt-1", streamDefinitionTwo.getFrom());
assertEquals(GroupingDefinition.Type.SHUFFLE, groupingDefinitionTwo.getType());
assertEquals("connection-2", streamDefinitionTwo.getId());
assertNull(groupingDefinitionTwo.getArgs());
}
use of org.apache.heron.eco.definition.EcoTopologyDefinition in project heron by twitter.
the class EcoParserTest method testParseFromInputStream_PropertyFiltering_SubstitutesAsExpected.
@Test
public void testParseFromInputStream_PropertyFiltering_SubstitutesAsExpected() throws Exception {
InputStream inputStream = new ByteArrayInputStream(PROPERTY_SUBSTITUION_YAML.getBytes());
InputStream propsStream = new ByteArrayInputStream(SAMPLE_PROPERTIES.getBytes());
EcoTopologyDefinition ecoTopologyDefinition = subject.parseFromInputStream(inputStream, propsStream, false);
BoltDefinition bolt = ecoTopologyDefinition.getBolt("ibasic-print-bolt");
List<Object> args = bolt.getConfigMethods().get(0).getArgs();
assertThat(args.get(0), is(equalTo("ecoValueOne")));
}
Aggregations