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