Search in sources :

Example 1 with FilterProcessor

use of org.apache.storm.streams.processors.FilterProcessor in project storm by apache.

the class ProcessorBoltTest method testEmitAndAck.

@Test
public void testEmitAndAck() throws Exception {
    setUpProcessorBolt(new FilterProcessor<Integer>(x -> true));
    bolt.execute(mockTuple1);
    ArgumentCaptor<Collection> anchor = ArgumentCaptor.forClass(Collection.class);
    ArgumentCaptor<Values> values = ArgumentCaptor.forClass(Values.class);
    ArgumentCaptor<String> os = ArgumentCaptor.forClass(String.class);
    Mockito.verify(mockOutputCollector).emit(os.capture(), anchor.capture(), values.capture());
    assertEquals("outputstream", os.getValue());
    assertArrayEquals(new Object[] { mockTuple1 }, anchor.getValue().toArray());
    assertEquals(new Values(100), values.getValue());
    Mockito.verify(mockOutputCollector, Mockito.times(1)).ack(mockTuple1);
}
Also used : LongSum(org.apache.storm.streams.operations.aggregators.LongSum) TopologyContext(org.apache.storm.task.TopologyContext) HashMap(java.util.HashMap) Multimap(org.apache.storm.shade.com.google.common.collect.Multimap) DefaultDirectedGraph(org.apache.storm.shade.org.jgrapht.graph.DefaultDirectedGraph) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) ArgumentCaptor(org.mockito.ArgumentCaptor) OutputCollector(org.apache.storm.task.OutputCollector) Map(java.util.Map) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Before(org.junit.Before) FilterProcessor(org.apache.storm.streams.processors.FilterProcessor) DirectedGraph(org.apache.storm.shade.org.jgrapht.DirectedGraph) Collection(java.util.Collection) Grouping(org.apache.storm.generated.Grouping) Set(java.util.Set) Test(org.junit.Test) Fields(org.apache.storm.tuple.Fields) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) AggregateProcessor(org.apache.storm.streams.processors.AggregateProcessor) Processor(org.apache.storm.streams.processors.Processor) Mockito(org.mockito.Mockito) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Values(org.apache.storm.tuple.Values) Collection(java.util.Collection) Test(org.junit.Test)

Example 2 with FilterProcessor

use of org.apache.storm.streams.processors.FilterProcessor in project storm by apache.

the class ProcessorBoltTest method testEmitTs.

@Test
public void testEmitTs() throws Exception {
    Tuple tupleWithTs = Mockito.mock(Tuple.class);
    setUpMockTuples(tupleWithTs);
    Mockito.when(tupleWithTs.getLongByField("ts")).thenReturn(12345L);
    setUpProcessorBolt(new FilterProcessor(x -> true), "ts");
    bolt.execute(tupleWithTs);
    ArgumentCaptor<Collection> anchor = ArgumentCaptor.forClass(Collection.class);
    ArgumentCaptor<Values> values = ArgumentCaptor.forClass(Values.class);
    ArgumentCaptor<String> os = ArgumentCaptor.forClass(String.class);
    Mockito.verify(mockOutputCollector).emit(os.capture(), anchor.capture(), values.capture());
    assertEquals("outputstream", os.getValue());
    assertArrayEquals(new Object[] { tupleWithTs }, anchor.getValue().toArray());
    assertEquals(new Values(100, 12345L), values.getValue());
    Mockito.verify(mockOutputCollector, Mockito.times(1)).ack(tupleWithTs);
}
Also used : LongSum(org.apache.storm.streams.operations.aggregators.LongSum) TopologyContext(org.apache.storm.task.TopologyContext) HashMap(java.util.HashMap) Multimap(org.apache.storm.shade.com.google.common.collect.Multimap) DefaultDirectedGraph(org.apache.storm.shade.org.jgrapht.graph.DefaultDirectedGraph) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) ArgumentCaptor(org.mockito.ArgumentCaptor) OutputCollector(org.apache.storm.task.OutputCollector) Map(java.util.Map) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Before(org.junit.Before) FilterProcessor(org.apache.storm.streams.processors.FilterProcessor) DirectedGraph(org.apache.storm.shade.org.jgrapht.DirectedGraph) Collection(java.util.Collection) Grouping(org.apache.storm.generated.Grouping) Set(java.util.Set) Test(org.junit.Test) Fields(org.apache.storm.tuple.Fields) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) AggregateProcessor(org.apache.storm.streams.processors.AggregateProcessor) Processor(org.apache.storm.streams.processors.Processor) Mockito(org.mockito.Mockito) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FilterProcessor(org.apache.storm.streams.processors.FilterProcessor) Values(org.apache.storm.tuple.Values) Collection(java.util.Collection) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Aggregations

Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)2 Grouping (org.apache.storm.generated.Grouping)2 Multimap (org.apache.storm.shade.com.google.common.collect.Multimap)2 DirectedGraph (org.apache.storm.shade.org.jgrapht.DirectedGraph)2 DefaultDirectedGraph (org.apache.storm.shade.org.jgrapht.graph.DefaultDirectedGraph)2 LongSum (org.apache.storm.streams.operations.aggregators.LongSum)2 AggregateProcessor (org.apache.storm.streams.processors.AggregateProcessor)2 FilterProcessor (org.apache.storm.streams.processors.FilterProcessor)2 Processor (org.apache.storm.streams.processors.Processor)2 OutputCollector (org.apache.storm.task.OutputCollector)2 TopologyContext (org.apache.storm.task.TopologyContext)2 Fields (org.apache.storm.tuple.Fields)2 Tuple (org.apache.storm.tuple.Tuple)2 Values (org.apache.storm.tuple.Values)2 Assert.assertArrayEquals (org.junit.Assert.assertArrayEquals)2