@@ -4347,6 +4347,25 @@ public void call(Throwable t1) {
4347
4347
assertEquals (1 , HystrixRequestLog .getCurrentRequest ().getAllExecutedCommands ().size ());
4348
4348
}
4349
4349
4350
+ @ Test
4351
+ public void testExceptionConvertedToBadRequestExceptionInExecutionHookBypassesCircuitBreaker (){
4352
+ TestCircuitBreaker circuitBreaker = new TestCircuitBreaker ();
4353
+ try {
4354
+ new ExceptionToBadRequestByExecutionHookCommand (circuitBreaker , ExecutionIsolationStrategy .THREAD ).execute ();
4355
+ fail ("we expect to receive a " + HystrixBadRequestException .class .getSimpleName ());
4356
+ } catch (HystrixBadRequestException e ) {
4357
+ // success
4358
+ e .printStackTrace ();
4359
+ } catch (Exception e ) {
4360
+ e .printStackTrace ();
4361
+ fail ("We expect a " + HystrixBadRequestException .class .getSimpleName () + " but got a " + e .getClass ().getSimpleName ());
4362
+ }
4363
+
4364
+ assertEquals (0 , circuitBreaker .metrics .getRollingCount (HystrixRollingNumberEvent .SUCCESS ));
4365
+ assertEquals (0 , circuitBreaker .metrics .getRollingCount (HystrixRollingNumberEvent .EXCEPTION_THROWN ));
4366
+ assertEquals (0 , circuitBreaker .metrics .getRollingCount (HystrixRollingNumberEvent .FAILURE ));
4367
+ }
4368
+
4350
4369
/* ******************************************************************************** */
4351
4370
/* ******************************************************************************** */
4352
4371
/* private HystrixCommand class implementations for unit testing */
@@ -4435,6 +4454,11 @@ TestCommandBuilder setExecutionSemaphore(TryableSemaphore executionSemaphore) {
4435
4454
return this ;
4436
4455
}
4437
4456
4457
+ TestCommandBuilder setExecutionHook (TestExecutionHook executionHook ) {
4458
+ this .executionHook = executionHook ;
4459
+ return this ;
4460
+ }
4461
+
4438
4462
}
4439
4463
4440
4464
}
@@ -5217,6 +5241,37 @@ protected String getCacheKey() {
5217
5241
5218
5242
}
5219
5243
5244
+ private static class BusinessException extends Exception {
5245
+ public BusinessException (String msg ) {
5246
+ super (msg );
5247
+ }
5248
+ }
5249
+
5250
+ private static class ExceptionToBadRequestByExecutionHookCommand extends TestHystrixCommand <Boolean > {
5251
+ public ExceptionToBadRequestByExecutionHookCommand (TestCircuitBreaker circuitBreaker , ExecutionIsolationStrategy isolationType ) {
5252
+ super (testPropsBuilder ()
5253
+ .setCircuitBreaker (circuitBreaker )
5254
+ .setCommandPropertiesDefaults (HystrixCommandPropertiesTest .getUnitTestPropertiesSetter ().withExecutionIsolationStrategy (isolationType ))
5255
+ .setExecutionHook (new TestExecutionHook (){
5256
+ @ Override
5257
+ public <T > Exception onRunError (HystrixInvokable <T > commandInstance , Exception e ) {
5258
+ super .onRunError (commandInstance , e );
5259
+ return new HystrixBadRequestException ("autoconverted exception" , e );
5260
+ }
5261
+ }));
5262
+ }
5263
+
5264
+ @ Override
5265
+ protected Boolean run () throws BusinessException {
5266
+ throw new BusinessException ("invalid input by the user" );
5267
+ }
5268
+
5269
+ @ Override
5270
+ protected String getCacheKey () {
5271
+ return "nein" ;
5272
+ }
5273
+ }
5274
+
5220
5275
private static class CommandWithErrorThrown extends TestHystrixCommand <Boolean > {
5221
5276
5222
5277
public CommandWithErrorThrown (TestCircuitBreaker circuitBreaker ) {
@@ -5404,4 +5459,5 @@ public <T> void onThreadComplete(HystrixInvokable<T> commandInstance) {
5404
5459
}
5405
5460
5406
5461
}
5462
+
5407
5463
}
0 commit comments