use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestRestClientInvocation method testSetCseContext_failed.
@Test
public void testSetCseContext_failed() throws JsonProcessingException {
LogCollector logCollector = new LogCollector();
logCollector.setLogLevel(RestClientInvocation.class.getName(), Level.DEBUG);
new Expectations(JsonUtils.class) {
{
JsonUtils.writeValueAsString(any);
result = new RuntimeExceptionWithoutStackTrace();
}
};
restClientInvocation.setCseContext();
Assert.assertEquals("Failed to encode and set cseContext, message=cause:RuntimeExceptionWithoutStackTrace,message:null.", logCollector.getEvents().get(0).getMessage());
logCollector.teardown();
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestMicroserviceWatchTask method testWatchFailed.
@Test
public void testWatchFailed(@Mocked ServiceRegistryConfig serviceRegistryConfig, @Mocked ServiceRegistryClient srClient, @Mocked Microservice microservice) {
initWatch(serviceRegistryConfig, srClient, microservice);
new MockUp<ServiceRegistryClient>(srClient) {
@Mock
void watch(String selfMicroserviceId, AsyncResultCallback<MicroserviceInstanceChangedEvent> callback, AsyncResultCallback<Void> onOpen, AsyncResultCallback<Void> onClose) {
callback.fail(new RuntimeExceptionWithoutStackTrace("test failed"));
}
};
Holder<Throwable> holder = new Holder<>();
eventBus.register(new Object() {
@Subscribe
public void onException(ExceptionEvent event) {
holder.value = event.getThrowable();
}
});
Assert.assertNull(holder.value);
microserviceWatchTask.run();
Assert.assertEquals("test failed", holder.value.getMessage());
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class AsyncUtilsTest method should_convert_fail_async_to_sync.
@Test
void should_convert_fail_async_to_sync() {
RuntimeExceptionWithoutStackTrace throwable = new RuntimeExceptionWithoutStackTrace();
CompletableFuture<String> future = AsyncUtils.completeExceptionally(throwable);
Throwable catchThrowable = catchThrowable(() -> AsyncUtils.toSync(future));
assertThat(catchThrowable).isSameAs(throwable);
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestJvmUtils method findMainClass_jar_readFailed.
@Test
public void findMainClass_jar_readFailed() throws Exception {
URL url = PowerMockito.mock(URL.class);
String command = "a.jar";
String manifestUri = "jar:file:" + new File(command).getAbsolutePath() + "!/" + JarFile.MANIFEST_NAME;
PowerMockito.whenNew(URL.class).withParameterTypes(String.class).withArguments(manifestUri).thenReturn(url);
PowerMockito.when(url.openStream()).thenThrow(new RuntimeExceptionWithoutStackTrace());
System.setProperty(JvmUtils.SUN_JAVA_COMMAND, command + " arg");
Assert.assertNull(JvmUtils.findMainClass());
}
Aggregations