Search in sources :

Example 21 with HystrixInvokableInfo

use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.

the class BasicCommandFallbackTest method testGetUserAsyncFallbackAsyncCommand.

@Test
public void testGetUserAsyncFallbackAsyncCommand() throws ExecutionException, InterruptedException {
    Future<User> f1 = userService.getUserAsyncFallbackAsyncCommand(" ", "name: ");
    assertEquals("def", f1.get().getName());
    assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
    HystrixInvokableInfo<?> getUserAsyncFallbackAsyncCommand = getHystrixCommandByKey("getUserAsyncFallbackAsyncCommand");
    com.netflix.hystrix.HystrixInvokableInfo firstAsyncFallbackCommand = getHystrixCommandByKey("firstAsyncFallbackCommand");
    com.netflix.hystrix.HystrixInvokableInfo secondAsyncFallbackCommand = getHystrixCommandByKey("secondAsyncFallbackCommand");
    com.netflix.hystrix.HystrixInvokableInfo thirdAsyncFallbackCommand = getHystrixCommandByKey("thirdAsyncFallbackCommand");
    assertEquals("getUserAsyncFallbackAsyncCommand", getUserAsyncFallbackAsyncCommand.getCommandKey().name());
    // confirm that command has failed
    assertTrue(getUserAsyncFallbackAsyncCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
    // confirm that first fallback has failed
    assertTrue(firstAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
    // and that second fallback was successful
    assertTrue(secondAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
    assertTrue(thirdAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
    assertTrue(thirdAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
}
Also used : User(com.netflix.hystrix.contrib.javanica.test.common.domain.User) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Test(org.junit.Test) BasicHystrixTest(com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)

Example 22 with HystrixInvokableInfo

use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.

the class BasicDefaultFallbackTest method testClassScopeCommandDefaultFallback.

@Test
public void testClassScopeCommandDefaultFallback() {
    String res = serviceWithDefaultCommandFallback.requestString("");
    assertEquals(ServiceWithDefaultFallback.DEFAULT_RESPONSE, res);
    assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
    HystrixInvokableInfo<?> requestStringCommand = getHystrixCommandByKey("requestString");
    com.netflix.hystrix.HystrixInvokableInfo fallback = getHystrixCommandByKey("classDefaultFallback");
    assertEquals("requestString", requestStringCommand.getCommandKey().name());
    // confirm that command has failed
    assertTrue(requestStringCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
    assertTrue(requestStringCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
    // confirm that fallback was successful
    assertTrue(fallback.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
Also used : HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Test(org.junit.Test) BasicHystrixTest(com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)

Example 23 with HystrixInvokableInfo

use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.

the class BasicCollapserTest method testGetUserByIdWithFallbackWithThrowableParam.

@Test
public void testGetUserByIdWithFallbackWithThrowableParam() throws ExecutionException, InterruptedException {
    Future<User> f1 = userService.getUserByIdWithFallbackWithThrowableParam("1");
    Future<User> f2 = userService.getUserByIdWithFallbackWithThrowableParam("2");
    Future<User> f3 = userService.getUserByIdWithFallbackWithThrowableParam("3");
    Future<User> f4 = userService.getUserByIdWithFallbackWithThrowableParam("4");
    Future<User> f5 = userService.getUserByIdWithFallbackWithThrowableParam("5");
    assertEquals("name: 1", f1.get().getName());
    assertEquals("name: 2", f2.get().getName());
    assertEquals("name: 3", f3.get().getName());
    assertEquals("name: 4", f4.get().getName());
    assertEquals("name: 5", f5.get().getName());
    // 4 commands should be executed
    assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
    HystrixInvokableInfo<?> batchCommand = getHystrixCommandByKey("getUserByIdsThrowsException");
    com.netflix.hystrix.HystrixInvokableInfo fallback1 = getHystrixCommandByKey("getUserByIdsFallbackWithThrowableParam1");
    com.netflix.hystrix.HystrixInvokableInfo fallback2 = getHystrixCommandByKey("getUserByIdsFallbackWithThrowableParam2");
    com.netflix.hystrix.HystrixInvokableInfo fallback3 = getHystrixCommandByKey("getUserByIdsFallbackWithThrowableParam3");
    // confirm that command has failed
    assertTrue(batchCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
    assertTrue(fallback1.getExecutionEvents().contains(HystrixEventType.FAILURE));
    assertTrue(fallback2.getExecutionEvents().contains(HystrixEventType.FAILURE));
    assertTrue(fallback2.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
    // and that last fallback3 was successful
    assertTrue(fallback3.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
Also used : User(com.netflix.hystrix.contrib.javanica.test.common.domain.User) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Test(org.junit.Test) BasicHystrixTest(com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)

Example 24 with HystrixInvokableInfo

use of com.netflix.hystrix.HystrixInvokableInfo in project Hystrix by Netflix.

the class BasicCollapserTest method testGetUserByIdWithFallback.

@Test
public void testGetUserByIdWithFallback() throws ExecutionException, InterruptedException {
    Future<User> f1 = userService.getUserByIdWithFallback("1");
    Future<User> f2 = userService.getUserByIdWithFallback("2");
    Future<User> f3 = userService.getUserByIdWithFallback("3");
    Future<User> f4 = userService.getUserByIdWithFallback("4");
    Future<User> f5 = userService.getUserByIdWithFallback("5");
    assertEquals("name: 1", f1.get().getName());
    assertEquals("name: 2", f2.get().getName());
    assertEquals("name: 3", f3.get().getName());
    assertEquals("name: 4", f4.get().getName());
    assertEquals("name: 5", f5.get().getName());
    // two command should be executed: "getUserByIdWithFallback" and "getUserByIdsWithFallback"
    assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
    HystrixInvokableInfo<?> getUserByIdsWithFallback = getHystrixCommandByKey("getUserByIdsWithFallback");
    com.netflix.hystrix.HystrixInvokableInfo getUserByIdsFallback = getHystrixCommandByKey("getUserByIdsFallback");
    // confirm that command has failed
    assertTrue(getUserByIdsWithFallback.getExecutionEvents().contains(HystrixEventType.FAILURE));
    assertTrue(getUserByIdsWithFallback.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
    // and that fallback was successful
    assertTrue(getUserByIdsFallback.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
Also used : User(com.netflix.hystrix.contrib.javanica.test.common.domain.User) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Test(org.junit.Test) BasicHystrixTest(com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)

Example 25 with HystrixInvokableInfo

use of com.netflix.hystrix.HystrixInvokableInfo 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)

Aggregations

HystrixInvokableInfo (com.netflix.hystrix.HystrixInvokableInfo)33 Test (org.junit.Test)31 HystrixRequestEvents (com.netflix.hystrix.metric.HystrixRequestEvents)22 ArrayList (java.util.ArrayList)21 BasicHystrixTest (com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)8 User (com.netflix.hystrix.contrib.javanica.test.common.domain.User)6 HttpResourceGroup (com.netflix.ribbon.http.HttpResourceGroup)2 FallbackHandler (com.netflix.ribbon.hystrix.FallbackHandler)2 ByteBuf (io.netty.buffer.ByteBuf)2 Map (java.util.Map)2 Observable (rx.Observable)2 Func1 (rx.functions.Func1)2 HttpClientResponse (io.reactivex.netty.protocol.http.client.HttpClientResponse)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1