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;
}
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);
}
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);
}
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);
}
Aggregations