Search in sources :

Example 6 with EcoTopologyDefinition

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());
}
Also used : ArrayList(java.util.ArrayList) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) SpoutDefinition(com.twitter.heron.eco.definition.SpoutDefinition) Test(org.junit.Test)

Example 7 with EcoTopologyDefinition

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());
}
Also used : BoltDefinition(com.twitter.heron.eco.definition.BoltDefinition) StreamDefinition(com.twitter.heron.eco.definition.StreamDefinition) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) GroupingDefinition(com.twitter.heron.eco.definition.GroupingDefinition) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 8 with EcoTopologyDefinition

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 9 with EcoTopologyDefinition

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);
    }
}
Also used : FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 10 with 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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BeanReference(com.twitter.heron.eco.definition.BeanReference) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) BeanDefinition(com.twitter.heron.eco.definition.BeanDefinition) PropertyDefinition(com.twitter.heron.eco.definition.PropertyDefinition) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

EcoTopologyDefinition (com.twitter.heron.eco.definition.EcoTopologyDefinition)26 Test (org.junit.Test)19 FileInputStream (java.io.FileInputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 InputStream (java.io.InputStream)13 Config (com.twitter.heron.api.Config)12 EcoParser (com.twitter.heron.eco.parser.EcoParser)8 BoltDefinition (com.twitter.heron.eco.definition.BoltDefinition)4 StreamDefinition (com.twitter.heron.eco.definition.StreamDefinition)3 ArrayList (java.util.ArrayList)3 ObjectBuilder (com.twitter.heron.eco.builder.ObjectBuilder)2 BeanDefinition (com.twitter.heron.eco.definition.BeanDefinition)2 EcoExecutionContext (com.twitter.heron.eco.definition.EcoExecutionContext)2 GroupingDefinition (com.twitter.heron.eco.definition.GroupingDefinition)2 ObjectDefinition (com.twitter.heron.eco.definition.ObjectDefinition)2 SpoutDefinition (com.twitter.heron.eco.definition.SpoutDefinition)2 HashMap (java.util.HashMap)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 BuilderUtility (com.twitter.heron.eco.builder.BuilderUtility)1 BeanReference (com.twitter.heron.eco.definition.BeanReference)1