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());
}
}
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));
}
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;
}
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);
}
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;
}
}
Aggregations