Search in sources :

Example 1 with ConsulHeartbeatTask

use of org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask in project spring-cloud-consul by spring-cloud.

the class ConsulHeartbeatTaskTests method disableReRegistration.

@Test
public void disableReRegistration() {
    TtlScheduler ttlScheduler = new TtlScheduler(heartbeatProperties, discoveryProperties, consulClient, ReregistrationPredicate.DEFAULT);
    ConsulHeartbeatTask consulHeartbeatTask = new ConsulHeartbeatTask(serviceId, ttlScheduler);
    heartbeatProperties.setReregisterServiceOnFailure(false);
    NewService service = new NewService();
    service.setId(serviceId);
    ttlScheduler.add(service);
    OperationException operationException = new OperationException(500, "Internal Server Error", "CheckID \"service:service-A\" does not have associated TTL");
    given(consulClient.agentCheckPass("service:" + serviceId)).willThrow(operationException);
    assertThatThrownBy(consulHeartbeatTask::run).isSameAs(operationException);
}
Also used : ConsulHeartbeatTask(org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask) NewService(com.ecwid.consul.v1.agent.model.NewService) OperationException(com.ecwid.consul.v1.OperationException) Test(org.junit.Test)

Example 2 with ConsulHeartbeatTask

use of org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask in project spring-cloud-consul by spring-cloud.

the class ConsulHeartbeatTaskTests method enableReRegistrationWithCustomPredicate.

@Test
public void enableReRegistrationWithCustomPredicate() {
    TtlScheduler ttlScheduler = new TtlScheduler(heartbeatProperties, discoveryProperties, consulClient, e -> e.getStatusContent().endsWith("does not have associated TTL"));
    ConsulHeartbeatTask consulHeartbeatTask = new ConsulHeartbeatTask(serviceId, ttlScheduler);
    heartbeatProperties.setReregisterServiceOnFailure(true);
    NewService service = new NewService();
    service.setId(serviceId);
    ttlScheduler.add(service);
    given(consulClient.agentCheckPass("service:" + serviceId)).willThrow(new OperationException(400, "Internal Server Error", "CheckID \"service:service-A\" does not have associated TTL"));
    consulHeartbeatTask.run();
    ArgumentCaptor<NewService> serviceCaptor = ArgumentCaptor.forClass(NewService.class);
    ArgumentCaptor<String> tokenCaptor = ArgumentCaptor.forClass(String.class);
    verify(consulClient, atLeastOnce()).agentServiceRegister(serviceCaptor.capture(), tokenCaptor.capture());
    assertThat(serviceCaptor.getValue()).isSameAs(service);
}
Also used : ConsulHeartbeatTask(org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask) NewService(com.ecwid.consul.v1.agent.model.NewService) OperationException(com.ecwid.consul.v1.OperationException) Test(org.junit.Test)

Example 3 with ConsulHeartbeatTask

use of org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask in project spring-cloud-consul by spring-cloud.

the class ConsulHeartbeatTaskTests method notEligibleForReRegistration.

@Test
public void notEligibleForReRegistration() {
    TtlScheduler ttlScheduler = new TtlScheduler(heartbeatProperties, discoveryProperties, consulClient, ReregistrationPredicate.DEFAULT);
    ConsulHeartbeatTask consulHeartbeatTask = new ConsulHeartbeatTask(serviceId, ttlScheduler);
    heartbeatProperties.setReregisterServiceOnFailure(true);
    NewService service = new NewService();
    service.setId(serviceId);
    ttlScheduler.add(service);
    OperationException operationException = new OperationException(400, "Internal Server Error", "CheckID \"service:service-A\" does not have associated TTL");
    given(consulClient.agentCheckPass("service:" + serviceId)).willThrow(operationException);
    assertThatThrownBy(consulHeartbeatTask::run).isSameAs(operationException);
}
Also used : ConsulHeartbeatTask(org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask) NewService(com.ecwid.consul.v1.agent.model.NewService) OperationException(com.ecwid.consul.v1.OperationException) Test(org.junit.Test)

Example 4 with ConsulHeartbeatTask

use of org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask in project spring-cloud-consul by spring-cloud.

the class ConsulHeartbeatTaskTests method enableReRegistration.

@Test
public void enableReRegistration() {
    TtlScheduler ttlScheduler = new TtlScheduler(heartbeatProperties, discoveryProperties, consulClient, ReregistrationPredicate.DEFAULT);
    ConsulHeartbeatTask consulHeartbeatTask = new ConsulHeartbeatTask(serviceId, ttlScheduler);
    heartbeatProperties.setReregisterServiceOnFailure(true);
    NewService service = new NewService();
    service.setId(serviceId);
    ttlScheduler.add(service);
    given(consulClient.agentCheckPass("service:" + serviceId)).willThrow(new OperationException(500, "Internal Server Error", "CheckID \"service:service-A\" does not have associated TTL"));
    consulHeartbeatTask.run();
    ArgumentCaptor<NewService> serviceCaptor = ArgumentCaptor.forClass(NewService.class);
    ArgumentCaptor<String> tokenCaptor = ArgumentCaptor.forClass(String.class);
    verify(consulClient, atLeastOnce()).agentServiceRegister(serviceCaptor.capture(), tokenCaptor.capture());
    assertThat(serviceCaptor.getValue()).isSameAs(service);
}
Also used : ConsulHeartbeatTask(org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask) NewService(com.ecwid.consul.v1.agent.model.NewService) OperationException(com.ecwid.consul.v1.OperationException) Test(org.junit.Test)

Aggregations

OperationException (com.ecwid.consul.v1.OperationException)4 NewService (com.ecwid.consul.v1.agent.model.NewService)4 Test (org.junit.Test)4 ConsulHeartbeatTask (org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask)4