use of com.hazelcast.jet.accumulator.LongAccumulator in project hazelcast by hazelcast.
the class MetricsTest method customUnit_notUsed.
@Test
public void customUnit_notUsed() {
pipeline.readFrom(TestSources.items(0L, 1L, 2L, 3L, 4L)).mapStateful(LongAccumulator::new, (acc, i) -> {
acc.add(i);
Metrics.metric("sum", Unit.COUNT);
return acc.get();
}).writeTo(Sinks.noop());
Job job = runPipeline(pipeline.toDag());
JobMetricsChecker checker = new JobMetricsChecker(job);
checker.assertSummedMetricValue("sum", 0L);
}
use of com.hazelcast.jet.accumulator.LongAccumulator in project hazelcast by hazelcast.
the class OrderedStreamParallelismTest method applyTransformAndGetDag.
private DAG applyTransformAndGetDag(FunctionEx<StreamStage<Integer>, StreamStage<Integer>> transform) {
PipelineImpl p = (PipelineImpl) Pipeline.create().setPreserveOrder(true);
StreamStage<Integer> source = p.readFrom(TestSources.items(1)).setLocalParallelism(UPSTREAM_PARALLELISM).addTimestamps(t -> 0, Long.MAX_VALUE);
StreamStage<Integer> applied = source.apply(transform);
applied.mapStateful(LongAccumulator::new, (s, x) -> x).writeTo(Sinks.noop());
return p.toDag(PIPELINE_CTX);
}
use of com.hazelcast.jet.accumulator.LongAccumulator in project hazelcast by hazelcast.
the class OrderedProcessingMultipleMemberTest method orderValidator.
private boolean orderValidator(LongAccumulator[] s, Long key, Map.Entry<Long, Long> entry) {
LongAccumulator acc = s[key.intValue()];
long value = entry.getValue();
if (acc.get() >= value) {
return false;
} else {
acc.set(value);
return true;
}
}
use of com.hazelcast.jet.accumulator.LongAccumulator in project hazelcast by hazelcast.
the class AggregateOperation2Test method when_withIdentityFinish.
@Test
public void when_withIdentityFinish() {
// Given
AggregateOperation2<Object, Object, LongAccumulator, Long> aggrOp = AggregateOperation.withCreate(LongAccumulator::new).andAccumulate0((acc, item) -> acc.addAllowingOverflow(1)).andAccumulate1((acc, item) -> acc.addAllowingOverflow(1)).andExportFinish(LongAccumulator::get);
// When
AggregateOperation2<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 by hazelcast.
the class AggregateOperation1Test method when_andThen_then_exportAndFinishChanged.
@Test
public void when_andThen_then_exportAndFinishChanged() {
// Given
AggregateOperation1<Long, LongAccumulator, Long> aggrOp = summingLong((Long x) -> x);
// When
AggregateOperation1<Long, LongAccumulator, Long> incAggrOp = aggrOp.andThen(a -> a + 1);
// Then
LongAccumulator acc = incAggrOp.createFn().get();
incAggrOp.accumulateFn().accept(acc, 13L);
long exported = incAggrOp.exportFn().apply(acc);
long finished = incAggrOp.finishFn().apply(acc);
assertEquals(14L, exported);
assertEquals(14L, finished);
}
Aggregations