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


Java ExceptionsHelper.unwrap方法代码示例

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


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

示例1: testPutWithPipelineFactoryError

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
public void testPutWithPipelineFactoryError() throws Exception {
    BytesReference source = jsonBuilder().startObject()
            .field("description", "my_pipeline")
            .startArray("processors")
            .startObject()
            .startObject("test")
            .field("unused", ":sad_face:")
            .endObject()
            .endObject()
            .endArray()
            .endObject().bytes();
    PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source, XContentType.JSON);
    try {
        client().admin().cluster().putPipeline(putPipelineRequest).get();
    } catch (ExecutionException e) {
        ElasticsearchParseException ex = (ElasticsearchParseException) ExceptionsHelper.unwrap(e, ElasticsearchParseException.class);
        assertNotNull(ex);
        assertThat(ex.getMessage(), equalTo("processor [test] doesn't support one or more provided configuration parameters [unused]"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:IngestClientIT.java

示例2: testGlobalBlock

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
public void testGlobalBlock() {
    Request request = new Request();
    PlainActionFuture<Response> listener = new PlainActionFuture<>();
    ClusterBlocks.Builder block = ClusterBlocks.builder()
            .addGlobalBlock(new ClusterBlock(1, "", false, true, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL));
    setState(clusterService, ClusterState.builder(clusterService.state()).blocks(block));
    try {
        action.new AsyncSingleAction(request, listener).start();
        listener.get();
        fail("expected ClusterBlockException");
    } catch (Exception e) {
        if (ExceptionsHelper.unwrap(e, ClusterBlockException.class) == null) {
            logger.info("expected ClusterBlockException  but got ", e);
            fail("expected ClusterBlockException");
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:TransportInstanceSingleOperationActionTests.java

示例3: testFailureWithoutRetry

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
public void testFailureWithoutRetry() throws Exception {
    Request request = new Request().index("test");
    request.shardId = new ShardId("test", "_na_", 0);
    PlainActionFuture<Response> listener = new PlainActionFuture<>();
    setState(clusterService, ClusterStateCreationUtils.state("test", randomBoolean(), ShardRoutingState.STARTED));

    action.new AsyncSingleAction(request, listener).start();
    assertThat(transport.capturedRequests().length, equalTo(1));
    long requestId = transport.capturedRequests()[0].requestId;
    transport.clear();
    // this should not trigger retry or anything and the listener should report exception immediately
    transport.handleRemoteError(requestId, new TransportException("a generic transport exception", new Exception("generic test exception")));

    try {
        // result should return immediately
        assertTrue(listener.isDone());
        listener.get();
        fail("this should fail with a transport exception");
    } catch (ExecutionException t) {
        if (ExceptionsHelper.unwrap(t, TransportException.class) == null) {
            logger.info("expected TransportException  but got ", t);
            fail("expected and TransportException");
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:TransportInstanceSingleOperationActionTests.java

示例4: assertBlocked

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
/**
 * 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(), Matchers.equalTo(replicatedBroadcastResponse.getTotalShards()));
    for (ShardOperationFailedException 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));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:ElasticsearchAssertions.java

示例5: testRetryOfAnAlreadyTimedOutRequest

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
public void testRetryOfAnAlreadyTimedOutRequest() throws Exception {
    Request request = new Request().index("test").timeout(new TimeValue(0, TimeUnit.MILLISECONDS));
    request.shardId = new ShardId("test", "_na_", 0);
    PlainActionFuture<Response> listener = new PlainActionFuture<>();
    setState(clusterService, ClusterStateCreationUtils.state("test", randomBoolean(), ShardRoutingState.STARTED));
    action.new AsyncSingleAction(request, listener).start();
    assertThat(transport.capturedRequests().length, equalTo(1));
    long requestId = transport.capturedRequests()[0].requestId;
    transport.clear();
    DiscoveryNode node = clusterService.state().getNodes().getLocalNode();
    transport.handleLocalError(requestId, new ConnectTransportException(node, "test exception"));

    // wait until the timeout was triggered and we actually tried to send for the second time
    assertBusy(new Runnable() {
        @Override
        public void run() {
            assertThat(transport.capturedRequests().length, equalTo(1));
        }
    });

    // let it fail the second time too
    requestId = transport.capturedRequests()[0].requestId;
    transport.handleLocalError(requestId, new ConnectTransportException(node, "test exception"));
    try {
        // result should return immediately
        assertTrue(listener.isDone());
        listener.get();
        fail("this should fail with a transport exception");
    } catch (ExecutionException t) {
        if (ExceptionsHelper.unwrap(t, ConnectTransportException.class) == null) {
            logger.info("expected ConnectTransportException  but got ", t);
            fail("expected and ConnectTransportException");
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:TransportInstanceSingleOperationActionTests.java

示例6: testUnresolvableRequestDoesNotHang

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
public void testUnresolvableRequestDoesNotHang() throws InterruptedException, ExecutionException, TimeoutException {
    action = new TestTransportInstanceSingleOperationAction(
            Settings.EMPTY,
            "indices:admin/test_unresolvable",
            transportService,
            new ActionFilters(new HashSet<>()),
            new MyResolver(),
            Request::new
    ) {
        @Override
        protected void resolveRequest(ClusterState state, Request request) {
            throw new IllegalStateException("request cannot be resolved");
        }
    };
    Request request = new Request().index("test");
    request.shardId = new ShardId("test", "_na_", 0);
    PlainActionFuture<Response> listener = new PlainActionFuture<>();
    setState(clusterService, ClusterStateCreationUtils.state("test", randomBoolean(), ShardRoutingState.STARTED));
    action.new AsyncSingleAction(request, listener).start();
    assertThat(transport.capturedRequests().length, equalTo(0));
    try {
        listener.get();
    } catch (Exception e) {
        if (ExceptionsHelper.unwrap(e, IllegalStateException.class) == null) {
            logger.info("expected IllegalStateException  but got ", e);
            fail("expected and IllegalStateException");
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:TransportInstanceSingleOperationActionTests.java

示例7: exceptionCaught

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
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;
    onException(ctx.channel(), t instanceof Exception ? (Exception) t : new ElasticsearchException(t));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:Netty4Transport.java

示例8: isMasterChannelException

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
private static boolean isMasterChannelException(TransportException exp) {
    return ExceptionsHelper.unwrap(exp, MASTER_CHANNEL_EXCEPTIONS) != null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:ShardStateAction.java

示例9: searchWithRetry

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
/**
 * Run a search action and call onResponse when a the response comes in, retrying if the action fails with an exception caused by
 * rejected execution.
 *
 * @param action consumes a listener and starts the action. The listener it consumes is rigged to retry on failure.
 * @param onResponse consumes the response from the action
 */
private void searchWithRetry(Consumer<ActionListener<SearchResponse>> action, Consumer<SearchResponse> onResponse) {
    /*
     * RetryHelper is both an AbstractRunnable and an ActionListener<SearchResponse> - meaning that it both starts the search and
     * handles reacts to the results. The complexity is all in onFailure which either adapts the failure to the "fail" listener or
     * retries the search. Since both AbstractRunnable and ActionListener define the onFailure method it is called for either failure
     * to run the action (either while running or before starting) and for failure on the response from the action.
     */
    class RetryHelper extends AbstractRunnable implements ActionListener<SearchResponse> {
        private final Iterator<TimeValue> retries = backoffPolicy.iterator();
        /**
         * The runnable to run that retries in the same context as the original call.
         */
        private Runnable retryWithContext;
        private volatile int retryCount = 0;

        @Override
        protected void doRun() throws Exception {
            action.accept(this);
        }

        @Override
        public void onResponse(SearchResponse response) {
            onResponse.accept(response);
        }

        @Override
        public void onFailure(Exception e) {
            if (ExceptionsHelper.unwrap(e, EsRejectedExecutionException.class) != null) {
                if (retries.hasNext()) {
                    retryCount += 1;
                    TimeValue delay = retries.next();
                    logger.trace((Supplier<?>) () -> new ParameterizedMessage("retrying rejected search after [{}]", delay), e);
                    countSearchRetry.run();
                    threadPool.schedule(delay, ThreadPool.Names.SAME, retryWithContext);
                } else {
                    logger.warn(
                        (Supplier<?>) () -> new ParameterizedMessage(
                            "giving up on search because we retried [{}] times without success", retryCount), e);
                    fail.accept(e);
                }
            } else {
                logger.warn("giving up on search because it failed with a non-retryable exception", e);
                fail.accept(e);
            }
        }
    }
    RetryHelper helper = new RetryHelper();
    // Wrap the helper in a runnable that preserves the current context so we keep it on retry.
    helper.retryWithContext = threadPool.getThreadContext().preserveContext(helper);
    helper.run();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:59,代码来源:ClientScrollableHitSource.java

示例10: expectNotFound

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
private ResourceNotFoundException expectNotFound(ThrowingRunnable r) {
    Exception e = expectThrows(Exception.class, r);
    ResourceNotFoundException notFound = (ResourceNotFoundException) ExceptionsHelper.unwrap(e, ResourceNotFoundException.class);
    if (notFound == null) throw new RuntimeException("Expected ResourceNotFoundException", e);
    return notFound;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:TasksIT.java


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