Search in sources :

Example 16 with User

use of com.netflix.hystrix.contrib.javanica.test.common.domain.User in project Hystrix by Netflix.

the class BasicObservableTest method testGetUserWithRxCommandFallback.

@Test
public void testGetUserWithRxCommandFallback() {
    final User exUser = new User("def", "def");
    // blocking
    Observable<User> userObservable = userService.getUserRxCommandFallback(" ", "");
    assertEquals(exUser, userObservable.toBlocking().single());
    assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
    com.netflix.hystrix.HystrixInvokableInfo getUserRxCommandFallback = getHystrixCommandByKey("getUserRxCommandFallback");
    com.netflix.hystrix.HystrixInvokableInfo rxCommandFallback = getHystrixCommandByKey("rxCommandFallback");
    // confirm that command has failed
    assertTrue(getUserRxCommandFallback.getExecutionEvents().contains(HystrixEventType.FAILURE));
    assertTrue(getUserRxCommandFallback.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS));
    // and that fallback command was successful
    assertTrue(rxCommandFallback.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
Also used : User(com.netflix.hystrix.contrib.javanica.test.common.domain.User) Test(org.junit.Test) BasicHystrixTest(com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)

Example 17 with User

use of com.netflix.hystrix.contrib.javanica.test.common.domain.User 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 18 with User

use of com.netflix.hystrix.contrib.javanica.test.common.domain.User 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 19 with User

use of com.netflix.hystrix.contrib.javanica.test.common.domain.User in project Hystrix by Netflix.

the class BasicCommandTest method shouldWorkWithInheritedMethod.

@Test
public void shouldWorkWithInheritedMethod() {
    User u1 = advancedUserService.getUserSync("1", "name: ");
    assertGetUserSnycCommandExecuted(u1);
}
Also used : User(com.netflix.hystrix.contrib.javanica.test.common.domain.User) Test(org.junit.Test) BasicHystrixTest(com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)

Example 20 with User

use of com.netflix.hystrix.contrib.javanica.test.common.domain.User in project Hystrix by Netflix.

the class BasicCommandTest method testGetUserSync.

@Test
public void testGetUserSync() {
    User u1 = userService.getUserSync("1", "name: ");
    assertGetUserSnycCommandExecuted(u1);
}
Also used : User(com.netflix.hystrix.contrib.javanica.test.common.domain.User) Test(org.junit.Test) BasicHystrixTest(com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)

Aggregations

BasicHystrixTest (com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)24 User (com.netflix.hystrix.contrib.javanica.test.common.domain.User)24 Test (org.junit.Test)24 HystrixInvokableInfo (com.netflix.hystrix.HystrixInvokableInfo)6 HystrixThreadPoolProperties (com.netflix.hystrix.HystrixThreadPoolProperties)1 Profile (com.netflix.hystrix.contrib.javanica.test.common.domain.Profile)1