use of com.hazelcast.jet.function.DistributedSupplier in project hazelcast-jet by hazelcast.
the class SlidingWindowPTest method before.
@Before
public void before() {
SlidingWindowPolicy windowDef = slidingWinPolicy(4, 1);
AggregateOperation1<Entry<?, Long>, LongAccumulator, Long> operation = AggregateOperation.withCreate(LongAccumulator::new).andAccumulate((LongAccumulator acc, Entry<?, Long> item) -> acc.add(item.getValue())).andCombine(LongAccumulator::add).andDeduct(hasDeduct ? LongAccumulator::subtract : null).andFinish(LongAccumulator::get);
DistributedFunction<?, Long> keyFn = t -> KEY;
DistributedToLongFunction<Entry<Long, Long>> timestampFn = Entry::getKey;
DistributedSupplier<Processor> procSupplier = singleStageProcessor ? aggregateToSlidingWindowP(singletonList(keyFn), singletonList(timestampFn), TimestampKind.EVENT, windowDef, operation, TimestampedEntry::new) : combineToSlidingWindowP(windowDef, operation, TimestampedEntry::new);
// new supplier to save the last supplied instance
supplier = () -> lastSuppliedProcessor = (SlidingWindowP) procSupplier.get();
}
use of com.hazelcast.jet.function.DistributedSupplier in project hazelcast-jet by hazelcast.
the class SlidingWindowP_CoGroupTest method test.
@Test
public void test() {
DistributedSupplier supplier = Processors.aggregateToSlidingWindowP(asList(entryKey(), entryKey()), asList(t -> 1L, t -> 1L), TimestampKind.FRAME, tumblingWinPolicy(1), AggregateOperations.toTwoBags(), TimestampedEntry::new);
Entry<String, String> entry1 = entry("k1", "a");
Entry<String, String> entry2 = entry("k2", "b");
Entry<String, String> entry3 = entry("k1", "c");
Entry<String, String> entry4 = entry("k3", "d");
Entry<String, String> entry5 = entry("k1", "e");
TestSupport.verifyProcessor(supplier).inputs(asList(asList(entry1, entry2), asList(entry3, entry4, entry5))).expectOutput(asList(new TimestampedEntry<>(1, "k1", twoBags(singletonList(entry1), asList(entry3, entry5))), new TimestampedEntry<>(1, "k2", twoBags(singletonList(entry2), emptyList())), new TimestampedEntry<>(1, "k3", twoBags(emptyList(), singletonList(entry4)))));
}
Aggregations