public String lookup(final String name, final String uriParamName, final boolean isReLookup)
    {
        final long beginNs = clock.nanoTime();
        maxTimeTracker.update(beginNs);
        String resolvedName = null;
        try
        {
            resolvedName = delegateResolver.lookup(name, uriParamName, isReLookup);
            return resolvedName;
        }
        finally
        {
            final long endNs = clock.nanoTime();
            maxTimeTracker.measureAndUpdate(endNs);
            logLookup(delegateResolver.getClass().getSimpleName(), endNs - beginNs, name, isReLookup, resolvedName);
        }
    }
@Test
    void lookupShouldMeasureExecutionTime()
    {
        final NameResolver delegateResolver = mock(NameResolver.class);
        when(delegateResolver.lookup(anyString(), anyString(), anyBoolean()))
            .thenAnswer(invocation ->
            {
                final String name = invocation.getArgument(0);
                return name.substring(0, name.indexOf(':'));
            });
        final NanoClock clock = mock(NanoClock.class);
        final long beginNs = 0;
        final long endNs = 123456789;
        when(clock.nanoTime()).thenReturn(beginNs, endNs);
        final DutyCycleTracker maxTime = mock(DutyCycleTracker.class);
        final TimeTrackingNameResolver resolver = new TimeTrackingNameResolver(delegateResolver, clock, maxTime);

        final String name = "my-host:8080";
        final String endpoint = "endpoint";
        final boolean isReLookup = false;
        assertEquals("my-host", resolver.lookup(name, endpoint, isReLookup));

        final InOrder inOrder = inOrder(delegateResolver, clock, maxTime);
        inOrder.verify(clock).nanoTime();
        inOrder.verify(maxTime).update(beginNs);
        inOrder.verify(delegateResolver).lookup(name, endpoint, isReLookup);
        inOrder.verify(clock).nanoTime();
        inOrder.verify(maxTime).measureAndUpdate(endNs);
        inOrder.verifyNoMoreInteractions();
    }