本文整理汇总了Java中com.netflix.appinfo.InstanceInfo.InstanceStatus类的典型用法代码示例。如果您正苦于以下问题:Java InstanceStatus类的具体用法?Java InstanceStatus怎么用?Java InstanceStatus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InstanceStatus类属于com.netflix.appinfo.InstanceInfo包,在下文中一共展示了InstanceStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInstanceRegistrationUsingProvidedEurekaClient
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的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: beforeMethod
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
@Before
public void beforeMethod() {
eurekaIsDisabledPropertySupplierMock = mock(Supplier.class);
datacenterTypePropertySupplierMock = mock(Supplier.class);
cloudInstanceConfigMock = mock(CloudInstanceConfig.class);
doReturn(false).when(eurekaIsDisabledPropertySupplierMock).get();
doReturn(MyOwn.name()).when(datacenterTypePropertySupplierMock).get();
handlerSpy = spy(new EurekaHandler(eurekaIsDisabledPropertySupplierMock, datacenterTypePropertySupplierMock));
doNothing().when(handlerSpy).initDiscoveryManager(any(EurekaInstanceConfig.class),
any(EurekaClientConfig.class));
doNothing().when(handlerSpy).shutdownDiscoveryManager();
doNothing().when(handlerSpy).setEurekaInstanceStatus(any(InstanceStatus.class));
doReturn(cloudInstanceConfigMock).when(handlerSpy).createCloudInstanceConfig(anyString());
}
示例3: mock
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
@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);
}
示例4: markAsUp_sets_instance_status_to_up_only_if_eureka_is_enabled
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
@DataProvider(value = {
"true",
"false"
})
@Test
public void markAsUp_sets_instance_status_to_up_only_if_eureka_is_enabled(
boolean eurekaDisabled
) {
// given
doReturn(eurekaDisabled).when(eurekaIsDisabledPropertySupplierMock).get();
// when
handlerSpy.markAsUp();
// then
if (eurekaDisabled)
verify(handlerSpy, never()).setEurekaInstanceStatus(any(InstanceStatus.class));
else
verify(handlerSpy).setEurekaInstanceStatus(InstanceStatus.UP);
}
示例5: onApplicationEvent
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
//we only want to tell Eureka that the application is up
//when the root application context (thisApplicationContext) has
//been fully started. we want to ignore any ContextRefreshedEvent
//from child application contexts.
if (!event.getSource().equals(thisApplicationContext)) {
return;
}
if (event instanceof ContextRefreshedEvent) {
if (!disableEureka) {
// tell Eureka the server UP which in turn starts the health checks and heartbeat
ApplicationInfoManager.getInstance().setInstanceStatus(InstanceStatus.UP);
}
} else if (event instanceof ContextClosedEvent) {
if (!disableEureka) {
ApplicationInfoManager.getInstance().setInstanceStatus(InstanceStatus.DOWN);
}
}
}
示例6: testServiceRegistration
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
@Test
public void testServiceRegistration() throws InterruptedException {
// Registers "chasis-default-name" with a Eurkea server running on local host.
// http://localhost:8184/v2/apps/chassis-default-name
// tell eureka the service is up which causes a registration
ApplicationInfoManager.getInstance().setInstanceStatus(InstanceInfo.InstanceStatus.UP);
// get application registration from Eureka
DiscoveryClient client = DiscoveryManager.getInstance().getDiscoveryClient();
InstanceInfo instanceInfo = null;
for (int i = 0; (instanceInfo == null) && (i < 50); i++) {
Thread.sleep(5000);
try {
instanceInfo = client.getNextServerFromEureka("default-service", false);
} catch (RuntimeException e) {
// eat not found runtime exception
}
}
Assert.assertNotNull(instanceInfo);
Assert.assertEquals(InstanceStatus.UP, instanceInfo.getStatus());
System.out.println("done");
}
示例7: sendHeartBeat
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
@Override
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id,
InstanceInfo info, InstanceStatus overriddenStatus) {
String urlPath = serviceUrl + "apps/" + appName + '/' + id + "?status="
+ info.getStatus().toString() + "&lastDirtyTimestamp="
+ info.getLastDirtyTimestamp().toString() + (overriddenStatus != null
? "&overriddenstatus=" + overriddenStatus.name() : "");
ResponseEntity<InstanceInfo> response = restTemplate.exchange(urlPath,
HttpMethod.PUT, null, InstanceInfo.class);
EurekaHttpResponseBuilder<InstanceInfo> eurekaResponseBuilder = anEurekaHttpResponse(
response.getStatusCodeValue(), InstanceInfo.class)
.headers(headersOf(response));
if (response.hasBody())
eurekaResponseBuilder.entity(response.getBody());
return eurekaResponseBuilder.build();
}
示例8: getStatus
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
@Override
public InstanceStatus getStatus(InstanceStatus currentStatus) {
try {
if (matcher != null) {
return getInstanceStatusForHealth(healthCheckAggregator.check(matcher).get());
} else {
return getInstanceStatusForHealth(healthCheckAggregator.check().get());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例9: getInstanceStatusForHealth
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
private InstanceStatus getInstanceStatusForHealth(HealthCheckStatus health) {
if (health.isHealthy()) {
return InstanceStatus.UP;
} else {
return InstanceStatus.DOWN;
}
}
示例10: register_does_nothing_if_eureka_is_disabled
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
@Test
public void register_does_nothing_if_eureka_is_disabled() {
// given
doReturn(true).when(eurekaIsDisabledPropertySupplierMock).get();
// when
handlerSpy.register();
// then
verify(handlerSpy, never()).createEurekaInstanceConfig();
verify(handlerSpy, never()).initDiscoveryManager(any(EurekaInstanceConfig.class),
any(EurekaClientConfig.class));
verify(handlerSpy, never()).setEurekaInstanceStatus(any(InstanceStatus.class));
}
示例11: register_does_nothing_if_already_registered
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
@Test
public void register_does_nothing_if_already_registered() {
// given
handlerSpy.registered.set(true);
// when
handlerSpy.register();
// then
verify(handlerSpy, never()).createEurekaInstanceConfig();
verify(handlerSpy, never()).initDiscoveryManager(any(EurekaInstanceConfig.class),
any(EurekaClientConfig.class));
verify(handlerSpy, never()).setEurekaInstanceStatus(any(InstanceStatus.class));
}
示例12: register
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
@Override
public InstanceInfo register(Application application) {
InstanceInfo instanceInfo = getInstanceInfo(application);
InstanceStatus status = InstanceStatus.UP;
if (application.getInstance_id().endsWith("down")) {
status = InstanceStatus.DOWN;
}
return instanceInfo;
}
开发者ID:spencergibb,项目名称:spring-cloud-netflix-eureka-lite,代码行数:10,代码来源:EurekaLiteApplicationTests.java
示例13: checkDiscovery
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
@Scheduled(fixedDelay = 3000L)
public void checkDiscovery() {
InstanceStatus latestStatus = discoveryClient.getInstanceRemoteStatus();
if(!latestStatus.equals(currentStatus)) {
this.currentStatus = latestStatus;
publisher.publishEvent(new EurekaStatusChangedEvent(latestStatus));
}
}
开发者ID:netflix-spring-one,项目名称:spring-cloud-netflix-contrib,代码行数:9,代码来源:EurekaStatusApplicationEventPublisher.java
示例14: onEurekaStatusDown
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
@EventListener
public void onEurekaStatusDown(EurekaStatusChangedEvent event)
{
if(event.getStatus() == InstanceStatus.DOWN || event.getStatus() == InstanceStatus.OUT_OF_SERVICE)
{
System.out.println("Stopping adapters...");
controlChannel.send("@*ChannelAdapter.stop()");
}
}
示例15: createInstance
import com.netflix.appinfo.InstanceInfo.InstanceStatus; //导入依赖的package包/类
InstanceInfo createInstance(int id) {
return InstanceInfo.Builder.newBuilder()
.setHostName("localhost:800" + id)
.setAppName("foo")
.setStatus(InstanceStatus.UP)
.build();
}