Search in sources :

Example 6 with AccumulatorProvider

use of org.apache.beam.sdk.extensions.euphoria.core.client.accumulators.AccumulatorProvider in project beam by apache.

the class SingleValueCollectorTest method testBasicAccumulatorsFunction.

@Test
public void testBasicAccumulatorsFunction() {
    final AccumulatorProvider accumulators = accumulatorFactory.create();
    SingleValueCollector collector = new SingleValueCollector(accumulators, "test-no_op_name");
    Counter counter = collector.getCounter(TEST_COUNTER_NAME);
    Assert.assertNotNull(counter);
    counter.increment();
    counter.increment(2);
    Map<String, Long> counterSnapshots = accumulatorFactory.getCounterSnapshots();
    long counteValue = counterSnapshots.get(TEST_COUNTER_NAME);
    Assert.assertEquals(3L, counteValue);
    Histogram histogram = collector.getHistogram(TEST_HISTOGRAM_NAME);
    Assert.assertNotNull(histogram);
    histogram.add(1);
    histogram.add(2, 2);
    Map<String, Map<Long, Long>> histogramSnapshots = accumulatorFactory.getHistogramSnapshots();
    Map<Long, Long> histogramValue = histogramSnapshots.get(TEST_HISTOGRAM_NAME);
    long numOfValuesOfOne = histogramValue.get(1L);
    Assert.assertEquals(1L, numOfValuesOfOne);
    long numOfValuesOfTwo = histogramValue.get(2L);
    Assert.assertEquals(2L, numOfValuesOfTwo);
// collector.getTimer() <- not yet supported
}
Also used : Histogram(org.apache.beam.sdk.extensions.euphoria.core.client.accumulators.Histogram) Counter(org.apache.beam.sdk.extensions.euphoria.core.client.accumulators.Counter) Map(java.util.Map) SingleJvmAccumulatorProvider(org.apache.beam.sdk.extensions.euphoria.core.testkit.accumulators.SingleJvmAccumulatorProvider) AccumulatorProvider(org.apache.beam.sdk.extensions.euphoria.core.client.accumulators.AccumulatorProvider) Test(org.junit.Test)

Aggregations

AccumulatorProvider (org.apache.beam.sdk.extensions.euphoria.core.client.accumulators.AccumulatorProvider)6 Counter (org.apache.beam.sdk.extensions.euphoria.core.client.accumulators.Counter)3 Histogram (org.apache.beam.sdk.extensions.euphoria.core.client.accumulators.Histogram)3 SingleJvmAccumulatorProvider (org.apache.beam.sdk.extensions.euphoria.core.testkit.accumulators.SingleJvmAccumulatorProvider)3 Test (org.junit.Test)3 Map (java.util.Map)2 Objects.requireNonNull (java.util.Objects.requireNonNull)1 StreamSupport (java.util.stream.StreamSupport)1 CannotProvideCoderException (org.apache.beam.sdk.coders.CannotProvideCoderException)1 Coder (org.apache.beam.sdk.coders.Coder)1 CoderRegistry (org.apache.beam.sdk.coders.CoderRegistry)1 BinaryFunction (org.apache.beam.sdk.extensions.euphoria.core.client.functional.BinaryFunction)1 CombinableBinaryFunction (org.apache.beam.sdk.extensions.euphoria.core.client.functional.CombinableBinaryFunction)1 ReduceFunctor (org.apache.beam.sdk.extensions.euphoria.core.client.functional.ReduceFunctor)1 UnaryFunction (org.apache.beam.sdk.extensions.euphoria.core.client.functional.UnaryFunction)1 VoidFunction (org.apache.beam.sdk.extensions.euphoria.core.client.functional.VoidFunction)1 ReduceByKey (org.apache.beam.sdk.extensions.euphoria.core.client.operator.ReduceByKey)1 TypeAwareness (org.apache.beam.sdk.extensions.euphoria.core.client.type.TypeAwareness)1 PCollectionLists (org.apache.beam.sdk.extensions.euphoria.core.client.util.PCollectionLists)1 AdaptableCollector (org.apache.beam.sdk.extensions.euphoria.core.translate.collector.AdaptableCollector)1