Search in sources :

Example 51 with TimeValue

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class ClusterServiceTests method testTimedOutUpdateTaskCleanedUp.

public void testTimedOutUpdateTaskCleanedUp() throws Exception {
    final CountDownLatch block = new CountDownLatch(1);
    final CountDownLatch blockCompleted = new CountDownLatch(1);
    clusterService.submitStateUpdateTask("block-task", new ClusterStateUpdateTask() {

        @Override
        public ClusterState execute(ClusterState currentState) {
            try {
                block.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            blockCompleted.countDown();
            return currentState;
        }

        @Override
        public void onFailure(String source, Exception e) {
            throw new RuntimeException(e);
        }
    });
    final CountDownLatch block2 = new CountDownLatch(1);
    clusterService.submitStateUpdateTask("test", new ClusterStateUpdateTask() {

        @Override
        public ClusterState execute(ClusterState currentState) {
            block2.countDown();
            return currentState;
        }

        @Override
        public TimeValue timeout() {
            return TimeValue.ZERO;
        }

        @Override
        public void onFailure(String source, Exception e) {
            block2.countDown();
        }
    });
    block.countDown();
    block2.await();
    blockCompleted.await();
    synchronized (clusterService.updateTasksPerExecutor) {
        assertTrue("expected empty map but was " + clusterService.updateTasksPerExecutor, clusterService.updateTasksPerExecutor.isEmpty());
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 52 with TimeValue

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class ClusterServiceTests method testTimeoutUpdateTask.

public void testTimeoutUpdateTask() throws Exception {
    final CountDownLatch block = new CountDownLatch(1);
    clusterService.submitStateUpdateTask("test1", new ClusterStateUpdateTask() {

        @Override
        public ClusterState execute(ClusterState currentState) {
            try {
                block.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return currentState;
        }

        @Override
        public void onFailure(String source, Exception e) {
            throw new RuntimeException(e);
        }
    });
    final CountDownLatch timedOut = new CountDownLatch(1);
    final AtomicBoolean executeCalled = new AtomicBoolean();
    clusterService.submitStateUpdateTask("test2", new ClusterStateUpdateTask() {

        @Override
        public TimeValue timeout() {
            return TimeValue.timeValueMillis(2);
        }

        @Override
        public void onFailure(String source, Exception e) {
            timedOut.countDown();
        }

        @Override
        public ClusterState execute(ClusterState currentState) {
            executeCalled.set(true);
            return currentState;
        }

        @Override
        public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
        }
    });
    timedOut.await();
    block.countDown();
    final CountDownLatch allProcessed = new CountDownLatch(1);
    clusterService.submitStateUpdateTask("test3", new ClusterStateUpdateTask() {

        @Override
        public void onFailure(String source, Exception e) {
            throw new RuntimeException(e);
        }

        @Override
        public ClusterState execute(ClusterState currentState) {
            allProcessed.countDown();
            return currentState;
        }
    });
    // executed another task to double check that execute on the timed out update task is not called...
    allProcessed.await();
    assertThat(executeCalled.get(), equalTo(false));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 53 with TimeValue

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class SearchRequestTests method mutate.

private SearchRequest mutate(SearchRequest searchRequest) throws IOException {
    SearchRequest mutation = copyRequest(searchRequest);
    List<Runnable> mutators = new ArrayList<>();
    mutators.add(() -> mutation.indices(ArrayUtils.concat(searchRequest.indices(), new String[] { randomAsciiOfLength(10) })));
    mutators.add(() -> mutation.indicesOptions(randomValueOtherThan(searchRequest.indicesOptions(), () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()))));
    mutators.add(() -> mutation.types(ArrayUtils.concat(searchRequest.types(), new String[] { randomAsciiOfLength(10) })));
    mutators.add(() -> mutation.preference(randomValueOtherThan(searchRequest.preference(), () -> randomAsciiOfLengthBetween(3, 10))));
    mutators.add(() -> mutation.routing(randomValueOtherThan(searchRequest.routing(), () -> randomAsciiOfLengthBetween(3, 10))));
    mutators.add(() -> mutation.requestCache((randomValueOtherThan(searchRequest.requestCache(), () -> randomBoolean()))));
    mutators.add(() -> mutation.scroll(randomValueOtherThan(searchRequest.scroll(), () -> new Scroll(new TimeValue(randomNonNegativeLong() % 100000)))));
    mutators.add(() -> mutation.searchType(randomValueOtherThan(searchRequest.searchType(), () -> randomFrom(SearchType.values()))));
    mutators.add(() -> mutation.source(randomValueOtherThan(searchRequest.source(), this::createSearchSourceBuilder)));
    randomFrom(mutators).run();
    return mutation;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) ArrayList(java.util.ArrayList) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 54 with TimeValue

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class AggregationsIntegrationIT method testScroll.

public void testScroll() {
    final int size = randomIntBetween(1, 4);
    SearchResponse response = client().prepareSearch("index").setSize(size).setScroll(new TimeValue(500)).addAggregation(terms("f").field("f")).get();
    assertSearchResponse(response);
    Aggregations aggregations = response.getAggregations();
    assertNotNull(aggregations);
    Terms terms = aggregations.get("f");
    assertEquals(Math.min(numDocs, 3L), terms.getBucketByKey("0").getDocCount());
    int total = response.getHits().getHits().length;
    while (response.getHits().getHits().length > 0) {
        response = client().prepareSearchScroll(response.getScrollId()).setScroll(new TimeValue(500)).execute().actionGet();
        assertNull(response.getAggregations());
        total += response.getHits().getHits().length;
    }
    clearScroll(response.getScrollId());
    assertEquals(numDocs, total);
}
Also used : Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) TimeValue(org.elasticsearch.common.unit.TimeValue) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 55 with TimeValue

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project crate by crate.

the class TableStatsService method onRefreshSettings.

@Override
public void onRefreshSettings(Settings settings) {
    TimeValue newRefreshInterval = extractRefreshInterval(settings);
    if (!newRefreshInterval.equals(lastRefreshInterval)) {
        if (refreshScheduledTask != null) {
            refreshScheduledTask.cancel();
        }
        refreshScheduledTask = scheduleRefresh(newRefreshInterval);
        lastRefreshInterval = newRefreshInterval;
    }
}
Also used : TimeValue(org.elasticsearch.common.unit.TimeValue)

Aggregations

TimeValue (org.elasticsearch.common.unit.TimeValue)169 SearchResponse (org.elasticsearch.action.search.SearchResponse)37 ArrayList (java.util.ArrayList)28 IOException (java.io.IOException)27 ClusterState (org.elasticsearch.cluster.ClusterState)26 SearchHit (org.elasticsearch.search.SearchHit)26 CountDownLatch (java.util.concurrent.CountDownLatch)18 Settings (org.elasticsearch.common.settings.Settings)18 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)17 Map (java.util.Map)16 Supplier (org.apache.logging.log4j.util.Supplier)16 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)16 List (java.util.List)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 AbstractRunnable (org.elasticsearch.common.util.concurrent.AbstractRunnable)13 Matchers.containsString (org.hamcrest.Matchers.containsString)13 TimeUnit (java.util.concurrent.TimeUnit)11 ThreadPool (org.elasticsearch.threadpool.ThreadPool)11 HashMap (java.util.HashMap)10 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)10