Как протестировать Storm с использованием Spock при генерации больших выходных кортежей

1

Поэтому у меня есть следующий тест:

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

И я получаю следующую ошибку, которую я не понимаю. Не соответствует ли inputTuple или нет выходного набора:

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)
  • 0
    Можете ли вы привести минимальный рабочий пример? Без этого трудно сказать что-то, что имеет какой-либо смысл.
Теги:
groovy
spock
apache-storm

1 ответ

0
Лучший ответ

Вот как этот тест, вероятно, должен быть написан (пример работы groovyConsole):

@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
    }
}
  • 0
    Спасибо, что приняли ответ, и рад, что Вы довольны им. Я также хотел бы спросить, можете ли вы присуждать награду?
  • 0
    извини опал. Я думал, что автоматически присуждается ответ. Спасибо!
Показать ещё 1 комментарий

Ещё вопросы

Сообщество Overcoder
Наверх
Меню