Search in sources :

Example 11 with RuntimeExceptionWithoutStackTrace

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());
    }
}
Also used : RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) Expectations(mockit.Expectations) MockUp(mockit.MockUp) EventBus(com.google.common.eventbus.EventBus) AsyncResultCallback(org.apache.servicecomb.foundation.vertx.AsyncResultCallback) Test(org.junit.Test)

Example 12 with RuntimeExceptionWithoutStackTrace

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");
    }
}
Also used : LogCollector(org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector) RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) Test(org.junit.jupiter.api.Test)

Example 13 with RuntimeExceptionWithoutStackTrace

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");
        }
    };
}
Also used : Expectations(mockit.Expectations) RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace)

Example 14 with RuntimeExceptionWithoutStackTrace

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();
}
Also used : RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) FilterNode(org.apache.servicecomb.core.filter.FilterNode) Expectations(mockit.Expectations) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) Invocation(org.apache.servicecomb.core.Invocation) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx) Exceptions(org.apache.servicecomb.core.exception.Exceptions) Injectable(mockit.Injectable) Response(org.apache.servicecomb.swagger.invocation.Response) Mocked(mockit.Mocked) Verifications(mockit.Verifications) RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) FilterNode(org.apache.servicecomb.core.filter.FilterNode)

Example 15 with RuntimeExceptionWithoutStackTrace

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");
        }
    };
}
Also used : Expectations(mockit.Expectations) RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace)

Aggregations

RuntimeExceptionWithoutStackTrace (org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace)24 Test (org.junit.Test)20 Expectations (mockit.Expectations)15 HttpServerFilterBaseForTest (org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest)8 Response (org.apache.servicecomb.swagger.invocation.Response)6 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)6 MockUp (mockit.MockUp)4 LogCollector (org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector)4 HashMap (java.util.HashMap)3 Holder (org.apache.servicecomb.foundation.common.Holder)3 MultiMap (io.vertx.core.MultiMap)2 Map (java.util.Map)2 Executor (java.util.concurrent.Executor)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Invocation (org.apache.servicecomb.core.Invocation)2 ReactiveExecutor (org.apache.servicecomb.core.executor.ReactiveExecutor)2 AsyncResultCallback (org.apache.servicecomb.foundation.vertx.AsyncResultCallback)2 AbstractHttpServletResponse (org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletResponse)2 Test (org.junit.jupiter.api.Test)2 EventBus (com.google.common.eventbus.EventBus)1