Created
September 11, 2014 16:13
-
-
Save lordofthejars/9abc84212f050f12b53b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| @Test | |
| public void should_execute_fallback_method_when_circuit_is_open() { | |
| //Initialize HystrixRequestContext to be able to get some metrics | |
| HystrixRequestContext context = HystrixRequestContext.initializeContext(); | |
| HystrixCommandMetrics creditCardMetrics = HystrixCommandMetrics.getInstance(HystrixCommandKey.Factory.asKey(HelloWorldRestCommand.class.getSimpleName())); | |
| //We use Archaius to set the circuit as closed. | |
| ConfigurationManager.getConfigInstance().setProperty("hystrix.command.default.circuitBreaker.forceOpen", false); | |
| String successMessage = new HelloWorldRestCommand().execute(); | |
| assertThat(successMessage, is("Hello World")); | |
| //We use Archaius to open the circuit | |
| ConfigurationManager.getConfigInstance().setProperty("hystrix.command.default.circuitBreaker.forceOpen", true); | |
| String failMessage = new HelloWorldRestCommand().execute(); | |
| assertThat(failMessage, is("Good Bye")); | |
| //Prints Request => HelloWorldRestCommand[SUCCESS][19ms], HelloWorldRestCommand[SHORT_CIRCUITED, FALLBACK_SUCCESS][0ms] | |
| System.out.println("Request => " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString()); | |
| assertThat(creditCardMetrics.getHealthCounts().getTotalRequests(), is(2)); | |
| assertThat(creditCardMetrics.getHealthCounts().getErrorCount(), is(1)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment