FnApiMonitoringInfoToCounterUpdateTransformer implements MonitoringInfoToCounterUpdateTransformer { @Override public @Nullable CounterUpdate transform(MonitoringInfo src) { MonitoringInfoToCounterUpdateTransformer transformer = urnToCounterTransformers.get(src.getUrn()); if (transformer == null) { return null; } return transformer.transform(src); } FnApiMonitoringInfoToCounterUpdateTransformer(
      Map<String, DataflowStepContext> stepContextMap,
      Map<String, NameContext> sdkPCollectionIdToNameContext); @VisibleForTesting  FnApiMonitoringInfoToCounterUpdateTransformer(
      Map<String, MonitoringInfoToCounterUpdateTransformer> urnToCounterTransformers); @Override @Nullable CounterUpdate transform(MonitoringInfo src);  }
@Test public void testTransformUtilizesRelevantCounterTransformer() { Map<String, MonitoringInfoToCounterUpdateTransformer> genericTransformers = new HashMap<>(); final String validUrn = "urn1"; final String validType = "type1"; genericTransformers.put(validUrn, mockTransformer1); genericTransformers.put("any:other:urn", mockTransformer2); FnApiMonitoringInfoToCounterUpdateTransformer testObject = new FnApiMonitoringInfoToCounterUpdateTransformer(genericTransformers); CounterUpdate expectedResult = new CounterUpdate(); when(mockTransformer1.transform(any())).thenReturn(expectedResult); MonitoringInfo monitoringInfo = MonitoringInfo.newBuilder() .setUrn(validUrn) .setType(validType) .putLabels(MonitoringInfoConstants.Labels.PTRANSFORM, "anyValue") .build(); CounterUpdate result = testObject.transform(monitoringInfo); assertSame(expectedResult, result); verifyZeroInteractions(mockTransformer2); }
@Test public void testTransformReturnsNullOnUnknownUrn() { Map<String, MonitoringInfoToCounterUpdateTransformer> genericTransformers = new HashMap<>(); final String validUrn = "known:urn"; final String validType = "known:type"; genericTransformers.put(validUrn, mockTransformer2); FnApiMonitoringInfoToCounterUpdateTransformer testObject = new FnApiMonitoringInfoToCounterUpdateTransformer(genericTransformers); MonitoringInfo unknownUrn = MonitoringInfo.newBuilder() .setUrn("unknown:urn") .setType(validType) .putLabels(MonitoringInfoConstants.Labels.PTRANSFORM, "anyValue") .build(); assertNull(testObject.transform(unknownUrn)); verifyZeroInteractions(mockTransformer1, mockTransformer2); }