Search in sources :

Example 1 with OutputFieldsDeclarer

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

the class KafkaSpoutBufferBehaviourTest method testDeclarations.

@Test
public void testDeclarations() {
    final OutputFieldsDeclarer declarer = mock(OutputFieldsDeclarer.class);
    _subject.declareOutputFields(declarer);
    // verify the spout declares to output single-field tuples
    verify(declarer).declare(argThat(new ArgumentMatcher<Fields>() {

        @Override
        public boolean matches(final Object argument) {
            final Fields fields = (Fields) argument;
            return fields.size() == 1 && fields.get(0).equals("bytes");
        }
    }));
    // verify the spout will not provide component configuration
    assertNull(_subject.getComponentConfiguration());
}
Also used : Fields(backtype.storm.tuple.Fields) ArgumentMatcher(org.mockito.ArgumentMatcher) OutputFieldsDeclarer(backtype.storm.topology.OutputFieldsDeclarer) Test(org.junit.Test)

Example 2 with OutputFieldsDeclarer

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

the class KafkaSpoutConstructorTest method testRawSchemeForDefaultConstructor.

@Test
public void testRawSchemeForDefaultConstructor() {
    final KafkaSpout spout = spy(new KafkaSpout());
    final OutputFieldsDeclarer declarer = mock(OutputFieldsDeclarer.class);
    spout.declareOutputFields(declarer);
    // Fields doesn't implement equals; match it manually
    verify(declarer).declare(argThat(new ArgumentMatcher<Fields>() {

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

Example 3 with OutputFieldsDeclarer

use of backtype.storm.topology.OutputFieldsDeclarer 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

OutputFieldsDeclarer (backtype.storm.topology.OutputFieldsDeclarer)3 Fields (backtype.storm.tuple.Fields)3 Test (org.junit.Test)3 ArgumentMatcher (org.mockito.ArgumentMatcher)3 Scheme (backtype.storm.spout.Scheme)1