aboutsummaryrefslogtreecommitdiffstats
path: root/jaxrs_client_utils/src/test
diff options
context:
space:
mode:
authorHarald Musum <musum@oath.com>2018-10-31 21:05:12 +0100
committerGitHub <noreply@github.com>2018-10-31 21:05:12 +0100
commit875c0cb04d0f0450bfb68d8e548fcaea6022bd49 (patch)
tree9c3b311dcbc9f7569ffc56939273f3f26831b311 /jaxrs_client_utils/src/test
parent3db4288215479f38f7db9c1ddeeceb69a8ff93e5 (diff)
Revert "Enforce CC timeouts in Orchestrator [4]"
Diffstat (limited to 'jaxrs_client_utils/src/test')
-rw-r--r--jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/HttpPatchTest.java3
-rw-r--r--jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/RetryingJaxRsStrategyTest.java48
2 files changed, 25 insertions, 26 deletions
diff --git a/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/HttpPatchTest.java b/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/HttpPatchTest.java
index 8161602cdac..63e2b814c24 100644
--- a/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/HttpPatchTest.java
+++ b/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/HttpPatchTest.java
@@ -74,7 +74,8 @@ public class HttpPatchTest extends JerseyTest {
final JaxRsStrategy<TestResourceApi> client = factory.apiNoRetries(TestResourceApi.class, apiPath);
final String responseBody;
- responseBody = client.apply(api -> api.doPatch(REQUEST_BODY));
+ responseBody = client.apply(api ->
+ api.doPatch(REQUEST_BODY));
assertThat(testResourceSingleton.invocation.get(60, TimeUnit.SECONDS), is(REQUEST_BODY));
assertThat(responseBody, is(REQUEST_BODY));
diff --git a/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/RetryingJaxRsStrategyTest.java b/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/RetryingJaxRsStrategyTest.java
index dbe886b7896..e31920febd6 100644
--- a/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/RetryingJaxRsStrategyTest.java
+++ b/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/RetryingJaxRsStrategyTest.java
@@ -5,10 +5,7 @@ import com.yahoo.vespa.applicationmodel.HostName;
import com.yahoo.vespa.defaults.Defaults;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.OngoingStubbing;
import javax.ws.rs.GET;
@@ -18,26 +15,24 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
-import java.util.stream.Collectors;
-import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
public class RetryingJaxRsStrategyTest {
private static final String API_PATH = "/";
- @Captor
- ArgumentCaptor<JaxRsClientFactory.Params<TestJaxRsApi>> paramsCaptor;
-
@Path(API_PATH)
private interface TestJaxRsApi {
@GET
@@ -58,7 +53,8 @@ public class RetryingJaxRsStrategyTest {
@Before
public void setup() {
- when(jaxRsClientFactory.createClient(any())).thenReturn(mockApi);
+ when(jaxRsClientFactory.createClient(eq(TestJaxRsApi.class), any(HostName.class), anyInt(), anyString(), anyString()))
+ .thenReturn(mockApi);
}
@Test
@@ -67,12 +63,11 @@ public class RetryingJaxRsStrategyTest {
verify(mockApi, times(1)).doSomething();
- verify(jaxRsClientFactory, times(1)).createClient(paramsCaptor.capture());
- JaxRsClientFactory.Params<TestJaxRsApi> params = paramsCaptor.getValue();
- assertEquals(REST_PORT, params.uri().getPort());
- assertEquals(API_PATH, params.uri().getPath());
- assertEquals("http", params.uri().getScheme());
- assertThat(SERVER_HOSTS, hasItem(new HostName(params.uri().getHost())));
+ // Check that one of the supplied hosts is contacted.
+ final ArgumentCaptor<HostName> hostNameCaptor = ArgumentCaptor.forClass(HostName.class);
+ verify(jaxRsClientFactory, times(1))
+ .createClient(eq(TestJaxRsApi.class), hostNameCaptor.capture(), eq(REST_PORT), eq(API_PATH), eq("http"));
+ assertThat(SERVER_HOSTS.contains(hostNameCaptor.getValue()), is(true));
}
@Test
@@ -104,10 +99,10 @@ public class RetryingJaxRsStrategyTest {
@Test
public void testRetryLoopsOverAvailableServers() throws Exception {
when(mockApi.doSomething())
- .thenThrow(new ProcessingException("Fake socket timeout 1 induced by test"))
- .thenThrow(new ProcessingException("Fake socket timeout 2 induced by test"))
- .thenThrow(new ProcessingException("Fake socket timeout 3 induced by test"))
- .thenThrow(new ProcessingException("Fake socket timeout 4 induced by test"))
+ .thenThrow(new ProcessingException("Fake timeout 1 induced by test"))
+ .thenThrow(new ProcessingException("Fake timeout 2 induced by test"))
+ .thenThrow(new ProcessingException("Fake timeout 3 induced by test"))
+ .thenThrow(new ProcessingException("Fake timeout 4 induced by test"))
.thenReturn("a response");
jaxRsStrategy.apply(TestJaxRsApi::doSomething);
@@ -147,9 +142,12 @@ public class RetryingJaxRsStrategyTest {
verifyAllServersContacted(jaxRsClientFactory);
}
- private void verifyAllServersContacted(final JaxRsClientFactory jaxRsClientFactory) {
- verify(jaxRsClientFactory, atLeast(SERVER_HOSTS.size())).createClient(paramsCaptor.capture());
- final Set<JaxRsClientFactory.Params<TestJaxRsApi>> actualServerHostsContacted = new HashSet<>(paramsCaptor.getAllValues());
- assertEquals(actualServerHostsContacted.stream().map(x -> new HostName(x.uri().getHost())).collect(Collectors.toSet()), SERVER_HOSTS);
+ private static void verifyAllServersContacted(
+ final JaxRsClientFactory jaxRsClientFactory) {
+ final ArgumentCaptor<HostName> hostNameCaptor = ArgumentCaptor.forClass(HostName.class);
+ verify(jaxRsClientFactory, atLeast(SERVER_HOSTS.size()))
+ .createClient(eq(TestJaxRsApi.class), hostNameCaptor.capture(), eq(REST_PORT), eq(API_PATH), eq("http"));
+ final Set<HostName> actualServerHostsContacted = new HashSet<>(hostNameCaptor.getAllValues());
+ assertThat(actualServerHostsContacted, equalTo(SERVER_HOSTS));
}
}