Skip to content

Commit

Permalink
Merge pull request Netflix#1453 from tbvh/hyst-1283-test
Browse files Browse the repository at this point in the history
Add Javanica test for NotWrapped checked exception
  • Loading branch information
mattrjacobs authored Jan 6, 2017
2 parents deb628d + 80af3fc commit fb428cb
Showing 1 changed file with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest;
import com.netflix.hystrix.contrib.javanica.test.common.domain.User;
import com.netflix.hystrix.exception.ExceptionNotWrappedByHystrix;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -31,9 +32,7 @@
import java.util.concurrent.TimeoutException;

import static com.netflix.hystrix.contrib.javanica.test.common.CommonUtils.getHystrixCommandByKey;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -198,6 +197,25 @@ public void testCommandWithFallbackThatFailsByTimeOut() {
}
}

@Test
public void testCommandThrowsNotWrappedException() {
try {
userService.throwNotWrappedCheckedException();
fail();
} catch (NotWrappedCheckedException e) {
// pass
} catch (Throwable e) {
fail("'NotWrappedCheckedException' is expected exception.");
}finally {
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
com.netflix.hystrix.HystrixInvokableInfo getUserCommand = getHystrixCommandByKey("throwNotWrappedCheckedException");
// record failure in metrics
assertTrue(getUserCommand.getExecutionEvents().contains(HystrixEventType.FAILURE));
// and will not trigger fallback logic
verify(failoverService, never()).activate();
}
}

public static class UserService {

private FailoverService failoverService;
Expand Down Expand Up @@ -270,6 +288,15 @@ private void validate(String val) throws BadRequestException {
}
}

@HystrixCommand(fallbackMethod = "voidFallback")
void throwNotWrappedCheckedException() throws NotWrappedCheckedException {
throw new NotWrappedCheckedException();
}

private void voidFallback(){
failoverService.activate();
}

/*********************************************************************************/

@HystrixCommand
Expand Down Expand Up @@ -375,6 +402,9 @@ private RuntimeOperationException(String message) {
}
}

private static class NotWrappedCheckedException extends Exception implements ExceptionNotWrappedByHystrix {
}

static class UserException extends RuntimeException {
final int level;

Expand Down

0 comments on commit fb428cb

Please sign in to comment.