コード例 #1
0
 @Test
 public void testGetUserByIdAsynchronouslySuccess()
     throws ExecutionException, InterruptedException {
   User user = restClient.getUserByIdAsync("1").get();
   User exUser = new User("1", "Alex");
   assertExecutedCommands("getUserByIdAsync");
   HystrixCommand getUserByIdCommand = getHystrixCommandByKey("getUserByIdAsync");
   assertEquals(1, HystrixRequestLog.getCurrentRequest().getExecutedCommands().size());
   assertEquals("SimpleRestClient", getUserByIdCommand.getCommandGroup().name());
   assertEquals("getUserByIdAsync", getUserByIdCommand.getCommandKey().name());
   assertEquals(exUser, user);
   // confirm that command has success
   assertTrue(getUserByIdCommand.getExecutionEvents().contains(HystrixEventType.SUCCESS));
 }
コード例 #2
0
 @Test
 public void testGetUserByIdAsynchronouslyWithFallback()
     throws ExecutionException, InterruptedException {
   Future<User> userFuture = restClient.getUserByIdAsync("non-exists");
   User exUser = userFuture.get();
   assertExecutedCommands("getUserByIdAsync", "getUserByIdSecondary");
   HystrixCommand getUserByIdCommand = getHystrixCommandByKey("getUserByIdAsync");
   assertEquals("SimpleRestClient", getUserByIdCommand.getCommandGroup().name());
   assertEquals("getUserByIdAsync", getUserByIdCommand.getCommandKey().name());
   assertEquals(DEF_USER, exUser);
   // confirm that command has failed
   assertTrue(getUserByIdCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
   // and that fallback was successful
   assertTrue(getUserByIdCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
 }