Search in sources :

Example 1 with ServerSentEvent

use of io.reactivex.netty.protocol.http.sse.ServerSentEvent in project Hystrix by Netflix.

the class HystrixMetricsStreamHandlerTest method testMetricsAreDeliveredAsSseStream.

@Test
public void testMetricsAreDeliveredAsSseStream() throws Exception {
    replayAll();
    Observable<ServerSentEvent> objectObservable = client.submit(HttpClientRequest.createGet(DEFAULT_HYSTRIX_PREFIX)).flatMap(new Func1<HttpClientResponse<ServerSentEvent>, Observable<? extends ServerSentEvent>>() {

        @Override
        public Observable<? extends ServerSentEvent> call(HttpClientResponse<ServerSentEvent> httpClientResponse) {
            return httpClientResponse.getContent().take(1);
        }
    });
    Object first = Observable.amb(objectObservable, Observable.timer(5000, TimeUnit.MILLISECONDS)).toBlocking().first();
    assertTrue("Expected SSE message", first instanceof ServerSentEvent);
    ServerSentEvent sse = (ServerSentEvent) first;
    JsonNode jsonNode = mapper.readTree(sse.contentAsString());
    assertEquals("Expected hystrix key name", HystrixCommandMetricsSamples.SAMPLE_1.getCommandKey().name(), jsonNode.get("name").asText());
}
Also used : HttpClientResponse(io.reactivex.netty.protocol.http.client.HttpClientResponse) ServerSentEvent(io.reactivex.netty.protocol.http.sse.ServerSentEvent) JsonNode(com.fasterxml.jackson.databind.JsonNode) Observable(rx.Observable) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 HttpClientResponse (io.reactivex.netty.protocol.http.client.HttpClientResponse)1 ServerSentEvent (io.reactivex.netty.protocol.http.sse.ServerSentEvent)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Observable (rx.Observable)1