本文整理汇总了Java中org.elasticsearch.common.collect.Tuple.tuple方法的典型用法代码示例。如果您正苦于以下问题:Java Tuple.tuple方法的具体用法?Java Tuple.tuple怎么用?Java Tuple.tuple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.collect.Tuple
的用法示例。
在下文中一共展示了Tuple.tuple方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDoesNotLimitExcludedRequests
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public void testDoesNotLimitExcludedRequests() throws Exception {
ensureGreen();
@SuppressWarnings("unchecked")
Tuple<String, CharSequence>[] requestUris = new Tuple[1500];
for (int i = 0; i < requestUris.length; i++) {
requestUris[i] = Tuple.tuple("/_cluster/settings",
"{ \"transient\": {\"search.default_search_timeout\": \"40s\" } }");
}
HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
TransportAddress transportAddress = (TransportAddress) randomFrom(httpServerTransport.boundAddress
().boundAddresses());
try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
Collection<FullHttpResponse> responses = nettyHttpClient.put(transportAddress.address(), requestUris);
assertThat(responses, hasSize(requestUris.length));
assertAllInExpectedStatus(responses, HttpResponseStatus.OK);
}
}
示例2: 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));
}
示例3: put
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
/**
* put an entry into the segment
*
* @param key the key of the entry to add to the cache
* @param value the value of the entry to add to the cache
* @param now the access time of this entry
* @return a tuple of the new entry and the existing entry, if there was one otherwise null
*/
Tuple<Entry<K, V>, Entry<K, V>> put(K key, V value, long now) {
Entry<K, V> entry = new Entry<>(key, value, now);
Entry<K, V> existing = null;
try (ReleasableLock ignored = writeLock.acquire()) {
try {
CompletableFuture<Entry<K, V>> future = map.put(key, CompletableFuture.completedFuture(entry));
if (future != null) {
existing = future.handle((ok, ex) -> {
if (ok != null) {
return ok;
} else {
return null;
}
}).get();
}
} catch (ExecutionException | InterruptedException e) {
throw new IllegalStateException(e);
}
}
return Tuple.tuple(entry, existing);
}
示例4: randomDeleteResponse
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
/**
* Returns a tuple of {@link DeleteResponse}s.
* <p>
* The left element is the actual {@link DeleteResponse} to serialize while the right element is the
* expected {@link DeleteResponse} after parsing.
*/
public static Tuple<DeleteResponse, DeleteResponse> randomDeleteResponse() {
String index = randomAsciiOfLength(5);
String indexUUid = randomAsciiOfLength(5);
int shardId = randomIntBetween(0, 5);
String type = randomAsciiOfLength(5);
String id = randomAsciiOfLength(5);
long seqNo = randomFrom(SequenceNumbersService.UNASSIGNED_SEQ_NO, randomNonNegativeLong(), (long) randomIntBetween(0, 10000));
long version = randomBoolean() ? randomNonNegativeLong() : randomIntBetween(0, 10000);
boolean found = randomBoolean();
boolean forcedRefresh = randomBoolean();
Tuple<ReplicationResponse.ShardInfo, ReplicationResponse.ShardInfo> shardInfos = RandomObjects.randomShardInfo(random());
DeleteResponse actual = new DeleteResponse(new ShardId(index, indexUUid, shardId), type, id, seqNo, version, found);
actual.setForcedRefresh(forcedRefresh);
actual.setShardInfo(shardInfos.v1());
DeleteResponse expected = new DeleteResponse(new ShardId(index, INDEX_UUID_NA_VALUE, -1), type, id, seqNo, version, found);
expected.setForcedRefresh(forcedRefresh);
expected.setShardInfo(shardInfos.v2());
return Tuple.tuple(actual, expected);
}
示例5: randomIndexResponse
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
/**
* Returns a tuple of {@link IndexResponse}s.
* <p>
* The left element is the actual {@link IndexResponse} to serialize while the right element is the
* expected {@link IndexResponse} after parsing.
*/
public static Tuple<IndexResponse, IndexResponse> randomIndexResponse() {
String index = randomAsciiOfLength(5);
String indexUUid = randomAsciiOfLength(5);
int shardId = randomIntBetween(0, 5);
String type = randomAsciiOfLength(5);
String id = randomAsciiOfLength(5);
long seqNo = randomFrom(SequenceNumbersService.UNASSIGNED_SEQ_NO, randomNonNegativeLong(), (long) randomIntBetween(0, 10000));
long version = randomBoolean() ? randomNonNegativeLong() : randomIntBetween(0, 10000);
boolean created = randomBoolean();
boolean forcedRefresh = randomBoolean();
Tuple<ReplicationResponse.ShardInfo, ReplicationResponse.ShardInfo> shardInfos = RandomObjects.randomShardInfo(random());
IndexResponse actual = new IndexResponse(new ShardId(index, indexUUid, shardId), type, id, seqNo, version, created);
actual.setForcedRefresh(forcedRefresh);
actual.setShardInfo(shardInfos.v1());
IndexResponse expected = new IndexResponse(new ShardId(index, INDEX_UUID_NA_VALUE, -1), type, id, seqNo, version, created);
expected.setForcedRefresh(forcedRefresh);
expected.setShardInfo(shardInfos.v2());
return Tuple.tuple(actual, expected);
}
示例6: testLimitsInFlightRequests
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public void testLimitsInFlightRequests() throws Exception {
ensureGreen();
// we use the limit size as a (very) rough indication on how many requests we should sent to hit the limit
int numRequests = LIMIT.bytesAsInt() / 100;
StringBuilder bulkRequest = new StringBuilder();
for (int i = 0; i < numRequests; i++) {
bulkRequest.append("{\"index\": {}}");
bulkRequest.append(System.lineSeparator());
bulkRequest.append("{ \"field\" : \"value\" }");
bulkRequest.append(System.lineSeparator());
}
@SuppressWarnings("unchecked")
Tuple<String, CharSequence>[] requests = new Tuple[150];
for (int i = 0; i < requests.length; i++) {
requests[i] = Tuple.tuple("/index/type/_bulk", bulkRequest);
}
HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
TransportAddress transportAddress = (TransportAddress) randomFrom(httpServerTransport.boundAddress
().boundAddresses());
try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
Collection<FullHttpResponse> singleResponse = nettyHttpClient.post(transportAddress.address(), requests[0]);
assertThat(singleResponse, hasSize(1));
assertAtLeastOnceExpectedStatus(singleResponse, HttpResponseStatus.OK);
Collection<FullHttpResponse> multipleResponses = nettyHttpClient.post(transportAddress.address(), requests);
assertThat(multipleResponses, hasSize(requests.length));
assertAtLeastOnceExpectedStatus(multipleResponses, HttpResponseStatus.SERVICE_UNAVAILABLE);
}
}
示例7: createEnv
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
/** Creates a test environment with bin, config and plugins directories. */
static Tuple<Path, Environment> createEnv(FileSystem fs, Function<String, Path> temp) throws IOException {
Path home = temp.apply("install-plugin-command-tests");
Files.createDirectories(home.resolve("bin"));
Files.createFile(home.resolve("bin").resolve("elasticsearch"));
Files.createDirectories(home.resolve("config"));
Files.createFile(home.resolve("config").resolve("elasticsearch.yml"));
Path plugins = Files.createDirectories(home.resolve("plugins"));
assertTrue(Files.exists(plugins));
Settings settings = Settings.builder()
.put("path.home", home)
.build();
return Tuple.tuple(home, new Environment(settings));
}
示例8: canBeAllocatedToAtLeastOneNode
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
/**
* Determines if the shard can be allocated on at least one node based on the allocation deciders.
*
* Returns the best allocation decision for allocating the shard on any node (i.e. YES if at least one
* node decided YES, THROTTLE if at least one node decided THROTTLE, and NO if none of the nodes decided
* YES or THROTTLE). If in explain mode, also returns the node-level explanations as the second element
* in the returned tuple.
*/
private Tuple<Decision, Map<String, NodeAllocationResult>> canBeAllocatedToAtLeastOneNode(ShardRouting shard,
RoutingAllocation allocation) {
Decision madeDecision = Decision.NO;
final boolean explain = allocation.debugDecision();
Map<String, NodeAllocationResult> nodeDecisions = explain ? new HashMap<>() : null;
for (ObjectCursor<DiscoveryNode> cursor : allocation.nodes().getDataNodes().values()) {
RoutingNode node = allocation.routingNodes().node(cursor.value.getId());
if (node == null) {
continue;
}
// if we can't allocate it on a node, ignore it, for example, this handles
// cases for only allocating a replica after a primary
Decision decision = allocation.deciders().canAllocate(shard, node, allocation);
if (decision.type() == Decision.Type.YES && madeDecision.type() != Decision.Type.YES) {
if (explain) {
madeDecision = decision;
} else {
return Tuple.tuple(decision, nodeDecisions);
}
} else if (madeDecision.type() == Decision.Type.NO && decision.type() == Decision.Type.THROTTLE) {
madeDecision = decision;
}
if (explain) {
nodeDecisions.put(node.nodeId(), new NodeAllocationResult(node.node(), null, decision));
}
}
return Tuple.tuple(madeDecision, nodeDecisions);
}
示例9: relocateShard
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
/**
* Relocate a shard to another node, adding the target initializing
* shard as well as assigning it.
*
* @return pair of source relocating and target initializing shards.
*/
public Tuple<ShardRouting,ShardRouting> relocateShard(ShardRouting startedShard, String nodeId, long expectedShardSize,
RoutingChangesObserver changes) {
ensureMutable();
relocatingShards++;
ShardRouting source = startedShard.relocate(nodeId, expectedShardSize);
ShardRouting target = source.getTargetRelocatingShard();
updateAssigned(startedShard, source);
node(target.currentNodeId()).add(target);
assignedShardsAdd(target);
addRecovery(target);
changes.relocationStarted(startedShard, target);
return Tuple.tuple(source, target);
}
示例10: receivedResponse
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
@Override
public void receivedResponse(long requestId, DiscoveryNode sourceNode, String action) {
if (MasterFaultDetection.MASTER_PING_ACTION_NAME.equals(action)) {
Tuple<DiscoveryNode, Long> ping = Tuple.tuple(sourceNode, requestId);
if (inflightPings.remove(ping)) {
completedPings.add(ping);
waitForPings.countDown();
}
}
}
示例11: randomGetResult
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public static Tuple<GetResult, GetResult> randomGetResult(XContentType xContentType) {
final String index = randomAsciiOfLengthBetween(3, 10);
final String type = randomAsciiOfLengthBetween(3, 10);
final String id = randomAsciiOfLengthBetween(3, 10);
final long version;
final boolean exists;
BytesReference source = null;
Map<String, GetField> fields = null;
Map<String, GetField> expectedFields = null;
if (frequently()) {
version = randomNonNegativeLong();
exists = true;
if (frequently()) {
source = RandomObjects.randomSource(random());
}
if (randomBoolean()) {
Tuple<Map<String, GetField>, Map<String, GetField>> tuple = randomGetFields(xContentType);
fields = tuple.v1();
expectedFields = tuple.v2();
}
} else {
version = -1;
exists = false;
}
GetResult getResult = new GetResult(index, type, id, version, exists, source, fields);
GetResult expectedGetResult = new GetResult(index, type, id, version, exists, source, expectedFields);
return Tuple.tuple(getResult, expectedGetResult);
}
示例12: randomGetFields
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
private static Tuple<Map<String, GetField>,Map<String, GetField>> randomGetFields(XContentType xContentType) {
int numFields = randomIntBetween(2, 10);
Map<String, GetField> fields = new HashMap<>(numFields);
Map<String, GetField> expectedFields = new HashMap<>(numFields);
for (int i = 0; i < numFields; i++) {
Tuple<GetField, GetField> tuple = randomGetField(xContentType);
GetField getField = tuple.v1();
GetField expectedGetField = tuple.v2();
fields.put(getField.getName(), getField);
expectedFields.put(expectedGetField.getName(), expectedGetField);
}
return Tuple.tuple(fields, expectedFields);
}
示例13: randomPrimariesAndReplicas
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
private static Tuple<Integer, Integer> randomPrimariesAndReplicas(final int numNodes) {
final int numPrimaries;
final int numReplicas;
if (randomBoolean()) {
// test with some nodes having no shards
numPrimaries = 1;
numReplicas = randomIntBetween(0, numNodes - 2);
} else {
// test with all nodes having at least one shard
numPrimaries = randomIntBetween(1, 5);
numReplicas = numNodes - 1;
}
return Tuple.tuple(numPrimaries, numReplicas);
}
示例14: setupStateAndRebalance
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
private Tuple<ClusterState, MoveDecision> setupStateAndRebalance(AllocationDecider allocationDecider,
Settings balancerSettings,
boolean rebalanceExpected) {
AllocationDecider rebalanceDecider = new AllocationDecider(Settings.EMPTY) {
@Override
public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) {
return Decision.YES;
}
};
List<AllocationDecider> allocationDeciders = Arrays.asList(rebalanceDecider, allocationDecider);
final int numShards = randomIntBetween(8, 13);
BalancedShardsAllocator allocator = new BalancedShardsAllocator(balancerSettings);
ClusterState clusterState = ClusterStateCreationUtils.state("idx", 2, numShards);
// add a new node so shards can be rebalanced there
DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder(clusterState.nodes());
nodesBuilder.add(newNode(randomAsciiOfLength(7)));
clusterState = ClusterState.builder(clusterState).nodes(nodesBuilder).build();
ShardRouting shard = clusterState.routingTable().index("idx").shard(0).primaryShard();
RoutingAllocation routingAllocation = newRoutingAllocation(
new AllocationDeciders(Settings.EMPTY, allocationDeciders), clusterState);
MoveDecision rebalanceDecision = allocator.decideShardAllocation(shard, routingAllocation).getMoveDecision();
if (rebalanceExpected == false) {
assertAssignedNodeRemainsSame(allocator, routingAllocation, shard);
}
return Tuple.tuple(clusterState, rebalanceDecision);
}
示例15: uniqueOperationId
import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
/**
* Generate a unique ID for an operation based on jobId and operationId.
*/
private static Tuple<Integer, UUID> uniqueOperationId(int operationId, UUID jobId) {
return Tuple.tuple(operationId, jobId);
}