Search in sources :

Example 1 with FrameworkTimingKeys

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(", ")));
}
Also used : LatencyInstrumentationResource(com.linkedin.restli.examples.instrumentation.server.LatencyInstrumentationResource) Arrays(java.util.Arrays) DataProvider(org.testng.annotations.DataProvider) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) AfterMethod(org.testng.annotations.AfterMethod) RestResponse(com.linkedin.r2.message.rest.RestResponse) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Request(com.linkedin.r2.message.Request) Assert(org.testng.Assert) RequestFinalizer(com.linkedin.r2.util.finalizer.RequestFinalizer) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) ResponseFuture(com.linkedin.restli.client.ResponseFuture) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) Map(java.util.Map) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) RequestContextUtil(com.linkedin.r2.util.RequestContextUtil) FilterChain(com.linkedin.r2.filter.FilterChain) FrameworkTimingKeys(com.linkedin.r2.message.timing.FrameworkTimingKeys) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) RestRequest(com.linkedin.r2.message.rest.RestRequest) SingleRetry(com.linkedin.test.util.retry.SingleRetry) StreamFilter(com.linkedin.r2.filter.message.stream.StreamFilter) FilterChains(com.linkedin.r2.filter.FilterChains) LatencyInstrumentationBuilders(com.linkedin.restli.examples.instrumentation.client.LatencyInstrumentationBuilders) Response(com.linkedin.r2.message.Response) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) Collection(java.util.Collection) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) InstrumentationControl(com.linkedin.restli.examples.instrumentation.api.InstrumentationControl) TimingKey(com.linkedin.r2.message.timing.TimingKey) RequestFinalizerManager(com.linkedin.r2.util.finalizer.RequestFinalizerManager) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) NextFilter(com.linkedin.r2.filter.NextFilter) RequestContext(com.linkedin.r2.message.RequestContext) CreateIdEntityRequest(com.linkedin.restli.client.CreateIdEntityRequest) RestFilter(com.linkedin.r2.filter.message.rest.RestFilter) TimingContextUtil(com.linkedin.r2.message.timing.TimingContextUtil) TimingImportance(com.linkedin.r2.message.timing.TimingImportance) Collections(java.util.Collections) TimingKey(com.linkedin.r2.message.timing.TimingKey)

Aggregations

RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)1 FilterChain (com.linkedin.r2.filter.FilterChain)1 FilterChains (com.linkedin.r2.filter.FilterChains)1 NextFilter (com.linkedin.r2.filter.NextFilter)1 RestFilter (com.linkedin.r2.filter.message.rest.RestFilter)1 StreamFilter (com.linkedin.r2.filter.message.stream.StreamFilter)1 Request (com.linkedin.r2.message.Request)1 RequestContext (com.linkedin.r2.message.RequestContext)1 Response (com.linkedin.r2.message.Response)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RestResponse (com.linkedin.r2.message.rest.RestResponse)1 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)1 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)1 FrameworkTimingKeys (com.linkedin.r2.message.timing.FrameworkTimingKeys)1 TimingContextUtil (com.linkedin.r2.message.timing.TimingContextUtil)1 TimingImportance (com.linkedin.r2.message.timing.TimingImportance)1 TimingKey (com.linkedin.r2.message.timing.TimingKey)1 RequestContextUtil (com.linkedin.r2.util.RequestContextUtil)1 RequestFinalizer (com.linkedin.r2.util.finalizer.RequestFinalizer)1 RequestFinalizerManager (com.linkedin.r2.util.finalizer.RequestFinalizerManager)1