use of com.hazelcast.jet.accumulator.LongAccumulator in project hazelcast-jet by hazelcast.
the class AggregateOperation2Test method when_withCombiningAccumulateFn_then_accumulateFnCombines.
@Test
public void when_withCombiningAccumulateFn_then_accumulateFnCombines() {
// Given
AggregateOperation2<Object, Object, LongAccumulator, LongAccumulator> aggrOp = AggregateOperation.withCreate(LongAccumulator::new).andAccumulate0((acc, item) -> acc.addAllowingOverflow(1)).andAccumulate1((acc, item) -> acc.addAllowingOverflow(10)).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());
}
use of com.hazelcast.jet.accumulator.LongAccumulator in project hazelcast-jet by hazelcast.
the class AggregateOperation3Test method when_withCombiningAccumulateFn_then_accumulateFnCombines.
@Test
public void when_withCombiningAccumulateFn_then_accumulateFnCombines() {
// Given
AggregateOperation3<Object, Object, Object, LongAccumulator, LongAccumulator> aggrOp = AggregateOperation.withCreate(LongAccumulator::new).andAccumulate0((acc, item) -> acc.addAllowingOverflow(1)).andAccumulate1((acc, item) -> acc.addAllowingOverflow(10)).andAccumulate2((acc, item) -> acc.addAllowingOverflow(100)).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());
}
use of com.hazelcast.jet.accumulator.LongAccumulator in project hazelcast-jet by hazelcast.
the class AggregateOperationTest method when_withCombiningAccumulateFn_then_accumulateFnCombines.
@Test
public void when_withCombiningAccumulateFn_then_accumulateFnCombines() {
// Given
AggregateOperation<LongAccumulator, Long> aggrOp = AggregateOperation.withCreate(LongAccumulator::new).andAccumulate(tag0(), (acc, item) -> acc.addAllowingOverflow(1)).andAccumulate(tag1(), (acc, item) -> acc.addAllowingOverflow(10)).andCombine(LongAccumulator::addAllowingOverflow).andFinish(LongAccumulator::get);
AggregateOperation1<LongAccumulator, LongAccumulator, Long> combiningAggrOp = aggrOp.withCombiningAccumulateFn(wholeItem());
DistributedBiConsumer<? super LongAccumulator, ? super Object> accFn = combiningAggrOp.accumulateFn(tag0());
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