use of io.github.resilience4j.common.timelimiter.monitoring.endpoint.TimeLimiterEventDTO in project resilience4j by resilience4j.
the class TimeLimiterEventDTOTest method shouldMapTimeLimiterOnErrorEvent.
@Test
public void shouldMapTimeLimiterOnErrorEvent() {
TimeLimiterOnErrorEvent event = new TimeLimiterOnErrorEvent("name", new IOException("Error message"));
TimeLimiterEventDTO timeLimiterEventDTO = TimeLimiterEventDTO.createTimeLimiterEventDTO(event);
assertThat(timeLimiterEventDTO.getTimeLimiterName()).isEqualTo("name");
assertThat(timeLimiterEventDTO.getType()).isEqualTo(TimeLimiterEvent.Type.ERROR);
assertThat(timeLimiterEventDTO.getCreationTime()).isNotNull();
}
use of io.github.resilience4j.common.timelimiter.monitoring.endpoint.TimeLimiterEventDTO in project resilience4j by resilience4j.
the class TimeLimiterEventDTOTest method shouldMapTimeLimiterOnTimeoutEvent.
@Test
public void shouldMapTimeLimiterOnTimeoutEvent() {
TimeLimiterOnTimeoutEvent event = new TimeLimiterOnTimeoutEvent("name");
TimeLimiterEventDTO timeLimiterEventDTO = TimeLimiterEventDTO.createTimeLimiterEventDTO(event);
assertThat(timeLimiterEventDTO.getTimeLimiterName()).isEqualTo("name");
assertThat(timeLimiterEventDTO.getType()).isEqualTo(TimeLimiterEvent.Type.TIMEOUT);
assertThat(timeLimiterEventDTO.getCreationTime()).isNotNull();
}
use of io.github.resilience4j.common.timelimiter.monitoring.endpoint.TimeLimiterEventDTO in project resilience4j by resilience4j.
the class TimeLimiterEventDTOTest method shouldMapTimeLimiterOnSuccessEvent.
@Test
public void shouldMapTimeLimiterOnSuccessEvent() {
TimeLimiterOnSuccessEvent event = new TimeLimiterOnSuccessEvent("name");
TimeLimiterEventDTO timeLimiterEventDTO = TimeLimiterEventDTO.createTimeLimiterEventDTO(event);
assertThat(timeLimiterEventDTO.getTimeLimiterName()).isEqualTo("name");
assertThat(timeLimiterEventDTO.getType()).isEqualTo(TimeLimiterEvent.Type.SUCCESS);
assertThat(timeLimiterEventDTO.getCreationTime()).isNotNull();
}
use of io.github.resilience4j.common.timelimiter.monitoring.endpoint.TimeLimiterEventDTO in project resilience4j by resilience4j.
the class TimeLimiterChain method execute.
@Override
public void execute(Chain chain) throws Exception {
String prefix = chain.getRegistry().get(Resilience4jConfig.class).getEndpoints().getTimelimiter().getPath();
chain.prefix(prefix, chain1 -> {
chain1.get("events", ctx -> Promise.<TimeLimiterEventsEndpointResponse>async(d -> {
List<TimeLimiterEventDTO> eventsList = eventConsumerRegistry.getAllEventConsumer().stream().flatMap(CircularEventConsumer::getBufferedEventsStream).sorted(Comparator.comparing(TimeLimiterEvent::getCreationTime)).map(TimeLimiterEventDTO::createTimeLimiterEventDTO).collect(Collectors.toList());
d.success(new TimeLimiterEventsEndpointResponse(eventsList));
}).then(r -> ctx.render(Jackson.json(r))));
chain1.get("stream/events", ctx -> {
Flux<TimeLimiterEvent> eventStreams = Flux.fromIterable(timeLimiterRegistry.getAllTimeLimiters()).flatMap(timeLimiter -> ReactorAdapter.toFlux(timeLimiter.getEventPublisher()));
Function<TimeLimiterEvent, String> data = r -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(TimeLimiterEventDTO.createTimeLimiterEventDTO(r));
ServerSentEvents events = ServerSentEvents.serverSentEvents(eventStreams, e -> e.id(TimeLimiterEvent::getTimeLimiterName).event(c -> c.getEventType().name()).data(data));
ctx.render(events);
});
chain1.get("events/:name", ctx -> {
String timeLimiterName = ctx.getPathTokens().get("name");
Promise.<TimeLimiterEventsEndpointResponse>async(d -> {
List<TimeLimiterEventDTO> eventsList = eventConsumerRegistry.getEventConsumer(timeLimiterName).getBufferedEventsStream().sorted(Comparator.comparing(TimeLimiterEvent::getCreationTime)).map(TimeLimiterEventDTO::createTimeLimiterEventDTO).collect(Collectors.toList());
d.success(new TimeLimiterEventsEndpointResponse(eventsList));
}).then(r -> ctx.render(Jackson.json(r)));
});
chain1.get("stream/events/:name", ctx -> {
String timeLimiterName = ctx.getPathTokens().get("name");
TimeLimiter timeLimiter = timeLimiterRegistry.getAllTimeLimiters().stream().filter(tL -> tL.getName().equals(timeLimiterName)).findAny().orElseThrow(() -> new IllegalArgumentException(String.format("time limiter with name %s not found", timeLimiterName)));
Function<TimeLimiterEvent, String> data = r -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(TimeLimiterEventDTO.createTimeLimiterEventDTO(r));
ServerSentEvents events = ServerSentEvents.serverSentEvents(ReactorAdapter.toFlux(timeLimiter.getEventPublisher()), e -> e.id(TimeLimiterEvent::getTimeLimiterName).event(c -> c.getEventType().name()).data(data));
ctx.render(events);
});
chain1.get("events/:name/:type", ctx -> {
String timeLimiterName = ctx.getPathTokens().get("name");
String eventType = ctx.getPathTokens().get("type");
Promise.<TimeLimiterEventsEndpointResponse>async(d -> {
List<TimeLimiterEventDTO> eventsList = eventConsumerRegistry.getEventConsumer(timeLimiterName).getBufferedEventsStream().sorted(Comparator.comparing(TimeLimiterEvent::getCreationTime)).filter(event -> event.getEventType() == TimeLimiterEvent.Type.valueOf(eventType.toUpperCase())).map(TimeLimiterEventDTO::createTimeLimiterEventDTO).collect(Collectors.toList());
d.success(new TimeLimiterEventsEndpointResponse(eventsList));
}).then(r -> ctx.render(Jackson.json(r)));
});
chain1.get("stream/events/:name/:type", ctx -> {
String timeLimiterName = ctx.getPathTokens().get("name");
String eventType = ctx.getPathTokens().get("type");
TimeLimiter timeLimiter = timeLimiterRegistry.getAllTimeLimiters().stream().filter(rL -> rL.getName().equals(timeLimiterName)).findAny().orElseThrow(() -> new IllegalArgumentException(String.format("time limiter with name %s not found", timeLimiterName)));
Flux<TimeLimiterEvent> eventStream = ReactorAdapter.toFlux(timeLimiter.getEventPublisher()).filter(event -> event.getEventType() == TimeLimiterEvent.Type.valueOf(eventType.toUpperCase()));
Function<TimeLimiterEvent, String> data = r -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(TimeLimiterEventDTO.createTimeLimiterEventDTO(r));
ServerSentEvents events = ServerSentEvents.serverSentEvents(eventStream, e -> e.id(TimeLimiterEvent::getTimeLimiterName).event(c -> c.getEventType().name()).data(data));
ctx.render(events);
});
});
}
Aggregations