@Test public void testInvokeTimeout() throws Exception { MethodConfig methodConfig = MethodConfig.createBuilder(SERVICE_NAME, BEAN_NAME + ":" + FIELD_NAME) .hystrixActive(true) .commandProperty(CommandProperties.EXECUTION_TIMEOUT_ENABLED, Boolean.TRUE.toString()) .build(); ServiceConfig serviceConfig = new ServiceConfig(methodConfig); HystrixMethodHandler hystrixMethodHandler = new HystrixMethodHandler(parentMethodHandler, serviceConfig); Method method = UnstableMicroservice.class.getMethod("timeout"); Mockito.when(parentMethodHandler.invoke(method)).thenAnswer(a -> method.invoke(UnstableMicroservice.class)); assertThatThrownBy(() -> hystrixMethodHandler.invoke(method)) .isInstanceOf(HystrixRuntimeException.class) .hasMessageContaining("timed-out"); }
@Override public Object invoke(final Method method, final Object... args) throws Exception { String serviceName = getProxyBean().getMicroserviceName(); String methodName = method.getName(); MethodConfig methodConfig = serviceConfig.getMethodConfig(method); if (methodConfig == null) { methodConfig = serviceConfig.getDefaultConfig(); } if (method.getDeclaringClass() == Object.class || methodConfig == null || !methodConfig.isHystrixActive()) { return methodHandler.invoke(method, args); } Setter setter = methodConfig.getHystrixCommandSetter(); String cacheKey = createCacheKey(serviceName, methodName, methodConfig, args); Callable<Object> fallback = fallbackService != null ? () -> method.invoke(fallbackService, args) : null; HystrixCommand<Object> hystrixCommand = new Builder<>(setter, () -> methodHandler.invoke(method, args)) .cacheKey(cacheKey) .fallback(fallback) .ignoredExceptions(methodConfig.getIgnoredExceptions()) .build(); try { return hystrixCommand.execute(); } catch (HystrixBadRequestException ex) { throw unwrapException(ex); } }
HystrixMethodHandler extends MicroserviceMethodHandler { @Override public Object invoke(final Method method, final Object... args) throws Exception { String serviceName = getProxyBean().getMicroserviceName(); String methodName = method.getName(); MethodConfig methodConfig = serviceConfig.getMethodConfig(method); if (methodConfig == null) { methodConfig = serviceConfig.getDefaultConfig(); } if (method.getDeclaringClass() == Object.class || methodConfig == null || !methodConfig.isHystrixActive()) { return methodHandler.invoke(method, args); } Setter setter = methodConfig.getHystrixCommandSetter(); String cacheKey = createCacheKey(serviceName, methodName, methodConfig, args); Callable<Object> fallback = fallbackService != null ? () -> method.invoke(fallbackService, args) : null; HystrixCommand<Object> hystrixCommand = new Builder<>(setter, () -> methodHandler.invoke(method, args)) .cacheKey(cacheKey) .fallback(fallback) .ignoredExceptions(methodConfig.getIgnoredExceptions()) .build(); try { return hystrixCommand.execute(); } catch (HystrixBadRequestException ex) { throw unwrapException(ex); } } }
HystrixMethodHandler extends MicroserviceMethodHandler { @Override public Object invoke(final Method method, final Object... args) throws Exception { String serviceName = getProxyBean().getMicroserviceName(); String methodName = method.getName(); MethodConfig methodConfig = serviceConfig.getMethodConfig(method); if (methodConfig == null) { methodConfig = serviceConfig.getDefaultConfig(); } if (method.getDeclaringClass() == Object.class || methodConfig == null || !methodConfig.isHystrixActive()) { return methodHandler.invoke(method, args); } Setter setter = methodConfig.getHystrixCommandSetter(); String cacheKey = createCacheKey(serviceName, methodName, methodConfig, args); Callable<Object> fallback = fallbackService != null ? () -> method.invoke(fallbackService, args) : null; HystrixCommand<Object> hystrixCommand = new Builder<>(setter, () -> methodHandler.invoke(method, args)) .cacheKey(cacheKey) .fallback(fallback) .ignoredExceptions(methodConfig.getIgnoredExceptions()) .build(); try { return hystrixCommand.execute(); } catch (HystrixBadRequestException ex) { throw unwrapException(ex); } } HystrixMethodHandler(final MicroserviceMethodHandler methodHandler);   HystrixMethodHandler(final MicroserviceMethodHandler methodHandler, final ServiceConfig serviceConfig); }
HystrixMethodHandler extends MicroserviceMethodHandler { @Override public Object invoke(final Method method, final Object... args) throws Exception { String serviceName = getProxyBean().getMicroserviceName(); String methodName = method.getName(); MethodConfig methodConfig = serviceConfig.getMethodConfig(method); if (methodConfig == null) { methodConfig = serviceConfig.getDefaultConfig(); } if (method.getDeclaringClass() == Object.class || methodConfig == null || !methodConfig.isHystrixActive()) { return methodHandler.invoke(method, args); } Setter setter = methodConfig.getHystrixCommandSetter(); String cacheKey = createCacheKey(serviceName, methodName, methodConfig, args); Callable<Object> fallback = fallbackService != null ? () -> method.invoke(fallbackService, args) : null; HystrixCommand<Object> hystrixCommand = new Builder<>(setter, () -> methodHandler.invoke(method, args)) .cacheKey(cacheKey) .fallback(fallback) .ignoredExceptions(methodConfig.getIgnoredExceptions()) .build(); try { return hystrixCommand.execute(); } catch (HystrixBadRequestException ex) { throw unwrapException(ex); } } HystrixMethodHandler(final MicroserviceMethodHandler methodHandler);   HystrixMethodHandler(final MicroserviceMethodHandler methodHandler, final ServiceConfig serviceConfig); @Override Object invoke(final Method method, final Object... args); @Override MicroserviceProxyBean getProxyBean(); @Override InjectionPoint getInjectionPoint(); }
HystrixMethodHandler extends MicroserviceMethodHandler { @Override public Object invoke(final Method method, final Object... args) throws Exception { String serviceName = getProxyBean().getMicroserviceName(); String methodName = method.getName(); MethodConfig methodConfig = serviceConfig.getMethodConfig(method); if (methodConfig == null) { methodConfig = serviceConfig.getDefaultConfig(); } if (method.getDeclaringClass() == Object.class || methodConfig == null || !methodConfig.isHystrixActive()) { return methodHandler.invoke(method, args); } Setter setter = methodConfig.getHystrixCommandSetter(); String cacheKey = createCacheKey(serviceName, methodName, methodConfig, args); Callable<Object> fallback = fallbackService != null ? () -> method.invoke(fallbackService, args) : null; HystrixCommand<Object> hystrixCommand = new Builder<>(setter, () -> methodHandler.invoke(method, args)) .cacheKey(cacheKey) .fallback(fallback) .ignoredExceptions(methodConfig.getIgnoredExceptions()) .build(); try { return hystrixCommand.execute(); } catch (HystrixBadRequestException ex) { throw unwrapException(ex); } } HystrixMethodHandler(final MicroserviceMethodHandler methodHandler);   HystrixMethodHandler(final MicroserviceMethodHandler methodHandler, final ServiceConfig serviceConfig); @Override Object invoke(final Method method, final Object... args); @Override MicroserviceProxyBean getProxyBean(); @Override InjectionPoint getInjectionPoint();  }