本文介绍了如何在发射大量输出元组时使用Spock测试Storm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有以下测试:$ $ p $
deftest execute(inputTuple)method emit an outputTuple contains a member ObjectType
使用inputTuple中的entity_id检索(){
given:
Tuple inputTuple = Mock(Tuple);
列表< String> objectTypeIDsEmittedByPreviousBolt = new ArrayList< String>();
objectTypeIDsEmittedByPreviousBolt.add(member);
objectTypeIDsEmittedByPreviousBolt.add(1196);
1 * inputTuple.getValues()>> objectTypeIDsEmittedByPreviousBolt;
当:
this.bolt.execute(inputTuple);
then:
1 * this.collector.emit(inputTuple,THE_OUTPUT_TUPLE);
1 * this.collector.ack(inputTuple);
}
我得到以下我不明白的错误。 inputTuple不匹配或者outputTuple不匹配?:
调用的次数太少:
1 * this.collector.emit(inputTuple,[['response':['status':'OK',...'member']]]])(0 invocations)
Unmatched invocations(按照相似性排序):
1 *< OutputCollector> .emit(模拟'Tuple'类型'inputTuple',[['response':['status':'OK',.. 。'member']]]])
在org.spockframework.mock.runtime.InteractionScope.verifyInteractions(InteractionScope.java:78)
在org.spockframework.mock执行(inputTuple)方法发出一个outputTuple,其中包含使用inputTuple中的entity_id检索的成员ObjectType(CallConsoleAPIToGetAllObjectTypeInfoBoltTest.groovy:63)
解决方案
这是(groovyConsole工作示例):
@Grab('org.spockframework:spock-core:0.7 -groovy-2.0')
@Grab('cglib:cglib-nodep:3.1')
import spock.lang。*
class Test extends Specification {
deftest execute(inputTuple)方法发出一个outputTuple,其中包含使用inputTuple中的entity_id检索到的成员ObjectType(){
given:
List< String> objectTypeIDsEmittedByPreviousBolt = new ArrayList< String>();
objectTypeIDsEmittedByPreviousBolt.add(member);
objectTypeIDsEmittedByPreviousBolt.add(1196);
Tuple inputTuple = new Tuple(objectTypeIDsEmittedByPreviousBolt);
Bolt bolt = new Bolt()
Collector collector = GroovyMock(Collector)
bolt.collector = collector
当:
bolt .execute(inputTuple);
then:
1 * collector.ack(inputTuple);
class Bolt {
Collector collector = new Collector()
def execute(o){
collector.ack o)
}
}
class Collector {
def ack(o){
println o
}
}
So I have the following test:
def "test execute(inputTuple) method emits an outputTuple containing a member ObjectType
retrieved using the entity_id in inputTuple"() {
given:
Tuple inputTuple = Mock(Tuple);
List<String> objectTypeIDsEmittedByPreviousBolt = new ArrayList<String>();
objectTypeIDsEmittedByPreviousBolt.add("member");
objectTypeIDsEmittedByPreviousBolt.add("1196");
1 * inputTuple.getValues() >> objectTypeIDsEmittedByPreviousBolt;
when:
this.bolt.execute(inputTuple);
then:
1 * this.collector.emit(inputTuple, THE_OUTPUT_TUPLE);
1 * this.collector.ack(inputTuple);
}
And I getting the following error which I don't understand. Is the inputTuple not matching or the outputTuple not matching?:
Too few invocations for:
1 * this.collector.emit( inputTuple, [['response':['status':'OK', ... 'member']]]]) (0 invocations)
Unmatched invocations (ordered by similarity):
1 * <OutputCollector>.emit(Mock for type 'Tuple' named 'inputTuple', [['response':['status':'OK', ...'member']]]])
at org.spockframework.mock.runtime.InteractionScope.verifyInteractions(InteractionScope.java:78)
at org.spockframework.mock.runtime.MockController.leaveScope(MockController.java:76)
at member.bolt.CallConsoleAPIToGetAllObjectTypeInfoBoltTest.test execute(inputTuple) method emits an outputTuple containing a member ObjectType retrieved using the entity_id in inputTuple(CallConsoleAPIToGetAllObjectTypeInfoBoltTest.groovy:63)
解决方案
This is how this test should probably be written (groovyConsole working example):
@Grab('org.spockframework:spock-core:0.7-groovy-2.0')
@Grab('cglib:cglib-nodep:3.1')
import spock.lang.*
class Test extends Specification {
def "test execute(inputTuple) method emits an outputTuple containing a member ObjectType retrieved using the entity_id in inputTuple"() {
given:
List<String> objectTypeIDsEmittedByPreviousBolt = new ArrayList<String>();
objectTypeIDsEmittedByPreviousBolt.add("member");
objectTypeIDsEmittedByPreviousBolt.add("1196");
Tuple inputTuple = new Tuple(objectTypeIDsEmittedByPreviousBolt);
Bolt bolt = new Bolt()
Collector collector = GroovyMock(Collector)
bolt.collector = collector
when:
bolt.execute(inputTuple);
then:
1 * collector.ack(inputTuple);
}
}
class Bolt {
Collector collector = new Collector()
def execute(o) {
collector.ack(o)
}
}
class Collector {
def ack(o) {
println o
}
}
这篇关于如何在发射大量输出元组时使用Spock测试Storm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!