use of com.linkedin.r2.message.timing.FrameworkTimingKeys in project rest.li by linkedin.
the class TestLatencyInstrumentation method checkTimingKeyCompleteness.
/**
* Ensures that the recorded timing keys are "complete", meaning that all keys which are expected to be present
* are present. Also ensures that no unexpected keys are present.
* @param forceException parameter from the test method
* @param timingImportanceThreshold parameter from the test method
*/
private void checkTimingKeyCompleteness(boolean forceException, TimingImportance timingImportanceThreshold, boolean useScatterGather) {
// Form the set of expected timing keys using the current test parameters
Set<TimingKey> expectedKeys = Arrays.stream(FrameworkTimingKeys.values()).map(FrameworkTimingKeys::key).filter(timingKey -> !(useScatterGather && timingKey.getName().startsWith(FrameworkTimingKeys.KEY_PREFIX + "client"))).filter(timingKey -> {
if (forceException) {
return !TIMING_KEYS_MISSING_ON_ERROR.contains(timingKey);
} else {
return !TIMING_KEYS_MISSING_ON_SUCCESS.contains(timingKey);
}
}).filter(timingKey -> !TIMING_KEYS_MISSING_ON_PROTOCOL_2_0_0.contains(timingKey)).filter(timingKey -> timingImportanceThreshold == null || TIMING_KEYS_ALWAYS_PRESENT.contains(timingKey) || timingKey.getTimingImportance().isAtLeast(timingImportanceThreshold)).collect(Collectors.toSet());
// Check that all keys have complete timings (not -1) and that there are no unexpected keys
for (TimingKey timingKey : _resultMap.keySet()) {
if (expectedKeys.contains(timingKey)) {
expectedKeys.remove(timingKey);
Assert.assertNotEquals(_resultMap.get(timingKey).getDurationNano(), -1, timingKey.getName() + " is -1");
} else if (timingKey.getName().contains(FrameworkTimingKeys.KEY_PREFIX)) {
Assert.fail("Encountered unexpected key: " + timingKey);
}
}
// Check that the set of recorded timing keys is "complete"
Assert.assertTrue(expectedKeys.isEmpty(), "Missing keys: " + expectedKeys.stream().map(key -> String.format("\"%s\"", key.getName())).collect(Collectors.joining(", ")));
}
Aggregations