Search in sources :

Example 1 with HystrixInvokableInfo

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

the class CommonUtils method getHystrixCommandByKey.

public static HystrixInvokableInfo getHystrixCommandByKey(String key) {
    HystrixInvokableInfo hystrixCommand = null;
    Collection<HystrixInvokableInfo<?>> executedCommands = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands();
    for (HystrixInvokableInfo command : executedCommands) {
        if (command.getCommandKey().name().equals(key)) {
            hystrixCommand = command;
            break;
        }
    }
    return hystrixCommand;
}
Also used : HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo)

Example 2 with HystrixInvokableInfo

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

the class BasicCommandFallbackTest method testAsyncCommandWithAsyncFallbackCommand.

@Test
public void testAsyncCommandWithAsyncFallbackCommand() throws ExecutionException, InterruptedException {
    Future<User> userFuture = userService.asyncCommandWithAsyncFallbackCommand("", "");
    User user = userFuture.get();
    assertEquals("def", user.getId());
    assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
    HystrixInvokableInfo<?> asyncCommandWithAsyncFallbackCommand = getHystrixCommandByKey("asyncCommandWithAsyncFallbackCommand");
    com.netflix.hystrix.HystrixInvokableInfo asyncFallbackCommand = getHystrixCommandByKey("asyncFallbackCommand");
    // confirm that command has failed
    assertTrue(asyncCommandWithAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
    assertTrue(asyncCommandWithAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
    // and that second fallback was successful
    assertTrue(asyncFallbackCommand.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 3 with HystrixInvokableInfo

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

the class BasicCommandFallbackTest method testGetUserAsyncWithFallbackCommand.

/**
     * * **************************** *
     * * * TEST FALLBACK COMMANDS * *
     * * **************************** *
     */
@Test
public void testGetUserAsyncWithFallbackCommand() throws ExecutionException, InterruptedException {
    Future<User> f1 = userService.getUserAsyncFallbackCommand(" ", "name: ");
    assertEquals("def", f1.get().getName());
    assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
    HystrixInvokableInfo<?> getUserAsyncFallbackCommand = getHystrixCommandByKey("getUserAsyncFallbackCommand");
    com.netflix.hystrix.HystrixInvokableInfo firstFallbackCommand = getHystrixCommandByKey("firstFallbackCommand");
    com.netflix.hystrix.HystrixInvokableInfo secondFallbackCommand = getHystrixCommandByKey("secondFallbackCommand");
    assertEquals("getUserAsyncFallbackCommand", getUserAsyncFallbackCommand.getCommandKey().name());
    // confirm that command has failed
    assertTrue(getUserAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
    // confirm that first fallback has failed
    assertTrue(firstFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
    // and that second fallback was successful
    assertTrue(secondFallbackCommand.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 4 with HystrixInvokableInfo

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

the class BasicCommandFallbackTest method testGetUserSyncWithFallbackCommand.

@Test
public void testGetUserSyncWithFallbackCommand() {
    User u1 = userService.getUserSyncFallbackCommand(" ", "name: ");
    assertEquals("def", u1.getName());
    assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
    HystrixInvokableInfo<?> getUserSyncFallbackCommand = getHystrixCommandByKey("getUserSyncFallbackCommand");
    com.netflix.hystrix.HystrixInvokableInfo firstFallbackCommand = getHystrixCommandByKey("firstFallbackCommand");
    com.netflix.hystrix.HystrixInvokableInfo secondFallbackCommand = getHystrixCommandByKey("secondFallbackCommand");
    assertEquals("getUserSyncFallbackCommand", getUserSyncFallbackCommand.getCommandKey().name());
    // confirm that command has failed
    assertTrue(getUserSyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
    // confirm that first fallback has failed
    assertTrue(firstFallbackCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
    // and that second fallback was successful
    assertTrue(secondFallbackCommand.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 5 with HystrixInvokableInfo

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

the class BasicDefaultFallbackTest method testCommandScopeCommandDefaultFallback.

@Test
public void testCommandScopeCommandDefaultFallback() {
    Long res = serviceWithDefaultCommandFallback.commandWithDefaultFallback(1L);
    assertEquals(Long.valueOf(0L), res);
    assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
    HystrixInvokableInfo<?> requestStringCommand = getHystrixCommandByKey("commandWithDefaultFallback");
    com.netflix.hystrix.HystrixInvokableInfo fallback = getHystrixCommandByKey("defaultCommandFallback");
    assertEquals("commandWithDefaultFallback", 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)

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