Search in sources :

Example 16 with HystrixRequestEvents

use of com.netflix.hystrix.metric.HystrixRequestEvents in project Hystrix by Netflix.

the class HystrixRequestEventsJsonStream method convertRequestsToJson.

public static String convertRequestsToJson(Collection<HystrixRequestEvents> requests) throws IOException {
    StringWriter jsonString = new StringWriter();
    JsonGenerator json = jsonFactory.createGenerator(jsonString);
    json.writeStartArray();
    for (HystrixRequestEvents request : requests) {
        writeRequestAsJson(json, request);
    }
    json.writeEndArray();
    json.close();
    return jsonString.getBuffer().toString();
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) HystrixRequestEvents(com.netflix.hystrix.metric.HystrixRequestEvents)

Example 17 with HystrixRequestEvents

use of com.netflix.hystrix.metric.HystrixRequestEvents in project Hystrix by Netflix.

the class SerialHystrixRequestEventsTest method testTwoSuccessesSameKey.

@Test
public void testTwoSuccessesSameKey() throws IOException {
    List<HystrixInvokableInfo<?>> executions = new ArrayList<HystrixInvokableInfo<?>>();
    HystrixInvokableInfo<Integer> foo1 = new SimpleExecution(fooKey, 23, HystrixEventType.SUCCESS);
    HystrixInvokableInfo<Integer> foo2 = new SimpleExecution(fooKey, 34, HystrixEventType.SUCCESS);
    executions.add(foo1);
    executions.add(foo2);
    HystrixRequestEvents request = new HystrixRequestEvents(executions);
    String actual = SerialHystrixRequestEvents.toJsonString(request);
    assertEquals("[{\"name\":\"Foo\",\"events\":[\"SUCCESS\"],\"latencies\":[23,34]}]", actual);
}
Also used : ArrayList(java.util.ArrayList) HystrixRequestEvents(com.netflix.hystrix.metric.HystrixRequestEvents) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Test(org.junit.Test)

Example 18 with HystrixRequestEvents

use of com.netflix.hystrix.metric.HystrixRequestEvents in project Hystrix by Netflix.

the class SerialHystrixRequestEventsTest method testSingleSuccessMultipleEmitsAndFallbackEmits.

@Test
public void testSingleSuccessMultipleEmitsAndFallbackEmits() throws IOException {
    List<HystrixInvokableInfo<?>> executions = new ArrayList<HystrixInvokableInfo<?>>();
    executions.add(new SimpleExecution(fooKey, 100, HystrixEventType.EMIT, HystrixEventType.EMIT, HystrixEventType.EMIT, HystrixEventType.FAILURE, HystrixEventType.FALLBACK_EMIT, HystrixEventType.FALLBACK_EMIT, HystrixEventType.FALLBACK_SUCCESS));
    HystrixRequestEvents request = new HystrixRequestEvents(executions);
    String actual = SerialHystrixRequestEvents.toJsonString(request);
    assertEquals("[{\"name\":\"Foo\",\"events\":[{\"name\":\"EMIT\",\"count\":3},\"FAILURE\",{\"name\":\"FALLBACK_EMIT\",\"count\":2},\"FALLBACK_SUCCESS\"],\"latencies\":[100]}]", actual);
}
Also used : ArrayList(java.util.ArrayList) HystrixRequestEvents(com.netflix.hystrix.metric.HystrixRequestEvents) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Test(org.junit.Test)

Example 19 with HystrixRequestEvents

use of com.netflix.hystrix.metric.HystrixRequestEvents in project Hystrix by Netflix.

the class SerialHystrixRequestEventsTest method testSingleFailureFallbackRejected.

@Test
public void testSingleFailureFallbackRejected() throws IOException {
    List<HystrixInvokableInfo<?>> executions = new ArrayList<HystrixInvokableInfo<?>>();
    executions.add(new SimpleExecution(fooKey, 103, HystrixEventType.FAILURE, HystrixEventType.FALLBACK_REJECTION));
    HystrixRequestEvents request = new HystrixRequestEvents(executions);
    String actual = SerialHystrixRequestEvents.toJsonString(request);
    assertEquals("[{\"name\":\"Foo\",\"events\":[\"FAILURE\",\"FALLBACK_REJECTION\"],\"latencies\":[103]}]", actual);
}
Also used : ArrayList(java.util.ArrayList) HystrixRequestEvents(com.netflix.hystrix.metric.HystrixRequestEvents) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Test(org.junit.Test)

Example 20 with HystrixRequestEvents

use of com.netflix.hystrix.metric.HystrixRequestEvents in project Hystrix by Netflix.

the class SerialHystrixRequestEventsTest method testMultipleResponsesFromCache.

@Test
public void testMultipleResponsesFromCache() throws IOException {
    List<HystrixInvokableInfo<?>> executions = new ArrayList<HystrixInvokableInfo<?>>();
    HystrixInvokableInfo<Integer> foo1 = new SimpleExecution(fooKey, 23, "cacheKeyA", HystrixEventType.SUCCESS);
    HystrixInvokableInfo<Integer> cachedFoo1 = new SimpleExecution(fooKey, "cacheKeyA");
    HystrixInvokableInfo<Integer> anotherCachedFoo1 = new SimpleExecution(fooKey, "cacheKeyA");
    executions.add(foo1);
    executions.add(cachedFoo1);
    executions.add(anotherCachedFoo1);
    HystrixRequestEvents request = new HystrixRequestEvents(executions);
    String actual = SerialHystrixRequestEvents.toJsonString(request);
    assertEquals("[{\"name\":\"Foo\",\"events\":[\"SUCCESS\"],\"latencies\":[23],\"cached\":2}]", actual);
}
Also used : ArrayList(java.util.ArrayList) HystrixRequestEvents(com.netflix.hystrix.metric.HystrixRequestEvents) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Test(org.junit.Test)

Aggregations

HystrixRequestEvents (com.netflix.hystrix.metric.HystrixRequestEvents)23 HystrixInvokableInfo (com.netflix.hystrix.HystrixInvokableInfo)22 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)21 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 StringWriter (java.io.StringWriter)1