Search in sources :

Example 16 with EcoTopologyDefinition

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

Example 17 with EcoTopologyDefinition

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

Example 18 with EcoTopologyDefinition

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

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

Example 20 with EcoTopologyDefinition

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

Aggregations

EcoTopologyDefinition (org.apache.heron.eco.definition.EcoTopologyDefinition)31 Test (org.junit.Test)21 FileInputStream (java.io.FileInputStream)15 ByteArrayInputStream (java.io.ByteArrayInputStream)13 InputStream (java.io.InputStream)13 Config (org.apache.heron.api.Config)13 EcoParser (org.apache.heron.eco.parser.EcoParser)8 ArrayList (java.util.ArrayList)4 BoltDefinition (org.apache.heron.eco.definition.BoltDefinition)4 StreamDefinition (org.apache.heron.eco.definition.StreamDefinition)4 HashMap (java.util.HashMap)3 GroupingDefinition (org.apache.heron.eco.definition.GroupingDefinition)3 ObjectDefinition (org.apache.heron.eco.definition.ObjectDefinition)3 SpoutDefinition (org.apache.heron.eco.definition.SpoutDefinition)3 BeanDefinition (org.apache.heron.eco.definition.BeanDefinition)2 ComponentStream (org.apache.heron.eco.definition.ComponentStream)2 Before (org.junit.Before)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Properties (java.util.Properties)1