Search in sources :

Example 6 with EurekaEndpoint

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()));
}
Also used : Jersey1TransportClientFactories(com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories) EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) DefaultEndpoint(com.netflix.discovery.shared.resolver.DefaultEndpoint) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint) Before(org.junit.Before)

Example 7 with EurekaEndpoint

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);
}
Also used : AwsEndpoint(com.netflix.discovery.shared.resolver.aws.AwsEndpoint) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint) Test(org.junit.Test)

Example 8 with EurekaEndpoint

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();
        }
    };
}
Also used : EurekaClientIdentity(com.netflix.appinfo.EurekaClientIdentity) TransportClientFactory(com.netflix.discovery.shared.transport.TransportClientFactory) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint)

Example 9 with EurekaEndpoint

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));
}
Also used : AwsEndpoint(com.netflix.discovery.shared.resolver.aws.AwsEndpoint) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint) Test(org.junit.Test)

Example 10 with EurekaEndpoint

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"));
    }
}
Also used : TransportException(com.netflix.discovery.shared.transport.TransportException) AwsEndpoint(com.netflix.discovery.shared.resolver.aws.AwsEndpoint) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint)

Aggregations

EurekaEndpoint (com.netflix.discovery.shared.resolver.EurekaEndpoint)10 TransportClientFactory (com.netflix.discovery.shared.transport.TransportClientFactory)4 AwsEndpoint (com.netflix.discovery.shared.resolver.aws.AwsEndpoint)3 EurekaClientIdentity (com.netflix.appinfo.EurekaClientIdentity)2 TransportException (com.netflix.discovery.shared.transport.TransportException)2 Test (org.junit.Test)2 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)1 DefaultEndpoint (com.netflix.discovery.shared.resolver.DefaultEndpoint)1 EurekaHttpClient (com.netflix.discovery.shared.transport.EurekaHttpClient)1 Jersey1TransportClientFactories (com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories)1 ExceptionsMetric (com.netflix.discovery.util.ExceptionsMetric)1 ClientFilter (com.sun.jersey.api.client.filter.ClientFilter)1 ApacheHttpClient4 (com.sun.jersey.client.apache4.ApacheHttpClient4)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Before (org.junit.Before)1