Search in sources :

Example 1 with HostMetricsRegistry

use of com.palantir.conjure.java.okhttp.HostMetricsRegistry in project conjure-java by palantir.

the class UndertowServiceEteTest method jaxrs_client_can_make_a_call_to_an_empty_path.

@Test
public void jaxrs_client_can_make_a_call_to_an_empty_path() {
    EmptyPathService emptyPathClient = JaxRsClient.create(EmptyPathService.class, clientUserAgent(), new HostMetricsRegistry(), clientConfiguration());
    assertThat(emptyPathClient.emptyPath()).isTrue();
}
Also used : EmptyPathService(com.palantir.product.EmptyPathService) HostMetricsRegistry(com.palantir.conjure.java.okhttp.HostMetricsRegistry) Test(org.junit.jupiter.api.Test)

Example 2 with HostMetricsRegistry

use of com.palantir.conjure.java.okhttp.HostMetricsRegistry in project conjure-java-runtime by palantir.

the class JaxRsClientCollectionHandlingTest method before.

@Before
public void before() {
    proxy = JaxRsClient.create(Service.class, AGENT, new HostMetricsRegistry(), createTestConfig("http://localhost:" + server.getPort()));
    MockResponse mockResponse = new MockResponse().setResponseCode(code).setBody(body);
    server.enqueue(mockResponse);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HostMetricsRegistry(com.palantir.conjure.java.okhttp.HostMetricsRegistry) Before(org.junit.Before)

Example 3 with HostMetricsRegistry

use of com.palantir.conjure.java.okhttp.HostMetricsRegistry in project conjure-java-runtime by palantir.

the class JaxRsClientConfigRefreshTest method testConfigRefresh.

@Test
public void testConfigRefresh() throws Exception {
    ClientConfiguration config1 = createTestConfig("http://localhost:" + server1.getPort());
    ClientConfiguration config2 = createTestConfig("http://localhost:" + server2.getPort());
    Refreshable<ClientConfiguration> refreshableConfig = Refreshable.of(config1);
    TestService proxy = JaxRsClient.create(TestService.class, UserAgents.tryParse("agent"), new HostMetricsRegistry(), refreshableConfig);
    // Call 1
    server1.enqueue(new MockResponse().setBody("\"server1\""));
    assertThat(proxy.string()).isEqualTo("server1");
    assertThat(server1.getRequestCount()).isEqualTo(1);
    assertThat(server2.getRequestCount()).isZero();
    // Call 2
    server1.enqueue(new MockResponse().setBody("\"server1\""));
    assertThat(proxy.string()).isEqualTo("server1");
    assertThat(server1.getRequestCount()).isEqualTo(2);
    assertThat(server2.getRequestCount()).isZero();
    // Switch config
    refreshableConfig.set(config2);
    // Call 3
    server2.enqueue(new MockResponse().setBody("\"server2\""));
    assertThat(proxy.string()).isEqualTo("server2");
    assertThat(server1.getRequestCount()).isEqualTo(2);
    assertThat(server2.getRequestCount()).isEqualTo(1);
    // Call 4
    server2.enqueue(new MockResponse().setBody("\"server2\""));
    assertThat(proxy.string()).isEqualTo("server2");
    assertThat(server1.getRequestCount()).isEqualTo(2);
    assertThat(server2.getRequestCount()).isEqualTo(2);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) HostMetricsRegistry(com.palantir.conjure.java.okhttp.HostMetricsRegistry) Test(org.junit.Test)

Example 4 with HostMetricsRegistry

use of com.palantir.conjure.java.okhttp.HostMetricsRegistry in project conjure-java-runtime by palantir.

the class JaxRsClientFailoverTest method testQosError_performsRetryWithOneNodeAndCache.

@Test
public void testQosError_performsRetryWithOneNodeAndCache() throws Exception {
    MockWebServer server1 = new MockWebServer();
    server1.enqueue(new MockResponse().setResponseCode(503));
    server1.enqueue(new MockResponse().setBody("\"foo\""));
    TestService anotherProxy = JaxRsClient.create(TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder().from(createTestConfig("http://localhost:" + server1.getPort())).maxNumRetries(2).failedUrlCooldown(Duration.ofMillis(CACHE_DURATION)).build());
    assertThat(anotherProxy.string()).isEqualTo("foo");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) MockWebServer(okhttp3.mockwebserver.MockWebServer) HostMetricsRegistry(com.palantir.conjure.java.okhttp.HostMetricsRegistry) Test(org.junit.Test)

Example 5 with HostMetricsRegistry

use of com.palantir.conjure.java.okhttp.HostMetricsRegistry in project conjure-java-runtime by palantir.

the class JaxRsClientFailoverTest method testQosError_performsRetryWithOneNode.

@Test
public void testQosError_performsRetryWithOneNode() throws Exception {
    MockWebServer server1 = new MockWebServer();
    server1.enqueue(new MockResponse().setResponseCode(503));
    server1.enqueue(new MockResponse().setBody("\"foo\""));
    TestService anotherProxy = JaxRsClient.create(TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder().from(createTestConfig("http://localhost:" + server1.getPort())).maxNumRetries(2).build());
    assertThat(anotherProxy.string()).isEqualTo("foo");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) MockWebServer(okhttp3.mockwebserver.MockWebServer) HostMetricsRegistry(com.palantir.conjure.java.okhttp.HostMetricsRegistry) Test(org.junit.Test)

Aggregations

HostMetricsRegistry (com.palantir.conjure.java.okhttp.HostMetricsRegistry)32 Test (org.junit.Test)25 MockResponse (okhttp3.mockwebserver.MockResponse)24 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)10 MockWebServer (okhttp3.mockwebserver.MockWebServer)8 ClientConfiguration (com.palantir.conjure.java.client.config.ClientConfiguration)6 TestService (com.palantir.conjure.java.client.jaxrs.TestService)4 Before (org.junit.Before)4 UserAgent (com.palantir.conjure.java.api.config.service.UserAgent)2 EmptyPathService (com.palantir.product.EmptyPathService)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 HttpUrl (okhttp3.HttpUrl)2 Theory (org.junit.experimental.theories.Theory)2 Test (org.junit.jupiter.api.Test)2 ServiceConfigurationFactory (com.palantir.conjure.java.api.config.service.ServiceConfigurationFactory)1 OkHttpClients (com.palantir.conjure.java.okhttp.OkHttpClients)1 Channel (com.palantir.dialogue.Channel)1 IOException (java.io.IOException)1