本文整理汇总了Java中org.elasticsearch.common.collect.Tuple.v1方法的典型用法代码示例。如果您正苦于以下问题:Java Tuple.v1方法的具体用法?Java Tuple.v1怎么用?Java Tuple.v1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.collect.Tuple
的用法示例。
在下文中一共展示了Tuple.v1方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: randomShardInfo
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
/**
* Returns a tuple that contains a randomized {@link ShardInfo} value (left side) and its corresponding
* value (right side) after it has been printed out as a {@link ToXContent} and parsed back using a parsing
* method like {@link ShardInfo#fromXContent(XContentParser)}. A `withShardFailures` parameter indicates if
* the randomized ShardInfo must or must not contain shard failures.
*
* @param random Random generator
* @param withShardFailures indicates if the generated ShardInfo must contain shard failures
*/
public static Tuple<ShardInfo, ShardInfo> randomShardInfo(Random random, boolean withShardFailures) {
int total = randomIntBetween(random, 1, 10);
if (withShardFailures == false) {
return Tuple.tuple(new ShardInfo(total, total), new ShardInfo(total, total));
}
int successful = randomIntBetween(random, 1, Math.max(1, (total - 1)));
int failures = Math.max(1, (total - successful));
Failure[] actualFailures = new Failure[failures];
Failure[] expectedFailures = new Failure[failures];
for (int i = 0; i < failures; i++) {
Tuple<Failure, Failure> failure = randomShardInfoFailure(random);
actualFailures[i] = failure.v1();
expectedFailures[i] = failure.v2();
}
return Tuple.tuple(new ShardInfo(total, successful, actualFailures), new ShardInfo(total, successful, expectedFailures));
}
示例2: AzureStorageServiceImpl
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public AzureStorageServiceImpl(Settings settings) {
super(settings);
Tuple<AzureStorageSettings, Map<String, AzureStorageSettings>> storageSettings = AzureStorageSettings.parse(settings);
this.primaryStorageSettings = storageSettings.v1();
this.secondariesStorageSettings = storageSettings.v2();
this.clients = new HashMap<>();
logger.debug("starting azure storage client instance");
// We register the primary client if any
if (primaryStorageSettings != null) {
logger.debug("registering primary client for account [{}]", primaryStorageSettings.getAccount());
createClient(primaryStorageSettings);
}
// We register all secondary clients
for (Map.Entry<String, AzureStorageSettings> azureStorageSettingsEntry : secondariesStorageSettings.entrySet()) {
logger.debug("registering secondary client for account [{}]", azureStorageSettingsEntry.getKey());
createClient(azureStorageSettingsEntry.getValue());
}
}
示例3: parseValue
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
private static void parseValue(final ParseContext context, ObjectMapper parentMapper, String currentFieldName, XContentParser.Token token) throws IOException {
if (currentFieldName == null) {
throw new MapperParsingException("object mapping [" + parentMapper.name() + "] trying to serialize a value with no field associated with it, current value [" + context.parser().textOrNull() + "]");
}
Mapper mapper = getMapper(parentMapper, currentFieldName);
if (mapper != null) {
parseObjectOrField(context, mapper);
} else {
final String[] paths = splitAndValidatePath(currentFieldName);
currentFieldName = paths[paths.length - 1];
Tuple<Integer, ObjectMapper> parentMapperTuple = getDynamicParentMapper(context, paths, parentMapper);
parentMapper = parentMapperTuple.v2();
parseDynamicValue(context, parentMapper, currentFieldName, token);
for (int i = 0; i < parentMapperTuple.v1(); i++) {
context.path().remove();
}
}
}
示例4: testToAndFromXContent
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public void testToAndFromXContent() throws Exception {
XContentType xContentType = randomFrom(XContentType.values());
Tuple<GetResult, GetResult> tuple = randomGetResult(xContentType);
GetResult getResult = tuple.v1();
GetResult expectedGetResult = tuple.v2();
boolean humanReadable = randomBoolean();
BytesReference originalBytes = toXContent(getResult, xContentType, humanReadable);
//test that we can parse what we print out
GetResult parsedGetResult;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
parsedGetResult = GetResult.fromXContent(parser);
assertNull(parser.nextToken());
}
assertEquals(expectedGetResult, parsedGetResult);
//print the parsed object out and test that the output is the same as the original output
BytesReference finalBytes = toXContent(parsedGetResult, xContentType, humanReadable);
assertToXContentEquivalent(originalBytes, finalBytes, xContentType);
//check that the source stays unchanged, no shuffling of keys nor anything like that
assertEquals(expectedGetResult.sourceAsString(), parsedGetResult.sourceAsString());
}
示例5: processRequestsWithBody
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
private Collection<FullHttpResponse> processRequestsWithBody(HttpMethod method, SocketAddress remoteAddress, Tuple<String,
CharSequence>... urisAndBodies) throws InterruptedException {
Collection<HttpRequest> requests = new ArrayList<>(urisAndBodies.length);
for (Tuple<String, CharSequence> uriAndBody : urisAndBodies) {
ByteBuf content = Unpooled.copiedBuffer(uriAndBody.v2(), StandardCharsets.UTF_8);
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, uriAndBody.v1(), content);
request.headers().add(HttpHeaderNames.HOST, "localhost");
request.headers().add(HttpHeaderNames.CONTENT_LENGTH, content.readableBytes());
request.headers().add(HttpHeaderNames.CONTENT_TYPE, "application/json");
requests.add(request);
}
return sendRequests(remoteAddress, requests);
}
示例6: parse
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public static LessThanAssertion parse(XContentParser parser) throws IOException {
XContentLocation location = parser.getTokenLocation();
Tuple<String,Object> stringObjectTuple = ParserUtils.parseTuple(parser);
if (false == stringObjectTuple.v2() instanceof Comparable) {
throw new IllegalArgumentException("lt section can only be used with objects that support natural ordering, found "
+ stringObjectTuple.v2().getClass().getSimpleName());
}
return new LessThanAssertion(location, stringObjectTuple.v1(), stringObjectTuple.v2());
}
示例7: parse
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public static LessThanOrEqualToAssertion parse(XContentParser parser) throws IOException {
XContentLocation location = parser.getTokenLocation();
Tuple<String,Object> stringObjectTuple = ParserUtils.parseTuple(parser);
if (false == stringObjectTuple.v2() instanceof Comparable) {
throw new IllegalArgumentException("lte section can only be used with objects that support natural ordering, found "
+ stringObjectTuple.v2().getClass().getSimpleName());
}
return new LessThanOrEqualToAssertion(location, stringObjectTuple.v1(), stringObjectTuple.v2());
}
示例8: testFailureToAndFromXContent
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public void testFailureToAndFromXContent() throws IOException {
final XContentType xContentType = randomFrom(XContentType.values());
int itemId = randomIntBetween(0, 100);
String index = randomAsciiOfLength(5);
String type = randomAsciiOfLength(5);
String id = randomAsciiOfLength(5);
DocWriteRequest.OpType opType = randomFrom(DocWriteRequest.OpType.values());
final Tuple<Throwable, ElasticsearchException> exceptions = randomExceptions();
Exception bulkItemCause = (Exception) exceptions.v1();
Failure bulkItemFailure = new Failure(index, type, id, bulkItemCause);
BulkItemResponse bulkItemResponse = new BulkItemResponse(itemId, opType, bulkItemFailure);
Failure expectedBulkItemFailure = new Failure(index, type, id, exceptions.v2(), ExceptionsHelper.status(bulkItemCause));
BulkItemResponse expectedBulkItemResponse = new BulkItemResponse(itemId, opType, expectedBulkItemFailure);
BytesReference originalBytes = toXContent(bulkItemResponse, xContentType, randomBoolean());
// Shuffle the XContent fields
if (randomBoolean()) {
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
originalBytes = shuffleXContent(parser, randomBoolean()).bytes();
}
}
BulkItemResponse parsedBulkItemResponse;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
parsedBulkItemResponse = BulkItemResponse.fromXContent(parser, itemId);
assertNull(parser.nextToken());
}
assertBulkItemResponse(expectedBulkItemResponse, parsedBulkItemResponse);
}
示例9: testResultCombine
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public void testResultCombine() throws InterruptedException, ExecutionException, IOException {
final String index = "test";
int numShards = 1 + randomInt(3);
setState(clusterService, stateWithAssignedPrimariesAndOneReplica(index, numShards));
logger.debug("--> using initial state:\n{}", clusterService.state());
Future<BroadcastResponse> response = (broadcastReplicationAction.execute(new DummyBroadcastRequest().indices(index)));
int succeeded = 0;
int failed = 0;
for (Tuple<ShardId, ActionListener<ReplicationResponse>> shardRequests : broadcastReplicationAction.capturedShardRequests) {
if (randomBoolean()) {
ReplicationResponse.ShardInfo.Failure[] failures = new ReplicationResponse.ShardInfo.Failure[0];
int shardsSucceeded = randomInt(1) + 1;
succeeded += shardsSucceeded;
ReplicationResponse replicationResponse = new ReplicationResponse();
if (shardsSucceeded == 1 && randomBoolean()) {
//sometimes add failure (no failure means shard unavailable)
failures = new ReplicationResponse.ShardInfo.Failure[1];
failures[0] = new ReplicationResponse.ShardInfo.Failure(shardRequests.v1(), null, new Exception("pretend shard failed"), RestStatus.GATEWAY_TIMEOUT, false);
failed++;
}
replicationResponse.setShardInfo(new ReplicationResponse.ShardInfo(2, shardsSucceeded, failures));
shardRequests.v2().onResponse(replicationResponse);
} else {
// sometimes fail
failed += 2;
// just add a general exception and see if failed shards will be incremented by 2
shardRequests.v2().onFailure(new Exception("pretend shard failed"));
}
}
assertBroadcastResponse(2 * numShards, succeeded, failed, response.get(), Exception.class);
}
示例10: parseCreateField
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
if (!enabled) {
return;
}
if (!fieldType().stored()) {
return;
}
BytesReference source = context.sourceToParse().source();
// Percolate and tv APIs may not set the source and that is ok, because these APIs will not index any data
if (source == null) {
return;
}
if (filter != null) {
// we don't update the context source if we filter, we want to keep it as is...
Tuple<XContentType, Map<String, Object>> mapTuple =
XContentHelper.convertToMap(source, true, context.sourceToParse().getXContentType());
Map<String, Object> filteredSource = filter.apply(mapTuple.v2());
BytesStreamOutput bStream = new BytesStreamOutput();
XContentType contentType = mapTuple.v1();
XContentBuilder builder = XContentFactory.contentBuilder(contentType, bStream).map(filteredSource);
builder.close();
source = bStream.bytes();
}
BytesRef ref = source.toBytesRef();
fields.add(new StoredField(fieldType().name(), ref.bytes, ref.offset, ref.length));
}
示例11: parse
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public DocumentMapper parse(@Nullable String type, CompressedXContent source, String defaultSource) throws MapperParsingException {
Map<String, Object> mapping = null;
if (source != null) {
Map<String, Object> root = XContentHelper.convertToMap(source.compressedReference(), true, XContentType.JSON).v2();
Tuple<String, Map<String, Object>> t = extractMapping(type, root);
type = t.v1();
mapping = t.v2();
}
if (mapping == null) {
mapping = new HashMap<>();
}
return parse(type, mapping, defaultSource);
}
示例12: getHandlerPageDownstreamContexts
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
private List<PageDownstreamContext> getHandlerPageDownstreamContexts(Tuple<List<ExecutionSubContext>, List<ListenableFuture<Bucket>>> onHandler) {
final List<PageDownstreamContext> pageDownstreamContexts = new ArrayList<>(onHandler.v1().size());
for (ExecutionSubContext handlerExecutionSubContext : onHandler.v1()) {
if (handlerExecutionSubContext instanceof DownstreamExecutionSubContext) {
PageDownstreamContext pageDownstreamContext = ((DownstreamExecutionSubContext) handlerExecutionSubContext).pageDownstreamContext((byte) 0);
pageDownstreamContexts.add(pageDownstreamContext);
}
}
return pageDownstreamContexts;
}
示例13: testShardInfoToAndFromXContent
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public void testShardInfoToAndFromXContent() throws IOException {
final Tuple<ShardInfo, ShardInfo> tuple = RandomObjects.randomShardInfo(random());
ShardInfo shardInfo = tuple.v1();
ShardInfo expectedShardInfo = tuple.v2();
final XContentType xContentType = randomFrom(XContentType.values());
boolean humanReadable = randomBoolean();
BytesReference originalBytes = toXContent(shardInfo, xContentType, humanReadable);
// Shuffle the XContent fields
if (randomBoolean()) {
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
originalBytes = shuffleXContent(parser, randomBoolean()).bytes();
}
}
ShardInfo parsedShardInfo;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
// Move to the first start object
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
parsedShardInfo = ShardInfo.fromXContent(parser);
assertNull(parser.nextToken());
}
assertShardInfo(expectedShardInfo, parsedShardInfo);
BytesReference expectedFinalBytes = toXContent(expectedShardInfo, xContentType, humanReadable);
BytesReference finalBytes = toXContent(parsedShardInfo, xContentType, humanReadable);
assertToXContentEquivalent(expectedFinalBytes, finalBytes, xContentType);
}
示例14: prepareRequest
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
Tuple<XContentType, BytesReference> sourceTuple = restRequest.contentOrSourceParam();
SimulatePipelineRequest request = new SimulatePipelineRequest(sourceTuple.v2(), sourceTuple.v1());
request.setId(restRequest.param("id"));
request.setVerbose(restRequest.paramAsBoolean("verbose", false));
return channel -> client.admin().cluster().simulatePipeline(request, new RestToXContentListener<>(channel));
}
示例15: pageDownstreamContextForNestedLoop
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
@Nullable
private PageDownstreamContext pageDownstreamContextForNestedLoop(int nlPhaseId,
PreparerContext ctx,
byte inputId,
@Nullable MergePhase mergePhase,
RowReceiver rowReceiver,
RamAccountingContext ramAccountingContext) {
if (mergePhase == null) {
ctx.phaseIdToRowReceivers.put(toKey(nlPhaseId, inputId), rowReceiver);
return null;
}
Tuple<PageDownstream, FlatProjectorChain> pageDownstreamWithChain = pageDownstreamFactory.createMergeNodePageDownstream(
mergePhase,
rowReceiver,
true,
ramAccountingContext,
Optional.of(threadPool.executor(ThreadPool.Names.SEARCH))
);
return new PageDownstreamContext(
pageDownstreamContextLogger,
nodeName(),
mergePhase.executionPhaseId(),
mergePhase.name(),
pageDownstreamWithChain.v1(),
StreamerVisitor.streamerFromOutputs(mergePhase),
ramAccountingContext,
mergePhase.numUpstreams(),
pageDownstreamWithChain.v2()
);
}