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


Java ListenableActionFuture.get方法代码示例

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


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

示例1: testTasksCancellation

import org.elasticsearch.action.ListenableActionFuture; //导入方法依赖的package包/类
public void testTasksCancellation() throws Exception {
    // Start blocking test task
    // Get real client (the plugin is not registered on transport nodes)
    ListenableActionFuture<TestTaskPlugin.NodesResponse> future = TestTaskPlugin.TestTaskAction.INSTANCE.newRequestBuilder(client())
            .execute();
    logger.info("--> started test tasks");

    // Wait for the task to start on all nodes
    assertBusy(() -> assertEquals(internalCluster().size(),
        client().admin().cluster().prepareListTasks().setActions(TestTaskPlugin.TestTaskAction.NAME + "[n]").get().getTasks().size()));

    logger.info("--> cancelling the main test task");
    CancelTasksResponse cancelTasksResponse = client().admin().cluster().prepareCancelTasks()
            .setActions(TestTaskPlugin.TestTaskAction.NAME).get();
    assertEquals(1, cancelTasksResponse.getTasks().size());

    future.get();

    logger.info("--> checking that test tasks are not running");
    assertEquals(0,
            client().admin().cluster().prepareListTasks().setActions(TestTaskPlugin.TestTaskAction.NAME + "*").get().getTasks().size());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:TasksIT.java

示例2: testTasksUnblocking

import org.elasticsearch.action.ListenableActionFuture; //导入方法依赖的package包/类
public void testTasksUnblocking() throws Exception {
    // Start blocking test task
    ListenableActionFuture<TestTaskPlugin.NodesResponse> future = TestTaskPlugin.TestTaskAction.INSTANCE.newRequestBuilder(client())
            .execute();
    // Wait for the task to start on all nodes
    assertBusy(() -> assertEquals(internalCluster().size(),
        client().admin().cluster().prepareListTasks().setActions(TestTaskPlugin.TestTaskAction.NAME + "[n]").get().getTasks().size()));

    TestTaskPlugin.UnblockTestTasksAction.INSTANCE.newRequestBuilder(client()).get();

    future.get();
    assertEquals(0, client().admin().cluster().prepareListTasks().setActions(TestTaskPlugin.TestTaskAction.NAME + "[n]").get()
            .getTasks().size());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:TasksIT.java

示例3: waitForTimeoutTestCase

import org.elasticsearch.action.ListenableActionFuture; //导入方法依赖的package包/类
/**
 * Test waiting for a task that times out.
 * @param wait wait for the running task and return all the failures you accumulated waiting for it
 */
private void waitForTimeoutTestCase(Function<TaskId, ? extends Iterable<? extends Throwable>> wait) throws Exception {
    // Start blocking test task
    ListenableActionFuture<TestTaskPlugin.NodesResponse> future = TestTaskPlugin.TestTaskAction.INSTANCE.newRequestBuilder(client())
            .execute();
    try {
        TaskId taskId = waitForTestTaskStartOnAllNodes();

        // Wait for the task to start
        assertBusy(() -> client().admin().cluster().prepareGetTask(taskId).get());

        // Spin up a request that should wait for those tasks to finish
        // It will timeout because we haven't unblocked the tasks
        Iterable<? extends Throwable> failures = wait.apply(taskId);

        for (Throwable failure : failures) {
            assertNotNull(
                    ExceptionsHelper.unwrap(failure, ElasticsearchTimeoutException.class, ReceiveTimeoutTransportException.class));
        }
    } finally {
        // Now we can unblock those requests
        TestTaskPlugin.UnblockTestTasksAction.INSTANCE.newRequestBuilder(client()).get();
    }
    future.get();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:TasksIT.java

示例4: truncateIndex

import org.elasticsearch.action.ListenableActionFuture; //导入方法依赖的package包/类
public IndexDeleteByQueryResponse truncateIndex() throws InterruptedException, ExecutionException {
    try (Client client = getClient()) {
        QueryBuilder queryBuilder = new MatchAllQueryBuilder();
        ListenableActionFuture<DeleteByQueryResponse> response = client.prepareDeleteByQuery(INDEX_NAME)
                .setTypes(DOCUMENT_TYPE).setQuery(queryBuilder).execute();
        DeleteByQueryResponse deleteByQueryResponse = response.get();
        IndexDeleteByQueryResponse indexResult = deleteByQueryResponse.getIndex(INDEX_NAME);
        return indexResult;
    }
}
 
开发者ID:datacleaner,项目名称:extension_elasticsearch,代码行数:11,代码来源:ElasticSearchTestServer.java

示例5: testCloseIndexDuringRestore

import org.elasticsearch.action.ListenableActionFuture; //导入方法依赖的package包/类
public void testCloseIndexDuringRestore() throws Exception {
    Client client = client();

    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo")
        .setType("mock").setSettings(Settings.builder()
            .put("location", randomRepoPath())
            .put("compress", randomBoolean())
            .put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)
        ));

    createIndex("test-idx-1", "test-idx-2");
    ensureGreen();

    logger.info("--> indexing some data");
    for (int i = 0; i < 100; i++) {
        index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i);
        index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i);
    }
    refresh();
    assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().getTotalHits(), equalTo(100L));

    logger.info("--> snapshot");
    assertThat(client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap")
        .setIndices("test-idx-*").setWaitForCompletion(true).get().getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS));

    logger.info("--> deleting indices before restoring");
    assertAcked(client.admin().indices().prepareDelete("test-idx-*").get());

    blockAllDataNodes("test-repo");
    logger.info("--> execution will be blocked on all data nodes");

    final ListenableActionFuture<RestoreSnapshotResponse> restoreFut;
    try {
        logger.info("--> start restore");
        restoreFut = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap")
            .setWaitForCompletion(true)
            .execute();

        logger.info("--> waiting for block to kick in");
        waitForBlockOnAnyDataNode("test-repo", TimeValue.timeValueMinutes(1));

        logger.info("--> close index while restore is running");
        try {
            client.admin().indices().prepareClose("test-idx-1").get();
            fail("Expected closing index to fail during restore");
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage(), containsString("Cannot close indices that are being restored: [[test-idx-1/"));
        }
    } finally {
        // unblock even if the try block fails otherwise we will get bogus failures when we delete all indices in test teardown.
        logger.info("--> unblocking all data nodes");
        unblockAllDataNodes("test-repo");
    }

    logger.info("--> wait for restore to finish");
    RestoreSnapshotResponse restoreSnapshotResponse = restoreFut.get();
    logger.info("--> check that all shards were recovered");
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    assertThat(restoreSnapshotResponse.getRestoreInfo().successfulShards(), greaterThan(0));
    assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:64,代码来源:SharedClusterSnapshotRestoreIT.java

示例6: testDeleteSnapshotWhileRestoringFails

import org.elasticsearch.action.ListenableActionFuture; //导入方法依赖的package包/类
public void testDeleteSnapshotWhileRestoringFails() throws Exception {
    Client client = client();

    logger.info("-->  creating repository");
    final String repoName = "test-repo";
    assertAcked(client.admin().cluster().preparePutRepository(repoName)
                    .setType("mock")
                    .setSettings(Settings.builder().put("location", randomRepoPath())));

    logger.info("--> creating index");
    final String indexName = "test-idx";
    assertAcked(prepareCreate(indexName).setWaitForActiveShards(ActiveShardCount.ALL));

    logger.info("--> indexing some data");
    for (int i = 0; i < 100; i++) {
        index(indexName, "doc", Integer.toString(i), "foo", "bar" + i);
    }
    refresh();
    assertThat(client.prepareSearch(indexName).setSize(0).get().getHits().getTotalHits(), equalTo(100L));

    logger.info("--> take snapshots");
    final String snapshotName = "test-snap";
    assertThat(client.admin().cluster().prepareCreateSnapshot(repoName, snapshotName)
                   .setIndices(indexName).setWaitForCompletion(true).get().getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS));
    final String snapshotName2 = "test-snap-2";
    assertThat(client.admin().cluster().prepareCreateSnapshot(repoName, snapshotName2)
                   .setIndices(indexName).setWaitForCompletion(true).get().getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS));

    logger.info("--> delete index before restoring");
    assertAcked(client.admin().indices().prepareDelete(indexName).get());

    logger.info("--> execution will be blocked on all data nodes");
    blockAllDataNodes(repoName);

    final ListenableActionFuture<RestoreSnapshotResponse> restoreFut;
    try {
        logger.info("--> start restore");
        restoreFut = client.admin().cluster().prepareRestoreSnapshot(repoName, snapshotName)
                         .setWaitForCompletion(true)
                         .execute();

        logger.info("--> waiting for block to kick in");
        waitForBlockOnAnyDataNode(repoName, TimeValue.timeValueMinutes(1));

        logger.info("--> try deleting the snapshot while the restore is in progress (should throw an error)");
        ConcurrentSnapshotExecutionException e = expectThrows(ConcurrentSnapshotExecutionException.class, () ->
            client().admin().cluster().prepareDeleteSnapshot(repoName, snapshotName).get());
        assertEquals(repoName, e.getRepositoryName());
        assertEquals(snapshotName, e.getSnapshotName());
        assertThat(e.getMessage(), containsString("cannot delete snapshot during a restore"));

        logger.info("-- try deleting another snapshot while the restore is in progress (should throw an error)");
        e = expectThrows(ConcurrentSnapshotExecutionException.class, () ->
            client().admin().cluster().prepareDeleteSnapshot(repoName, snapshotName2).get());
        assertEquals(repoName, e.getRepositoryName());
        assertEquals(snapshotName2, e.getSnapshotName());
        assertThat(e.getMessage(), containsString("cannot delete snapshot during a restore"));
    } finally {
        // unblock even if the try block fails otherwise we will get bogus failures when we delete all indices in test teardown.
        logger.info("--> unblocking all data nodes");
        unblockAllDataNodes(repoName);
    }

    logger.info("--> wait for restore to finish");
    restoreFut.get();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:67,代码来源:SharedClusterSnapshotRestoreIT.java


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