forked from Netflix/Hystrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce NotWrappedByHystrix to mark Exceptions that should not be w…
…rapped in HystrixRunetimeException
- Loading branch information
Tim van Heugten
committed
Nov 6, 2016
1 parent
7598e9a
commit 9c357df
Showing
10 changed files
with
214 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
hystrix-core/src/main/java/com/netflix/hystrix/exception/ExceptionNotWrappedByHystrix.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.netflix.hystrix.exception; | ||
|
||
/** | ||
* Exceptions can implement this interface to prevent Hystrix from wrapping detected exceptions in a HystrixRuntimeException | ||
*/ | ||
public interface ExceptionNotWrappedByHystrix { | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
hystrix-core/src/main/java/com/netflix/hystrix/util/Exceptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.netflix.hystrix.util; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
public class Exceptions { | ||
private Exceptions() { | ||
} | ||
|
||
/** | ||
* Throws the argument, return-type is RuntimeException so the caller can use a throw statement break out of the method | ||
*/ | ||
public static RuntimeException sneakyThrow(Throwable t) { | ||
return Exceptions.<RuntimeException>doThrow(t); | ||
} | ||
|
||
private static <T extends Throwable> T doThrow(Throwable ex) throws T { | ||
throw (T) ex; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
hystrix-core/src/test/java/com/netflix/hystrix/NotWrappedByHystrixTestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.netflix.hystrix; | ||
|
||
import com.netflix.hystrix.exception.ExceptionNotWrappedByHystrix; | ||
|
||
public class NotWrappedByHystrixTestException extends Exception implements ExceptionNotWrappedByHystrix { | ||
private static final long serialVersionUID = 1L; | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
hystrix-core/src/test/java/com/netflix/hystrix/NotWrappedByHystrixTestRuntimeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.netflix.hystrix; | ||
|
||
import com.netflix.hystrix.exception.ExceptionNotWrappedByHystrix; | ||
|
||
public class NotWrappedByHystrixTestRuntimeException extends RuntimeException implements ExceptionNotWrappedByHystrix { | ||
private static final long serialVersionUID = 1L; | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
hystrix-core/src/test/java/com/netflix/hystrix/util/ExceptionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.netflix.hystrix.util; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
public class ExceptionsTest { | ||
|
||
@Test | ||
public void testCastOfException(){ | ||
Exception exception = new IOException("simulated checked exception message"); | ||
try{ | ||
Exceptions.sneakyThrow(exception); | ||
fail(); | ||
} catch(Exception e){ | ||
assertTrue(e instanceof IOException); | ||
} | ||
} | ||
} |