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)));
}
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)));
}
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());
}
}
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;
}
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;
}
}
Aggregations