Search in sources :

Example 1 with LongLongAccumulator

use of com.hazelcast.jet.accumulator.LongLongAccumulator in project hazelcast by hazelcast.

the class StoreSnapshotTasklet method stateMachineStep.

private void stateMachineStep() {
    switch(state) {
        case DRAIN:
            progTracker.notDone();
            if (pendingEntry != null) {
                if (!ssWriter.offer(pendingEntry)) {
                    return;
                }
                progTracker.madeProgress();
            }
            pendingEntry = null;
            ProgressState result = inboundEdgeStream.drainTo(addToInboxFunction);
            if (result.isDone()) {
                assert ssWriter.isEmpty() : "input is done, but we had some entries and not the barrier";
                snapshotContext.storeSnapshotTaskletDone(pendingSnapshotId - 1, isHigherPrioritySource);
                state = DONE;
                progTracker.reset();
            }
            progTracker.madeProgress(result.isMadeProgress());
            if (hasReachedBarrier) {
                state = FLUSH;
                stateMachineStep();
            }
            break;
        case FLUSH:
            progTracker.notDone();
            if (ssWriter.flushAndResetMap()) {
                progTracker.madeProgress();
                state = REACHED_BARRIER;
            }
            break;
        case REACHED_BARRIER:
            if (ssWriter.hasPendingAsyncOps()) {
                progTracker.notDone();
                return;
            }
            // check for writing error
            Throwable error = ssWriter.getError();
            if (error != null) {
                logger.severe("Error writing to snapshot map", error);
                snapshotContext.reportError(error);
            }
            progTracker.madeProgress();
            long bytes = ssWriter.getTotalPayloadBytes();
            long keys = ssWriter.getTotalKeys();
            long chunks = ssWriter.getTotalChunks();
            snapshotContext.phase1DoneForTasklet(bytes, keys, chunks);
            metrics.set(new LongLongAccumulator(bytes, keys));
            ssWriter.resetStats();
            pendingSnapshotId++;
            hasReachedBarrier = false;
            state = DRAIN;
            progTracker.notDone();
            break;
        default:
            // note State.DONE also goes here
            throw new JetException("Unexpected state: " + state);
    }
}
Also used : LongLongAccumulator(com.hazelcast.jet.accumulator.LongLongAccumulator) ProgressState(com.hazelcast.jet.impl.util.ProgressState) JetException(com.hazelcast.jet.JetException)

Example 2 with LongLongAccumulator

use of com.hazelcast.jet.accumulator.LongLongAccumulator in project hazelcast by hazelcast.

the class AggregateOperationsTest method when_averagingLong_noInput_then_NaN.

@Test
public void when_averagingLong_noInput_then_NaN() {
    // Given
    AggregateOperation1<Long, LongLongAccumulator, Double> aggrOp = averagingLong(Long::longValue);
    LongLongAccumulator acc = aggrOp.createFn().get();
    // When
    double result = aggrOp.finishFn().apply(acc);
    // Then
    assertEquals(Double.NaN, result, 0.0);
}
Also used : LongLongAccumulator(com.hazelcast.jet.accumulator.LongLongAccumulator) AggregateOperations.averagingLong(com.hazelcast.jet.aggregate.AggregateOperations.averagingLong) AggregateOperations.summingLong(com.hazelcast.jet.aggregate.AggregateOperations.summingLong) AggregateOperations.averagingDouble(com.hazelcast.jet.aggregate.AggregateOperations.averagingDouble) AggregateOperations.summingDouble(com.hazelcast.jet.aggregate.AggregateOperations.summingDouble) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with LongLongAccumulator

use of com.hazelcast.jet.accumulator.LongLongAccumulator in project hazelcast-jet by hazelcast.

the class AggregateOperationsTest method when_averagingLongOverflow_thenException.

@Test
public void when_averagingLongOverflow_thenException() {
    // Given
    AggregateOperation1<Long, LongLongAccumulator, Double> aggrOp = averagingLong(Long::longValue);
    LongLongAccumulator acc = new LongLongAccumulator(Long.MAX_VALUE, 0L);
    // When and Then
    exception.expect(ArithmeticException.class);
    aggrOp.accumulateFn().accept(acc, 0L);
}
Also used : LongLongAccumulator(com.hazelcast.jet.accumulator.LongLongAccumulator) AggregateOperations.averagingLong(com.hazelcast.jet.aggregate.AggregateOperations.averagingLong) AggregateOperations.summingLong(com.hazelcast.jet.aggregate.AggregateOperations.summingLong) AggregateOperations.averagingDouble(com.hazelcast.jet.aggregate.AggregateOperations.averagingDouble) AggregateOperations.summingDouble(com.hazelcast.jet.aggregate.AggregateOperations.summingDouble) Test(org.junit.Test)

Example 4 with LongLongAccumulator

use of com.hazelcast.jet.accumulator.LongLongAccumulator in project hazelcast by hazelcast.

the class PipelineStreamTestSupport method streamStageFromList.

/**
 * The returned stream stage emits the items from the supplied list of
 * integers. It uses the integer as both timestamp and data.
 * <p>
 * The stage emits (1e9 / {@value SOURCE_EVENT_PERIOD_NANOS}) items per
 * second. After it exhausts the input, it remains idle forever.
 */
StreamStage<Integer> streamStageFromList(List<Integer> input, long earlyResultsPeriod) {
    Preconditions.checkPositive(earlyResultsPeriod, "earlyResultsPeriod must greater than zero");
    StreamSource<Integer> source = SourceBuilder.timestampedStream("sequence", x -> new LongLongAccumulator(System.nanoTime(), 0)).<Integer>fillBufferFn((deadline_emittedCount, buf) -> {
        int emittedCount = (int) deadline_emittedCount.get2();
        if (emittedCount == input.size() || System.nanoTime() < deadline_emittedCount.get1()) {
            return;
        }
        int item = input.get(emittedCount);
        buf.add(item, (long) item);
        deadline_emittedCount.add1(SOURCE_EVENT_PERIOD_NANOS);
        deadline_emittedCount.add2(1);
    }).build();
    return p.readFrom(source).withNativeTimestamps(2 * itemCount);
}
Also used : LongLongAccumulator(com.hazelcast.jet.accumulator.LongLongAccumulator) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Preconditions(com.hazelcast.internal.util.Preconditions) KeyedWindowResult(com.hazelcast.jet.datamodel.KeyedWindowResult) QuickTest(com.hazelcast.test.annotation.QuickTest) Category(org.junit.experimental.categories.Category) NavigableMap(java.util.NavigableMap) Function(java.util.function.Function) Long.max(java.lang.Long.max) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Stream(java.util.stream.Stream) LongLongAccumulator(com.hazelcast.jet.accumulator.LongLongAccumulator) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) SortedMap(java.util.SortedMap) WindowResult(com.hazelcast.jet.datamodel.WindowResult)

Example 5 with LongLongAccumulator

use of com.hazelcast.jet.accumulator.LongLongAccumulator in project hazelcast by hazelcast.

the class AggregateOperationsTest method when_averagingLong_sumTooLarge_then_exception.

@Test
public void when_averagingLong_sumTooLarge_then_exception() {
    // Given
    AggregateOperation1<Long, LongLongAccumulator, Double> aggrOp = averagingLong(Long::longValue);
    LongLongAccumulator acc = aggrOp.createFn().get();
    // Then
    exception.expect(ArithmeticException.class);
    // When
    aggrOp.accumulateFn().accept(acc, Long.MAX_VALUE);
    aggrOp.accumulateFn().accept(acc, 1L);
}
Also used : LongLongAccumulator(com.hazelcast.jet.accumulator.LongLongAccumulator) AggregateOperations.averagingLong(com.hazelcast.jet.aggregate.AggregateOperations.averagingLong) AggregateOperations.summingLong(com.hazelcast.jet.aggregate.AggregateOperations.summingLong) AggregateOperations.averagingDouble(com.hazelcast.jet.aggregate.AggregateOperations.averagingDouble) AggregateOperations.summingDouble(com.hazelcast.jet.aggregate.AggregateOperations.summingDouble) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

LongLongAccumulator (com.hazelcast.jet.accumulator.LongLongAccumulator)7 AggregateOperations.averagingDouble (com.hazelcast.jet.aggregate.AggregateOperations.averagingDouble)4 AggregateOperations.averagingLong (com.hazelcast.jet.aggregate.AggregateOperations.averagingLong)4 AggregateOperations.summingDouble (com.hazelcast.jet.aggregate.AggregateOperations.summingDouble)4 AggregateOperations.summingLong (com.hazelcast.jet.aggregate.AggregateOperations.summingLong)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 Preconditions (com.hazelcast.internal.util.Preconditions)1 JetException (com.hazelcast.jet.JetException)1 KeyedWindowResult (com.hazelcast.jet.datamodel.KeyedWindowResult)1 WindowResult (com.hazelcast.jet.datamodel.WindowResult)1 ProgressState (com.hazelcast.jet.impl.util.ProgressState)1 TestSources (com.hazelcast.jet.pipeline.test.TestSources)1 Long.max (java.lang.Long.max)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 NavigableMap (java.util.NavigableMap)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1