Search in sources :

Example 1 with BeanDefinition

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

the class ComponentBuilderTest method testBuildComponents_AllGood_BehavesAsExpected.

@Test
public void testBuildComponents_AllGood_BehavesAsExpected() throws ClassNotFoundException, InvocationTargetException, NoSuchFieldException, InstantiationException, IllegalAccessException {
    BeanDefinition beanDefinition = new BeanDefinition();
    final String id = "bean";
    beanDefinition.setId(id);
    BeanDefinition beanDefinition1 = new BeanDefinition();
    final String id1 = "bean1";
    beanDefinition1.setId(id1);
    List<BeanDefinition> componentDefinitions = new ArrayList<>();
    componentDefinitions.add(beanDefinition);
    componentDefinitions.add(beanDefinition1);
    EcoTopologyDefinition ecoTopologyDefinition = new EcoTopologyDefinition();
    ecoTopologyDefinition.setComponents(componentDefinitions);
    Object object = new Object();
    Object object1 = new Object();
    when(mockContext.getTopologyDefinition()).thenReturn(ecoTopologyDefinition);
    when(mockObjectBuilder.buildObject(eq(beanDefinition), eq(mockContext))).thenReturn(object);
    when(mockObjectBuilder.buildObject(eq(beanDefinition1), eq(mockContext))).thenReturn(object1);
    subject.buildComponents(mockContext, mockObjectBuilder);
    verify(mockContext).getTopologyDefinition();
    verify(mockObjectBuilder).buildObject(same(beanDefinition), same(mockContext));
    verify(mockObjectBuilder).buildObject(same(beanDefinition1), same(mockContext));
    verify(mockContext).addComponent(eq(id), anyObject());
    verify(mockContext).addComponent(eq(id1), anyObject());
}
Also used : ArrayList(java.util.ArrayList) Matchers.anyObject(org.mockito.Matchers.anyObject) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) BeanDefinition(com.twitter.heron.eco.definition.BeanDefinition) Test(org.junit.Test)

Example 2 with BeanDefinition

use of com.twitter.heron.eco.definition.BeanDefinition 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)

Example 3 with BeanDefinition

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

the class ComponentBuilder method buildComponents.

protected void buildComponents(EcoExecutionContext context, ObjectBuilder objectBuilder) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException, InvocationTargetException {
    List<BeanDefinition> componentDefinitions = context.getTopologyDefinition().getComponents();
    if (componentDefinitions != null) {
        for (BeanDefinition bean : componentDefinitions) {
            Object obj = objectBuilder.buildObject(bean, context);
            context.addComponent(bean.getId(), obj);
        }
    }
}
Also used : BeanDefinition(com.twitter.heron.eco.definition.BeanDefinition)

Aggregations

BeanDefinition (com.twitter.heron.eco.definition.BeanDefinition)3 EcoTopologyDefinition (com.twitter.heron.eco.definition.EcoTopologyDefinition)2 Test (org.junit.Test)2 BeanReference (com.twitter.heron.eco.definition.BeanReference)1 PropertyDefinition (com.twitter.heron.eco.definition.PropertyDefinition)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1