Skip to content

Commit

Permalink
changes after using palantir/palantir-java-format#94
Browse files Browse the repository at this point in the history
  • Loading branch information
dansanduleac committed Dec 4, 2019
1 parent 915552d commit b5d6f00
Show file tree
Hide file tree
Showing 36 changed files with 332 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public static Collection<Object[]> 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)
Expand All @@ -78,14 +79,15 @@ public static Collection<Object[]> 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<Error> expectationFailure = shouldSucceed ? expectSuccess(method) : expectFailure(method);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ public static Collection<Object[]> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<Map<String, String>>readValue(
"{\"test\":null}", new TypeReference<Map<String, String>>() {}))
assertThat(
MAPPER.<Map<String, String>>readValue(
"{\"test\":null}", new TypeReference<Map<String, String>>() {}))
.isEqualTo(Collections.singletonMap("test", null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public static <T> T create(
UserAgent userAgent,
HostEventsSink hostEventsSink,
Refreshable<ClientConfiguration> 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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public QosErrorDecoder(ErrorDecoder delegate) {
@Override
public Exception decode(String methodKey, Response response) {
Optional<Exception> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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());
Expand All @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

public final class HeaderAccessUtilsTest {
private static final ImmutableMap<String, Collection<String>> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public final class ServiceConfigTest extends TestBase {

@Rule
public final DropwizardAppRule<ServiceConfigTestAppConfig> rule = new DropwizardAppRule<>(
ServiceConfigTestServer.ServiceConfigTestApp.class, ServiceConfigTest.class
ServiceConfigTestServer.ServiceConfigTestApp.class,
ServiceConfigTest.class
.getClassLoader()
.getResource("service-config-example.yml")
.getPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public String toString(final T value) {
return new ParamConverter<T>() {
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading

0 comments on commit b5d6f00

Please sign in to comment.