Search in sources :

Example 6 with EurekaClientConfig

use of com.netflix.discovery.EurekaClientConfig in project eureka by Netflix.

the class DiscoveryClientResource method getClient.

public EurekaClient getClient() {
    if (client == null) {
        try {
            applicationInfoManager = createApplicationManager();
            EurekaClientConfig clientConfig = createEurekaClientConfig();
            Jersey1DiscoveryClientOptionalArgs optionalArgs = new Jersey1DiscoveryClientOptionalArgs();
            eventBus = new EventBusImpl();
            optionalArgs.setEventBus(eventBus);
            client = new DiscoveryClient(applicationInfoManager, clientConfig, optionalArgs);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return client;
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) EventBusImpl(com.netflix.eventbus.impl.EventBusImpl) DiscoveryClient(com.netflix.discovery.DiscoveryClient) InvalidSubscriberException(com.netflix.eventbus.spi.InvalidSubscriberException) Jersey1DiscoveryClientOptionalArgs(com.netflix.discovery.shared.transport.jersey.Jersey1DiscoveryClientOptionalArgs)

Example 7 with EurekaClientConfig

use of com.netflix.discovery.EurekaClientConfig in project riposte by Nike-Inc.

the class EurekaHandlerTest method register_uses_createEurekaInstanceConfig_then_calls_initDiscoveryManager_with_it_and_sets_instance_status_UP.

@Test
public void register_uses_createEurekaInstanceConfig_then_calls_initDiscoveryManager_with_it_and_sets_instance_status_UP() {
    // given
    EurekaInstanceConfig instanceConfigMock = mock(EurekaInstanceConfig.class);
    doReturn(instanceConfigMock).when(handlerSpy).createEurekaInstanceConfig();
    assertThat(handlerSpy.registered.get()).isFalse();
    // when
    handlerSpy.register();
    // then
    assertThat(handlerSpy.registered.get()).isTrue();
    verify(handlerSpy).createEurekaInstanceConfig();
    ArgumentCaptor<EurekaClientConfig> clientConfigCaptor = ArgumentCaptor.forClass(EurekaClientConfig.class);
    verify(handlerSpy).initDiscoveryManager(eq(instanceConfigMock), clientConfigCaptor.capture());
    EurekaClientConfig clientConfigUsed = clientConfigCaptor.getValue();
    assertThat(clientConfigUsed).isInstanceOf(DefaultEurekaClientConfig.class);
    assertThat(Whitebox.getInternalState(clientConfigUsed, "namespace")).isEqualTo(handlerSpy.eurekaClientNamespace);
    verify(handlerSpy).setEurekaInstanceStatus(InstanceStatus.UP);
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) Test(org.junit.Test)

Example 8 with EurekaClientConfig

use of com.netflix.discovery.EurekaClientConfig in project eureka by Netflix.

the class Jersey2EurekaModuleTest method testDI.

@SuppressWarnings("deprecation")
@Test
public void testDI() {
    InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
    Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
    EurekaClient eurekaClient = injector.getInstance(EurekaClient.class);
    DiscoveryClient discoveryClient = injector.getInstance(DiscoveryClient.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClient(), eurekaClient);
    Assert.assertEquals(DiscoveryManager.getInstance().getDiscoveryClient(), discoveryClient);
    Assert.assertEquals(eurekaClient, discoveryClient);
    EurekaClientConfig eurekaClientConfig = injector.getInstance(EurekaClientConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClientConfig(), eurekaClientConfig);
    EurekaInstanceConfig eurekaInstanceConfig = injector.getInstance(EurekaInstanceConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaInstanceConfig(), eurekaInstanceConfig);
    Binding<TransportClientFactories> binding = injector.getExistingBinding(Key.get(TransportClientFactories.class));
    // has a binding for jersey2
    Assert.assertNotNull(binding);
    TransportClientFactories transportClientFactories = injector.getInstance(TransportClientFactories.class);
    Assert.assertTrue(transportClientFactories instanceof Jersey2TransportClientFactories);
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) Jersey2TransportClientFactories(com.netflix.discovery.shared.transport.jersey2.Jersey2TransportClientFactories) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient) Jersey2TransportClientFactories(com.netflix.discovery.shared.transport.jersey2.Jersey2TransportClientFactories) TransportClientFactories(com.netflix.discovery.shared.transport.jersey.TransportClientFactories) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 9 with EurekaClientConfig

use of com.netflix.discovery.EurekaClientConfig in project eureka by Netflix.

the class StatusUtilTest method getStatusUtil.

/**
     * @param replicas the number of replicas to mock
     * @param instances the number of instances to mock
     * @param minimum the minimum number of peers
     * @return the status utility with the mocked replicas/instances
     */
private StatusUtil getStatusUtil(int replicas, int instances, int minimum) {
    EurekaServerContext mockEurekaServerContext = mock(EurekaServerContext.class);
    List<InstanceInfo> mockInstanceInfos = getMockInstanceInfos(instances);
    Application mockApplication = mock(Application.class);
    when(mockApplication.getInstances()).thenReturn(mockInstanceInfos);
    ApplicationInfoManager mockAppInfoManager = mock(ApplicationInfoManager.class);
    when(mockAppInfoManager.getInfo()).thenReturn(mockInstanceInfos.get(0));
    when(mockEurekaServerContext.getApplicationInfoManager()).thenReturn(mockAppInfoManager);
    PeerAwareInstanceRegistry mockRegistry = mock(PeerAwareInstanceRegistry.class);
    when(mockRegistry.getApplication("stuff", false)).thenReturn(mockApplication);
    when(mockEurekaServerContext.getRegistry()).thenReturn(mockRegistry);
    List<PeerEurekaNode> mockNodes = getMockNodes(replicas);
    EurekaTransportConfig mockTransportConfig = mock(EurekaTransportConfig.class);
    when(mockTransportConfig.applicationsResolverUseIp()).thenReturn(false);
    EurekaClientConfig mockClientConfig = mock(EurekaClientConfig.class);
    when(mockClientConfig.getTransportConfig()).thenReturn(mockTransportConfig);
    EurekaServerConfig mockServerConfig = mock(EurekaServerConfig.class);
    when(mockServerConfig.getHealthStatusMinNumberOfAvailablePeers()).thenReturn(minimum);
    PeerEurekaNodes peerEurekaNodes = new PeerEurekaNodes(mockRegistry, mockServerConfig, mockClientConfig, null, mockAppInfoManager);
    PeerEurekaNodes spyPeerEurekaNodes = spy(peerEurekaNodes);
    when(spyPeerEurekaNodes.getPeerEurekaNodes()).thenReturn(mockNodes);
    when(mockEurekaServerContext.getPeerEurekaNodes()).thenReturn(spyPeerEurekaNodes);
    return new StatusUtil(mockEurekaServerContext);
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) InstanceInfo(com.netflix.appinfo.InstanceInfo) PeerAwareInstanceRegistry(com.netflix.eureka.registry.PeerAwareInstanceRegistry) EurekaServerContext(com.netflix.eureka.EurekaServerContext) PeerEurekaNode(com.netflix.eureka.cluster.PeerEurekaNode) PeerEurekaNodes(com.netflix.eureka.cluster.PeerEurekaNodes) EurekaServerConfig(com.netflix.eureka.EurekaServerConfig) EurekaTransportConfig(com.netflix.discovery.shared.transport.EurekaTransportConfig) Application(com.netflix.discovery.shared.Application) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Aggregations

EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)9 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)6 DiscoveryClient (com.netflix.discovery.DiscoveryClient)6 InstanceInfo (com.netflix.appinfo.InstanceInfo)5 Test (org.junit.Test)5 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)4 EurekaClient (com.netflix.discovery.EurekaClient)4 DefaultEurekaClientConfig (com.netflix.discovery.DefaultEurekaClientConfig)3 Archaius2VipAddressResolver (com.netflix.appinfo.providers.Archaius2VipAddressResolver)2 VipAddressResolver (com.netflix.appinfo.providers.VipAddressResolver)2 TransportClientFactories (com.netflix.discovery.shared.transport.jersey.TransportClientFactories)2 PeerEurekaNodes (com.netflix.eureka.cluster.PeerEurekaNodes)2 PeerAwareInstanceRegistry (com.netflix.eureka.registry.PeerAwareInstanceRegistry)2 AmazonInfo (com.netflix.appinfo.AmazonInfo)1 CloudInstanceConfig (com.netflix.appinfo.CloudInstanceConfig)1 Ec2EurekaArchaius2InstanceConfig (com.netflix.appinfo.Ec2EurekaArchaius2InstanceConfig)1 EurekaArchaius2InstanceConfig (com.netflix.appinfo.EurekaArchaius2InstanceConfig)1 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)1 EurekaConfigBasedInstanceInfoProvider (com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider)1 Application (com.netflix.discovery.shared.Application)1