Java Code Examples for org.elasticsearch.ExceptionsHelper#unwrap()

The following examples show how to use org.elasticsearch.ExceptionsHelper#unwrap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoggingIT.java    From elasticsearch-learning-to-rank with Apache License 2.0 5 votes vote down vote up
private void assertExcWithMessage(ThrowingRunnable r, Class<? extends Exception> exc, String msg) {
    Throwable e = expectThrows(Throwable.class, r);
    e = ExceptionsHelper.unwrap(e, exc);
    assertNotNull(e);
    assertThat(e, instanceOf(IllegalArgumentException.class));
    assertThat(e.getMessage(), containsString(msg));

}
 
Example 2
Source File: ElasticsearchAssertions.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that all shard requests of a replicated broadcast request failed due to a cluster block
 *
 * @param replicatedBroadcastResponse the response that should only contain failed shard responses
 *
 * */
public static void assertBlocked(BroadcastResponse replicatedBroadcastResponse) {
    assertThat("all shard requests should have failed",
            replicatedBroadcastResponse.getFailedShards(), equalTo(replicatedBroadcastResponse.getTotalShards()));
    for (DefaultShardOperationFailedException exception : replicatedBroadcastResponse.getShardFailures()) {
        ClusterBlockException clusterBlockException =
                (ClusterBlockException) ExceptionsHelper.unwrap(exception.getCause(), ClusterBlockException.class);
        assertNotNull("expected the cause of failure to be a ClusterBlockException but got " + exception.getCause().getMessage(),
                clusterBlockException);
        assertThat(clusterBlockException.blocks().size(), greaterThan(0));
        assertThat(clusterBlockException.status(), CoreMatchers.equalTo(RestStatus.FORBIDDEN));
    }
}
 
Example 3
Source File: Netty4Transport.java    From crate with Apache License 2.0 4 votes vote down vote up
protected final void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    final Throwable unwrapped = ExceptionsHelper.unwrap(cause, ElasticsearchException.class);
    final Throwable t = unwrapped != null ? unwrapped : cause;
    Channel channel = ctx.channel();
    onException(channel.attr(CHANNEL_KEY).get(), t instanceof Exception ? (Exception) t : new ElasticsearchException(t));
}
 
Example 4
Source File: ShardStateAction.java    From crate with Apache License 2.0 4 votes vote down vote up
private static boolean isMasterChannelException(TransportException exp) {
    return ExceptionsHelper.unwrap(exp, MASTER_CHANNEL_EXCEPTIONS) != null;
}