use of org.apache.beam.runners.dataflow.worker.counters.NameContext in project beam by apache.
the class MeanByteCountMonitoringInfoToCounterUpdateTransformerTest method testTransformReturnsValidCounterUpdateWhenValidMonitoringInfoReceived.
@Test
public void testTransformReturnsValidCounterUpdateWhenValidMonitoringInfoReceived() throws Exception {
Map<String, NameContext> pcollectionNameMapping = new HashMap<>();
pcollectionNameMapping.put("anyValue", NameContext.create("anyStageName", "anyOriginName", "anySystemName", "transformedValue"));
MonitoringInfo monitoringInfo = MonitoringInfo.newBuilder().setUrn(Urns.SAMPLED_BYTE_SIZE).setType(TypeUrns.DISTRIBUTION_INT64_TYPE).putLabels(MonitoringInfoConstants.Labels.PCOLLECTION, "anyValue").setPayload(encodeInt64Distribution(DistributionData.create(2L, /* sum */
1L, /* count */
3L, /* min */
4L))).build();
MeanByteCountMonitoringInfoToCounterUpdateTransformer testObject = new MeanByteCountMonitoringInfoToCounterUpdateTransformer(mockSpecValidator, pcollectionNameMapping);
when(mockSpecValidator.validate(any())).thenReturn(Optional.empty());
CounterUpdate result = testObject.transform(monitoringInfo);
assertNotNull(result);
assertEqualsAsJson("{cumulative:true, integerMean:{count:{highBits:0, lowBits:1}, " + "sum:{highBits:0, lowBits:2}}, " + "nameAndKind:{kind:'MEAN', " + "name:'transformedValue-MeanByteCount'}}", result);
}
use of org.apache.beam.runners.dataflow.worker.counters.NameContext in project beam by apache.
the class MeanByteCountMonitoringInfoToCounterUpdateTransformerTest method testTransformThrowsIfMonitoringInfoWithWrongUrnReceived.
@Test
public void testTransformThrowsIfMonitoringInfoWithWrongUrnReceived() {
Map<String, NameContext> pcollectionNameMapping = new HashMap<>();
MonitoringInfo monitoringInfo = MonitoringInfo.newBuilder().setUrn(Urns.ELEMENT_COUNT).setType(TypeUrns.SUM_INT64_TYPE).build();
MeanByteCountMonitoringInfoToCounterUpdateTransformer testObject = new MeanByteCountMonitoringInfoToCounterUpdateTransformer(mockSpecValidator, pcollectionNameMapping);
when(mockSpecValidator.validate(any())).thenReturn(Optional.empty());
exception.expect(RuntimeException.class);
testObject.transform(monitoringInfo);
}
use of org.apache.beam.runners.dataflow.worker.counters.NameContext in project beam by apache.
the class ElementCountMonitoringInfoToCounterUpdateTransformerTest method testTransformReturnsNullIfMonitoringInfoWithUnknownPCollectionLabelPresent.
@Test
public void testTransformReturnsNullIfMonitoringInfoWithUnknownPCollectionLabelPresent() {
Map<String, NameContext> pcollectionNameMapping = new HashMap<>();
MonitoringInfo monitoringInfo = MonitoringInfo.newBuilder().setUrn(Urns.ELEMENT_COUNT).setType(TypeUrns.SUM_INT64_TYPE).putLabels(MonitoringInfoConstants.Labels.PCOLLECTION, "anyValue").build();
ElementCountMonitoringInfoToCounterUpdateTransformer testObject = new ElementCountMonitoringInfoToCounterUpdateTransformer(mockSpecValidator, pcollectionNameMapping);
when(mockSpecValidator.validate(any())).thenReturn(Optional.empty());
assertNull(testObject.transform(monitoringInfo));
}
use of org.apache.beam.runners.dataflow.worker.counters.NameContext in project beam by apache.
the class ElementCountMonitoringInfoToCounterUpdateTransformerTest method testTransformReturnsValidCounterUpdateWhenValidMonitoringInfoReceived.
@Test
public void testTransformReturnsValidCounterUpdateWhenValidMonitoringInfoReceived() throws Exception {
Map<String, NameContext> pcollectionNameMapping = new HashMap<>();
pcollectionNameMapping.put("anyValue", NameContext.create("anyStageName", "anyOriginName", "anySystemName", "transformedValue"));
MonitoringInfo monitoringInfo = MonitoringInfo.newBuilder().setUrn(Urns.ELEMENT_COUNT).setType(TypeUrns.SUM_INT64_TYPE).putLabels(MonitoringInfoConstants.Labels.PCOLLECTION, "anyValue").setPayload(encodeInt64Counter(1L)).build();
ElementCountMonitoringInfoToCounterUpdateTransformer testObject = new ElementCountMonitoringInfoToCounterUpdateTransformer(mockSpecValidator, pcollectionNameMapping);
when(mockSpecValidator.validate(any())).thenReturn(Optional.empty());
CounterUpdate result = testObject.transform(monitoringInfo);
assertNotNull(result);
assertEqualsAsJson("{cumulative:true, integer:{highBits:0, lowBits:1}, " + "nameAndKind:{kind:'SUM', " + "name:'transformedValue-ElementCount'}}", result);
}
use of org.apache.beam.runners.dataflow.worker.counters.NameContext in project beam by apache.
the class ElementCountMonitoringInfoToCounterUpdateTransformerTest method testTransformThrowsIfMonitoringInfoWithWrongUrnPrefixReceived.
@Test
public void testTransformThrowsIfMonitoringInfoWithWrongUrnPrefixReceived() {
Map<String, NameContext> pcollectionNameMapping = new HashMap<>();
MonitoringInfo monitoringInfo = MonitoringInfo.newBuilder().setUrn(Urns.USER_SUM_INT64).build();
ElementCountMonitoringInfoToCounterUpdateTransformer testObject = new ElementCountMonitoringInfoToCounterUpdateTransformer(mockSpecValidator, pcollectionNameMapping);
when(mockSpecValidator.validate(any())).thenReturn(Optional.empty());
exception.expect(RuntimeException.class);
testObject.transform(monitoringInfo);
}
Aggregations