Search in sources :

Example 1 with BoltDefinition

use of com.twitter.heron.eco.definition.BoltDefinition 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 2 with BoltDefinition

use of com.twitter.heron.eco.definition.BoltDefinition in project incubator-heron by apache.

the class BoltBuilderTest method testBuildBolts_AllGood_BehavesAsExpected.

@Test
public void testBuildBolts_AllGood_BehavesAsExpected() throws ClassNotFoundException, InvocationTargetException, NoSuchFieldException, InstantiationException, IllegalAccessException {
    EcoTopologyDefinition ecoTopologyDefinition = new EcoTopologyDefinition();
    BoltDefinition boltDefinition = new BoltDefinition();
    final String id = "id";
    boltDefinition.setId(id);
    BoltDefinition boltDefinition1 = new BoltDefinition();
    final String id1 = "id1";
    boltDefinition1.setId(id1);
    List<BoltDefinition> boltDefinitions = new ArrayList<>();
    boltDefinitions.add(boltDefinition);
    boltDefinitions.add(boltDefinition1);
    ecoTopologyDefinition.setBolts(boltDefinitions);
    Object object = new Object();
    Object object1 = new Object();
    when(mockContext.getTopologyDefinition()).thenReturn(ecoTopologyDefinition);
    when(mockObjectBuilder.buildObject(eq(boltDefinition), eq(mockContext))).thenReturn(object);
    when(mockObjectBuilder.buildObject(eq(boltDefinition1), eq(mockContext))).thenReturn(object1);
    subject.buildBolts(mockContext, mockObjectBuilder);
    verify(mockContext).getTopologyDefinition();
    verify(mockObjectBuilder).buildObject(same(boltDefinition), same(mockContext));
    verify(mockObjectBuilder).buildObject(same(boltDefinition1), same(mockContext));
    verify(mockContext).addBolt(eq(id), anyObject());
    verify(mockContext).addBolt(eq(id1), anyObject());
}
Also used : BoltDefinition(com.twitter.heron.eco.definition.BoltDefinition) ArrayList(java.util.ArrayList) Matchers.anyObject(org.mockito.Matchers.anyObject) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) Test(org.junit.Test)

Example 3 with BoltDefinition

use of com.twitter.heron.eco.definition.BoltDefinition in project incubator-heron by apache.

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

Example 4 with BoltDefinition

use of com.twitter.heron.eco.definition.BoltDefinition in project incubator-heron by apache.

the class Eco method printTopologyInfo.

static void printTopologyInfo(EcoExecutionContext ctx) {
    EcoTopologyDefinition t = ctx.getTopologyDefinition();
    LOG.info("---------- TOPOLOGY DETAILS ----------");
    LOG.info(String.format("Topology Name: %s", t.getName()));
    LOG.info("--------------- SPOUTS ---------------");
    for (SpoutDefinition s : t.getSpouts()) {
        LOG.info(String.format("%s [%d] (%s)", s.getId(), s.getParallelism(), s.getClassName()));
    }
    LOG.info("---------------- BOLTS ---------------");
    for (BoltDefinition b : t.getBolts()) {
        LOG.info(String.format("%s [%d] (%s)", b.getId(), b.getParallelism(), b.getClassName()));
    }
    LOG.info("--------------- STREAMS ---------------");
    for (StreamDefinition sd : t.getStreams()) {
        LOG.info(String.format("%s --%s--> %s", sd.getFrom(), sd.getGrouping().getType(), sd.getTo()));
    }
    LOG.info("--------------------------------------");
}
Also used : BoltDefinition(com.twitter.heron.eco.definition.BoltDefinition) StreamDefinition(com.twitter.heron.eco.definition.StreamDefinition) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) SpoutDefinition(com.twitter.heron.eco.definition.SpoutDefinition)

Aggregations

BoltDefinition (com.twitter.heron.eco.definition.BoltDefinition)4 EcoTopologyDefinition (com.twitter.heron.eco.definition.EcoTopologyDefinition)4 Test (org.junit.Test)3 StreamDefinition (com.twitter.heron.eco.definition.StreamDefinition)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 GroupingDefinition (com.twitter.heron.eco.definition.GroupingDefinition)1 SpoutDefinition (com.twitter.heron.eco.definition.SpoutDefinition)1 ArrayList (java.util.ArrayList)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1