use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method scheduleInvocationTimeout.
@Test
public void scheduleInvocationTimeout(@Mocked OperationMeta operationMeta) {
Executor executor = Runnable::run;
new Expectations() {
{
restOperation.getOperationMeta();
result = operationMeta;
operationMeta.getExecutor();
result = executor;
operationMeta.getMicroserviceQualifiedName();
result = "sayHi";
}
};
requestEx = new AbstractHttpServletRequestForTest();
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected void runOnExecutor() {
throw new RuntimeExceptionWithoutStackTrace("run on executor");
}
};
restInvocation.requestEx = requestEx;
restInvocation.restOperationMeta = restOperation;
// will not throw exception
restInvocation.scheduleInvocation();
invocation.onFinish(Response.ok(null));
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestHttpServerFilterBeforeSendResponseExecutor method runFail.
@Test
public void runFail() throws InterruptedException, ExecutionException {
httpServerFilters.add(new HttpServerFilterBaseForTest() {
@Override
public CompletableFuture<Void> beforeSendResponseAsync(Invocation invocation, HttpServletResponseEx responseEx) {
throw new RuntimeExceptionWithoutStackTrace();
}
});
CompletableFuture<Void> result = executor.run();
expectedException.expect(ExecutionException.class);
expectedException.expectCause(Matchers.instanceOf(RuntimeExceptionWithoutStackTrace.class));
result.get();
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method sendFailResponseNoProduceProcessor.
@Test
public void sendFailResponseNoProduceProcessor() {
invocation.onStart(0);
restInvocation.produceProcessor = null;
restInvocation.sendFailResponse(new RuntimeExceptionWithoutStackTrace());
Assert.assertSame(ProduceProcessorManager.INSTANCE.findDefaultJsonProcessor(), restInvocation.produceProcessor);
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestAbstractEdgeDispatcher method onFailure.
@Test
public void onFailure(@Mocked RoutingContext context) {
Map<String, Object> map = new HashMap<>();
HttpServerResponse response = new MockUp<HttpServerResponse>() {
@Mock
HttpServerResponse setStatusCode(int statusCode) {
map.put("code", statusCode);
return null;
}
@Mock
HttpServerResponse setStatusMessage(String statusMessage) {
map.put("msg", statusMessage);
return null;
}
}.getMockInstance();
new Expectations() {
{
context.failure();
returns(new RuntimeExceptionWithoutStackTrace("failed"), null);
context.response();
result = response;
}
};
AbstractEdgeDispatcherForTest dispatcher = new AbstractEdgeDispatcherForTest();
dispatcher.onFailure(context);
Assert.assertEquals(502, map.get("code"));
Assert.assertEquals("Bad Gateway", map.get("msg"));
new Expectations() {
{
context.failure();
returns(new InvocationException(401, "unauthorized", "unauthorized"), new InvocationException(401, "unauthorized", "unauthorized"));
context.response();
result = response;
}
};
dispatcher = new AbstractEdgeDispatcherForTest();
dispatcher.onFailure(context);
Assert.assertEquals(401, map.get("code"));
Assert.assertEquals("unauthorized", map.get("msg"));
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestInspectorImpl method downloadSchemas_failed.
@Test
public void downloadSchemas_failed() {
SchemaFormat format = SchemaFormat.SWAGGER;
new Expectations(format) {
{
format.getSuffix();
result = new RuntimeExceptionWithoutStackTrace("zip failed.");
}
};
try (LogCollector logCollector = new LogCollector()) {
Response response = inspector.downloadSchemas(format);
Assert.assertEquals("failed to create schemas zip file, format=SWAGGER.", logCollector.getLastEvents().getMessage());
InvocationException invocationException = response.getResult();
Assert.assertEquals(Status.INTERNAL_SERVER_ERROR, invocationException.getStatus());
Assert.assertEquals("failed to create schemas zip file, format=SWAGGER.", ((CommonExceptionData) invocationException.getErrorData()).getMessage());
Assert.assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
Assert.assertEquals(Status.INTERNAL_SERVER_ERROR.getReasonPhrase(), response.getReasonPhrase());
}
}
Aggregations