当前位置: 首页>>代码示例>>Java>>正文


Java ExceptionUtils.getCause方法代码示例

本文整理汇总了Java中org.apache.commons.lang.exception.ExceptionUtils.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java ExceptionUtils.getCause方法的具体用法?Java ExceptionUtils.getCause怎么用?Java ExceptionUtils.getCause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang.exception.ExceptionUtils的用法示例。


在下文中一共展示了ExceptionUtils.getCause方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldHandleRequestSentThatNeverReturns

import org.apache.commons.lang.exception.ExceptionUtils; //导入方法依赖的package包/类
@Test
@org.junit.Ignore("Can't seem to make this test pass consistently")
public void shouldHandleRequestSentThatNeverReturns() throws Exception {
    final Cluster cluster = Cluster.open();
    final Client client = cluster.connect();

    final ResultSet results = client.submit("Thread.sleep(10000); 'should-not-ever-get-back-coz-we-killed-the-server'");

    stopServer();

    // give the server a chance to kill everything
    Thread.sleep(1000);

    try {
        results.all().get(10000, TimeUnit.MILLISECONDS);
        fail("Server was stopped before the request could execute");
    } catch (TimeoutException toe) {
        fail("Should not have tossed a TimeOutException getting the result");
    } catch (Exception ex) {
        final Throwable cause = ExceptionUtils.getCause(ex);
        assertThat(cause.getMessage(), containsString("rejected from java.util.concurrent.ThreadPoolExecutor"));
    }

    cluster.close();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:26,代码来源:GremlinDriverIntegrateTest.java

示例2: shouldHaveTheSessionTimeout

import org.apache.commons.lang.exception.ExceptionUtils; //导入方法依赖的package包/类
@Test
public void shouldHaveTheSessionTimeout() throws Exception {
    final Cluster cluster = Cluster.build().create();
    final Client client = cluster.connect(name.getMethodName());

    final ResultSet results1 = client.submit("x = [1,2,3,4,5,6,7,8,9]");
    final AtomicInteger counter = new AtomicInteger(0);
    results1.stream().map(i -> i.get(Integer.class) * 2).forEach(i -> assertEquals(counter.incrementAndGet() * 2, Integer.parseInt(i.toString())));

    final ResultSet results2 = client.submit("x[0]+1");
    assertEquals(2, results2.all().get().get(0).getInt());

    // session times out in 3 seconds
    Thread.sleep(3500);

    try {
        // the original session should be dead so this call will open a new session with the same name but fail
        // because the state is now gone - x is an invalid property
        client.submit("x[1]+2").all().get();
        fail("Session should be dead");
    } catch (Exception ex) {
        final Throwable cause = ExceptionUtils.getCause(ex);
        assertThat(cause, instanceOf(ResponseException.class));
        assertEquals(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION, ((ResponseException) cause).getResponseStatusCode());

        // validate that we can still send messages to the server
        assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
    } finally {
        cluster.close();
    }

    assertEquals(1, recordingAppender.getMessages().stream()
            .filter(msg -> msg.equals("INFO - Session shouldHaveTheSessionTimeout closed\n")).count());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:35,代码来源:GremlinServerSessionIntegrateTest.java

示例3: getThrowableList

import org.apache.commons.lang.exception.ExceptionUtils; //导入方法依赖的package包/类
/**
 * <p>Returns the list of <code>Throwable</code> objects in the
 * exception chain.</p>
 *
 * <p>A throwable without cause will return a list containing
 * one element - the input throwable.
 * A throwable with one cause will return a list containing
 * two elements. - the input throwable and the cause throwable.
 * A <code>null</code> throwable will return a list of size zero.</p>
 *
 * <p>This method handles recursive cause structures that might
 * otherwise cause infinite loops. The cause chain is processed until
 * the end is reached, or until the next item in the chain is already
 * in the result set.</p>
 *
 * @param throwable  the throwable to inspect, may be null
 * @return the list of throwables, never null
 * @since Commons Lang 2.2
 */
public static List getThrowableList(Throwable throwable) {
    List list = new ArrayList();
    while (throwable != null && list.contains(throwable) == false) {
        list.add(throwable);
        throwable = ExceptionUtils.getCause(throwable);
    }
    return list;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:ExceptionUtils.java


注:本文中的org.apache.commons.lang.exception.ExceptionUtils.getCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。