Search in sources :

Example 1 with UdafAggregator

use of io.confluent.ksql.function.UdafAggregator in project ksql by confluentinc.

the class HoppingWindowExpressionTest method shouldCreateHoppingWindowAggregate.

@Test
public void shouldCreateHoppingWindowAggregate() {
    final KGroupedStream stream = EasyMock.createNiceMock(KGroupedStream.class);
    final TimeWindowedKStream windowedKStream = EasyMock.createNiceMock(TimeWindowedKStream.class);
    final UdafAggregator aggregator = EasyMock.createNiceMock(UdafAggregator.class);
    final HoppingWindowExpression windowExpression = new HoppingWindowExpression(10, TimeUnit.SECONDS, 4, TimeUnit.MILLISECONDS);
    final Initializer initializer = () -> 0;
    final Materialized<String, GenericRow, WindowStore<Bytes, byte[]>> store = Materialized.as("store");
    EasyMock.expect(stream.windowedBy(TimeWindows.of(10000L).advanceBy(4L))).andReturn(windowedKStream);
    EasyMock.expect(windowedKStream.aggregate(same(initializer), same(aggregator), same(store))).andReturn(null);
    EasyMock.replay(stream, windowedKStream);
    windowExpression.applyAggregate(stream, initializer, aggregator, store);
    EasyMock.verify(stream, windowedKStream);
}
Also used : GenericRow(io.confluent.ksql.GenericRow) WindowStore(org.apache.kafka.streams.state.WindowStore) KGroupedStream(org.apache.kafka.streams.kstream.KGroupedStream) Initializer(org.apache.kafka.streams.kstream.Initializer) TimeWindowedKStream(org.apache.kafka.streams.kstream.TimeWindowedKStream) UdafAggregator(io.confluent.ksql.function.UdafAggregator) Test(org.junit.Test)

Example 2 with UdafAggregator

use of io.confluent.ksql.function.UdafAggregator in project ksql by confluentinc.

the class TumblingWindowExpressionTest method shouldCreateTumblingWindowAggregate.

@Test
public void shouldCreateTumblingWindowAggregate() {
    final KGroupedStream stream = EasyMock.createNiceMock(KGroupedStream.class);
    final TimeWindowedKStream windowedKStream = EasyMock.createNiceMock(TimeWindowedKStream.class);
    final UdafAggregator aggregator = EasyMock.createNiceMock(UdafAggregator.class);
    final TumblingWindowExpression windowExpression = new TumblingWindowExpression(10, TimeUnit.SECONDS);
    final Initializer initializer = () -> 0;
    final Materialized<String, GenericRow, WindowStore<Bytes, byte[]>> store = Materialized.as("store");
    EasyMock.expect(stream.windowedBy(TimeWindows.of(10000L))).andReturn(windowedKStream);
    EasyMock.expect(windowedKStream.aggregate(same(initializer), same(aggregator), same(store))).andReturn(null);
    EasyMock.replay(stream, windowedKStream);
    windowExpression.applyAggregate(stream, initializer, aggregator, store);
    EasyMock.verify(stream, windowedKStream);
}
Also used : GenericRow(io.confluent.ksql.GenericRow) WindowStore(org.apache.kafka.streams.state.WindowStore) KGroupedStream(org.apache.kafka.streams.kstream.KGroupedStream) Initializer(org.apache.kafka.streams.kstream.Initializer) TimeWindowedKStream(org.apache.kafka.streams.kstream.TimeWindowedKStream) UdafAggregator(io.confluent.ksql.function.UdafAggregator) Test(org.junit.Test)

Aggregations

GenericRow (io.confluent.ksql.GenericRow)2 UdafAggregator (io.confluent.ksql.function.UdafAggregator)2 Initializer (org.apache.kafka.streams.kstream.Initializer)2 KGroupedStream (org.apache.kafka.streams.kstream.KGroupedStream)2 TimeWindowedKStream (org.apache.kafka.streams.kstream.TimeWindowedKStream)2 WindowStore (org.apache.kafka.streams.state.WindowStore)2 Test (org.junit.Test)2