@Test
    void testLimitedRequest() throws Exception {
        final ClientRequestContext ctx1 = newContext();
        final ClientRequestContext ctx2 = newContext();
        final HttpRequest req1 = newReq();
        final HttpRequest req2 = newReq();
        final HttpResponseWriter actualRes1 = HttpResponse.streaming();
        final HttpResponseWriter actualRes2 = HttpResponse.streaming();

        when(delegate.execute(ctx1, req1)).thenReturn(actualRes1);
        when(delegate.execute(ctx2, req2)).thenReturn(actualRes2);

        final ConcurrencyLimitingClient client =
                newDecorator(1).apply(delegate);

        // The first request should be delegated immediately.
        final HttpResponse res1 = client.execute(ctx1, req1);
        await().untilAsserted(() -> verify(delegate).execute(ctx1, req1));
        assertThat(res1.isOpen()).isTrue();

        final HttpResponse res2 = client.execute(ctx2, req2);
        // The second request should never be delegated until the first response is closed.
        Thread.sleep(200);
        verify(delegate, never()).execute(ctx2, req2);
        assertThat(res2.isOpen()).isTrue();
        assertThat(client.numActiveRequests()).isEqualTo(1); // Only req1 is active.

        // Complete res1.
        closeAndDrain(actualRes1, res1);

        // Once res1 is complete, req2 should be delegated.
        await().untilAsserted(() -> verify(delegate).execute(ctx2, req2));
        assertThat(client.numActiveRequests()).isEqualTo(1); // Only req2 is active.

        // Complete res2, leaving no active requests.
        closeAndDrain(actualRes2, res2);
        await().untilAsserted(() -> assertThat(client.numActiveRequests()).isZero());
    }
Tests the request pattern that exceeds maxConcurrency.
core/src/test/java/com/linecorp/armeria/client/limit/ConcurrencyLimitingClientTest.java