use of com.netflix.discovery.shared.resolver.EurekaEndpoint in project eureka by Netflix.
the class EurekaHttpClientsTest method setUp.
@Before
public void setUp() throws IOException {
clientConfig = mock(EurekaClientConfig.class);
transportConfig = mock(EurekaTransportConfig.class);
when(clientConfig.getEurekaServerTotalConnectionsPerHost()).thenReturn(10);
when(clientConfig.getEurekaServerTotalConnections()).thenReturn(10);
when(transportConfig.getSessionedClientReconnectIntervalSeconds()).thenReturn(10);
writeServer = new SimpleEurekaHttpServer(writeRequestHandler);
clusterResolver = new StaticClusterResolver<EurekaEndpoint>("regionA", new DefaultEndpoint("localhost", writeServer.getServerPort(), false, "/v2/"));
readServer = new SimpleEurekaHttpServer(readRequestHandler);
readServerURI = "http://localhost:" + readServer.getServerPort();
clientFactory = EurekaHttpClients.canonicalClientFactory("test", transportConfig, clusterResolver, new Jersey1TransportClientFactories().newTransportClientFactory(clientConfig, Collections.<ClientFilter>emptyList(), applicationInfoManager.getInfo()));
}
use of com.netflix.discovery.shared.resolver.EurekaEndpoint in project eureka by Netflix.
the class RetryableEurekaHttpClientTest method testQuarantineListIsResetWhenNoMoreServerAreAvailable.
@Test
public void testQuarantineListIsResetWhenNoMoreServerAreAvailable() throws Exception {
// First two call fail
simulateTransportError(0, CLUSTER_SIZE);
for (int i = 0; i < 2; i++) {
executeWithTransportErrorExpectation();
}
// Second call, should reset cluster quarantine list, and hit health node 0
when(clientFactory.newClient(Matchers.<EurekaEndpoint>anyVararg())).thenReturn(clusterDelegates.get(0));
reset(requestExecutor);
when(requestExecutor.execute(clusterDelegates.get(0))).thenReturn(EurekaHttpResponse.status(200));
retryableClient.execute(requestExecutor);
}
use of com.netflix.discovery.shared.resolver.EurekaEndpoint in project eureka by Netflix.
the class Jersey2TransportClientFactories method newTransportClientFactory.
@Override
public TransportClientFactory newTransportClientFactory(final EurekaClientConfig clientConfig, final Collection<ClientRequestFilter> additionalFilters, final InstanceInfo myInstanceInfo) {
final TransportClientFactory jerseyFactory = Jersey2ApplicationClientFactory.create(clientConfig, additionalFilters, myInstanceInfo, new EurekaClientIdentity(myInstanceInfo.getIPAddr(), "Jersey2DefaultClient"));
final TransportClientFactory metricsFactory = MetricsCollectingEurekaHttpClient.createFactory(jerseyFactory);
return new TransportClientFactory() {
@Override
public EurekaHttpClient newClient(EurekaEndpoint serviceUrl) {
return metricsFactory.newClient(serviceUrl);
}
@Override
public void shutdown() {
metricsFactory.shutdown();
jerseyFactory.shutdown();
}
};
}
use of com.netflix.discovery.shared.resolver.EurekaEndpoint in project eureka by Netflix.
the class RetryableEurekaHttpClientTest method testRequestsReuseSameConnectionIfThereIsNoError.
@Test
public void testRequestsReuseSameConnectionIfThereIsNoError() throws Exception {
when(clientFactory.newClient(Matchers.<EurekaEndpoint>anyVararg())).thenReturn(clusterDelegates.get(0));
when(requestExecutor.execute(clusterDelegates.get(0))).thenReturn(EurekaHttpResponse.status(200));
// First request creates delegate, second reuses it
for (int i = 0; i < 3; i++) {
EurekaHttpResponse<Void> httpResponse = retryableClient.execute(requestExecutor);
assertThat(httpResponse.getStatusCode(), is(equalTo(200)));
}
verify(clientFactory, times(1)).newClient(Matchers.<EurekaEndpoint>anyVararg());
verify(requestExecutor, times(3)).execute(clusterDelegates.get(0));
}
use of com.netflix.discovery.shared.resolver.EurekaEndpoint in project eureka by Netflix.
the class RetryableEurekaHttpClientTest method simulateTransportError.
private void simulateTransportError(int delegateFrom, int count) {
for (int i = 0; i < count; i++) {
int delegateId = delegateFrom + i;
when(clientFactory.newClient(Matchers.<EurekaEndpoint>anyVararg())).thenReturn(clusterDelegates.get(delegateId));
when(requestExecutor.execute(clusterDelegates.get(delegateId))).thenThrow(new TransportException("simulated network error"));
}
}
Aggregations