本文整理汇总了Java中com.netflix.discovery.EurekaClient类的典型用法代码示例。如果您正苦于以下问题:Java EurekaClient类的具体用法?Java EurekaClient怎么用?Java EurekaClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EurekaClient类属于com.netflix.discovery包,在下文中一共展示了EurekaClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInstanceRegistrationUsingProvidedEurekaClient
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
@Test
public void testInstanceRegistrationUsingProvidedEurekaClient() {
EurekaClient eurekaClient = mock(EurekaClient.class);
ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
EurekaInstanceConfig eurekaInstanceConfig = mock(EurekaInstanceConfig.class);
when(eurekaClient.getApplicationInfoManager()).thenReturn(applicationInfoManager);
when(eurekaClient.getApplication(anyString())).thenReturn(new Application(APP_NAME));
when(applicationInfoManager.getEurekaInstanceConfig()).thenReturn(eurekaInstanceConfig);
when(eurekaInstanceConfig.getAppname()).thenReturn(APP_NAME);
// use provided EurekaClient
EurekaOneDiscoveryStrategyFactory.setEurekaClient(eurekaClient);
HazelcastInstance hz1 = factory.newHazelcastInstance();
HazelcastInstance hz2 = factory.newHazelcastInstance();
verify(eurekaClient, times(2)).getApplicationInfoManager();
verify(eurekaClient, times(2)).getApplication(APP_NAME);
verify(applicationInfoManager, never()).setInstanceStatus(InstanceStatus.UP);
verify(applicationInfoManager, never()).setInstanceStatus(any(InstanceStatus.class));
assertClusterSizeEventually(2, hz1);
assertClusterSizeEventually(2, hz2);
}
示例2: onWhenRequested
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
@Test
public void onWhenRequested() throws Exception {
setup("spring.cloud.config.discovery.enabled=true",
"eureka.instance.metadataMap.foo:bar",
"eureka.instance.nonSecurePort:7001", "eureka.instance.hostname:foo");
assertEquals(1, this.context.getBeanNamesForType(
EurekaDiscoveryClientConfigServiceAutoConfiguration.class).length);
EurekaClient eurekaClient = this.context.getParent().getBean(EurekaClient.class);
Mockito.verify(eurekaClient, times(2)).getInstancesByVipAddress(DEFAULT_CONFIG_SERVER,
false);
Mockito.verify(eurekaClient, times(1)).shutdown();
ConfigClientProperties locator = this.context
.getBean(ConfigClientProperties.class);
assertEquals("http://foo:7001/", locator.getRawUri());
ApplicationInfoManager infoManager = this.context
.getBean(ApplicationInfoManager.class);
assertEquals("bar", infoManager.getInfo().getMetadata().get("foo"));
}
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:19,代码来源:DiscoveryClientConfigServiceAutoConfigurationTests.java
示例3: testFailIfDiscoveryIsNotAvailable
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testFailIfDiscoveryIsNotAvailable() {
EurekaNotificationServerListUpdater serverListUpdater = new EurekaNotificationServerListUpdater(
new Provider<EurekaClient>() {
@Override
public EurekaClient get() {
return null;
}
},
testExecutor
);
serverListUpdater.start(new ServerListUpdater.UpdateAction() {
@Override
public void doUpdate() {
Assert.fail("Should not reach here");
}
});
}
示例4: setUp
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
@Before
public void setUp() {
PowerMock.mockStatic(DiscoveryClient.class);
EasyMock
.expect(DiscoveryClient.getZone(EasyMock.isA(InstanceInfo.class)))
.andReturn("zone")
.anyTimes();
eurekaClientMock = setUpEurekaClientMock(servers);
eurekaClientProvider = new Provider<EurekaClient>() {
@Override
public EurekaClient get() {
return eurekaClientMock;
}
};
config = DefaultClientConfigImpl.getClientConfigWithDefaultValues();
config.setProperty(CommonClientConfigKey.DeploymentContextBasedVipAddresses, vipAddress);
config.setProperty(CommonClientConfigKey.ServerListUpdaterClassName, EurekaNotificationServerListUpdater.class.getName());
}
示例5: setUpEurekaClientMock
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
private EurekaClient setUpEurekaClientMock(List<InstanceInfo> servers) {
final EurekaClient eurekaClientMock = PowerMock.createMock(EurekaClient.class);
EasyMock
.expect(eurekaClientMock.getInstancesByVipAddress(EasyMock.anyString(), EasyMock.anyBoolean(), EasyMock.anyString()))
.andReturn(servers.subList(0, initialServerListSize)).times(1)
.andReturn(servers.subList(initialServerListSize, servers.size())).anyTimes();
EasyMock
.expectLastCall();
EasyMock
.expect(eurekaClientMock.unregisterEventListener(EasyMock.isA(EurekaEventListener.class)))
.andReturn(true).anyTimes();
return eurekaClientMock;
}
示例6: EurekaServerRelationshipDetector
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
/**
* Eureka Server relationship detector.
*
* @param eurekaClients
* Eureka Client instances available (nullable).
*/
public EurekaServerRelationshipDetector(List<EurekaClient> eurekaClients) {
this.eurekaClients = new ArrayList<>();
if (eurekaClients != null) {
this.eurekaClients.addAll(eurekaClients);
}
}
示例7: multipleEurekaClientsShouldReturnSingleDependencyOnEurekaServer
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
@Test
public void multipleEurekaClientsShouldReturnSingleDependencyOnEurekaServer() {
EurekaClient eurekaClientMock = Mockito.mock(EurekaClient.class);
EurekaServerRelationshipDetector detector = new EurekaServerRelationshipDetector(
Arrays.asList(eurekaClientMock));
Dependency dependency = Dependency.on(Component.of("eureka-server", ComponentType.HTTP_APPLICATION_REGISTRY));
Set<Relationship> expected = new HashSet<>(Arrays.asList(dependency));
Assertions.assertThat(detector.detect()).isEqualTo(expected);
}
示例8: InstanceRegistry
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
public InstanceRegistry(EurekaServerConfig serverConfig,
EurekaClientConfig clientConfig, ServerCodecs serverCodecs,
EurekaClient eurekaClient, int expectedNumberOfRenewsPerMin,
int defaultOpenForTrafficCount) {
super(serverConfig, clientConfig, serverCodecs, eurekaClient);
this.expectedNumberOfRenewsPerMin = expectedNumberOfRenewsPerMin;
this.defaultOpenForTrafficCount = defaultOpenForTrafficCount;
}
示例9: getEurekaClient
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
private EurekaClient getEurekaClient(){
if (eurekaClient==null){
LifecycleInjectorBuilder builder = LifecycleInjector.builder();
Injector injector = builder.build().createInjector();
eurekaClient = injector.getInstance(EurekaClient.class);
}
return eurekaClient;
}
示例10: testHealthCheckHandlerRegistered
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
@Test
public void testHealthCheckHandlerRegistered() {
InjectorBuilder.fromModules(new EurekaHealthStatusBridgeModule(), new AbstractModule() {
@Override
protected void configure() {
bind(ApplicationInfoManager.class).toInstance(infoManager);
bind(EurekaClient.class).toInstance(eurekaClient);
bind(HealthCheckAggregator.class).toInstance(healthCheckAggregator);
}
}).createInjector();
Mockito.verify(eurekaClient, Mockito.times(1)).registerHealthCheck(Mockito.any(HealthCheckHandler.class));
}
示例11: setEurekaClient
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
EurekaOneDiscoveryStrategyBuilder setEurekaClient(final EurekaClient eurekaClient) {
this.eurekaClient = eurekaClient;
if (eurekaClient != null) {
this.applicationInfoManager = eurekaClient.getApplicationInfoManager();
this.changeStrategy = new NoopUpdater();
}
return this;
}
示例12: CompositeInfoEndpoint
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired
public CompositeInfoEndpoint(RestTemplate loadBalancedRestTemplate, DiscoveryClient discoveryClient, EurekaClient eurekaClient) {
this.restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(
HttpClientBuilder.create().setSSLHostnameVerifier((s, sslSession) -> true).build()));
this.loadBalancedRestTemplate = loadBalancedRestTemplate;
this.discoveryClient = discoveryClient;
this.eurekaClient = eurekaClient;
}
示例13: configure
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
@Override
protected void configure() {
bind(ApplicationInfoManager.class).in(Scopes.SINGLETON);
bind(EurekaClientConfig.class).in(Scopes.SINGLETON);
bind(InstanceInfo.class).in(Scopes.SINGLETON);
bind(EurekaClient.class).in(Scopes.SINGLETON);
bind(EurekaHealthCheck.class).asEagerSingleton();
bind(EurekaService.class).asEagerSingleton();
}
示例14: ribbonServerList
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public ServerList<?> ribbonServerList(IClientConfig config, Provider<EurekaClient> eurekaClientProvider) {
if (this.propertiesFactory.isSet(ServerList.class, serviceId)) {
return this.propertiesFactory.get(ServerList.class, config, serviceId);
}
DiscoveryEnabledNIWSServerList discoveryServerList = new DiscoveryEnabledNIWSServerList(
config, eurekaClientProvider);
DomainExtractingServerList serverList = new DomainExtractingServerList(
discoveryServerList, config, this.approximateZoneFromHostname);
return serverList;
}
示例15: EurekaHealthIndicator
import com.netflix.discovery.EurekaClient; //导入依赖的package包/类
public EurekaHealthIndicator(EurekaClient eurekaClient,
EurekaInstanceConfig instanceConfig, EurekaClientConfig clientConfig) {
super();
this.eurekaClient = eurekaClient;
this.instanceConfig = instanceConfig;
this.clientConfig = clientConfig;
}