本文整理汇总了Java中org.elasticsearch.action.ActionFuture.get方法的典型用法代码示例。如果您正苦于以下问题:Java ActionFuture.get方法的具体用法?Java ActionFuture.get怎么用?Java ActionFuture.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.ActionFuture
的用法示例。
在下文中一共展示了ActionFuture.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTaskManagementOptOut
import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testTaskManagementOptOut() throws Exception {
setupTestNodes(Settings.EMPTY);
connectNodes(testNodes);
CountDownLatch checkLatch = new CountDownLatch(1);
// Starting actions that disable task manager
ActionFuture<NodesResponse> future = startBlockingTestNodesAction(checkLatch, new NodesRequest("Test Request", false));
TestNode testNode = testNodes[randomIntBetween(0, testNodes.length - 1)];
// Get the parent task
ListTasksRequest listTasksRequest = new ListTasksRequest();
listTasksRequest.setActions("testAction*");
ListTasksResponse response = testNode.transportListTasksAction.execute(listTasksRequest).get();
assertEquals(0, response.getTasks().size());
// Release all tasks and wait for response
checkLatch.countDown();
NodesResponse responses = future.get();
assertEquals(0, responses.failureCount());
}
示例2: closeWhileListenerEngaged
import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
private void closeWhileListenerEngaged(ActionFuture<String> future) throws Exception {
// Wait for the refresh listener to start waiting
assertBusy(() -> {
Map<String, Object> stats;
try {
stats = entityAsMap(client().performRequest("GET", indexName() + "/_stats/refresh"));
} catch (IOException e) {
throw new RuntimeException(e);
}
@SuppressWarnings("unchecked")
Map<String, Object> indices = (Map<String, Object>) stats.get("indices");
@SuppressWarnings("unchecked")
Map<String, Object> theIndex = (Map<String, Object>) indices.get(indexName());
@SuppressWarnings("unchecked")
Map<String, Object> total = (Map<String, Object>) theIndex.get("total");
@SuppressWarnings("unchecked")
Map<String, Object> refresh = (Map<String, Object>) total.get("refresh");
int listeners = (int) refresh.get("listeners");
assertEquals(1, listeners);
});
// Close the index. That should flush the listener.
client().performRequest("POST", indexName() + "/_close");
// The request shouldn't fail. It certainly shouldn't hang.
future.get();
}
示例3: testFindChildTasks
import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testFindChildTasks() throws Exception {
setupTestNodes(Settings.EMPTY);
connectNodes(testNodes);
CountDownLatch checkLatch = new CountDownLatch(1);
ActionFuture<NodesResponse> future = startBlockingTestNodesAction(checkLatch);
TestNode testNode = testNodes[randomIntBetween(0, testNodes.length - 1)];
// Get the parent task
ListTasksRequest listTasksRequest = new ListTasksRequest();
listTasksRequest.setActions("testAction");
ListTasksResponse response = testNode.transportListTasksAction.execute(listTasksRequest).get();
assertEquals(1, response.getTasks().size());
String parentNode = response.getTasks().get(0).getTaskId().getNodeId();
long parentTaskId = response.getTasks().get(0).getId();
// Find tasks with common parent
listTasksRequest = new ListTasksRequest();
listTasksRequest.setParentTaskId(new TaskId(parentNode, parentTaskId));
response = testNode.transportListTasksAction.execute(listTasksRequest).get();
assertEquals(testNodes.length, response.getTasks().size());
for (TaskInfo task : response.getTasks()) {
assertEquals("testAction[n]", task.getAction());
assertEquals(parentNode, task.getParentTaskId().getNodeId());
assertEquals(parentTaskId, task.getParentTaskId().getId());
}
// Release all tasks and wait for response
checkLatch.countDown();
NodesResponse responses = future.get();
assertEquals(0, responses.failureCount());
}
示例4: assertListenerThrows
import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
void assertListenerThrows(String msg, ActionFuture<?> listener, Class<?> klass) throws InterruptedException {
try {
listener.get();
fail(msg);
} catch (ExecutionException ex) {
assertThat(ex.getCause(), instanceOf(klass));
}
}
示例5: testTaskLevelActionFailures
import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testTaskLevelActionFailures() throws ExecutionException, InterruptedException, IOException {
setupTestNodes(Settings.EMPTY);
connectNodes(testNodes);
CountDownLatch checkLatch = new CountDownLatch(1);
ActionFuture<NodesResponse> future = startBlockingTestNodesAction(checkLatch);
TestTasksAction[] tasksActions = new TestTasksAction[nodesCount];
final int failTaskOnNode = randomIntBetween(1, nodesCount - 1);
for (int i = 0; i < testNodes.length; i++) {
final int node = i;
// Simulate task action that fails on one of the tasks on one of the nodes
tasksActions[i] = new TestTasksAction(CLUSTER_SETTINGS, "testTasksAction", threadPool, testNodes[i].clusterService,
testNodes[i].transportService) {
@Override
protected void taskOperation(TestTasksRequest request, Task task, ActionListener<TestTaskResponse> listener) {
logger.info("Task action on node {}", node);
if (failTaskOnNode == node && task.getParentTaskId().isSet()) {
logger.info("Failing on node {}", node);
// Fail in a random way to make sure we can handle all these ways
Runnable failureMode = randomFrom(
() -> {
logger.info("Throwing exception from taskOperation");
throw new RuntimeException("Task level failure (direct)");
},
() -> {
logger.info("Calling listener synchronously with exception from taskOperation");
listener.onFailure(new RuntimeException("Task level failure (sync listener)"));
},
() -> {
logger.info("Calling listener asynchronously with exception from taskOperation");
threadPool.generic()
.execute(() -> listener.onFailure(new RuntimeException("Task level failure (async listener)")));
}
);
failureMode.run();
} else {
if (randomBoolean()) {
listener.onResponse(new TestTaskResponse("Success on node (sync)" + node));
} else {
threadPool.generic().execute(() -> listener.onResponse(new TestTaskResponse("Success on node (async)" + node)));
}
}
}
};
}
// Run task action on node tasks that are currently running
// should be successful on all nodes except one
TestTasksRequest testTasksRequest = new TestTasksRequest();
testTasksRequest.setActions("testAction[n]"); // pick all test actions
TestTasksResponse response = tasksActions[0].execute(testTasksRequest).get();
assertThat(response.getTaskFailures(), hasSize(1)); // one task failed
assertThat(response.getTaskFailures().get(0).getReason(), containsString("Task level failure"));
// Get successful responses from all nodes except one
assertEquals(testNodes.length - 1, response.tasks.size());
assertEquals(0, response.getNodeFailures().size()); // no nodes failed
// Release all node tasks and wait for response
checkLatch.countDown();
NodesResponse responses = future.get();
assertEquals(0, responses.failureCount());
}
示例6: testTaskNodeFiltering
import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
/**
* This test starts nodes actions that blocks on all nodes. While node actions are blocked in the middle of execution
* it executes a tasks action that targets these blocked node actions. The test verifies that task actions are only
* getting executed on nodes that are not listed in the node filter.
*/
public void testTaskNodeFiltering() throws ExecutionException, InterruptedException, IOException {
setupTestNodes(Settings.EMPTY);
connectNodes(testNodes);
CountDownLatch checkLatch = new CountDownLatch(1);
// Start some test nodes action so we could have something to run tasks actions on
ActionFuture<NodesResponse> future = startBlockingTestNodesAction(checkLatch);
String[] allNodes = new String[testNodes.length];
for (int i = 0; i < testNodes.length; i++) {
allNodes[i] = testNodes[i].getNodeId();
}
int filterNodesSize = randomInt(allNodes.length);
Set<String> filterNodes = new HashSet<>(randomSubsetOf(filterNodesSize, allNodes));
logger.info("Filtering out nodes {} size: {}", filterNodes, filterNodesSize);
TestTasksAction[] tasksActions = new TestTasksAction[nodesCount];
for (int i = 0; i < testNodes.length; i++) {
final int node = i;
// Simulate a task action that works on all nodes except nodes listed in filterNodes.
// We are testing that it works.
tasksActions[i] = new TestTasksAction(CLUSTER_SETTINGS, "testTasksAction", threadPool,
testNodes[i].clusterService, testNodes[i].transportService) {
@Override
protected String[] filterNodeIds(DiscoveryNodes nodes, String[] nodesIds) {
String[] superNodes = super.filterNodeIds(nodes, nodesIds);
List<String> filteredNodes = new ArrayList<>();
for (String node : superNodes) {
if (filterNodes.contains(node) == false) {
filteredNodes.add(node);
}
}
return filteredNodes.toArray(new String[filteredNodes.size()]);
}
@Override
protected void taskOperation(TestTasksRequest request, Task task, ActionListener<TestTaskResponse> listener) {
if (randomBoolean()) {
listener.onResponse(new TestTaskResponse(testNodes[node].getNodeId()));
} else {
threadPool.generic().execute(() -> listener.onResponse(new TestTaskResponse(testNodes[node].getNodeId())));
}
}
};
}
// Run task action on node tasks that are currently running
// should be successful on all nodes except nodes that we filtered out
TestTasksRequest testTasksRequest = new TestTasksRequest();
testTasksRequest.setActions("testAction[n]"); // pick all test actions
TestTasksResponse response = tasksActions[randomIntBetween(0, nodesCount - 1)].execute(testTasksRequest).get();
// Get successful responses from all nodes except nodes that we filtered out
assertEquals(testNodes.length - filterNodes.size(), response.tasks.size());
assertEquals(0, response.getTaskFailures().size()); // no task failed
assertEquals(0, response.getNodeFailures().size()); // no nodes failed
// Make sure that filtered nodes didn't send any responses
for (TestTaskResponse taskResponse : response.tasks) {
String nodeId = taskResponse.getStatus();
assertFalse("Found response from filtered node " + nodeId, filterNodes.contains(nodeId));
}
// Release all node tasks and wait for response
checkLatch.countDown();
NodesResponse responses = future.get();
assertEquals(0, responses.failureCount());
}