use of com.ecwid.consul.v1.OperationException in project spring-cloud-consul by spring-cloud.
the class ConsulInboundMessageProducer method getEvents.
// @Scheduled(fixedDelayString = "${spring.cloud.consul.binder.eventDelay:30000}")
public void getEvents() {
try {
List<Event> events = this.eventService.watch();
for (Event event : events) {
// Map<String, Object> headers = new HashMap<>();
// headers.put(MessageHeaders.REPLY_CHANNEL, outputChannel.)
String decoded = new String(decodeFromString(event.getPayload()));
sendMessage(getMessageBuilderFactory().withPayload(decoded).build());
}
} catch (OperationException e) {
if (logger.isErrorEnabled()) {
logger.error("Error getting consul events: " + e);
}
} catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error("Error getting consul events: " + e.getMessage());
}
if (logger.isDebugEnabled()) {
logger.debug("Error getting consul events", e);
}
}
}
use of com.ecwid.consul.v1.OperationException 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 com.ecwid.consul.v1.OperationException 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 com.ecwid.consul.v1.OperationException 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 com.ecwid.consul.v1.OperationException 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