本文整理汇总了Java中org.apache.storm.topology.IRichSpout类的典型用法代码示例。如果您正苦于以下问题:Java IRichSpout类的具体用法?Java IRichSpout怎么用?Java IRichSpout使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IRichSpout类属于org.apache.storm.topology包,在下文中一共展示了IRichSpout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRunExecuteFixedNumber
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testRunExecuteFixedNumber() throws Exception {
final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
declarer.declare(new Fields("dummy"));
PowerMockito.whenNew(SetupOutputFieldsDeclarer.class).withNoArguments()
.thenReturn(declarer);
final StreamingRuntimeContext taskContext = mock(StreamingRuntimeContext.class);
when(taskContext.getExecutionConfig()).thenReturn(mock(ExecutionConfig.class));
when(taskContext.getTaskName()).thenReturn("name");
final IRichSpout spout = mock(IRichSpout.class);
final int numberOfCalls = this.r.nextInt(50);
final SpoutWrapper<?> spoutWrapper = new SpoutWrapper<Object>(spout,
numberOfCalls);
spoutWrapper.setRuntimeContext(taskContext);
spoutWrapper.run(mock(SourceContext.class));
verify(spout, times(numberOfCalls)).nextTuple();
}
示例2: testCancel
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
@Test
public void testCancel() throws Exception {
final int numberOfCalls = 5 + this.r.nextInt(5);
final StreamingRuntimeContext taskContext = mock(StreamingRuntimeContext.class);
when(taskContext.getExecutionConfig()).thenReturn(mock(ExecutionConfig.class));
when(taskContext.getTaskName()).thenReturn("name");
final IRichSpout spout = new FiniteTestSpout(numberOfCalls);
final SpoutWrapper<Tuple1<Integer>> spoutWrapper = new SpoutWrapper<Tuple1<Integer>>(spout);
spoutWrapper.setRuntimeContext(taskContext);
spoutWrapper.cancel();
final TestContext collector = new TestContext();
spoutWrapper.run(collector);
Assert.assertEquals(new LinkedList<Tuple1<Integer>>(), collector.result);
}
示例3: testRawType
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testRawType() throws Exception {
IComponent boltOrSpout;
if (this.r.nextBoolean()) {
boltOrSpout = mock(IRichSpout.class);
} else {
boltOrSpout = mock(IRichBolt.class);
}
final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
declarer.declare(new Fields("dummy1", "dummy2"));
PowerMockito.whenNew(SetupOutputFieldsDeclarer.class).withNoArguments().thenReturn(declarer);
WrapperSetupHelper.getNumberOfAttributes(boltOrSpout,
new HashSet<String>(singleton(Utils.DEFAULT_STREAM_ID)));
}
示例4: testToManyAttributes
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testToManyAttributes() throws Exception {
IComponent boltOrSpout;
if (this.r.nextBoolean()) {
boltOrSpout = mock(IRichSpout.class);
} else {
boltOrSpout = mock(IRichBolt.class);
}
final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
final String[] schema = new String[26];
for (int i = 0; i < schema.length; ++i) {
schema[i] = "a" + i;
}
declarer.declare(new Fields(schema));
PowerMockito.whenNew(SetupOutputFieldsDeclarer.class).withNoArguments().thenReturn(declarer);
WrapperSetupHelper.getNumberOfAttributes(boltOrSpout, null);
}
示例5: testMethodCalls
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
@Test
public void testMethodCalls() {
Map<String, Object> compConfig = new HashMap<String, Object>();
IRichSpout spoutMock = mock(IRichSpout.class);
when(spoutMock.getComponentConfiguration()).thenReturn(compConfig);
Map<?, ?> conf = mock(Map.class);
TopologyContext context = mock(TopologyContext.class);
Object msgId = mock(Object.class);
OutputFieldsDeclarer declarer = mock(OutputFieldsDeclarer.class);
NullTerminatingSpout spout = new NullTerminatingSpout(spoutMock);
spout.open(conf, context, null);
spout.close();
spout.activate();
spout.deactivate();
spout.ack(msgId);
spout.fail(msgId);
spout.declareOutputFields(declarer);
Map<String, Object> c = spoutMock.getComponentConfiguration();
verify(spoutMock).open(same(conf), same(context), any(SpoutOutputCollector.class));
verify(spoutMock).close();
verify(spoutMock).activate();
verify(spoutMock).deactivate();
verify(spoutMock).ack(same(msgId));
verify(spoutMock).fail(same(msgId));
verify(spoutMock).declareOutputFields(same(declarer));
Assert.assertSame(compConfig, c);
}
示例6: testClose
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
@Test
public void testClose() throws Exception {
final IRichSpout spout = mock(IRichSpout.class);
final SpoutWrapper<Tuple1<Integer>> spoutWrapper = new SpoutWrapper<Tuple1<Integer>>(spout);
spoutWrapper.close();
verify(spout).close();
}
示例7: testEmptyDeclarerBolt
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
@Test
public void testEmptyDeclarerBolt() {
IComponent boltOrSpout;
if (this.r.nextBoolean()) {
boltOrSpout = mock(IRichSpout.class);
} else {
boltOrSpout = mock(IRichBolt.class);
}
Assert.assertEquals(new HashMap<String, Integer>(),
WrapperSetupHelper.getNumberOfAttributes(boltOrSpout, null));
}
示例8: testTupleTypes
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
private void testTupleTypes(final int numberOfAttributes) throws Exception {
String[] schema;
if (numberOfAttributes == -1) {
schema = new String[1];
} else {
schema = new String[numberOfAttributes];
}
for (int i = 0; i < schema.length; ++i) {
schema[i] = "a" + i;
}
IComponent boltOrSpout;
if (this.r.nextBoolean()) {
boltOrSpout = mock(IRichSpout.class);
} else {
boltOrSpout = mock(IRichBolt.class);
}
final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
declarer.declare(new Fields(schema));
PowerMockito.whenNew(SetupOutputFieldsDeclarer.class).withNoArguments().thenReturn(declarer);
HashMap<String, Integer> attributes = new HashMap<String, Integer>();
attributes.put(Utils.DEFAULT_STREAM_ID, numberOfAttributes);
Assert.assertEquals(attributes, WrapperSetupHelper.getNumberOfAttributes(
boltOrSpout,
numberOfAttributes == -1 ? new HashSet<String>(singleton(Utils.DEFAULT_STREAM_ID)) : null));
}
示例9: createSpouts
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
private void createSpouts()
throws StreamingException
{
List<? extends IRichOperator> sources = getInputStreams();
checkInputStreams(sources);
for (IRichOperator input : sources)
{
IRichSpout spout = ComponentCreator.createSpout(input);
builder.setSpout(input.getOperatorId(), spout, input.getParallelNumber());
}
}
示例10: create
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
/**
* 创建storm Spout
*/
public static IRichSpout create(IRichOperator operator)
{
StormSpout spout = new StormSpout();
spout.setOperator(operator);
return spout;
}
示例11: buildSpouts
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
protected void buildSpouts(EcoExecutionContext executionContext,
TopologyBuilder builder,
ObjectBuilder objectBuilder)
throws ClassNotFoundException, InstantiationException, IllegalAccessException,
NoSuchFieldException, InvocationTargetException {
EcoTopologyDefinition topologyDefinition = executionContext.getTopologyDefinition();
for (ObjectDefinition def: topologyDefinition.getSpouts()) {
Object obj = objectBuilder.buildObject(def, executionContext);
builder.setSpout(def.getId(), (IRichSpout) obj, def.getParallelism());
executionContext.addSpout(def.getId(), obj);
}
}
示例12: TopologyModule
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
public TopologyModule(ThresholdingConfiguration threshConfig, Config stormConfig,
IRichSpout metricSpout, IRichSpout eventSpout) {
this(threshConfig);
this.stormConfig = stormConfig;
this.metricSpout = metricSpout;
this.eventSpout = eventSpout;
}
示例13: createUrlGeneratorSpout
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
protected IRichSpout createUrlGeneratorSpout(ServiceProvider serviceProvider) {
return new UrlGeneratorSpout(serviceProvider);
}
示例14: open
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
public static <T extends IRichSpout> T open(Map config, T spout, TopologyContext context, ISpoutOutputCollector emitter) {
spout.open(config, context, new SpoutOutputCollector(emitter));
return spout;
}
示例15: NullTerminatingSpout
import org.apache.storm.topology.IRichSpout; //导入依赖的package包/类
public NullTerminatingSpout(IRichSpout spout) {
this.spout = spout;
}