use of com.linkedin.r2.message.timing.TimingImportance 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(", ")));
}
use of com.linkedin.r2.message.timing.TimingImportance in project rest.li by linkedin.
the class TestTimingCallback method testBuilder.
/**
* Ensures that the builder can correctly determine how to filter out timing keys based on the current timing
* importance threshold, and that it can correctly determine when to return the original callback rather than wrapping
* it with a new one.
* @param timingImportanceThreshold timing importance threshold
*/
@Test(dataProvider = "timingImportanceThreshold")
public void testBuilder(TimingImportance timingImportanceThreshold) {
final RequestContext requestContext = new RequestContext();
if (timingImportanceThreshold != null) {
requestContext.putLocalAttr(TimingContextUtil.TIMING_IMPORTANCE_THRESHOLD_KEY_NAME, timingImportanceThreshold);
}
final Callback<Long> callback = new Callback<Long>() {
@Override
public void onSuccess(Long result) {
Map<TimingKey, TimingContextUtil.TimingContext> timings = TimingContextUtil.getTimingsMap(requestContext);
// Ensure that keys have been filtered out correctly
if (timingImportanceThreshold == null || TimingImportance.LOW.isAtLeast(timingImportanceThreshold)) {
Assert.assertTrue(timings.containsKey(KEY_L));
Assert.assertTrue(timings.containsKey(KEY_M));
} else if (TimingImportance.MEDIUM.isAtLeast(timingImportanceThreshold)) {
Assert.assertFalse(timings.containsKey(KEY_L));
Assert.assertTrue(timings.containsKey(KEY_M));
} else {
Assert.assertFalse(timings.containsKey(KEY_L));
Assert.assertFalse(timings.containsKey(KEY_M));
}
}
@Override
public void onError(Throwable e) {
}
};
final Callback<Long> timingCallback = new TimingCallback.Builder<>(callback, requestContext).addBeginTimingKey(KEY_L).addBeginTimingKey(KEY_M).addEndTimingKey(KEY_L).addEndTimingKey(KEY_M).build();
// Ensure that the builder can correctly determine when to return the original callback
if (timingImportanceThreshold == null || !timingImportanceThreshold.equals(TimingImportance.HIGH)) {
Assert.assertTrue(timingCallback instanceof TimingCallback);
} else {
Assert.assertFalse(timingCallback instanceof TimingCallback);
}
timingCallback.onSuccess(1L);
}
use of com.linkedin.r2.message.timing.TimingImportance in project rest.li by linkedin.
the class TestLatencyInstrumentation method provideLatencyInstrumentationData.
@DataProvider(name = "latencyInstrumentation")
private Object[][] provideLatencyInstrumentationData() {
List<Object[]> data = new ArrayList<>();
boolean[] booleanOptions = new boolean[] { true, false };
Collection<TimingImportance> timingImportanceOptions = new ArrayList<>(Arrays.asList(TimingImportance.values()));
timingImportanceOptions.add(null);
for (boolean useStreaming : booleanOptions) {
for (boolean forceException : booleanOptions) {
for (boolean useScatterGather : booleanOptions) {
for (TimingImportance timingImportanceThreshold : timingImportanceOptions) {
data.add(new Object[] { useStreaming, forceException, useScatterGather, timingImportanceThreshold });
}
}
}
}
return data.toArray(new Object[data.size()][4]);
}
use of com.linkedin.r2.message.timing.TimingImportance in project rest.li by linkedin.
the class TestLatencyInstrumentation method beforeMethod.
@BeforeMethod
public void beforeMethod(Object[] args) throws Exception {
_countDownLatch = new CountDownLatch(1);
_useStreaming = (boolean) args[0];
_timingImportanceThreshold = (TimingImportance) args[3];
final InstrumentationTrackingFilter instrumentationTrackingFilter = new InstrumentationTrackingFilter();
final FilterChain filterChain = FilterChains.empty().addFirst(instrumentationTrackingFilter).addFirstRest(instrumentationTrackingFilter);
// System.setProperty("test.useStreamCodecServer", "true"); // Uncomment this to test with server streaming codec in IDEA
super.init(Collections.emptyList(), filterChain, false);
}
Aggregations