Search in sources :

Example 1 with KStreamSessionWindowAggregate

use of org.apache.kafka.streams.kstream.internals.KStreamSessionWindowAggregate in project kafka by apache.

the class GraphGraceSearchUtilTest method shouldExtractGraceFromKStreamSessionWindowAggregateNode.

@Test
public void shouldExtractGraceFromKStreamSessionWindowAggregateNode() {
    final SessionWindows windows = SessionWindows.ofInactivityGapAndGrace(ofMillis(10L), ofMillis(1234L));
    final StatefulProcessorNode<String, Long> node = new StatefulProcessorNode<>("asdf", new ProcessorParameters<>(new KStreamSessionWindowAggregate<String, Long, Integer>(windows, "asdf", null, null, null), "asdf"), (StoreBuilder<?>) null);
    final long extracted = GraphGraceSearchUtil.findAndVerifyWindowGrace(node);
    assertThat(extracted, is(windows.gracePeriodMs() + windows.inactivityGap()));
}
Also used : SessionWindows(org.apache.kafka.streams.kstream.SessionWindows) KStreamSessionWindowAggregate(org.apache.kafka.streams.kstream.internals.KStreamSessionWindowAggregate) Test(org.junit.Test)

Example 2 with KStreamSessionWindowAggregate

use of org.apache.kafka.streams.kstream.internals.KStreamSessionWindowAggregate in project kafka by apache.

the class GraphGraceSearchUtilTest method shouldExtractGraceFromSessionAncestorThroughStatefulParent.

@Test
public void shouldExtractGraceFromSessionAncestorThroughStatefulParent() {
    final SessionWindows windows = SessionWindows.ofInactivityGapAndGrace(ofMillis(10L), ofMillis(1234L));
    final StatefulProcessorNode<String, Long> graceGrandparent = new StatefulProcessorNode<>("asdf", new ProcessorParameters<>(new KStreamSessionWindowAggregate<String, Long, Integer>(windows, "asdf", null, null, null), "asdf"), (StoreBuilder<?>) null);
    final StatefulProcessorNode<String, Long> statefulParent = new StatefulProcessorNode<>("stateful", new ProcessorParameters<>(() -> new Processor<String, Long, String, Long>() {

        @Override
        public void init(final ProcessorContext<String, Long> context) {
        }

        @Override
        public void process(final Record<String, Long> record) {
        }

        @Override
        public void close() {
        }
    }, "dummy"), (StoreBuilder<?>) null);
    graceGrandparent.addChild(statefulParent);
    final ProcessorGraphNode<String, Long> node = new ProcessorGraphNode<>("stateless", null);
    statefulParent.addChild(node);
    final long extracted = GraphGraceSearchUtil.findAndVerifyWindowGrace(node);
    assertThat(extracted, is(windows.gracePeriodMs() + windows.inactivityGap()));
}
Also used : Processor(org.apache.kafka.streams.processor.api.Processor) ProcessorContext(org.apache.kafka.streams.processor.api.ProcessorContext) SessionWindows(org.apache.kafka.streams.kstream.SessionWindows) Record(org.apache.kafka.streams.processor.api.Record) KStreamSessionWindowAggregate(org.apache.kafka.streams.kstream.internals.KStreamSessionWindowAggregate) Test(org.junit.Test)

Example 3 with KStreamSessionWindowAggregate

use of org.apache.kafka.streams.kstream.internals.KStreamSessionWindowAggregate in project kafka by apache.

the class GraphGraceSearchUtilTest method shouldExtractGraceFromSessionAncestorThroughStatelessParent.

@Test
public void shouldExtractGraceFromSessionAncestorThroughStatelessParent() {
    final SessionWindows windows = SessionWindows.ofInactivityGapAndGrace(ofMillis(10L), ofMillis(1234L));
    final StatefulProcessorNode<String, Long> graceGrandparent = new StatefulProcessorNode<>("asdf", new ProcessorParameters<>(new KStreamSessionWindowAggregate<String, Long, Integer>(windows, "asdf", null, null, null), "asdf"), (StoreBuilder<?>) null);
    final ProcessorGraphNode<String, Long> statelessParent = new ProcessorGraphNode<>("stateless", null);
    graceGrandparent.addChild(statelessParent);
    final ProcessorGraphNode<String, Long> node = new ProcessorGraphNode<>("stateless", null);
    statelessParent.addChild(node);
    final long extracted = GraphGraceSearchUtil.findAndVerifyWindowGrace(node);
    assertThat(extracted, is(windows.gracePeriodMs() + windows.inactivityGap()));
}
Also used : SessionWindows(org.apache.kafka.streams.kstream.SessionWindows) KStreamSessionWindowAggregate(org.apache.kafka.streams.kstream.internals.KStreamSessionWindowAggregate) Test(org.junit.Test)

Example 4 with KStreamSessionWindowAggregate

use of org.apache.kafka.streams.kstream.internals.KStreamSessionWindowAggregate in project kafka by apache.

the class GraphGraceSearchUtil method extractGracePeriod.

@SuppressWarnings("rawtypes")
private static Long extractGracePeriod(final GraphNode node) {
    if (node instanceof StatefulProcessorNode) {
        final ProcessorSupplier processorSupplier = ((StatefulProcessorNode) node).processorParameters().processorSupplier();
        if (processorSupplier instanceof KStreamWindowAggregate) {
            final KStreamWindowAggregate kStreamWindowAggregate = (KStreamWindowAggregate) processorSupplier;
            final Windows windows = kStreamWindowAggregate.windows();
            return windows.gracePeriodMs();
        } else if (processorSupplier instanceof KStreamSessionWindowAggregate) {
            final KStreamSessionWindowAggregate kStreamSessionWindowAggregate = (KStreamSessionWindowAggregate) processorSupplier;
            final SessionWindows windows = kStreamSessionWindowAggregate.windows();
            return windows.gracePeriodMs() + windows.inactivityGap();
        } else if (processorSupplier instanceof KStreamSlidingWindowAggregate) {
            final KStreamSlidingWindowAggregate kStreamSlidingWindowAggregate = (KStreamSlidingWindowAggregate) processorSupplier;
            final SlidingWindows windows = kStreamSlidingWindowAggregate.windows();
            return windows.gracePeriodMs();
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : SessionWindows(org.apache.kafka.streams.kstream.SessionWindows) ProcessorSupplier(org.apache.kafka.streams.processor.api.ProcessorSupplier) SessionWindows(org.apache.kafka.streams.kstream.SessionWindows) Windows(org.apache.kafka.streams.kstream.Windows) SlidingWindows(org.apache.kafka.streams.kstream.SlidingWindows) KStreamSessionWindowAggregate(org.apache.kafka.streams.kstream.internals.KStreamSessionWindowAggregate) KStreamWindowAggregate(org.apache.kafka.streams.kstream.internals.KStreamWindowAggregate) KStreamSlidingWindowAggregate(org.apache.kafka.streams.kstream.internals.KStreamSlidingWindowAggregate) SlidingWindows(org.apache.kafka.streams.kstream.SlidingWindows)

Aggregations

SessionWindows (org.apache.kafka.streams.kstream.SessionWindows)4 KStreamSessionWindowAggregate (org.apache.kafka.streams.kstream.internals.KStreamSessionWindowAggregate)4 Test (org.junit.Test)3 SlidingWindows (org.apache.kafka.streams.kstream.SlidingWindows)1 Windows (org.apache.kafka.streams.kstream.Windows)1 KStreamSlidingWindowAggregate (org.apache.kafka.streams.kstream.internals.KStreamSlidingWindowAggregate)1 KStreamWindowAggregate (org.apache.kafka.streams.kstream.internals.KStreamWindowAggregate)1 Processor (org.apache.kafka.streams.processor.api.Processor)1 ProcessorContext (org.apache.kafka.streams.processor.api.ProcessorContext)1 ProcessorSupplier (org.apache.kafka.streams.processor.api.ProcessorSupplier)1 Record (org.apache.kafka.streams.processor.api.Record)1