use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestMicroserviceWatchTask method testNeedToWatch.
@Test
public void testNeedToWatch(@Mocked ServiceRegistryConfig serviceRegistryConfig, @Mocked ServiceRegistryClient srClient, @Mocked Microservice microservice) {
EventBus eventBus = new EventBus();
MicroserviceWatchTask microserviceWatchTask = new MicroserviceWatchTask(eventBus, serviceRegistryConfig, srClient, microservice);
microserviceWatchTask.taskStatus = TaskStatus.READY;
new MockUp<ServiceRegistryClient>(srClient) {
@Mock
void watch(String selfMicroserviceId, AsyncResultCallback<MicroserviceInstanceChangedEvent> callback, AsyncResultCallback<Void> onOpen, AsyncResultCallback<Void> onClose) {
throw new RuntimeExceptionWithoutStackTrace("called watch");
}
};
new Expectations() {
{
serviceRegistryConfig.isWatch();
result = false;
}
};
// no watch
try {
microserviceWatchTask.run();
} catch (Throwable e) {
Assert.fail("must do not watch");
}
new Expectations() {
{
serviceRegistryConfig.isWatch();
result = true;
}
};
// no watch
try {
microserviceWatchTask.run();
} catch (Throwable e) {
// ready state, service id can not be null , will always watch
Assert.assertEquals("called watch", e.getMessage());
}
new Expectations() {
{
serviceRegistryConfig.isWatch();
result = false;
}
};
// no watch
try {
microserviceWatchTask.run();
} catch (Throwable e) {
// ready state, service id can not be null , will always watch
Assert.assertEquals("called watch", e.getMessage());
}
new Expectations() {
{
serviceRegistryConfig.isWatch();
result = true;
microservice.getServiceId();
result = "serviceId";
}
};
// watch
try {
microserviceWatchTask.run();
Assert.fail("must watch");
} catch (Throwable e) {
Assert.assertEquals("called watch", e.getMessage());
}
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class ExceptionsTest method should_protect_when_converter_throw_exception.
@Test
void should_protect_when_converter_throw_exception() {
DefaultExceptionProcessor processor = new DefaultExceptionProcessor().setConverters(Collections.singletonList(new ThrowExceptionWhenConvert()));
try (LogCollector logCollector = new LogCollector()) {
InvocationException exception = processor.convert(null, new RuntimeExceptionWithoutStackTrace("exception need convert"), BAD_REQUEST);
assertThat(exception.getStatus()).isSameAs(INTERNAL_SERVER_ERROR);
assertThat(exception.getErrorData().toString()).isEqualTo("CommonExceptionData{code='SCB.50000000', message='Internal Server Error', dynamic={}}");
assertThat(logCollector.getLastEvents().getRenderedMessage().replace("\r\n", "\n")).isEqualTo("BUG: ExceptionConverter.convert MUST not throw exception, please fix it.\n" + "original exception :org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace: exception need convert\n" + "converter exception:org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace: mock exception when convert\n");
}
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class HighwayServerCodecFilterTest method mockDecodeRequestFail.
private void mockDecodeRequestFail() throws Exception {
new Expectations(invocation) {
{
invocation.getTransportContext();
result = transportContext;
}
};
new Expectations(HighwayCodec.class) {
{
HighwayCodec.decodeRequest(invocation, (RequestHeader) any, (OperationProtobuf) any, (Buffer) any);
result = new RuntimeExceptionWithoutStackTrace("encode request failed");
}
};
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class ProducerInvocationFlowTest method mockInvocationFailed.
private void mockInvocationFailed() {
filterNode = new FilterNode((_invocation, _node) -> {
throw new RuntimeExceptionWithoutStackTrace();
});
mockFilterChain();
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class RestServerCodecFilterTest method mockDecodeRequestFail.
private void mockDecodeRequestFail() {
new Expectations(invocation) {
{
invocation.getTransportContext();
result = transportContext;
invocation.getRequestEx();
result = new RuntimeExceptionWithoutStackTrace("mock encode request failed");
}
};
}
Aggregations