本文整理汇总了Java中com.netflix.hystrix.exception.HystrixRuntimeException类的典型用法代码示例。如果您正苦于以下问题:Java HystrixRuntimeException类的具体用法?Java HystrixRuntimeException怎么用?Java HystrixRuntimeException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HystrixRuntimeException类属于com.netflix.hystrix.exception包,在下文中一共展示了HystrixRuntimeException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleException
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
protected ClientHttpResponse handleException(Map<String, Object> info,
HystrixRuntimeException ex) throws ZuulException {
int statusCode = HttpStatus.INTERNAL_SERVER_ERROR.value();
Throwable cause = ex;
String message = ex.getFailureType().toString();
ClientException clientException = findClientException(ex);
if (clientException == null) {
clientException = findClientException(ex.getFallbackException());
}
if (clientException != null) {
if (clientException
.getErrorType() == ClientException.ErrorType.SERVER_THROTTLED) {
statusCode = HttpStatus.SERVICE_UNAVAILABLE.value();
}
cause = clientException;
message = clientException.getErrorType().toString();
}
info.put("status", String.valueOf(statusCode));
throw new ZuulException(cause, "Forwarding error", statusCode, message);
}
示例2: itShouldFailCreatingDeviceCertificateIfApplicationDoesNotExist
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
@Test
public void itShouldFailCreatingDeviceCertificateIfApplicationDoesNotExist() throws Exception {
Cryptotool.Keys keys = cryptotool.generateKeys().block();
String publicKeyBase64 = CryptotoolUtils.encodeHexAsBase64(keys.getPublicKey());
CreateDeviceCertificateRequestDto body = CreateDeviceCertificateRequestDto.builder()
.devicePublicKey(publicKeyBase64)
.build();
String appId = application.getAppId().toHex();
String nonExistingApiKey = application.getApiKey() + "123";
try {
this.deviceCertClient
.createDeviceCertificate(appId, nonExistingApiKey, body)
.execute();
Assert.fail("Should have thrown exception.");
} catch (HystrixRuntimeException e) {
assertThat(e.getCause(), is(notNullValue()));
assertThat(e.getCause(), instanceOf(FeignException.class));
assertThat(((FeignException) e.getCause()).status(), is(HttpStatus.UNAUTHORIZED.value()));
}
}
示例3: itShouldFailGetAccessCertificateIfNonceHeaderIsMissing
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
@Test
public void itShouldFailGetAccessCertificateIfNonceHeaderIsMissing() throws Exception {
DeviceEntity device = deviceWithKeys.getDevice();
try {
GetAccessCertificatesResponseDto execute = accessCertClient
.fetchAccessCertificates("", "", device.getSerialNumber().toHex())
.execute();
Assert.fail("Should have thrown exception.");
} catch (HystrixRuntimeException e) {
assertThat(e.getCause(), is(notNullValue()));
assertThat(e.getCause(), instanceOf(FeignException.class));
assertThat(((FeignException) e.getCause()).status(), is(HttpStatus.BAD_REQUEST.value()));
}
}
示例4: errorInFallbackHasExpectedBehavior
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
@Test
public void errorInFallbackHasExpectedBehavior() {
thrown.expect(HystrixRuntimeException.class);
thrown.expectMessage("GitHub#contributors(String,String) failed and fallback failed.");
thrown.expectCause(
isA(FeignException.class)); // as opposed to RuntimeException (from the fallback)
server.enqueue(new MockResponse().setResponseCode(500));
GitHub fallback = new GitHub() {
@Override
public List<String> contributors(String owner, String repo) {
throw new RuntimeException("oops");
}
};
GitHub api = HystrixFeign.builder()
.target(GitHub.class, "http://localhost:" + server.getPort(), fallback);
api.contributors("Netflix", "feign");
}
示例5: rxObservableListFall_noFallback
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
@Test
public void rxObservableListFall_noFallback() {
server.enqueue(new MockResponse().setResponseCode(500));
TestInterface api = targetWithoutFallback();
Observable<List<String>> observable = api.listObservable();
assertThat(observable).isNotNull();
assertThat(server.getRequestCount()).isEqualTo(0);
TestSubscriber<List<String>> testSubscriber = new TestSubscriber<List<String>>();
observable.subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
assertThat(testSubscriber.getOnNextEvents()).isEmpty();
assertThat(testSubscriber.getOnErrorEvents().get(0))
.isInstanceOf(HystrixRuntimeException.class)
.hasMessage("TestInterface#listObservable() failed and no fallback available.");
}
示例6: rxCompletableFailWithoutFallback
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
@Test
public void rxCompletableFailWithoutFallback() {
server.enqueue(new MockResponse().setResponseCode(500));
TestInterface api = HystrixFeign.builder()
.target(TestInterface.class, "http://localhost:" + server.getPort());
Completable completable = api.completable();
assertThat(completable).isNotNull();
assertThat(server.getRequestCount()).isEqualTo(0);
TestSubscriber<String> testSubscriber = new TestSubscriber<String>();
completable.subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
testSubscriber.assertError(HystrixRuntimeException.class);
}
示例7: customSetter
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
@Test
public void customSetter() {
thrown.expect(HystrixRuntimeException.class);
thrown.expectMessage("POST / failed and no fallback available.");
server.enqueue(new MockResponse().setResponseCode(500));
SetterFactory commandKeyIsRequestLine = (target, method) -> {
String groupKey = target.name();
String commandKey = method.getAnnotation(RequestLine.class).value();
return HystrixCommand.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
};
TestInterface api = HystrixFeign.builder()
.setterFactory(commandKeyIsRequestLine)
.target(TestInterface.class, "http://localhost:" + server.getPort());
api.invoke();
}
示例8: testWithTimeout
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
@Test(expected = HystrixRuntimeException.class)
public void testWithTimeout() {
Underwood.forSingle(Integer.class)
.withGroup(GROUP)
.withName(NAME)
.withTimeout(TIMEOUT)
.execute(() -> {
try {
// Simulate delay to throw a timeout
Thread.sleep(TIMEOUT*2);
} catch (InterruptedException e) {
// Do nothing
}
return EXPECTED_VALUE;
});
}
示例9: testWithTimeout
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
@Test(expected = HystrixRuntimeException.class)
public void testWithTimeout() {
Underwood.forSet(Integer.class)
.withGroup(GROUP)
.withName(NAME)
.withTimeout(TIMEOUT)
.execute(() -> {
try {
// Simulate delay to throw a timeout
Thread.sleep(TIMEOUT*2);
} catch (InterruptedException e) {
// Do nothing
}
return EXPECTED_VALUE;
});
}
示例10: testWithTimeout
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
@Test(expected = HystrixRuntimeException.class)
public void testWithTimeout() {
Underwood.forList(Integer.class)
.withGroup(GROUP)
.withName(NAME)
.withTimeout(TIMEOUT)
.execute(() -> {
try {
// Simulate delay to throw a timeout
Thread.sleep(TIMEOUT*2);
} catch (InterruptedException e) {
// Do nothing
}
return EXPECTED_VALUE;
});
}
示例11: execute
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
/**
* Execute a function that returns a value
*/
private static <T> T execute(String commandKey, Supplier<T> function) {
try {
return new HystrixCommand<T>(buildSetter(commandKey)) {
@Override
protected T run() {
return function.get();
}
}.execute();
} catch (HystrixRuntimeException e) {
LOGGER.error("commandKey:" + commandKey);
if (e.getCause() instanceof RuntimeException) {
// Convert back to the underlying exception type
throw (RuntimeException) e.getCause();
} else {
throw e;
}
}
}
示例12: shouldPropagateExceptionWhenHystrixCommandThrowsException
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
@Test(expected = HystrixRuntimeException.class)
public void shouldPropagateExceptionWhenHystrixCommandThrowsException() throws Exception {
EndpointCallExecutable<HystrixCommand<String>, String> executable = factory
.create(new SimpleEndpointMethod(SomeType.class.getMethod("command")), delegate);
HystrixCommand<String> hystrixCommand = executable.execute(() -> {throw new RuntimeException("oooh!");}, null);
hystrixCommand.execute();
}
开发者ID:ljtfreitas,项目名称:java-restify,代码行数:10,代码来源:HystrixCommandEndpointCallExecutableFactoryTest.java
示例13: apply
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
public GatewayFilter apply(Setter setter, URI fallbackUri) {
return (exchange, chain) -> {
RouteHystrixCommand command = new RouteHystrixCommand(setter, fallbackUri, exchange, chain);
return Mono.create(s -> {
Subscription sub = command.toObservable().subscribe(s::success, s::error, s::success);
s.onCancel(sub::unsubscribe);
}).onErrorResume((Function<Throwable, Mono<Void>>) throwable -> {
if (throwable instanceof HystrixRuntimeException) {
HystrixRuntimeException e = (HystrixRuntimeException) throwable;
if (e.getFailureType() == TIMEOUT) { //TODO: optionally set status
setResponseStatus(exchange, HttpStatus.GATEWAY_TIMEOUT);
return exchange.getResponse().setComplete();
}
}
return Mono.empty();
}).then();
};
}
示例14: shouldCloseSpanOnInternalServerError
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
@Test
public void shouldCloseSpanOnInternalServerError() throws InterruptedException {
try {
this.feignInterface.internalError();
} catch (HystrixRuntimeException e) {
}
Awaitility.await().untilAsserted(() -> {
then(this.capture.toString())
.doesNotContain("Tried to close span but it is not the current span");
then(ExceptionUtils.getLastException()).isNull();
then(new ListOfSpans(this.listener.getEvents()))
.hasASpanWithTagEqualTo(Span.SPAN_ERROR_TAG_NAME,
"Request processing failed; nested exception is java.lang.RuntimeException: Internal Error");
});
}
示例15: execute
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入依赖的package包/类
protected T execute() throws Throwable {
HystrixCommand<HystrixResult<T>> command = createHystrixCommand();
HystrixResult<T> result;
try {
result = command.execute();
} catch (HystrixRuntimeException e) {
// TODO: Add unit test for this case
e.printStackTrace();
throw new ServiceUnavailableException(e.getFailureType().toString());
}
throwExceptionIfExecutionFailed(result);
return result.getResult();
}