當前位置: 首頁>>代碼示例>>Java>>正文


Java ExceptionsHelper.unwrapCause方法代碼示例

本文整理匯總了Java中org.elasticsearch.ExceptionsHelper.unwrapCause方法的典型用法代碼示例。如果您正苦於以下問題:Java ExceptionsHelper.unwrapCause方法的具體用法?Java ExceptionsHelper.unwrapCause怎麽用?Java ExceptionsHelper.unwrapCause使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.ExceptionsHelper的用法示例。


在下文中一共展示了ExceptionsHelper.unwrapCause方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBadPercents

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
public void testBadPercents() throws Exception {
    double[] badPercents = {-1.0, 110.0};

    try {
        client().prepareSearch("idx")
                .addAggregation(terms("terms").field("tag").subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
                .addAggregation(percentilesBucket("percentiles_bucket", "terms>sum")
                        .percents(badPercents)).execute().actionGet();

        fail("Illegal percent's were provided but no exception was thrown.");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }

}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:PercentilesBucketIT.java

示例2: testIndexIntoDefaultMapping

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
public void testIndexIntoDefaultMapping() throws Throwable {
    // 1. test implicit index creation
    ExecutionException e = expectThrows(ExecutionException.class, () -> {
        client().prepareIndex("index1", MapperService.DEFAULT_MAPPING, "1").setSource("{}", XContentType.JSON).execute().get();
    });
    Throwable throwable = ExceptionsHelper.unwrapCause(e.getCause());
    if (throwable instanceof IllegalArgumentException) {
        assertEquals("It is forbidden to index into the default mapping [_default_]", throwable.getMessage());
    } else {
        throw e;
    }

    // 2. already existing index
    IndexService indexService = createIndex("index2");
    e = expectThrows(ExecutionException.class, () -> {
        client().prepareIndex("index1", MapperService.DEFAULT_MAPPING, "2").setSource().execute().get();
    });
    throwable = ExceptionsHelper.unwrapCause(e.getCause());
    if (throwable instanceof IllegalArgumentException) {
        assertEquals("It is forbidden to index into the default mapping [_default_]", throwable.getMessage());
    } else {
        throw e;
    }
    assertFalse(indexService.mapperService().hasMapping(MapperService.DEFAULT_MAPPING));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:MapperServiceTests.java

示例3: onFailure

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
@Override
public void onFailure(Throwable e) {
    if (ExceptionsHelper.unwrapCause(e) instanceof ConnectTransportException) {
        int i = ++this.i;
        if (i >= nodes.size()) {
            listener.onFailure(new NoNodeAvailableException("None of the configured nodes were available: " + nodes, e));
        } else {
            try {
                callback.doWithNode(nodes.get((index + i) % nodes.size()), this);
            } catch(final Throwable t) {
                // this exception can't come from the TransportService as it doesn't throw exceptions at all
                listener.onFailure(t);
            }
        }
    } else {
        listener.onFailure(e);
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:19,代碼來源:TransportClientNodesService.java

示例4: ShardSearchFailure

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
public ShardSearchFailure(Exception e, @Nullable SearchShardTarget shardTarget) {
    final Throwable actual = ExceptionsHelper.unwrapCause(e);
    if (actual != null && actual instanceof SearchException) {
        this.shardTarget = ((SearchException) actual).shard();
    } else if (shardTarget != null) {
        this.shardTarget = shardTarget;
    }
    status = ExceptionsHelper.status(actual);
    this.reason = ExceptionsHelper.detailedMessage(e);
    this.cause = actual;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:12,代碼來源:ShardSearchFailure.java

示例5: toXContent

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    Throwable ex = ExceptionsHelper.unwrapCause(this);
    if (ex != this) {
        generateThrowableXContent(builder, params, this);
    } else {
        // We don't have a cause when all shards failed, but we do have shards failures so we can "guess" a cause
        // (see {@link #getCause()}). Here, we use super.getCause() because we don't want the guessed exception to
        // be rendered twice (one in the "cause" field, one in "failed_shards")
        innerToXContent(builder, params, this, getExceptionName(), getMessage(), getHeaders(), getMetadata(), super.getCause());
    }
    return builder;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:14,代碼來源:SearchPhaseExecutionException.java

示例6: isShardNotAvailableException

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
public static boolean isShardNotAvailableException(final Throwable e) {
    final Throwable actual = ExceptionsHelper.unwrapCause(e);
    return (actual instanceof ShardNotFoundException ||
            actual instanceof IndexNotFoundException ||
            actual instanceof IllegalIndexShardStateException ||
            actual instanceof NoShardAvailableActionException ||
            actual instanceof UnavailableShardsException ||
            actual instanceof AlreadyClosedException);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:10,代碼來源:TransportActions.java

示例7: canRetry

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
private boolean canRetry(BulkResponse bulkItemResponses) {
    if (!backoff.hasNext()) {
        return false;
    }
    for (BulkItemResponse bulkItemResponse : bulkItemResponses) {
        if (bulkItemResponse.isFailed()) {
            final Throwable cause = bulkItemResponse.getFailure().getCause();
            final Throwable rootCause = ExceptionsHelper.unwrapCause(cause);
            if (!rootCause.getClass().equals(retryOnThrowable)) {
                return false;
            }
        }
    }
    return true;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:Retry.java

示例8: testSingleValueAggDerivative_invalidPath

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
public void testSingleValueAggDerivative_invalidPath() throws Exception {
    try {
        client().prepareSearch("idx")
                .addAggregation(
                        histogram("histo")
                                .field(SINGLE_VALUED_FIELD_NAME)
                                .interval(interval)
                                .subAggregation(
                                        filters("filters", QueryBuilders.termQuery("tag", "foo")).subAggregation(
                                                sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
                                .subAggregation(derivative("deriv", "filters>get>sum"))).execute().actionGet();
        fail("Expected an Exception but didn't get one");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:28,代碼來源:DerivativeIT.java

示例9: testBadPercents_asSubAgg

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
public void testBadPercents_asSubAgg() throws Exception {
    double[] badPercents = {-1.0, 110.0};

    try {
        client()
            .prepareSearch("idx")
            .addAggregation(
                    terms("terms")
                            .field("tag")
                            .order(Terms.Order.term(true))
                            .subAggregation(
                                    histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval)
                                            .extendedBounds(minRandomValue, maxRandomValue))
                            .subAggregation(percentilesBucket("percentiles_bucket", "histo>_count")
                                    .percents(badPercents))).execute().actionGet();

        fail("Illegal percent's were provided but no exception was thrown.");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }

}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:34,代碼來源:PercentilesBucketIT.java

示例10: testBadSigmaAsSubAgg

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
public void testBadSigmaAsSubAgg() throws Exception {
    try {
        SearchResponse response = client()
                .prepareSearch("idx")
                .addAggregation(
                        terms("terms")
                                .field("tag")
                                .order(Order.term(true))
                                .subAggregation(
                                        histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval)
                                                .extendedBounds(minRandomValue, maxRandomValue)
                                                .subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
                                .subAggregation(extendedStatsBucket("extended_stats_bucket", "histo>sum")
                                        .sigma(-1.0))).execute().actionGet();
        fail("Illegal sigma was provided but no exception was thrown.");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:31,代碼來源:ExtendedStatsBucketIT.java

示例11: ShardSearchFailure

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
public ShardSearchFailure(Throwable t, @Nullable SearchShardTarget shardTarget) {
    Throwable actual = ExceptionsHelper.unwrapCause(t);
    if (actual != null && actual instanceof SearchException) {
        this.shardTarget = ((SearchException) actual).shard();
    } else if (shardTarget != null) {
        this.shardTarget = shardTarget;
    }
    status = ExceptionsHelper.status(actual);
    this.reason = ExceptionsHelper.detailedMessage(t);
    this.cause = actual;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:12,代碼來源:ShardSearchFailure.java

示例12: isConflictException

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
protected boolean isConflictException(Throwable e) {
    Throwable cause = ExceptionsHelper.unwrapCause(e);
    // on version conflict or document missing, it means
    // that a new change has crept into the replica, and it's fine
    if (cause instanceof VersionConflictEngineException) {
        return true;
    }
    if (cause instanceof DocumentAlreadyExistsException) {
        return true;
    }
    return false;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:13,代碼來源:TransportReplicationAction.java

示例13: isShardNotAvailableException

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
public static boolean isShardNotAvailableException(Throwable t) {
    Throwable actual = ExceptionsHelper.unwrapCause(t);
    if (actual instanceof ShardNotFoundException ||
            actual instanceof IndexNotFoundException ||
            actual instanceof IllegalIndexShardStateException ||
            actual instanceof NoShardAvailableActionException ||
            actual instanceof UnavailableShardsException ||
            actual instanceof AlreadyClosedException) {
        return true;
    }
    return false;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:13,代碼來源:TransportActions.java

示例14: canRetry

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
private boolean canRetry(BulkResponse bulkItemResponses) {
    if (!backoff.hasNext()) {
        return false;
    }
    for (BulkItemResponse bulkItemResponse : bulkItemResponses) {
        if (bulkItemResponse.isFailed()) {
            Throwable cause = bulkItemResponse.getFailure().getCause();
            Throwable rootCause = ExceptionsHelper.unwrapCause(cause);
            if (!rootCause.getClass().equals(retryOnThrowable)) {
                return false;
            }
        }
    }
    return true;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:16,代碼來源:Retry.java

示例15: isConflictException

import org.elasticsearch.ExceptionsHelper; //導入方法依賴的package包/類
private static boolean isConflictException(final Exception e) {
    return ExceptionsHelper.unwrapCause(e) instanceof VersionConflictEngineException;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:4,代碼來源:TransportShardBulkAction.java


注:本文中的org.elasticsearch.ExceptionsHelper.unwrapCause方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。