Search in sources :

Example 21 with BasicClassicHttpResponse

use of org.apache.hc.core5.http.message.BasicClassicHttpResponse in project dialogue by palantir.

the class InactivityValidationAwareConnectionKeepAliveStrategyTest method testKeepAliveHeaderWithTimeoutAndMax.

@Test
void testKeepAliveHeaderWithTimeoutAndMax() {
    InactivityValidationAwareConnectionKeepAliveStrategy strategy = new InactivityValidationAwareConnectionKeepAliveStrategy(manager, "name");
    BasicClassicHttpResponse response = new BasicClassicHttpResponse(200);
    response.addHeader("Keep-Alive", "timeout=60, max=10");
    TimeValue value = strategy.getKeepAliveDuration(response, CONTEXT);
    TimeValue expected = TimeValue.ofSeconds(60);
    assertThat(value).isEqualTo(expected);
    verify(manager).setValidateAfterInactivity(eq(expected));
}
Also used : TimeValue(org.apache.hc.core5.util.TimeValue) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 22 with BasicClassicHttpResponse

use of org.apache.hc.core5.http.message.BasicClassicHttpResponse in project dialogue by palantir.

the class InactivityValidationAwareConnectionKeepAliveStrategyTest method testKeepAliveHeaderWithNegativeTimeout.

@Test
void testKeepAliveHeaderWithNegativeTimeout() {
    InactivityValidationAwareConnectionKeepAliveStrategy strategy = new InactivityValidationAwareConnectionKeepAliveStrategy(manager, "name");
    BasicClassicHttpResponse response = new BasicClassicHttpResponse(200);
    response.addHeader("Keep-Alive", "timeout=-1");
    TimeValue value = strategy.getKeepAliveDuration(response, CONTEXT);
    assertThat(value).isEqualTo(CONTEXT.getRequestConfig().getConnectionKeepAlive());
    verify(manager).setValidateAfterInactivity(eq(INITIAL_TIMEOUT));
}
Also used : TimeValue(org.apache.hc.core5.util.TimeValue) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 23 with BasicClassicHttpResponse

use of org.apache.hc.core5.http.message.BasicClassicHttpResponse in project dialogue by palantir.

the class InactivityValidationAwareConnectionKeepAliveStrategyTest method testNoKeepAliveHeader.

@Test
void testNoKeepAliveHeader() {
    InactivityValidationAwareConnectionKeepAliveStrategy strategy = new InactivityValidationAwareConnectionKeepAliveStrategy(manager, "name");
    BasicClassicHttpResponse response = new BasicClassicHttpResponse(200);
    TimeValue value = strategy.getKeepAliveDuration(response, CONTEXT);
    assertThat(value).isEqualTo(CONTEXT.getRequestConfig().getConnectionKeepAlive());
    verify(manager).setValidateAfterInactivity(eq(INITIAL_TIMEOUT));
}
Also used : TimeValue(org.apache.hc.core5.util.TimeValue) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 24 with BasicClassicHttpResponse

use of org.apache.hc.core5.http.message.BasicClassicHttpResponse in project dialogue by palantir.

the class InactivityValidationAwareConnectionKeepAliveStrategyTest method testKeepAliveHeaderWithTimeoutIgnoredNon2xx.

@Test
void testKeepAliveHeaderWithTimeoutIgnoredNon2xx() {
    InactivityValidationAwareConnectionKeepAliveStrategy strategy = new InactivityValidationAwareConnectionKeepAliveStrategy(manager, "name");
    BasicClassicHttpResponse response = new BasicClassicHttpResponse(500);
    response.addHeader("Keep-Alive", "timeout=60");
    TimeValue value = strategy.getKeepAliveDuration(response, CONTEXT);
    assertThat(value).isEqualTo(TimeValue.ofSeconds(60));
    verify(manager, never()).setValidateAfterInactivity(any());
}
Also used : TimeValue(org.apache.hc.core5.util.TimeValue) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 25 with BasicClassicHttpResponse

use of org.apache.hc.core5.http.message.BasicClassicHttpResponse in project dialogue by palantir.

the class InactivityValidationAwareConnectionKeepAliveStrategyTest method testKeepAliveHeaderWithTimeout.

@Test
void testKeepAliveHeaderWithTimeout() {
    InactivityValidationAwareConnectionKeepAliveStrategy strategy = new InactivityValidationAwareConnectionKeepAliveStrategy(manager, "name");
    BasicClassicHttpResponse response = new BasicClassicHttpResponse(200);
    response.addHeader("Keep-Alive", "timeout=60");
    TimeValue value = strategy.getKeepAliveDuration(response, CONTEXT);
    TimeValue expected = TimeValue.ofSeconds(60);
    assertThat(value).isEqualTo(expected);
    verify(manager).setValidateAfterInactivity(eq(expected));
}
Also used : TimeValue(org.apache.hc.core5.util.TimeValue) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

BasicClassicHttpResponse (org.apache.hc.core5.http.message.BasicClassicHttpResponse)69 Test (org.junit.jupiter.api.Test)57 ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)56 Header (org.apache.hc.core5.http.Header)34 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)29 BasicClassicHttpRequest (org.apache.hc.core5.http.message.BasicClassicHttpRequest)19 ClassicHttpRequest (org.apache.hc.core5.http.ClassicHttpRequest)14 StringEntity (org.apache.hc.core5.http.io.entity.StringEntity)13 HttpEntity (org.apache.hc.core5.http.HttpEntity)12 HttpCoreContext (org.apache.hc.core5.http.protocol.HttpCoreContext)11 HttpClientConnection (org.apache.hc.core5.http.io.HttpClientConnection)10 HttpProcessor (org.apache.hc.core5.http.protocol.HttpProcessor)10 BasicHttpEntity (org.apache.hc.core5.http.io.entity.BasicHttpEntity)9 TimeValue (org.apache.hc.core5.util.TimeValue)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IOException (java.io.IOException)6 HttpResponse (org.apache.hc.core5.http.HttpResponse)4 Timeout (org.apache.hc.core5.util.Timeout)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3