From 77856197e3039cdeb7f73a73b3f83f5c7bbfdd14 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Tue, 10 Jul 2018 11:53:02 -0400 Subject: [PATCH] Update gradle, formatting changes --- gradle/wrapper/gradle-wrapper.properties | 2 +- .../jaeger/throttler/HttpThrottlerProxy.java | 20 +++++----- .../uber/jaeger/mocks/MockAgentResource.java | 2 +- .../throttler/HttpThrottlerProxyTest.java | 14 +++++++ .../jaeger/throttler/RemoteThrottlerTest.java | 39 ++++++++++++------- 5 files changed, 50 insertions(+), 27 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 89626ea..933b647 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip diff --git a/jaeger-core/src/main/java/com/uber/jaeger/throttler/HttpThrottlerProxy.java b/jaeger-core/src/main/java/com/uber/jaeger/throttler/HttpThrottlerProxy.java index 6bc43d6..72bd7d3 100644 --- a/jaeger-core/src/main/java/com/uber/jaeger/throttler/HttpThrottlerProxy.java +++ b/jaeger-core/src/main/java/com/uber/jaeger/throttler/HttpThrottlerProxy.java @@ -28,8 +28,7 @@ public class HttpThrottlerProxy implements ThrottlerProxy { private static final String DEFAULT_HOST_PORT = "localhost:5778"; - private static final Type RESPONSE_TYPE = new TypeToken() { - }.getType(); + private static final Type RESPONSE_TYPE = new TypeToken() {}.getType(); private final Gson gson = new Gson(); private final String hostPort; @@ -46,11 +45,8 @@ CreditResponse parseJson(String json) throws ThrottlerException { } @Override - public CreditResponse getCredits( - int clientId, - String serviceName, - List operations - ) throws ThrottlerException { + public CreditResponse getCredits(int clientId, String serviceName, List operations) + throws ThrottlerException { String jsonString; try { StringBuffer operationsQueryBuffer = new StringBuffer(); @@ -59,9 +55,13 @@ public CreditResponse getCredits( } jsonString = makeGetRequest( - "http://" + hostPort + "/credits?" - + "uuid=" + URLEncoder.encode(Integer.toString(clientId), "UTF-8") - + "&service=" + URLEncoder.encode(serviceName, "UTF-8") + "http://" + + hostPort + + "/credits?" + + "uuid=" + + URLEncoder.encode(Integer.toString(clientId), "UTF-8") + + "&service=" + + URLEncoder.encode(serviceName, "UTF-8") + operationsQueryBuffer.toString()); } catch (IOException e) { throw new ThrottlerException( diff --git a/jaeger-core/src/test/java/com/uber/jaeger/mocks/MockAgentResource.java b/jaeger-core/src/test/java/com/uber/jaeger/mocks/MockAgentResource.java index 5f389d8..cfdbe66 100644 --- a/jaeger-core/src/test/java/com/uber/jaeger/mocks/MockAgentResource.java +++ b/jaeger-core/src/test/java/com/uber/jaeger/mocks/MockAgentResource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Uber Technologies, Inc + * Copyright (c) 2016-2018, Uber Technologies, Inc * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at diff --git a/jaeger-core/src/test/java/com/uber/jaeger/throttler/HttpThrottlerProxyTest.java b/jaeger-core/src/test/java/com/uber/jaeger/throttler/HttpThrottlerProxyTest.java index 0b482a7..d7dd902 100644 --- a/jaeger-core/src/test/java/com/uber/jaeger/throttler/HttpThrottlerProxyTest.java +++ b/jaeger-core/src/test/java/com/uber/jaeger/throttler/HttpThrottlerProxyTest.java @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2018, Uber Technologies, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + package com.uber.jaeger.throttler; import com.uber.jaeger.mocks.MockAgentResource; diff --git a/jaeger-core/src/test/java/com/uber/jaeger/throttler/RemoteThrottlerTest.java b/jaeger-core/src/test/java/com/uber/jaeger/throttler/RemoteThrottlerTest.java index d2ed206..a4f2810 100644 --- a/jaeger-core/src/test/java/com/uber/jaeger/throttler/RemoteThrottlerTest.java +++ b/jaeger-core/src/test/java/com/uber/jaeger/throttler/RemoteThrottlerTest.java @@ -5,7 +5,10 @@ import com.uber.jaeger.metrics.Metrics; import com.uber.jaeger.throttler.http.CreditResponse; import com.uber.jaeger.throttler.http.OperationBalance; -import org.glassfish.hk2.api.Operation; + +import java.util.Collections; +import java.util.List; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -13,17 +16,11 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.class) public class RemoteThrottlerTest { @@ -52,15 +49,23 @@ public void testFetchCredits() throws Exception { final int REFRESH_INTERVAL_MS = 10; throttler = new RemoteThrottler(proxy, metrics, REFRESH_INTERVAL_MS, true); throttler.isAllowed(OPERATION_NAME); - final List operationBalances = Collections.singletonList(new OperationBalance(OPERATION_NAME, 1)); + final List operationBalances = + Collections.singletonList(new OperationBalance(OPERATION_NAME, 1)); final CreditResponse response = new CreditResponse(operationBalances); - when(proxy.getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), anyList())).thenReturn(response).thenReturn(new CreditResponse(Collections.EMPTY_LIST)); - verify(proxy, timeout(REFRESH_INTERVAL_MS * 3).times(0)).getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), anyList()); + when(proxy.getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), anyList())) + .thenReturn(response) + .thenReturn(new CreditResponse(Collections.EMPTY_LIST)); + verify(proxy, timeout(REFRESH_INTERVAL_MS * 3).times(0)) + .getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), anyList()); throttler.setProcess(new TracedProcess(SERVICE_NAME, 123, Collections.EMPTY_MAP)); final List operations = Collections.singletonList(OPERATION_NAME); - verify(proxy, timeout(REFRESH_INTERVAL_MS * 10).atLeastOnce()).getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), eq(operations)); - assertTrue(metricsFactory.getCounter("jaeger:throttler_updates", Collections.singletonMap("result", "ok")) > 0); + verify(proxy, timeout(REFRESH_INTERVAL_MS * 10).atLeastOnce()) + .getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), eq(operations)); + assertTrue( + metricsFactory.getCounter( + "jaeger:throttler_updates", Collections.singletonMap("result", "ok")) + > 0); assertTrue(throttler.isAllowed(OPERATION_NAME)); assertFalse(throttler.isAllowed(OPERATION_NAME)); assertFalse(throttler.isAllowed(OPERATION_NAME)); @@ -73,7 +78,11 @@ public void testNullResponse() throws Exception { throttler.setProcess(new TracedProcess(SERVICE_NAME, 123, Collections.EMPTY_MAP)); throttler.isAllowed(OPERATION_NAME); final List operations = Collections.singletonList(OPERATION_NAME); - verify(proxy, timeout(REFRESH_INTERVAL_MS * 10).atLeastOnce()).getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), eq(operations)); - assertTrue(metricsFactory.getCounter("jaeger:throttler_updates", Collections.singletonMap("result", "err")) > 0); + verify(proxy, timeout(REFRESH_INTERVAL_MS * 10).atLeastOnce()) + .getCredits(eq(CLIENT_ID), eq(SERVICE_NAME), eq(operations)); + assertTrue( + metricsFactory.getCounter( + "jaeger:throttler_updates", Collections.singletonMap("result", "err")) + > 0); } }