Search in sources :

Example 36 with LongAccumulator

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());
}
Also used : LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) AggregateOperations.summingLong(com.hazelcast.jet.aggregate.AggregateOperations.summingLong) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 37 with LongAccumulator

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));
}
Also used : LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) FunctionEx(com.hazelcast.function.FunctionEx) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) BiConsumerEx(com.hazelcast.function.BiConsumerEx) Tag.tag2(com.hazelcast.jet.datamodel.Tag.tag2) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) SupplierEx(com.hazelcast.function.SupplierEx) Tag.tag1(com.hazelcast.jet.datamodel.Tag.tag1) Tag.tag0(com.hazelcast.jet.datamodel.Tag.tag0) Assert.assertSame(org.junit.Assert.assertSame) Tag.tag(com.hazelcast.jet.datamodel.Tag.tag) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) AggregateOperations.summingLong(com.hazelcast.jet.aggregate.AggregateOperations.summingLong) Functions.wholeItem(com.hazelcast.function.Functions.wholeItem) AggregateOperations.aggregateOperation3(com.hazelcast.jet.aggregate.AggregateOperations.aggregateOperation3) Assert.assertEquals(org.junit.Assert.assertEquals) Tuple3(com.hazelcast.jet.datamodel.Tuple3) AggregateOperations.summingLong(com.hazelcast.jet.aggregate.AggregateOperations.summingLong) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 38 with LongAccumulator

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);
}
Also used : LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Context(com.hazelcast.jet.core.Processor.Context) Entry(java.util.Map.Entry) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) Outbox(com.hazelcast.jet.core.Outbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext)

Example 39 with LongAccumulator

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);
}
Also used : LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Context(com.hazelcast.jet.core.Processor.Context) Entry(java.util.Map.Entry) TimestampedEntry(com.hazelcast.jet.datamodel.TimestampedEntry) SlidingWindowPolicy(com.hazelcast.jet.core.SlidingWindowPolicy) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) Outbox(com.hazelcast.jet.core.Outbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext)

Example 40 with LongAccumulator

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());
}
Also used : LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Test(org.junit.Test)

Aggregations

LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)43 Test (org.junit.Test)32 Category (org.junit.experimental.categories.Category)24 RunWith (org.junit.runner.RunWith)20 QuickTest (com.hazelcast.test.annotation.QuickTest)19 Arrays (java.util.Arrays)17 List (java.util.List)17 Assert.assertEquals (org.junit.Assert.assertEquals)17 Job (com.hazelcast.jet.Job)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)16 HazelcastInstance (com.hazelcast.core.HazelcastInstance)14 FunctionEx (com.hazelcast.function.FunctionEx)14 Pipeline (com.hazelcast.jet.pipeline.Pipeline)14 Util.entry (com.hazelcast.jet.Util.entry)13 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)13 Entry (java.util.Map.Entry)13 SupplierEx (com.hazelcast.function.SupplierEx)11 Sinks (com.hazelcast.jet.pipeline.Sinks)11 Tag.tag0 (com.hazelcast.jet.datamodel.Tag.tag0)10 Tag.tag1 (com.hazelcast.jet.datamodel.Tag.tag1)10