From b5d6f00b8aeb1e9b0e4edc234c7a0cac89bf5c18 Mon Sep 17 00:00:00 2001 From: Dan Sanduleac Date: Wed, 4 Dec 2019 17:05:33 +0000 Subject: [PATCH] changes after using https://github.com/palantir/palantir-java-format/pull/94 --- .../config/ClientConfigurationsTest.java | 20 ++++---- .../verification/AutoDeserializeTest.java | 22 +++++---- .../verification/SingleParamServicesTest.java | 10 ++-- .../java/serialization/ObjectMappersTest.java | 5 +- .../java/client/jaxrs/JaxRsClient.java | 5 +- .../feignimpl/EmptyContainerDecoder.java | 5 +- .../feignimpl/GuavaOptionalAwareContract.java | 7 +-- .../feignimpl/Java8OptionalAwareContract.java | 7 +-- .../jaxrs/feignimpl/QosErrorDecoder.java | 7 +-- .../client/jaxrs/JaxRsClientFailoverTest.java | 38 ++++++++++----- .../jaxrs/JaxRsClientStackTraceTest.java | 12 +++-- .../GuavaOptionalAwareDecoderTest.java | 15 +++--- .../feignimpl/HeaderAccessUtilsTest.java | 5 +- .../jaxrs/feignimpl/ServiceConfigTest.java | 3 +- .../client/jaxrs/feignimpl/UserAgentTest.java | 6 ++- .../GuavaOptionalParamConverterProvider.java | 4 +- .../server/jersey/JsonExceptionMapper.java | 11 +++-- .../CoerceNullValuesCallAdapterFactory.java | 5 +- .../client/retrofit2/Retrofit2Client.java | 5 +- ...nalObjectToStringConverterFactoryTest.java | 10 ++-- .../retrofit2/Retrofit2ClientApiTest.java | 10 +++- .../retrofit2/Retrofit2ClientBuilderTest.java | 20 +++++--- .../Retrofit2ClientFailoverTest.java | 35 +++++++++++--- .../server/AutoDeserializeTest.java | 44 +++++++++-------- .../undertest/ServerUnderTestApplication.java | 5 +- .../java/client/jaxrs/JaxRsScalaClient.java | 5 +- .../java/config/ssl/SslSocketFactories.java | 25 ++++++---- .../java/config/ssl/KeyStoresTests.java | 44 ++++++++++------- .../java/okhttp/ConcurrencyLimiters.java | 48 ++++++++++--------- .../ConcurrencyLimitingInterceptor.java | 9 ++-- .../java/okhttp/DispatcherMetricSet.java | 16 ++++--- .../conjure/java/okhttp/OkHttpClients.java | 36 ++++++++------ .../java/okhttp/RemotingOkHttpCall.java | 20 ++++---- .../java/okhttp/RemotingOkHttpClient.java | 5 +- .../ConcurrencyLimitingInterceptorTest.java | 5 +- .../java/okhttp/OkHttpClientsTest.java | 15 +++--- 36 files changed, 332 insertions(+), 212 deletions(-) diff --git a/client-config/src/test/java/com/palantir/conjure/java/client/config/ClientConfigurationsTest.java b/client-config/src/test/java/com/palantir/conjure/java/client/config/ClientConfigurationsTest.java index cd04e037e..7ca86d332 100644 --- a/client-config/src/test/java/com/palantir/conjure/java/client/config/ClientConfigurationsTest.java +++ b/client-config/src/test/java/com/palantir/conjure/java/client/config/ClientConfigurationsTest.java @@ -120,11 +120,12 @@ public void roundRobin_noCooldown() throws Exception { .security(SslConfiguration.of(Paths.get("src/test/resources/trustStore.jks"))) .build(); - assertThatThrownBy(() -> ClientConfiguration.builder() - .from(ClientConfigurations.of(serviceConfig)) - .nodeSelectionStrategy(NodeSelectionStrategy.ROUND_ROBIN) - .failedUrlCooldown(Duration.ofMillis(0)) - .build()) + assertThatThrownBy(() -> + ClientConfiguration.builder() + .from(ClientConfigurations.of(serviceConfig)) + .nodeSelectionStrategy(NodeSelectionStrategy.ROUND_ROBIN) + .failedUrlCooldown(Duration.ofMillis(0)) + .build()) .isInstanceOf(IllegalArgumentException.class) .hasMessage("If nodeSelectionStrategy is ROUND_ROBIN then failedUrlCooldown must be positive"); } @@ -146,10 +147,11 @@ public void overriding_tagged_metric_registry_is_convenient() { @Test public void sslSocketFactory_has_keepalives_enabled() throws IOException { - ClientConfiguration config = ClientConfigurations.of(ServiceConfiguration.builder() - .uris(uris) - .security(SslConfiguration.of(Paths.get("src/test/resources/trustStore.jks"))) - .build()); + ClientConfiguration config = ClientConfigurations.of( + ServiceConfiguration.builder() + .uris(uris) + .security(SslConfiguration.of(Paths.get("src/test/resources/trustStore.jks"))) + .build()); try (Socket socket = config.sslSocketFactory().createSocket("google.com", 443)) { assertThat(socket.getKeepAlive()).describedAs("keepAlives enabled").isTrue(); diff --git a/conjure-java-client-verifier/src/test/java/com/palantir/verification/AutoDeserializeTest.java b/conjure-java-client-verifier/src/test/java/com/palantir/verification/AutoDeserializeTest.java index c5980a1a1..2cb4eb6ed 100644 --- a/conjure-java-client-verifier/src/test/java/com/palantir/verification/AutoDeserializeTest.java +++ b/conjure-java-client-verifier/src/test/java/com/palantir/verification/AutoDeserializeTest.java @@ -63,8 +63,9 @@ public static Collection data() { int positiveSize = positiveAndNegativeTestCases.getPositive().size(); int negativeSize = positiveAndNegativeTestCases.getNegative().size(); - IntStream.range(0, positiveSize).forEach(i -> objects.add( - new Object[] {endpointName, i, true, positiveAndNegativeTestCases.getPositive().get(i)})); + IntStream.range(0, positiveSize).forEach(i -> + objects.add( + new Object[] {endpointName, i, true, positiveAndNegativeTestCases.getPositive().get(i)})); IntStream.range(0, negativeSize).forEach(i -> objects.add(new Object[] { endpointName, positiveSize + i, false, positiveAndNegativeTestCases.getNegative().get(i) @@ -78,14 +79,15 @@ public static Collection data() { public void runTestCase() throws Error, NoSuchMethodException { boolean shouldIgnore = Cases.shouldIgnore(endpointName, jsonString); Method method = testService.getClass().getMethod(endpointName.get(), int.class); - System.out.println(String.format( - "[%s%s test case %s]: %s(%s), expected client to %s", - shouldIgnore ? "ignored " : "", - shouldSucceed ? "positive" : "negative", - index, - endpointName, - jsonString, - shouldSucceed ? "succeed" : "fail")); + System.out.println( + String.format( + "[%s%s test case %s]: %s(%s), expected client to %s", + shouldIgnore ? "ignored " : "", + shouldSucceed ? "positive" : "negative", + index, + endpointName, + jsonString, + shouldSucceed ? "succeed" : "fail")); Optional expectationFailure = shouldSucceed ? expectSuccess(method) : expectFailure(method); diff --git a/conjure-java-client-verifier/src/test/java/com/palantir/verification/SingleParamServicesTest.java b/conjure-java-client-verifier/src/test/java/com/palantir/verification/SingleParamServicesTest.java index e4bbfeafd..e2ed655c8 100644 --- a/conjure-java-client-verifier/src/test/java/com/palantir/verification/SingleParamServicesTest.java +++ b/conjure-java-client-verifier/src/test/java/com/palantir/verification/SingleParamServicesTest.java @@ -74,14 +74,16 @@ public static Collection data() { Cases.TEST_CASES.getSinglePathParamService().forEach((endpointName, singleHeaderTestCases) -> { int size = singleHeaderTestCases.size(); - IntStream.range(0, size).forEach(i -> objects.add( - new Object[] {"singlePathParamService", endpointName, i, singleHeaderTestCases.get(i)})); + IntStream.range(0, size).forEach(i -> + objects.add( + new Object[] {"singlePathParamService", endpointName, i, singleHeaderTestCases.get(i)})); }); Cases.TEST_CASES.getSingleQueryParamService().forEach((endpointName, singleQueryTestCases) -> { int size = singleQueryTestCases.size(); - IntStream.range(0, size).forEach(i -> objects.add( - new Object[] {"singleQueryParamService", endpointName, i, singleQueryTestCases.get(i)})); + IntStream.range(0, size).forEach(i -> + objects.add( + new Object[] {"singleQueryParamService", endpointName, i, singleQueryTestCases.get(i)})); }); return objects; diff --git a/conjure-java-jackson-serialization/src/test/java/com/palantir/conjure/java/serialization/ObjectMappersTest.java b/conjure-java-jackson-serialization/src/test/java/com/palantir/conjure/java/serialization/ObjectMappersTest.java index 8be612cb2..c74779f65 100644 --- a/conjure-java-jackson-serialization/src/test/java/com/palantir/conjure/java/serialization/ObjectMappersTest.java +++ b/conjure-java-jackson-serialization/src/test/java/com/palantir/conjure/java/serialization/ObjectMappersTest.java @@ -106,8 +106,9 @@ public void testJdk8DateTimeSerialization() throws IOException { @Test public void testMapWithNullValues() throws IOException { // This is potentially a bug, see conjure-java#291 - assertThat(MAPPER.>readValue( - "{\"test\":null}", new TypeReference>() {})) + assertThat( + MAPPER.>readValue( + "{\"test\":null}", new TypeReference>() {})) .isEqualTo(Collections.singletonMap("test", null)); } diff --git a/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/JaxRsClient.java b/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/JaxRsClient.java index ed49249ca..a580a7d9d 100644 --- a/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/JaxRsClient.java +++ b/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/JaxRsClient.java @@ -49,7 +49,8 @@ public static T create( UserAgent userAgent, HostEventsSink hostEventsSink, Refreshable config) { - return Reflection.newProxy(serviceClass, RefreshableProxyInvocationHandler.create( - config, serviceConfiguration -> create(serviceClass, userAgent, hostEventsSink, serviceConfiguration))); + return Reflection.newProxy( + serviceClass, RefreshableProxyInvocationHandler.create(config, serviceConfiguration -> + create(serviceClass, userAgent, hostEventsSink, serviceConfiguration))); } } diff --git a/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/EmptyContainerDecoder.java b/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/EmptyContainerDecoder.java index 152b926c4..3b57dae93 100644 --- a/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/EmptyContainerDecoder.java +++ b/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/EmptyContainerDecoder.java @@ -68,8 +68,9 @@ public Object decode(Response response, Type type) throws IOException { if (response.status() == 204 || (response.status() == 200 && delegateResult == null)) { @Nullable Object object = blankInstanceCache.get(type); return Preconditions.checkNotNull( - object, "Received HTTP 204 but unable to construct an empty instance for return type", SafeArg.of( - "type", type)); + object, + "Received HTTP 204 but unable to construct an empty instance for return type", + SafeArg.of("type", type)); } else { return delegateResult; } diff --git a/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/GuavaOptionalAwareContract.java b/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/GuavaOptionalAwareContract.java index 20ec99864..7268f3cc6 100644 --- a/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/GuavaOptionalAwareContract.java +++ b/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/GuavaOptionalAwareContract.java @@ -55,9 +55,10 @@ protected void processMetadata(Class targetType, Method method, MethodMetadat } else if (paramAnnotations.contains(QueryParam.class)) { metadata.indexToExpanderClass().put(i, GuavaNullOptionalExpander.class); } else if (paramAnnotations.contains(PathParam.class)) { - throw new RuntimeException(String.format( - "Cannot use Guava Optionals with PathParams. (Class: %s, Method: %s, Param: arg%d)", - targetType.getName(), method.getName(), i)); + throw new RuntimeException( + String.format( + "Cannot use Guava Optionals with PathParams. (Class: %s, Method: %s, Param: arg%d)", + targetType.getName(), method.getName(), i)); } } } diff --git a/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/Java8OptionalAwareContract.java b/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/Java8OptionalAwareContract.java index 77877f8a7..498b0687c 100644 --- a/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/Java8OptionalAwareContract.java +++ b/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/Java8OptionalAwareContract.java @@ -96,9 +96,10 @@ private void configureOptionalExpanders( } else if (paramAnnotations.contains(QueryParam.class)) { metadata.indexToExpanderClass().put(index, nullExpanderClass); } else if (paramAnnotations.contains(PathParam.class)) { - throw new RuntimeException(String.format( - "Cannot use Java8 Optionals with PathParams. (Class: %s, Method: %s, Param: arg%d)", - targetType.getName(), method.getName(), index)); + throw new RuntimeException( + String.format( + "Cannot use Java8 Optionals with PathParams. (Class: %s, Method: %s, Param: arg%d)", + targetType.getName(), method.getName(), index)); } } diff --git a/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/QosErrorDecoder.java b/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/QosErrorDecoder.java index cfb104069..bc818796d 100644 --- a/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/QosErrorDecoder.java +++ b/conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/QosErrorDecoder.java @@ -34,9 +34,10 @@ public QosErrorDecoder(ErrorDecoder delegate) { @Override public Exception decode(String methodKey, Response response) { Optional exception = QosExceptionResponseMapper.mapResponseCodeHeaderStream( - response.status(), header -> Optional.ofNullable(response.headers().get(header)) - .map(Collection::stream) - .orElseGet(Stream::empty)) + response.status(), header -> + Optional.ofNullable(response.headers().get(header)) + .map(Collection::stream) + .orElseGet(Stream::empty)) .map(Function.identity()); return exception.orElseGet(() -> delegate.decode(methodKey, response)); } diff --git a/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/JaxRsClientFailoverTest.java b/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/JaxRsClientFailoverTest.java index dda8fec4b..8cbddd47c 100644 --- a/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/JaxRsClientFailoverTest.java +++ b/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/JaxRsClientFailoverTest.java @@ -144,7 +144,10 @@ public void testConnectionError_performsFailoverOnDnsFailure( failoverTestCase.server1.enqueue(new MockResponse().setBody("\"foo\"")); TestService bogusHostProxy = JaxRsClient.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from(createTestConfig("http://foo-bar-bogus-host.unresolvable:80", "http://localhost:" + failoverTestCase.server1.getPort())) .maxNumRetries(2) @@ -160,7 +163,10 @@ public void testQosError_performsRetryWithOneNode() throws Exception { server1.enqueue(new MockResponse().setBody("\"foo\"")); TestService anotherProxy = JaxRsClient.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from(createTestConfig("http://localhost:" + server1.getPort())) .maxNumRetries(2) .build()); @@ -175,7 +181,10 @@ public void testQosError_performsRetryWithOneNodeAndCache() throws Exception { server1.enqueue(new MockResponse().setBody("\"foo\"")); TestService anotherProxy = JaxRsClient.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from(createTestConfig("http://localhost:" + server1.getPort())) .maxNumRetries(2) .failedUrlCooldown(Duration.ofMillis(CACHE_DURATION)) @@ -189,7 +198,10 @@ public void testCache_recovery() throws Exception { MockWebServer server1 = new MockWebServer(); TestService anotherProxy = JaxRsClient.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from(createTestConfig("http://localhost:" + server1.getPort())) .maxNumRetries(1) .failedUrlCooldown(Duration.ofMillis(CACHE_DURATION)) @@ -246,13 +258,17 @@ private static class FailoverTestCase { } public TestService getProxy() { - return JaxRsClient.create(TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() - .from(createTestConfig("http://localhost:" + server1.getPort(), "http://localhost:" - + server2.getPort())) - .maxNumRetries(2) - .nodeSelectionStrategy(nodeSelectionStrategy) - .failedUrlCooldown(Duration.ofMillis(duration)) - .build()); + return JaxRsClient.create( + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() + .from(createTestConfig("http://localhost:" + server1.getPort(), "http://localhost:" + + server2.getPort())) + .maxNumRetries(2) + .nodeSelectionStrategy(nodeSelectionStrategy) + .failedUrlCooldown(Duration.ofMillis(duration)) + .build()); } } } diff --git a/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/JaxRsClientStackTraceTest.java b/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/JaxRsClientStackTraceTest.java index 62ed28f40..45bc61c26 100644 --- a/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/JaxRsClientStackTraceTest.java +++ b/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/JaxRsClientStackTraceTest.java @@ -40,10 +40,14 @@ public final class JaxRsClientStackTraceTest extends TestBase { @Before public void before() throws Exception { - proxy = JaxRsClient.create(TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() - .from(createTestConfig("http://localhost:" + server1.getPort())) - .maxNumRetries(1) - .build()); + proxy = JaxRsClient.create( + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() + .from(createTestConfig("http://localhost:" + server1.getPort())) + .maxNumRetries(1) + .build()); } @Test diff --git a/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/GuavaOptionalAwareDecoderTest.java b/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/GuavaOptionalAwareDecoderTest.java index 5d9853ea1..85b102715 100644 --- a/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/GuavaOptionalAwareDecoderTest.java +++ b/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/GuavaOptionalAwareDecoderTest.java @@ -118,8 +118,9 @@ public void testOptionalString() { public void testComplexType() { GuavaOptionalComplexType value = new GuavaOptionalComplexType( com.google.common.base.Optional.of(new GuavaOptionalComplexType( - com.google.common.base.Optional.absent(), com.google.common.base.Optional.absent(), Paths.get( - "bar"))), + com.google.common.base.Optional.absent(), + com.google.common.base.Optional.absent(), + Paths.get("bar"))), com.google.common.base.Optional.of("baz"), Paths.get("foo")); // Hint: set breakpoint in Feign's SynchronousMethodHandler#executeAndDecode to inspect serialized parameter. @@ -130,8 +131,9 @@ public void testComplexType() { public void testCborResponse() { GuavaOptionalComplexType value = new GuavaOptionalComplexType( com.google.common.base.Optional.of(new GuavaOptionalComplexType( - com.google.common.base.Optional.absent(), com.google.common.base.Optional.absent(), Paths.get( - "bar"))), + com.google.common.base.Optional.absent(), + com.google.common.base.Optional.absent(), + Paths.get("bar"))), com.google.common.base.Optional.of("baz"), Paths.get("foo")); assertThat(service.getCborResponse(value)).isEqualTo(value); @@ -141,8 +143,9 @@ public void testCborResponse() { public void testCborRequest() { GuavaOptionalComplexType value = new GuavaOptionalComplexType( com.google.common.base.Optional.of(new GuavaOptionalComplexType( - com.google.common.base.Optional.absent(), com.google.common.base.Optional.absent(), Paths.get( - "bar"))), + com.google.common.base.Optional.absent(), + com.google.common.base.Optional.absent(), + Paths.get("bar"))), com.google.common.base.Optional.of("baz"), Paths.get("foo")); assertThat(service.postCborRequest(value)).isEqualTo(value); diff --git a/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/HeaderAccessUtilsTest.java b/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/HeaderAccessUtilsTest.java index e15e2acdc..503ceb71d 100644 --- a/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/HeaderAccessUtilsTest.java +++ b/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/HeaderAccessUtilsTest.java @@ -25,8 +25,9 @@ public final class HeaderAccessUtilsTest { private static final ImmutableMap> TEST_HEADERS_MAP = ImmutableMap.of( - "header", Arrays.asList("value1"), "Header", Arrays.asList("value2", "value3"), "HEADER", Arrays.asList( - "value4", "value5")); + "header", Arrays.asList("value1"), + "Header", Arrays.asList("value2", "value3"), + "HEADER", Arrays.asList("value4", "value5")); @Test public void caseInsensitiveContainsShouldReturnTrueIgnoringCase() { diff --git a/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/ServiceConfigTest.java b/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/ServiceConfigTest.java index e14de69b0..b25d19647 100644 --- a/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/ServiceConfigTest.java +++ b/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/ServiceConfigTest.java @@ -39,7 +39,8 @@ public final class ServiceConfigTest extends TestBase { @Rule public final DropwizardAppRule rule = new DropwizardAppRule<>( - ServiceConfigTestServer.ServiceConfigTestApp.class, ServiceConfigTest.class + ServiceConfigTestServer.ServiceConfigTestApp.class, + ServiceConfigTest.class .getClassLoader() .getResource("service-config-example.yml") .getPath()); diff --git a/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/UserAgentTest.java b/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/UserAgentTest.java index b536931c7..bd29ffc03 100644 --- a/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/UserAgentTest.java +++ b/conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/UserAgentTest.java @@ -78,8 +78,10 @@ public void testUserAgent_augmentedByHttpRemotingAndServiceComponents() throws E RecordedRequest request = server.takeRequest(); String conjureVersion = OkHttpClients.class.getPackage().getImplementationVersion(); - UserAgent expected = AGENT.addAgent(UserAgent.Agent.of("TestService", "0.0.0")).addAgent(UserAgent.Agent.of( - UserAgents.CONJURE_AGENT_NAME, conjureVersion != null ? conjureVersion : "0.0.0")); + UserAgent expected = AGENT.addAgent(UserAgent.Agent.of("TestService", "0.0.0")) + .addAgent( + UserAgent.Agent.of( + UserAgents.CONJURE_AGENT_NAME, conjureVersion != null ? conjureVersion : "0.0.0")); assertThat(request.getHeader("User-Agent")).isEqualTo(UserAgents.format(expected)); } } diff --git a/conjure-java-jersey-server/src/main/java/com/palantir/conjure/java/server/jersey/GuavaOptionalParamConverterProvider.java b/conjure-java-jersey-server/src/main/java/com/palantir/conjure/java/server/jersey/GuavaOptionalParamConverterProvider.java index 3371df42f..58adae18a 100644 --- a/conjure-java-jersey-server/src/main/java/com/palantir/conjure/java/server/jersey/GuavaOptionalParamConverterProvider.java +++ b/conjure-java-jersey-server/src/main/java/com/palantir/conjure/java/server/jersey/GuavaOptionalParamConverterProvider.java @@ -64,8 +64,8 @@ public String toString(final T value) { return new ParamConverter() { @Override public T fromString(final String value) { - return rawType.cast(com.google.common.base.Optional.fromNullable(value) - .transform(s -> converter.fromString(value))); + return rawType.cast(com.google.common.base.Optional.fromNullable(value).transform(s -> + converter.fromString(value))); } @Override diff --git a/conjure-java-jersey-server/src/main/java/com/palantir/conjure/java/server/jersey/JsonExceptionMapper.java b/conjure-java-jersey-server/src/main/java/com/palantir/conjure/java/server/jersey/JsonExceptionMapper.java index 0378c4df4..6c0dc0352 100644 --- a/conjure-java-jersey-server/src/main/java/com/palantir/conjure/java/server/jersey/JsonExceptionMapper.java +++ b/conjure-java-jersey-server/src/main/java/com/palantir/conjure/java/server/jersey/JsonExceptionMapper.java @@ -76,11 +76,12 @@ static Response createResponse(ErrorType errorType, String errorInstanceId) { static Response createResponse(int httpErrorCode, String errorCode, String errorName, String errorInstanceId) { ResponseBuilder builder = Response.status(httpErrorCode); try { - builder.entity(SerializableError.builder() - .errorCode(errorCode) - .errorName(errorName) - .errorInstanceId(errorInstanceId) - .build()) + builder.entity( + SerializableError.builder() + .errorCode(errorCode) + .errorName(errorName) + .errorInstanceId(errorInstanceId) + .build()) .type(MediaType.APPLICATION_JSON); } catch (RuntimeException e) { log.warn( diff --git a/conjure-java-retrofit2-client/src/main/java/com/palantir/conjure/java/client/retrofit2/CoerceNullValuesCallAdapterFactory.java b/conjure-java-retrofit2-client/src/main/java/com/palantir/conjure/java/client/retrofit2/CoerceNullValuesCallAdapterFactory.java index 4c96e3a88..70718714e 100644 --- a/conjure-java-retrofit2-client/src/main/java/com/palantir/conjure/java/client/retrofit2/CoerceNullValuesCallAdapterFactory.java +++ b/conjure-java-retrofit2-client/src/main/java/com/palantir/conjure/java/client/retrofit2/CoerceNullValuesCallAdapterFactory.java @@ -51,8 +51,9 @@ final class CoerceNullValuesCallAdapterFactory extends CallAdapter.Factory { public CallAdapter get(Type returnType, Annotation[] annotations, Retrofit retrofit) { // we only support Call and CompletableFuture Preconditions.checkState( - returnType instanceof ParameterizedType, "Function must return a ParametrizedType", SafeArg.of( - "type", returnType)); + returnType instanceof ParameterizedType, + "Function must return a ParametrizedType", + SafeArg.of("type", returnType)); Type innerType = getParameterUpperBound(0, (ParameterizedType) returnType); CallAdapter maybeCallAdapter = delegate.get(returnType, annotations, retrofit); diff --git a/conjure-java-retrofit2-client/src/main/java/com/palantir/conjure/java/client/retrofit2/Retrofit2Client.java b/conjure-java-retrofit2-client/src/main/java/com/palantir/conjure/java/client/retrofit2/Retrofit2Client.java index d420a3b0b..9cd89bf85 100644 --- a/conjure-java-retrofit2-client/src/main/java/com/palantir/conjure/java/client/retrofit2/Retrofit2Client.java +++ b/conjure-java-retrofit2-client/src/main/java/com/palantir/conjure/java/client/retrofit2/Retrofit2Client.java @@ -47,7 +47,8 @@ public static T create( UserAgent userAgent, HostEventsSink hostEventsSink, Refreshable config) { - return Reflection.newProxy(serviceClass, RefreshableProxyInvocationHandler.create( - config, serviceConfiguration -> create(serviceClass, userAgent, hostEventsSink, serviceConfiguration))); + return Reflection.newProxy( + serviceClass, RefreshableProxyInvocationHandler.create(config, serviceConfiguration -> + create(serviceClass, userAgent, hostEventsSink, serviceConfiguration))); } } diff --git a/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/OptionalObjectToStringConverterFactoryTest.java b/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/OptionalObjectToStringConverterFactoryTest.java index 6353fda95..72b95c203 100644 --- a/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/OptionalObjectToStringConverterFactoryTest.java +++ b/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/OptionalObjectToStringConverterFactoryTest.java @@ -87,15 +87,17 @@ public void testRequiresPathHeaderQueryAnnotation() throws Exception { .isNull(); // Guava - assertThat(factory.stringConverter( - com.google.common.base.Optional.class, createAnnotations(Header.class), null)) + assertThat( + factory.stringConverter( + com.google.common.base.Optional.class, createAnnotations(Header.class), null)) .isNotNull(); assertThat(factory.stringConverter(com.google.common.base.Optional.class, createAnnotations(Path.class), null)) .isNotNull(); assertThat(factory.stringConverter(com.google.common.base.Optional.class, createAnnotations(Query.class), null)) .isNotNull(); - assertThat(factory.stringConverter( - com.google.common.base.Optional.class, createAnnotations(Nonnull.class), null)) + assertThat( + factory.stringConverter( + com.google.common.base.Optional.class, createAnnotations(Nonnull.class), null)) .isNull(); } diff --git a/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/Retrofit2ClientApiTest.java b/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/Retrofit2ClientApiTest.java index 3c6707e4b..689f9fbeb 100644 --- a/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/Retrofit2ClientApiTest.java +++ b/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/Retrofit2ClientApiTest.java @@ -281,7 +281,10 @@ public void connectionFailureWithFuture_listenable() { private void connectionFailureWithFuture(Supplier> futureSupplier) { service = Retrofit2Client.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from(createTestConfig("https://invalid.service.dev")) .connectTimeout(Duration.ofMillis(10)) .build()); @@ -333,7 +336,10 @@ public void future_should_throw_normal_IoException_for_client_side_errors_listen private void future_should_throw_normal_IoException_for_client_side_errors( Supplier> futureSupplier) { service = Retrofit2Client.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from(createTestConfig("https://invalid.service.dev")) .connectTimeout(Duration.ofMillis(10)) .build()); diff --git a/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/Retrofit2ClientBuilderTest.java b/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/Retrofit2ClientBuilderTest.java index 9d5a5ffc7..bf4bda9d2 100644 --- a/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/Retrofit2ClientBuilderTest.java +++ b/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/Retrofit2ClientBuilderTest.java @@ -64,8 +64,11 @@ private void assertRequestUrlYieldsHttpPath(String basePath, String expectedQuer @Test public void testUserAgent_defaultHeaderIsSent() throws InterruptedException, IOException { TestService service = Retrofit2Client.create( - TestService.class, AGENT, new HostMetricsRegistry(), createTestConfig(String.format( - "http://%s:%s/api/", server.getHostName().toUpperCase(), server.getPort()))); + TestService.class, + AGENT, + new HostMetricsRegistry(), + createTestConfig( + String.format("http://%s:%s/api/", server.getHostName().toUpperCase(), server.getPort()))); server.enqueue(new MockResponse().setBody("\"server\"")); service.get().execute(); @@ -91,15 +94,20 @@ public void testUserAgent_usesUnknownAgentIfBogusAgentIsGiven() throws Interrupt @Test public void testUserAgent_augmentedByHttpRemotingAndServiceComponents() throws Exception { TestService service = Retrofit2Client.create( - TestService.class, AGENT, new HostMetricsRegistry(), createTestConfig(String.format( - "http://%s:%s/api/", server.getHostName().toUpperCase(), server.getPort()))); + TestService.class, + AGENT, + new HostMetricsRegistry(), + createTestConfig( + String.format("http://%s:%s/api/", server.getHostName().toUpperCase(), server.getPort()))); server.enqueue(new MockResponse().setBody("\"server\"")); service.get().execute(); RecordedRequest request = server.takeRequest(); String conjureVersion = OkHttpClients.class.getPackage().getImplementationVersion(); - UserAgent expected = AGENT.addAgent(UserAgent.Agent.of("TestService", "0.0.0")).addAgent(UserAgent.Agent.of( - UserAgents.CONJURE_AGENT_NAME, conjureVersion != null ? conjureVersion : "0.0.0")); + UserAgent expected = AGENT.addAgent(UserAgent.Agent.of("TestService", "0.0.0")) + .addAgent( + UserAgent.Agent.of( + UserAgents.CONJURE_AGENT_NAME, conjureVersion != null ? conjureVersion : "0.0.0")); assertThat(request.getHeader("User-Agent")).isEqualTo(UserAgents.format(expected)); } } diff --git a/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/Retrofit2ClientFailoverTest.java b/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/Retrofit2ClientFailoverTest.java index 16caa1065..592957736 100644 --- a/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/Retrofit2ClientFailoverTest.java +++ b/conjure-java-retrofit2-client/src/test/java/com/palantir/conjure/java/client/retrofit2/Retrofit2ClientFailoverTest.java @@ -139,7 +139,10 @@ public void testConnectionError_performsFailoverOnDnsFailure( failoverTestCase.server1.enqueue(new MockResponse().setBody("\"foo\"")); TestService bogusHostProxy = Retrofit2Client.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from(createTestConfig("http://foo-bar-bogus-host.unresolvable:80", "http://localhost:" + failoverTestCase.server1.getPort())) .maxNumRetries(2) @@ -155,7 +158,10 @@ public void testQosError_performsRetryWithOneNode_forSynchronousOperation() thro server1.enqueue(new MockResponse().setBody("\"foo\"")); TestService anotherProxy = Retrofit2Client.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from(createTestConfig("http://localhost:" + server1.getPort())) .maxNumRetries(2) .build()); @@ -170,7 +176,10 @@ public void testQosError_performsRetryWithOneNodeAndCache_forSynchronousOperatio server1.enqueue(new MockResponse().setBody("\"foo\"")); TestService anotherProxy = Retrofit2Client.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from(createTestConfig("http://localhost:" + server1.getPort())) .maxNumRetries(2) .failedUrlCooldown(Duration.ofMillis(CACHE_DURATION)) @@ -186,7 +195,10 @@ public void testQosError_performsRetryWithOneNode_forAsynchronousOperation() thr server1.enqueue(new MockResponse().setBody("\"foo\"")); TestService anotherProxy = Retrofit2Client.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from(createTestConfig("http://localhost:" + server1.getPort())) .maxNumRetries(2) .build()); @@ -214,7 +226,10 @@ public void testQosError_performsRetryWithOneNodeAndCache_forAsynchronousOperati server1.enqueue(new MockResponse().setBody("\"foo\"")); TestService anotherProxy = Retrofit2Client.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from(createTestConfig("http://localhost:" + server1.getPort())) .maxNumRetries(2) .failedUrlCooldown(Duration.ofMillis(CACHE_DURATION)) @@ -241,7 +256,10 @@ public void testCache_recovery() throws Exception { MockWebServer server1 = new MockWebServer(); TestService anotherProxy = Retrofit2Client.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from(createTestConfig("http://localhost:" + server1.getPort())) .maxNumRetries(1) .failedUrlCooldown(Duration.ofMillis(CACHE_DURATION)) @@ -285,7 +303,10 @@ private static class FailoverTestCase { public TestService getProxy() { return Retrofit2Client.create( - TestService.class, AGENT, new HostMetricsRegistry(), ClientConfiguration.builder() + TestService.class, + AGENT, + new HostMetricsRegistry(), + ClientConfiguration.builder() .from( createTestConfig( String.format( diff --git a/conjure-java-server-verifier/src/test/java/com/palantir/verification/server/AutoDeserializeTest.java b/conjure-java-server-verifier/src/test/java/com/palantir/verification/server/AutoDeserializeTest.java index 9101b2872..82553f2d8 100644 --- a/conjure-java-server-verifier/src/test/java/com/palantir/verification/server/AutoDeserializeTest.java +++ b/conjure-java-server-verifier/src/test/java/com/palantir/verification/server/AutoDeserializeTest.java @@ -67,8 +67,9 @@ public static Collection data() { int positiveSize = positiveAndNegativeTestCases.getPositive().size(); int negativeSize = positiveAndNegativeTestCases.getNegative().size(); - IntStream.range(0, positiveSize).forEach(i -> objects.add( - new Object[] {endpointName, i, true, positiveAndNegativeTestCases.getPositive().get(i)})); + IntStream.range(0, positiveSize).forEach(i -> + objects.add( + new Object[] {endpointName, i, true, positiveAndNegativeTestCases.getPositive().get(i)})); IntStream.range(0, negativeSize).forEach(i -> objects.add(new Object[] { endpointName, positiveSize + i, false, positiveAndNegativeTestCases.getNegative().get(i) @@ -80,14 +81,15 @@ public static Collection data() { @Test public void runTestCase() throws Exception { boolean shouldIgnore = Cases.shouldIgnore(endpointName, jsonString); - System.out.println(String.format( - "[%s%s test case %s]: %s(%s), expected client to %s", - shouldIgnore ? "ignored " : "", - shouldSucceed ? "positive" : "negative", - index, - endpointName, - jsonString, - shouldSucceed ? "succeed" : "fail")); + System.out.println( + String.format( + "[%s%s test case %s]: %s(%s), expected client to %s", + shouldIgnore ? "ignored " : "", + shouldSucceed ? "positive" : "negative", + index, + endpointName, + jsonString, + shouldSucceed ? "succeed" : "fail")); Optional expectationFailure = shouldSucceed ? expectSuccess() : expectFailure(); @@ -107,11 +109,12 @@ public void runTestCase() throws Exception { private Optional expectSuccess() throws Exception { try { - verificationService.runTestCase(VerificationClientRequest.builder() - .endpointName(endpointName) - .testCase(index) - .baseUrl(String.format("http://localhost:%d/test/api", serverUnderTestRule.getLocalPort())) - .build()); + verificationService.runTestCase( + VerificationClientRequest.builder() + .endpointName(endpointName) + .testCase(index) + .baseUrl(String.format("http://localhost:%d/test/api", serverUnderTestRule.getLocalPort())) + .build()); return Optional.empty(); } catch (RemoteException e) { return Optional.of(new AssertionError("Expected call to succeed, but caught exception", e)); @@ -120,11 +123,12 @@ private Optional expectSuccess() throws Exception { private Optional expectFailure() { try { - verificationService.runTestCase(VerificationClientRequest.builder() - .endpointName(endpointName) - .testCase(index) - .baseUrl(String.format("http://localhost:%d/test/api", serverUnderTestRule.getLocalPort())) - .build()); + verificationService.runTestCase( + VerificationClientRequest.builder() + .endpointName(endpointName) + .testCase(index) + .baseUrl(String.format("http://localhost:%d/test/api", serverUnderTestRule.getLocalPort())) + .build()); return Optional.of(new AssertionError("Result should have caused an exception")); } catch (RemoteException e) { // It's not an expected failure to get a 404 or 403 back diff --git a/conjure-java-server-verifier/src/test/java/com/palantir/verification/server/undertest/ServerUnderTestApplication.java b/conjure-java-server-verifier/src/test/java/com/palantir/verification/server/undertest/ServerUnderTestApplication.java index 95a3f165e..d13da861b 100644 --- a/conjure-java-server-verifier/src/test/java/com/palantir/verification/server/undertest/ServerUnderTestApplication.java +++ b/conjure-java-server-verifier/src/test/java/com/palantir/verification/server/undertest/ServerUnderTestApplication.java @@ -45,8 +45,9 @@ public void initialize(Bootstrap bootstrap) { @Override public void run(Configuration _configuration, Environment environment) { - environment.jersey().register(Reflection.newProxy( - AutoDeserializeService.class, new EchoResourceInvocationHandler())); + environment + .jersey() + .register(Reflection.newProxy(AutoDeserializeService.class, new EchoResourceInvocationHandler())); // must register ConjureJerseyFeature to map conjure error types. environment.jersey().register(ConjureJerseyFeature.INSTANCE); diff --git a/conjure-scala-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/JaxRsScalaClient.java b/conjure-scala-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/JaxRsScalaClient.java index a251f1927..b6d7370ca 100644 --- a/conjure-scala-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/JaxRsScalaClient.java +++ b/conjure-scala-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/JaxRsScalaClient.java @@ -42,7 +42,8 @@ public static T create( UserAgent userAgent, HostEventsSink hostEventsSink, Refreshable config) { - return Reflection.newProxy(serviceClass, RefreshableProxyInvocationHandler.create( - config, serviceConfiguration -> create(serviceClass, userAgent, hostEventsSink, serviceConfiguration))); + return Reflection.newProxy( + serviceClass, RefreshableProxyInvocationHandler.create(config, serviceConfiguration -> + create(serviceClass, userAgent, hostEventsSink, serviceConfiguration))); } } diff --git a/keystores/src/main/java/com/palantir/conjure/java/config/ssl/SslSocketFactories.java b/keystores/src/main/java/com/palantir/conjure/java/config/ssl/SslSocketFactories.java index 5d193e934..292d1b606 100644 --- a/keystores/src/main/java/com/palantir/conjure/java/config/ssl/SslSocketFactories.java +++ b/keystores/src/main/java/com/palantir/conjure/java/config/ssl/SslSocketFactories.java @@ -73,8 +73,10 @@ public static SSLContext createSslContext(SslConfiguration config) { KeyManager[] keyManagers = null; if (config.keyStorePath().isPresent()) { keyManagers = createKeyManagerFactory( - config.keyStorePath().get(), config.keyStorePassword() - .get(), config.keyStoreType(), config.keyStoreKeyAlias()) + config.keyStorePath().get(), + config.keyStorePassword().get(), + config.keyStoreType(), + config.keyStoreKeyAlias()) .getKeyManagers(); } @@ -156,11 +158,13 @@ public static X509TrustManager createX509TrustManager(SslConfiguration config) { if (trustManager instanceof X509TrustManager) { return (X509TrustManager) trustManager; } else { - throw new RuntimeException(String.format( - "First TrustManager associated with SslConfiguration was expected to be a %s, but was a %s: %s", - X509TrustManager.class.getSimpleName(), - trustManager.getClass().getSimpleName(), - config.trustStorePath())); + throw new RuntimeException( + String.format( + "First TrustManager associated with SslConfiguration was expected to be a %s, but was a" + + " %s: %s", + X509TrustManager.class.getSimpleName(), + trustManager.getClass().getSimpleName(), + config.trustStorePath())); } } @@ -169,9 +173,10 @@ public static X509TrustManager createX509TrustManager(Map KeyStores.createTrustStoreFromCertificates(certFolder.toPath())) .isInstanceOf(RuntimeException.class) .hasCauseInstanceOf(CertificateParsingException.class) - .hasMessageContaining(String.format( - "Could not read file at \"%s\" as an X.509 certificate", tempCertFile.getAbsolutePath())); + .hasMessageContaining( + String.format( + "Could not read file at \"%s\" as an X.509 certificate", + tempCertFile.getAbsolutePath())); } @Test @@ -100,8 +102,10 @@ public void testCreateTrustStoreFromDirectoryFailsWithDirectories() throws IOExc assertThatThrownBy(() -> KeyStores.createTrustStoreFromCertificates(certFolder.toPath())) .isInstanceOf(RuntimeException.class) .hasCauseInstanceOf(CertificateException.class) - .hasMessageContaining(String.format( - "Could not read file at \"%s\" as an X.509 certificate", tempDirFile.getAbsolutePath())); + .hasMessageContaining( + String.format( + "Could not read file at \"%s\" as an X.509 certificate", + tempDirFile.getAbsolutePath())); } @Test @@ -117,8 +121,9 @@ public void createTrustStoreFromCertificatesFromCertificatesByAlias() throws Exc public void createTrustStoreFromCertificatesFromCertificatesByAliasInvalidCert() throws Exception { String cert = Files.toString(TestConstants.COMBINED_CRL_PATH.toFile(), StandardCharsets.UTF_8); - assertThatThrownBy(() -> KeyStores.createTrustStoreFromCertificates( - ImmutableMap.of("invalid.crt", PemX509Certificate.of(cert)))) + assertThatThrownBy(() -> + KeyStores.createTrustStoreFromCertificates( + ImmutableMap.of("invalid.crt", PemX509Certificate.of(cert)))) .isInstanceOf(RuntimeException.class) .hasCauseInstanceOf(CertificateParsingException.class) .hasMessageContaining("Could not read certificate alias \"invalid.crt\" as an X.509 certificate"); @@ -189,8 +194,9 @@ public void testCreateKeyStoreFromDirectoryFailsWithNonKeyFiles() throws IOExcep assertThatThrownBy(() -> KeyStores.createKeyStoreFromCombinedPems(keyFolder.toPath(), "changeit")) .isInstanceOf(RuntimeException.class) .hasCauseInstanceOf(GeneralSecurityException.class) - .hasMessageContaining(String.format( - "Failed to read private key from file at \"%s\"", tempCertFile.getAbsolutePath())); + .hasMessageContaining( + String.format( + "Failed to read private key from file at \"%s\"", tempCertFile.getAbsolutePath())); } @Test @@ -221,12 +227,14 @@ public void testCreateKeyStoreFromPemDirectoriesFailsIfCertMissing() throws IOEx File certFolder = tempFolder.newFolder(); Files.copy(TestConstants.SERVER_KEY_PEM_PATH.toFile(), keyFolder.toPath().resolve("server.key").toFile()); - assertThatThrownBy(() -> KeyStores.createKeyStoreFromPemDirectories( - keyFolder.toPath(), ".key", certFolder.toPath(), ".cer", password)) + assertThatThrownBy(() -> + KeyStores.createKeyStoreFromPemDirectories( + keyFolder.toPath(), ".key", certFolder.toPath(), ".cer", password)) .hasCauseInstanceOf(NoSuchFileException.class) - .hasMessageContaining(String.format( - "Failed to read certificates from file at \"%s\"", - certFolder.toPath().resolve("server.cer").toString())); + .hasMessageContaining( + String.format( + "Failed to read certificates from file at \"%s\"", + certFolder.toPath().resolve("server.cer").toString())); } @Test @@ -235,13 +243,15 @@ public void testCreateKeyStoreFromPemDirectoriesFailsIfArgIsNotDirectory() throw File folder = tempFolder.newFolder(); File file = tempFolder.newFile(); - assertThatThrownBy(() -> KeyStores.createKeyStoreFromPemDirectories( - file.toPath(), ".key", folder.toPath(), ".cer", password)) + assertThatThrownBy(() -> + KeyStores.createKeyStoreFromPemDirectories( + file.toPath(), ".key", folder.toPath(), ".cer", password)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining(String.format("keyDirPath is not a directory: \"%s\"", file.toPath().toString())); - assertThatThrownBy(() -> KeyStores.createKeyStoreFromPemDirectories( - folder.toPath(), ".key", file.toPath(), ".cer", password)) + assertThatThrownBy(() -> + KeyStores.createKeyStoreFromPemDirectories( + folder.toPath(), ".key", file.toPath(), ".cer", password)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining( String.format("certDirPath is not a directory: \"%s\"", file.toPath().toString())); diff --git a/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/ConcurrencyLimiters.java b/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/ConcurrencyLimiters.java index 863cefc48..8f9f95712 100644 --- a/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/ConcurrencyLimiters.java +++ b/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/ConcurrencyLimiters.java @@ -107,29 +107,31 @@ ConcurrencyLimiter acquireLimiterInternal(Key limiterKey) { @VisibleForTesting Limit newLimit() { - return new ConjureWindowedLimit(AIMDLimit.newBuilder() - /** - * Requests slower than this timeout are treated as failures, which reduce concurrency. Since we have - * plenty of long streaming requests, we set this timeout to 292.27726 years to effectively turn it off. - */ - .timeout(Long.MAX_VALUE, TimeUnit.NANOSECONDS) - /** - * Our initial limit is pretty conservative - only 10 concurrent requests in flight at the same time. If - * a client is consistently maxing out its concurrency permits, this increases additively once per - * second (see {@link ConjureWindowedLimit#MIN_WINDOW_TIME}. - */ - .initialLimit(10) - /** - * We reduce concurrency _immediately_ as soon as a request fails, which can result in drastic limit - * reductions, e.g. starting with 30 concurrent permits, 100 failures in a row results in: 30 * 0.9^100 - * = 0.0007 (rounded up to the minLimit of 1). - */ - .backoffRatio(0.9) - /** However many failures we get, we always need at least 1 permit so we can keep trying. */ - .minLimit(1) - /** Note that the Dispatcher in {@link OkHttpClients} has a max concurrent requests too. */ - .maxLimit(Integer.MAX_VALUE) - .build()); + return new ConjureWindowedLimit( + AIMDLimit.newBuilder() + /** + * Requests slower than this timeout are treated as failures, which reduce concurrency. Since we + * have plenty of long streaming requests, we set this timeout to 292.27726 years to effectively + * turn it off. + */ + .timeout(Long.MAX_VALUE, TimeUnit.NANOSECONDS) + /** + * Our initial limit is pretty conservative - only 10 concurrent requests in flight at the same + * time. If a client is consistently maxing out its concurrency permits, this increases + * additively once per second (see {@link ConjureWindowedLimit#MIN_WINDOW_TIME}. + */ + .initialLimit(10) + /** + * We reduce concurrency _immediately_ as soon as a request fails, which can result in drastic + * limit reductions, e.g. starting with 30 concurrent permits, 100 failures in a row results in: + * 30 * 0.9^100 = 0.0007 (rounded up to the minLimit of 1). + */ + .backoffRatio(0.9) + /** However many failures we get, we always need at least 1 permit so we can keep trying. */ + .minLimit(1) + /** Note that the Dispatcher in {@link OkHttpClients} has a max concurrent requests too. */ + .maxLimit(Integer.MAX_VALUE) + .build()); } private MetricName generateMetricNameWithServiceName(String name, Class service) { diff --git a/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/ConcurrencyLimitingInterceptor.java b/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/ConcurrencyLimitingInterceptor.java index 38e42f9a2..d241a99c8 100644 --- a/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/ConcurrencyLimitingInterceptor.java +++ b/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/ConcurrencyLimitingInterceptor.java @@ -100,10 +100,11 @@ private static Response wrapResponse(Limiter.Listener listener, Response respons } private static BufferedSource wrapSource(BufferedSource currentSource, Limiter.Listener listener) { - return (BufferedSource) Proxy.newProxyInstance( - BufferedSource.class.getClassLoader(), - new Class[] {BufferedSource.class}, - new ReleaseConcurrencyLimitProxy(currentSource, listener)); + return (BufferedSource) + Proxy.newProxyInstance( + BufferedSource.class.getClassLoader(), + new Class[] {BufferedSource.class}, + new ReleaseConcurrencyLimitProxy(currentSource, listener)); } /** This proxy enables e.g. Okio to make additive additions to their API without breaking us. */ diff --git a/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/DispatcherMetricSet.java b/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/DispatcherMetricSet.java index 2b6ca1a14..2e17c3394 100644 --- a/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/DispatcherMetricSet.java +++ b/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/DispatcherMetricSet.java @@ -32,12 +32,16 @@ class DispatcherMetricSet implements TaggedMetricSet { DispatcherMetricSet(Dispatcher dispatcher, ConnectionPool connectionPool) { ImmutableMap.Builder map = ImmutableMap.builder(); - map.put(MetricName.builder() - .safeName("com.palantir.conjure.java.dispatcher.calls.queued") - .build(), (Gauge) dispatcher::queuedCallsCount); - map.put(MetricName.builder() - .safeName("com.palantir.conjure.java.dispatcher.calls.running") - .build(), (Gauge) dispatcher::runningCallsCount); + map.put( + MetricName.builder() + .safeName("com.palantir.conjure.java.dispatcher.calls.queued") + .build(), + (Gauge) dispatcher::queuedCallsCount); + map.put( + MetricName.builder() + .safeName("com.palantir.conjure.java.dispatcher.calls.running") + .build(), + (Gauge) dispatcher::runningCallsCount); map.put( MetricName.builder() .safeName("com.palantir.conjure.java.connection-pool.connections.total") diff --git a/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/OkHttpClients.java b/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/OkHttpClients.java index b44d9cb84..9a4a80cc9 100644 --- a/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/OkHttpClients.java +++ b/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/OkHttpClients.java @@ -57,11 +57,12 @@ public final class OkHttpClients { @VisibleForTesting static final int NUM_SCHEDULING_THREADS = 5; private static final ThreadFactory executionThreads = new ThreadFactoryBuilder() - .setUncaughtExceptionHandler((thread, uncaughtException) -> log.error( - "An exception was uncaught in an execution thread. " - + "This likely left a thread blocked, and is as such a serious bug " - + "which requires debugging.", - uncaughtException)) + .setUncaughtExceptionHandler((thread, uncaughtException) -> + log.error( + "An exception was uncaught in an execution thread. " + + "This likely left a thread blocked, and is as such a serious bug " + + "which requires debugging.", + uncaughtException)) .setNameFormat("remoting-okhttp-dispatcher-%d") // This diverges from the OkHttp default value, allowing the JVM to cleanly exit // while idle dispatcher threads are still alive. @@ -99,9 +100,10 @@ public final class OkHttpClients { } /** The {@link ScheduledExecutorService} used for recovering leaked limits. */ - private static final Supplier limitReviver = Suppliers.memoize( - () -> Tracers.wrap(Executors.newSingleThreadScheduledExecutor( - Util.threadFactory("conjure-java-runtime/leaked limit reviver", true)))); + private static final Supplier limitReviver = Suppliers.memoize(() -> + Tracers.wrap( + Executors.newSingleThreadScheduledExecutor( + Util.threadFactory("conjure-java-runtime/leaked limit reviver", true)))); /** * The {@link ScheduledExecutorService} used for scheduling call retries. This thread pool is distinct from OkHttp's @@ -111,9 +113,11 @@ public final class OkHttpClients { * #executionExecutor}, {@code corePoolSize} must not be zero for a {@link ScheduledThreadPoolExecutor}, see its * Javadoc. Since this executor will never hit zero threads, it must use daemon threads. */ - private static final Supplier schedulingExecutor = Suppliers.memoize( - () -> Tracers.wrap(Executors.newScheduledThreadPool( - NUM_SCHEDULING_THREADS, Util.threadFactory("conjure-java-runtime/OkHttp Scheduler", true)))); + private static final Supplier schedulingExecutor = Suppliers.memoize(() -> + Tracers.wrap( + Executors.newScheduledThreadPool( + NUM_SCHEDULING_THREADS, + Util.threadFactory("conjure-java-runtime/OkHttp Scheduler", true)))); private OkHttpClients() {} @@ -257,12 +261,14 @@ private static UserAgent augmentUserAgent(UserAgent agent, Class serviceClass UserAgent augmentedAgent = agent; String maybeServiceVersion = serviceClass.getPackage().getImplementationVersion(); - augmentedAgent = augmentedAgent.addAgent(UserAgent.Agent.of( - serviceClass.getSimpleName(), maybeServiceVersion != null ? maybeServiceVersion : "0.0.0")); + augmentedAgent = augmentedAgent.addAgent( + UserAgent.Agent.of( + serviceClass.getSimpleName(), maybeServiceVersion != null ? maybeServiceVersion : "0.0.0")); String maybeRemotingVersion = OkHttpClients.class.getPackage().getImplementationVersion(); - augmentedAgent = augmentedAgent.addAgent(UserAgent.Agent.of( - UserAgents.CONJURE_AGENT_NAME, maybeRemotingVersion != null ? maybeRemotingVersion : "0.0.0")); + augmentedAgent = augmentedAgent.addAgent( + UserAgent.Agent.of( + UserAgents.CONJURE_AGENT_NAME, maybeRemotingVersion != null ? maybeRemotingVersion : "0.0.0")); return augmentedAgent; } diff --git a/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/RemotingOkHttpCall.java b/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/RemotingOkHttpCall.java index f60d0b16f..6365ec6c4 100644 --- a/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/RemotingOkHttpCall.java +++ b/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/RemotingOkHttpCall.java @@ -227,8 +227,9 @@ public void onFailure(Call call, IOException exception) { Optional backoff = backoffStrategy.nextBackoff(); if (!shouldRetry(exception, backoff)) { callback.onFailure(call, new SafeIoException( - "Failed to complete the request due to an IOException", exception, UnsafeArg.of( - "requestUrl", call.request().url().toString()))); + "Failed to complete the request due to an IOException", + exception, + UnsafeArg.of("requestUrl", call.request().url().toString()))); return; } @@ -361,8 +362,9 @@ public Void visit(QosException.Throttle exception) { Optional nonAdvertizedBackoff = backoffStrategy.nextBackoff(); if (!nonAdvertizedBackoff.isPresent()) { callback.onFailure(call, new SafeIoException( - "Failed to complete the request due to QosException.Throttle", exception, UnsafeArg.of( - "requestUrl", call.request().url().toString()))); + "Failed to complete the request due to QosException.Throttle", + exception, + UnsafeArg.of("requestUrl", call.request().url().toString()))); return null; } @@ -389,8 +391,9 @@ public Void visit(QosException.Throttle exception) { public Void visit(QosException.RetryOther exception) { if (maxNumRelocations <= 0) { callback.onFailure(call, new SafeIoException( - "Exceeded the maximum number of allowed redirects", exception, UnsafeArg.of( - "requestUrl", call.request().url().toString()))); + "Exceeded the maximum number of allowed redirects", + exception, + UnsafeArg.of("requestUrl", call.request().url().toString()))); return null; } @@ -435,8 +438,9 @@ public Void visit(QosException.Unavailable exception) { Optional backoff = backoffStrategy.nextBackoff(); if (!backoff.isPresent()) { callback.onFailure(call, new SafeIoException( - "Failed to complete the request due to QosException.Unavailable", exception, UnsafeArg.of( - "requestUrl", call.request().url().toString()))); + "Failed to complete the request due to QosException.Unavailable", + exception, + UnsafeArg.of("requestUrl", call.request().url().toString()))); return null; } diff --git a/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/RemotingOkHttpClient.java b/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/RemotingOkHttpClient.java index 7c2fc5645..f457537d8 100644 --- a/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/RemotingOkHttpClient.java +++ b/okhttp-clients/src/main/java/com/palantir/conjure/java/okhttp/RemotingOkHttpClient.java @@ -136,7 +136,8 @@ private Optional redirectToNewRequest(HttpUrl current) { return urls.redirectToCurrent(current); } - throw new SafeIllegalStateException("Encountered unknown node selection strategy", SafeArg.of( - "nodeSelectionStrategy", nodeSelectionStrategy)); + throw new SafeIllegalStateException( + "Encountered unknown node selection strategy", + SafeArg.of("nodeSelectionStrategy", nodeSelectionStrategy)); } } diff --git a/okhttp-clients/src/test/java/com/palantir/conjure/java/okhttp/ConcurrencyLimitingInterceptorTest.java b/okhttp-clients/src/test/java/com/palantir/conjure/java/okhttp/ConcurrencyLimitingInterceptorTest.java index 217e8160d..c7ee89752 100644 --- a/okhttp-clients/src/test/java/com/palantir/conjure/java/okhttp/ConcurrencyLimitingInterceptorTest.java +++ b/okhttp-clients/src/test/java/com/palantir/conjure/java/okhttp/ConcurrencyLimitingInterceptorTest.java @@ -53,8 +53,9 @@ public final class ConcurrencyLimitingInterceptorTest { public void before() { request = new Request.Builder() .url("https://localhost:1234/call") - .tag(ConcurrencyLimiterListener.class, ConcurrencyLimiterListener.create() - .setLimiterListener(Futures.immediateFuture(listener))) + .tag( + ConcurrencyLimiterListener.class, + ConcurrencyLimiterListener.create().setLimiterListener(Futures.immediateFuture(listener))) .get() .build(); response = new Response.Builder() diff --git a/okhttp-clients/src/test/java/com/palantir/conjure/java/okhttp/OkHttpClientsTest.java b/okhttp-clients/src/test/java/com/palantir/conjure/java/okhttp/OkHttpClientsTest.java index 91891224e..2cfbd8272 100644 --- a/okhttp-clients/src/test/java/com/palantir/conjure/java/okhttp/OkHttpClientsTest.java +++ b/okhttp-clients/src/test/java/com/palantir/conjure/java/okhttp/OkHttpClientsTest.java @@ -822,13 +822,14 @@ public void sync_call_to_a_slow_endpoint_should_not_time_out_if_read_timeout_is_ .setBody("Hello, world!")); OkHttpClient client = OkHttpClients.withStableUris( - ClientConfigurations.of(ServiceConfiguration.builder() - .addUris(url) - // ClientConfigurations has a connectTimeout default of 10 seconds - .readTimeout(Duration.ZERO) // unlimited pls - .writeTimeout(Duration.ZERO) // unlimited pls - .security(SslConfiguration.of(Paths.get("src", "test", "resources", "trustStore.jks"))) - .build()), + ClientConfigurations.of( + ServiceConfiguration.builder() + .addUris(url) + // ClientConfigurations has a connectTimeout default of 10 seconds + .readTimeout(Duration.ZERO) // unlimited pls + .writeTimeout(Duration.ZERO) // unlimited pls + .security(SslConfiguration.of(Paths.get("src", "test", "resources", "trustStore.jks"))) + .build()), AGENT, hostEventsSink, OkHttpClientsTest.class);