Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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