use of com.twitter.heron.eco.definition.EcoTopologyDefinition in project incubator-heron by apache.
the class SpoutBuilderTest 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 com.twitter.heron.eco.definition.EcoTopologyDefinition in project incubator-heron by apache.
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("com.twitter.heron.sample.TestWordCounter", bolt1.getClassName());
assertEquals(BOLT_1, bolt1.getId());
BoltDefinition bolt2 = topologyDefinition.getBolt(BOLT_2);
assertEquals(1, bolt2.getParallelism());
assertEquals("com.twitter.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 com.twitter.heron.eco.definition.EcoTopologyDefinition in project incubator-heron by apache.
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 com.twitter.heron.eco.definition.EcoTopologyDefinition in project incubator-heron by apache.
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 com.twitter.heron.eco.definition.EcoTopologyDefinition in project incubator-heron by apache.
the class EcoParserTest method testParseFromInputStream_VerifyComponents_MapsAsExpected.
@Test
public void testParseFromInputStream_VerifyComponents_MapsAsExpected() throws Exception {
InputStream inputStream = new ByteArrayInputStream(YAML_STR_1.getBytes());
FileInputStream mockPropsStream = PowerMockito.mock(FileInputStream.class);
EcoTopologyDefinition topologyDefinition = subject.parseFromInputStream(inputStream, mockPropsStream, false);
List<BeanDefinition> components = topologyDefinition.getComponents();
assertEquals("kafka-topology", topologyDefinition.getName());
assertEquals(4, components.size());
BeanDefinition stringSchemeComponent = components.get(0);
assertEquals("stringScheme", stringSchemeComponent.getId());
assertEquals("org.apache.storm.kafka.StringScheme", stringSchemeComponent.getClassName());
BeanDefinition stringMultiSchemeComponent = components.get(1);
assertEquals("stringMultiScheme", stringMultiSchemeComponent.getId());
assertEquals("org.apache.storm.spout.SchemeAsMultiScheme", stringMultiSchemeComponent.getClassName());
assertEquals(1, stringMultiSchemeComponent.getConstructorArgs().size());
BeanReference multiStringReference = (BeanReference) stringMultiSchemeComponent.getConstructorArgs().get(0);
assertEquals("stringScheme", multiStringReference.getId());
BeanDefinition zkHostsComponent = components.get(2);
assertEquals("zkHosts", zkHostsComponent.getId());
assertEquals("org.apache.storm.kafka.ZkHosts", zkHostsComponent.getClassName());
assertEquals(1, zkHostsComponent.getConstructorArgs().size());
assertEquals("localhost:2181", zkHostsComponent.getConstructorArgs().get(0));
BeanDefinition spoutConfigComponent = components.get(3);
List<Object> spoutConstructArgs = spoutConfigComponent.getConstructorArgs();
assertEquals("spoutConfig", spoutConfigComponent.getId());
assertEquals("org.apache.storm.kafka.SpoutConfig", spoutConfigComponent.getClassName());
BeanReference spoutBrokerHostComponent = (BeanReference) spoutConstructArgs.get(0);
assertEquals("zkHosts", spoutBrokerHostComponent.getId());
assertEquals("myKafkaTopic", spoutConstructArgs.get(1));
assertEquals("/kafkaSpout", spoutConstructArgs.get(2));
List<PropertyDefinition> properties = spoutConfigComponent.getProperties();
assertEquals("ignoreZkOffsets", properties.get(0).getName());
assertEquals(true, properties.get(0).getValue());
assertEquals("scheme", properties.get(1).getName());
assertEquals(true, properties.get(1).isReference());
assertEquals("stringMultiScheme", properties.get(1).getRef());
}
Aggregations