Search in sources :

Example 1 with Scheme

use of backtype.storm.spout.Scheme in project kafka-spout by HolmesNL.

the class KafkaSpoutBufferBehaviourTest method setup.

@Before
public void setup() {
    final Scheme scheme = spy(new RawScheme());
    // main test subject
    _subject = new KafkaSpout(scheme);
    // assign the topic to be used for stream retrieval
    _subject._topic = "test-topic";
    // use a buffer size higher than the expected amount of messages available
    _subject._bufSize = 4;
    // assign the default FailHandler
    _subject._failHandler = ConfigUtils.DEFAULT_FAIL_HANDLER;
    // mocked consumer to avoid actually contacting zookeeper
    _consumer = mock(ConsumerConnector.class);
    // ... but make sure it will return a valid (empty) stream
    when(_consumer.createMessageStreams(any(Map.class))).thenReturn(EMPTY_STREAM);
    // assign the consumer to the test subject
    _subject._consumer = _consumer;
    // provide a mocked collector to be able to check for emitted values
    _subject._collector = mock(SpoutOutputCollector.class);
}
Also used : Scheme(backtype.storm.spout.Scheme) RawScheme(backtype.storm.spout.RawScheme) RawScheme(backtype.storm.spout.RawScheme) SpoutOutputCollector(backtype.storm.spout.SpoutOutputCollector) ConsumerConnector(kafka.javaapi.consumer.ConsumerConnector) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Before(org.junit.Before)

Example 2 with Scheme

use of backtype.storm.spout.Scheme in project kafka-spout by HolmesNL.

the class KafkaSpoutConstructorTest method testDelegateCustomScheme.

@Test
public void testDelegateCustomScheme() {
    final Scheme scheme = new Scheme() {

        @Override
        public List<Object> deserialize(final byte[] bytes) {
            return Arrays.<Object>asList(new byte[] { bytes[0] }, Arrays.copyOfRange(bytes, 1, bytes.length));
        }

        @Override
        public Fields getOutputFields() {
            return new Fields("head", "tail");
        }
    };
    final OutputFieldsDeclarer declarer = mock(OutputFieldsDeclarer.class);
    // test for both constructors that accept a scheme
    new KafkaSpout(scheme).declareOutputFields(declarer);
    new KafkaSpout("topic", scheme).declareOutputFields(declarer);
    // Fields doesn't implement equals; match it manually
    verify(declarer, times(2)).declare(argThat(new ArgumentMatcher<Fields>() {

        @Override
        public boolean matches(final Object argument) {
            final Fields fields = (Fields) argument;
            return fields.size() == 2 && fields.get(0).equals("head") && fields.get(1).equals("tail");
        }
    }));
}
Also used : Scheme(backtype.storm.spout.Scheme) Fields(backtype.storm.tuple.Fields) ArgumentMatcher(org.mockito.ArgumentMatcher) OutputFieldsDeclarer(backtype.storm.topology.OutputFieldsDeclarer) Test(org.junit.Test)

Aggregations

Scheme (backtype.storm.spout.Scheme)2 RawScheme (backtype.storm.spout.RawScheme)1 SpoutOutputCollector (backtype.storm.spout.SpoutOutputCollector)1 OutputFieldsDeclarer (backtype.storm.topology.OutputFieldsDeclarer)1 Fields (backtype.storm.tuple.Fields)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 ConsumerConnector (kafka.javaapi.consumer.ConsumerConnector)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1