use of com.hazelcast.jet.accumulator.LongAccumulator in project hazelcast by hazelcast.
the class AggregateOperation1Test method when_withCombiningAccumulateFn_then_accumulateFnCombines.
@Test
public void when_withCombiningAccumulateFn_then_accumulateFnCombines() {
// Given
AggregateOperation1<Object, LongAccumulator, Long> aggrOp = AggregateOperation.withCreate(LongAccumulator::new).andAccumulate((acc, item) -> acc.addAllowingOverflow(1)).andCombine(LongAccumulator::addAllowingOverflow).andExportFinish(LongAccumulator::get);
AggregateOperation1<LongAccumulator, LongAccumulator, Long> combiningAggrOp = aggrOp.withCombiningAccumulateFn(wholeItem());
BiConsumerEx<? super LongAccumulator, ? super LongAccumulator> accFn = combiningAggrOp.accumulateFn();
LongAccumulator partialAcc1 = combiningAggrOp.createFn().get();
LongAccumulator partialAcc2 = combiningAggrOp.createFn().get();
LongAccumulator combinedAcc = combiningAggrOp.createFn().get();
// When
partialAcc1.set(2);
partialAcc2.set(3);
accFn.accept(combinedAcc, partialAcc1);
accFn.accept(combinedAcc, partialAcc2);
// Then
assertEquals(5, combinedAcc.get());
}
use of com.hazelcast.jet.accumulator.LongAccumulator in project hazelcast by hazelcast.
the class AggregateOperation3Test method when_withIdentityFinish.
@Test
public void when_withIdentityFinish() {
// Given
AggregateOperation3<Object, Object, Object, LongAccumulator, Long> aggrOp = AggregateOperation.withCreate(LongAccumulator::new).andAccumulate0((acc, item) -> {
}).andAccumulate1((acc, item) -> {
}).andAccumulate2((acc, item) -> {
}).andExportFinish(LongAccumulator::get);
// When
AggregateOperation3<Object, Object, Object, LongAccumulator, LongAccumulator> newAggrOp = aggrOp.withIdentityFinish();
// Then
LongAccumulator acc = newAggrOp.createFn().get();
assertSame(acc, newAggrOp.finishFn().apply(acc));
}
use of com.hazelcast.jet.accumulator.LongAccumulator in project hazelcast-jet by hazelcast.
the class SessionWindowP_failoverTest method init.
private void init(ProcessingGuarantee guarantee) {
AggregateOperation1<Object, LongAccumulator, Long> aggrOp = counting();
p = new SessionWindowP<>(5000, singletonList((DistributedToLongFunction<Entry<?, Long>>) Entry::getValue), singletonList(entryKey()), aggrOp, WindowResult::new);
Outbox outbox = new TestOutbox(128);
Context context = new TestProcessorContext().setProcessingGuarantee(guarantee);
p.init(outbox, context);
}
use of com.hazelcast.jet.accumulator.LongAccumulator in project hazelcast-jet by hazelcast.
the class SlidingWindowP_failoverTest method init.
private void init(ProcessingGuarantee guarantee) {
SlidingWindowPolicy wDef = SlidingWindowPolicy.tumblingWinPolicy(1);
AggregateOperation1<Object, LongAccumulator, Long> aggrOp = counting();
p = new SlidingWindowP<>(singletonList(entryKey()), singletonList((DistributedToLongFunction<Entry<?, Long>>) Entry::getValue), wDef, aggrOp, TimestampedEntry::new, true);
Outbox outbox = new TestOutbox(128);
Context context = new TestProcessorContext().setProcessingGuarantee(guarantee);
p.init(outbox, context);
}
use of com.hazelcast.jet.accumulator.LongAccumulator in project hazelcast-jet by hazelcast.
the class AggregateOperation1Test method when_withCombiningAccumulateFn_then_accumulateFnCombines.
@Test
public void when_withCombiningAccumulateFn_then_accumulateFnCombines() {
// Given
AggregateOperation1<Object, LongAccumulator, LongAccumulator> aggrOp = AggregateOperation.withCreate(LongAccumulator::new).andAccumulate((acc, item) -> acc.addAllowingOverflow(1)).andCombine(LongAccumulator::addAllowingOverflow).andIdentityFinish();
AggregateOperation1<LongAccumulator, LongAccumulator, LongAccumulator> combiningAggrOp = aggrOp.withCombiningAccumulateFn(wholeItem());
DistributedBiConsumer<? super LongAccumulator, ? super LongAccumulator> accFn = combiningAggrOp.accumulateFn();
LongAccumulator partialAcc1 = combiningAggrOp.createFn().get();
LongAccumulator partialAcc2 = combiningAggrOp.createFn().get();
LongAccumulator combinedAcc = combiningAggrOp.createFn().get();
// When
partialAcc1.set(2);
partialAcc2.set(3);
accFn.accept(combinedAcc, partialAcc1);
accFn.accept(combinedAcc, partialAcc2);
// Then
assertEquals(5, combinedAcc.get());
}
Aggregations