Search in sources :

Example 6 with DistributionUpdate

use of com.google.api.services.dataflow.model.DistributionUpdate in project beam by apache.

the class CounterUpdateAggregatorsTest method testAggregateDistribution.

@Test
public void testAggregateDistribution() {
    List<CounterUpdate> distributionUpdates = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        distributionUpdates.add(new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setMetadata(new CounterMetadata().setKind(Kind.DISTRIBUTION.toString()))).setDistribution(new DistributionUpdate().setSum(longToSplitInt((long) i)).setMax(longToSplitInt((long) i)).setMin(longToSplitInt((long) i)).setCount(longToSplitInt((long) 1))));
    }
    List<CounterUpdate> aggregated = CounterUpdateAggregators.aggregate(distributionUpdates);
    assertEquals(1, aggregated.size());
    CounterUpdate combined = aggregated.get(0);
    assertEquals(45L, splitIntToLong(combined.getDistribution().getSum()));
    assertEquals(10L, splitIntToLong(combined.getDistribution().getCount()));
    assertEquals(9L, splitIntToLong(combined.getDistribution().getMax()));
    assertEquals(0L, splitIntToLong(combined.getDistribution().getMin()));
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) ArrayList(java.util.ArrayList) DistributionUpdate(com.google.api.services.dataflow.model.DistributionUpdate) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Test(org.junit.Test)

Aggregations

CounterStructuredNameAndMetadata (com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata)6 CounterUpdate (com.google.api.services.dataflow.model.CounterUpdate)6 DistributionUpdate (com.google.api.services.dataflow.model.DistributionUpdate)6 CounterMetadata (com.google.api.services.dataflow.model.CounterMetadata)5 CounterStructuredName (com.google.api.services.dataflow.model.CounterStructuredName)3 Test (org.junit.Test)3 Distribution (org.apache.beam.sdk.metrics.Distribution)2 ArrayList (java.util.ArrayList)1 DistributionData (org.apache.beam.runners.core.metrics.DistributionData)1 DataflowStepContext (org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 Before (org.junit.Before)1