Search in sources :

Example 6 with FixedTuple

use of org.apache.storm.testing.FixedTuple in project heron by twitter.

the class ObjectBuilderTest method buildObject_WithArgsBeanReferenceAndOther_BehavesAsExpected.

@Test
public void buildObject_WithArgsBeanReferenceAndOther_BehavesAsExpected() throws ClassNotFoundException, InvocationTargetException, NoSuchFieldException, InstantiationException, IllegalAccessException {
    final String beanReference1 = "bean1";
    List<Object> constructorArgs = new ArrayList<>();
    List<Object> objects = new ArrayList<>();
    List<Object> firstObject = new ArrayList<>();
    objects.add(firstObject);
    constructorArgs.add(objects);
    Object someComponent = new Object();
    final String className = FixedTuple.class.getName();
    final Class testClass = FixedTuple.class;
    final String methodName = "toString";
    List<ConfigurationMethodDefinition> methodDefinitions = new ArrayList<>();
    methodDefinitions.add(mockMethodDefinition);
    when(mockObjectDefinition.getClassName()).thenReturn(className);
    when(mockObjectDefinition.hasConstructorArgs()).thenReturn(true);
    when(mockObjectDefinition.getConstructorArgs()).thenReturn(constructorArgs);
    when(mockObjectDefinition.hasReferences()).thenReturn(true);
    when(mockContext.getComponent(eq(beanReference1))).thenReturn(someComponent);
    when(mockBuilderUtility.resolveReferences(eq(constructorArgs), eq(mockContext))).thenCallRealMethod();
    when(mockBuilderUtility.classForName(eq(className))).thenReturn(testClass);
    when(mockObjectDefinition.getConfigMethods()).thenReturn(methodDefinitions);
    when(mockMethodDefinition.hasReferences()).thenReturn(true);
    when(mockMethodDefinition.getArgs()).thenReturn(null);
    when(mockMethodDefinition.getName()).thenReturn(methodName);
    Object object = subject.buildObject(mockObjectDefinition, mockContext);
    verify(mockObjectDefinition).getClassName();
    verify(mockObjectDefinition).hasConstructorArgs();
    verify(mockObjectDefinition).getConstructorArgs();
    verify(mockObjectDefinition).hasReferences();
    verify(mockBuilderUtility).classForName(same(className));
    verify(mockBuilderUtility).resolveReferences(same(constructorArgs), same(mockContext));
    verify(mockBuilderUtility).applyProperties(eq(mockObjectDefinition), any(Object.class), same(mockContext));
    verify(mockObjectDefinition).getConfigMethods();
    verify(mockMethodDefinition).hasReferences();
    verify(mockMethodDefinition).getArgs();
    verify(mockBuilderUtility, times(2)).resolveReferences(anyListOf(Object.class), same(mockContext));
    verify(mockMethodDefinition).getName();
    assertThat(object, is(instanceOf(FixedTuple.class)));
    FixedTuple fixedTuple = (FixedTuple) object;
    assertThat(fixedTuple.values, is(equalTo(objects)));
    assertThat(fixedTuple.values.get(0), is(equalTo(firstObject)));
}
Also used : FixedTuple(org.apache.storm.testing.FixedTuple) ConfigurationMethodDefinition(org.apache.heron.eco.definition.ConfigurationMethodDefinition) ArrayList(java.util.ArrayList) Matchers.anyObject(org.mockito.Matchers.anyObject) Test(org.junit.Test)

Example 7 with FixedTuple

use of org.apache.storm.testing.FixedTuple in project incubator-heron by apache.

the class ObjectBuilderTest method buildObject_WithArgsBeanReferenceAndOther_BehavesAsExpected.

@Test
public void buildObject_WithArgsBeanReferenceAndOther_BehavesAsExpected() throws ClassNotFoundException, InvocationTargetException, NoSuchFieldException, InstantiationException, IllegalAccessException {
    final String beanReference1 = "bean1";
    List<Object> constructorArgs = new ArrayList<>();
    List<Object> objects = new ArrayList<>();
    List<Object> firstObject = new ArrayList<>();
    objects.add(firstObject);
    constructorArgs.add(objects);
    Object someComponent = new Object();
    final String className = FixedTuple.class.getName();
    final Class testClass = FixedTuple.class;
    final String methodName = "toString";
    List<ConfigurationMethodDefinition> methodDefinitions = new ArrayList<>();
    methodDefinitions.add(mockMethodDefinition);
    when(mockObjectDefinition.getClassName()).thenReturn(className);
    when(mockObjectDefinition.hasConstructorArgs()).thenReturn(true);
    when(mockObjectDefinition.getConstructorArgs()).thenReturn(constructorArgs);
    when(mockObjectDefinition.hasReferences()).thenReturn(true);
    when(mockContext.getComponent(eq(beanReference1))).thenReturn(someComponent);
    when(mockBuilderUtility.resolveReferences(eq(constructorArgs), eq(mockContext))).thenCallRealMethod();
    when(mockBuilderUtility.classForName(eq(className))).thenReturn(testClass);
    when(mockObjectDefinition.getConfigMethods()).thenReturn(methodDefinitions);
    when(mockMethodDefinition.hasReferences()).thenReturn(true);
    when(mockMethodDefinition.getArgs()).thenReturn(null);
    when(mockMethodDefinition.getName()).thenReturn(methodName);
    Object object = subject.buildObject(mockObjectDefinition, mockContext);
    verify(mockObjectDefinition).getClassName();
    verify(mockObjectDefinition).hasConstructorArgs();
    verify(mockObjectDefinition).getConstructorArgs();
    verify(mockObjectDefinition).hasReferences();
    verify(mockBuilderUtility).classForName(same(className));
    verify(mockBuilderUtility).resolveReferences(same(constructorArgs), same(mockContext));
    verify(mockBuilderUtility).applyProperties(eq(mockObjectDefinition), any(Object.class), same(mockContext));
    verify(mockObjectDefinition).getConfigMethods();
    verify(mockMethodDefinition).hasReferences();
    verify(mockMethodDefinition).getArgs();
    verify(mockBuilderUtility, times(2)).resolveReferences(anyListOf(Object.class), same(mockContext));
    verify(mockMethodDefinition).getName();
    assertThat(object, is(instanceOf(FixedTuple.class)));
    FixedTuple fixedTuple = (FixedTuple) object;
    assertThat(fixedTuple.values, is(equalTo(objects)));
    assertThat(fixedTuple.values.get(0), is(equalTo(firstObject)));
}
Also used : FixedTuple(org.apache.storm.testing.FixedTuple) ConfigurationMethodDefinition(com.twitter.heron.eco.definition.ConfigurationMethodDefinition) ArrayList(java.util.ArrayList) Matchers.anyObject(org.mockito.Matchers.anyObject) Test(org.junit.Test)

Example 8 with FixedTuple

use of org.apache.storm.testing.FixedTuple in project storm by apache.

the class MessagingTest method testRemoteTransportWithManyTasksInReceivingExecutor.

@Test
public void testRemoteTransportWithManyTasksInReceivingExecutor() throws Exception {
    // STORM-3141 regression test
    // Verify that remote worker can handle many tasks in one executor
    Config topoConf = new Config();
    topoConf.put(Config.TOPOLOGY_WORKERS, 2);
    topoConf.put(Config.STORM_MESSAGING_TRANSPORT, "org.apache.storm.messaging.netty.Context");
    try (ILocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withSupervisors(1).withPortsPerSupervisor(2).withDaemonConf(topoConf).build()) {
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("1", new TestWordSpout(true), 1);
        builder.setBolt("2", new TestGlobalCount(), 1).setNumTasks(10).shuffleGrouping("1");
        StormTopology stormTopology = builder.createTopology();
        List<FixedTuple> fixedTuples = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            fixedTuples.add(new FixedTuple(Collections.singletonList("a")));
            fixedTuples.add(new FixedTuple(Collections.singletonList("b")));
        }
        Map<String, List<FixedTuple>> data = new HashMap<>();
        data.put("1", fixedTuples);
        MockedSources mockedSources = new MockedSources(data);
        CompleteTopologyParam completeTopologyParam = new CompleteTopologyParam();
        completeTopologyParam.setMockedSources(mockedSources);
        Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
        Assert.assertEquals(6 * 4, Testing.readTuples(results, "2").size());
    }
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) StormTopology(org.apache.storm.generated.StormTopology) ArrayList(java.util.ArrayList) FixedTuple(org.apache.storm.testing.FixedTuple) MockedSources(org.apache.storm.testing.MockedSources) TestGlobalCount(org.apache.storm.testing.TestGlobalCount) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) TestWordSpout(org.apache.storm.testing.TestWordSpout) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 9 with FixedTuple

use of org.apache.storm.testing.FixedTuple in project storm by apache.

the class Testing method readTuples.

/**
 * Get all of the tuples from a given component on a given stream.
 * @param results the results of running a completed topology
 * @param componentId the id of the component to look at
 * @param streamId the id of the stream to look for.
 * @return a list of the tuple values.
 */
public static List<List<Object>> readTuples(Map<String, List<FixedTuple>> results, String componentId, String streamId) {
    List<List<Object>> ret = new ArrayList<>();
    List<FixedTuple> streamResult = results.get(componentId);
    if (streamResult != null) {
        for (FixedTuple tuple : streamResult) {
            if (streamId.equals(tuple.stream)) {
                ret.add(tuple.values);
            }
        }
    }
    return ret;
}
Also used : FixedTuple(org.apache.storm.testing.FixedTuple) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with FixedTuple

use of org.apache.storm.testing.FixedTuple in project storm by apache.

the class TopologyIntegrationTest method tryCompleteWordCountTopology.

private boolean tryCompleteWordCountTopology(LocalCluster cluster, StormTopology topology) throws Exception {
    try {
        List<FixedTuple> testTuples = Arrays.asList("nathan", "bob", "joey", "nathan").stream().map(value -> new FixedTuple(new Values(value))).collect(Collectors.toList());
        MockedSources mockedSources = new MockedSources(Collections.singletonMap("1", testTuples));
        CompleteTopologyParam completeTopologyParam = new CompleteTopologyParam();
        completeTopologyParam.setMockedSources(mockedSources);
        completeTopologyParam.setStormConf(Collections.singletonMap(Config.TOPOLOGY_WORKERS, 2));
        Testing.completeTopology(cluster, topology, completeTopologyParam);
        return false;
    } catch (InvalidTopologyException e) {
        return true;
    }
}
Also used : FixedTuple(org.apache.storm.testing.FixedTuple) CoreMatchers.is(org.hamcrest.CoreMatchers.is) OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) BaseRichSpout(org.apache.storm.topology.base.BaseRichSpout) Arrays(java.util.Arrays) TopologyContext(org.apache.storm.task.TopologyContext) SubmitOptions(org.apache.storm.generated.SubmitOptions) AssertLoop.assertFailed(org.apache.storm.AssertLoop.assertFailed) Assert.assertThat(org.junit.Assert.assertThat) Map(java.util.Map) TestAggregatesCounter(org.apache.storm.testing.TestAggregatesCounter) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TestWordSpout(org.apache.storm.testing.TestWordSpout) MockedSources(org.apache.storm.testing.MockedSources) BaseRichBolt(org.apache.storm.topology.base.BaseRichBolt) EmitInfo(org.apache.storm.hooks.info.EmitInfo) FixedTuple(org.apache.storm.testing.FixedTuple) BoltAckInfo(org.apache.storm.hooks.info.BoltAckInfo) Fields(org.apache.storm.tuple.Fields) Collectors(java.util.stream.Collectors) TestWordCounter(org.apache.storm.testing.TestWordCounter) Test(org.junit.jupiter.api.Test) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) TrackedTopology(org.apache.storm.testing.TrackedTopology) Config(org.apache.storm.Config) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) TestGlobalCount(org.apache.storm.testing.TestGlobalCount) IntStream(java.util.stream.IntStream) TestConfBolt(org.apache.storm.testing.TestConfBolt) Testing(org.apache.storm.Testing) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FeederSpout(org.apache.storm.testing.FeederSpout) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) OutputCollector(org.apache.storm.task.OutputCollector) StormTopology(org.apache.storm.generated.StormTopology) BoltFailInfo(org.apache.storm.hooks.info.BoltFailInfo) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) BoltExecuteInfo(org.apache.storm.hooks.info.BoltExecuteInfo) TestPlannerSpout(org.apache.storm.testing.TestPlannerSpout) ValueSource(org.junit.jupiter.params.provider.ValueSource) AssertLoop.assertAcked(org.apache.storm.AssertLoop.assertAcked) AckFailMapTracker(org.apache.storm.testing.AckFailMapTracker) TopologyInitialStatus(org.apache.storm.generated.TopologyInitialStatus) BaseTaskHook(org.apache.storm.hooks.BaseTaskHook) Consumer(java.util.function.Consumer) LocalCluster(org.apache.storm.LocalCluster) IntegrationTest(org.apache.storm.testing.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) Collections(java.util.Collections) MockedSources(org.apache.storm.testing.MockedSources) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) Values(org.apache.storm.tuple.Values)

Aggregations

FixedTuple (org.apache.storm.testing.FixedTuple)14 ArrayList (java.util.ArrayList)13 List (java.util.List)12 StormTopology (org.apache.storm.generated.StormTopology)11 CompleteTopologyParam (org.apache.storm.testing.CompleteTopologyParam)11 MockedSources (org.apache.storm.testing.MockedSources)11 HashMap (java.util.HashMap)10 TestWordSpout (org.apache.storm.testing.TestWordSpout)10 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)10 TestGlobalCount (org.apache.storm.testing.TestGlobalCount)9 Map (java.util.Map)8 Collectors (java.util.stream.Collectors)8 LocalCluster (org.apache.storm.LocalCluster)8 IntegrationTest (org.apache.storm.testing.IntegrationTest)8 Collections (java.util.Collections)7 Config (org.apache.storm.Config)7 Testing (org.apache.storm.Testing)7 TopologyContext (org.apache.storm.task.TopologyContext)7 Arrays (java.util.Arrays)6 Consumer (java.util.function.Consumer)6