use of org.apache.storm.testing.FixedTuple in project storm by apache.
the class NettyIntegrationTest method testIntegration.
@Test
public void testIntegration() throws Exception {
Map<String, Object> daemonConf = new HashMap<>();
daemonConf.put(Config.STORM_LOCAL_MODE_ZMQ, true);
daemonConf.put(Config.STORM_MESSAGING_TRANSPORT, "org.apache.storm.messaging.netty.Context");
daemonConf.put(Config.STORM_MESSAGING_NETTY_AUTHENTICATION, false);
daemonConf.put(Config.STORM_MESSAGING_NETTY_BUFFER_SIZE, 1024000);
daemonConf.put(Config.STORM_MESSAGING_NETTY_MIN_SLEEP_MS, 1000);
daemonConf.put(Config.STORM_MESSAGING_NETTY_MAX_SLEEP_MS, 5000);
daemonConf.put(Config.STORM_MESSAGING_NETTY_CLIENT_WORKER_THREADS, 1);
daemonConf.put(Config.STORM_MESSAGING_NETTY_SERVER_WORKER_THREADS, 1);
Builder builder = new Builder().withSimulatedTime().withSupervisors(4).withSupervisorSlotPortMin(6710).withDaemonConf(daemonConf);
try (LocalCluster cluster = builder.build()) {
TopologyBuilder topologyBuilder = new TopologyBuilder();
topologyBuilder.setSpout("1", new TestWordSpout(true), 4);
topologyBuilder.setBolt("2", new TestGlobalCount(), 6).shuffleGrouping("1");
StormTopology topology = topologyBuilder.createTopology();
// important for test that tuples = multiple of 4 and 6
List<FixedTuple> testTuples = Stream.of("a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b").map(value -> new FixedTuple(new Values(value))).collect(Collectors.toList());
MockedSources mockedSources = new MockedSources(Collections.singletonMap("1", testTuples));
CompleteTopologyParam completeTopologyParams = new CompleteTopologyParam();
completeTopologyParams.setStormConf(Collections.singletonMap(Config.TOPOLOGY_WORKERS, 3));
completeTopologyParams.setMockedSources(mockedSources);
Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, topology, completeTopologyParams);
assertEquals(6 * 4, Testing.readTuples(results, "2").size());
}
}
use of org.apache.storm.testing.FixedTuple in project storm by apache.
the class TopologyIntegrationTest method testHooks.
@Test
public void testHooks() throws Exception {
try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().build()) {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("1", new TestPlannerSpout(new Fields("conf")));
builder.setBolt("2", new HooksBolt()).shuffleGrouping("1");
StormTopology topology = builder.createTopology();
List<FixedTuple> testTuples = Arrays.asList(1, 1, 1, 1).stream().map(value -> new FixedTuple(new Values(value))).collect(Collectors.toList());
MockedSources mockedSources = new MockedSources(Collections.singletonMap("1", testTuples));
CompleteTopologyParam completeTopologyParams = new CompleteTopologyParam();
completeTopologyParams.setMockedSources(mockedSources);
Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, topology, completeTopologyParams);
List<List<Object>> expectedTuples = Arrays.asList(Arrays.asList(0, 0, 0, 0), Arrays.asList(2, 1, 0, 1), Arrays.asList(4, 1, 1, 2), Arrays.asList(6, 2, 1, 3));
assertThat(Testing.readTuples(results, "2"), is(expectedTuples));
}
}
use of org.apache.storm.testing.FixedTuple in project storm by apache.
the class TopologyIntegrationTest method testMultiTasksPerCluster.
@Test
public void testMultiTasksPerCluster() throws Exception {
try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withSupervisors(4).build()) {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("1", new TestWordSpout(true));
builder.setBolt("2", new EmitTaskIdBolt(), 3).allGrouping("1").addConfigurations(Collections.singletonMap(Config.TOPOLOGY_TASKS, 6));
StormTopology topology = builder.createTopology();
MockedSources mockedSources = new MockedSources(Collections.singletonMap("1", Collections.singletonList(new FixedTuple(new Values("a")))));
CompleteTopologyParam completeTopologyParams = new CompleteTopologyParam();
completeTopologyParams.setMockedSources(mockedSources);
Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, topology, completeTopologyParams);
assertThat(Testing.readTuples(results, "2"), containsInAnyOrder(new Values(0), new Values(1), new Values(2), new Values(3), new Values(4), new Values(5)));
}
}
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 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)));
}
Aggregations