Search in sources :

Example 1 with ESTestCase

use of org.elasticsearch.test.ESTestCase in project elasticsearch by elastic.

the class AbstractBulkByScrollRequestTestCase method testForSlice.

public void testForSlice() {
    R original = newRequest();
    original.setAbortOnVersionConflict(randomBoolean());
    original.setRefresh(randomBoolean());
    original.setTimeout(parseTimeValue(randomPositiveTimeValue(), "timeout"));
    original.setWaitForActiveShards(randomFrom(ActiveShardCount.ALL, ActiveShardCount.NONE, ActiveShardCount.ONE, ActiveShardCount.DEFAULT));
    original.setRetryBackoffInitialTime(parseTimeValue(randomPositiveTimeValue(), "retry_backoff_initial_time"));
    original.setMaxRetries(between(0, 1000));
    original.setSlices(between(2, 1000));
    original.setRequestsPerSecond(randomBoolean() ? Float.POSITIVE_INFINITY : randomValueOtherThanMany(r -> r < 0, ESTestCase::randomFloat));
    original.setSize(randomBoolean() ? AbstractBulkByScrollRequest.SIZE_ALL_MATCHES : between(0, Integer.MAX_VALUE));
    TaskId slicingTask = new TaskId(randomAsciiOfLength(5), randomLong());
    SearchRequest sliceRequest = new SearchRequest();
    R forSliced = original.forSlice(slicingTask, sliceRequest);
    assertEquals(original.isAbortOnVersionConflict(), forSliced.isAbortOnVersionConflict());
    assertEquals(original.isRefresh(), forSliced.isRefresh());
    assertEquals(original.getTimeout(), forSliced.getTimeout());
    assertEquals(original.getWaitForActiveShards(), forSliced.getWaitForActiveShards());
    assertEquals(original.getRetryBackoffInitialTime(), forSliced.getRetryBackoffInitialTime());
    assertEquals(original.getMaxRetries(), forSliced.getMaxRetries());
    assertEquals("only the parent task should store results", false, forSliced.getShouldStoreResult());
    assertEquals("slice requests always have a single worker", 1, forSliced.getSlices());
    assertEquals("requests_per_second is split between all workers", original.getRequestsPerSecond() / original.getSlices(), forSliced.getRequestsPerSecond(), Float.MIN_NORMAL);
    assertEquals("size is split evenly between all workers", original.getSize() == AbstractBulkByScrollRequest.SIZE_ALL_MATCHES ? AbstractBulkByScrollRequest.SIZE_ALL_MATCHES : original.getSize() / original.getSlices(), forSliced.getSize());
    assertEquals(slicingTask, forSliced.getParentTask());
    extraForSliceAssertions(original, forSliced);
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) ESTestCase(org.elasticsearch.test.ESTestCase) TaskId(org.elasticsearch.tasks.TaskId)

Example 2 with ESTestCase

use of org.elasticsearch.test.ESTestCase in project elasticsearch by elastic.

the class TimeValueTests method testCompareValue.

public void testCompareValue() {
    long firstRandom = randomNonNegativeLong();
    long secondRandom = randomValueOtherThan(firstRandom, ESTestCase::randomNonNegativeLong);
    TimeUnit unit = randomFrom(TimeUnit.values());
    TimeValue firstValue = new TimeValue(firstRandom, unit);
    TimeValue secondValue = new TimeValue(secondRandom, unit);
    assertEquals(firstRandom > secondRandom, firstValue.compareTo(secondValue) > 0);
    assertEquals(secondRandom > firstRandom, secondValue.compareTo(firstValue) > 0);
}
Also used : ESTestCase(org.elasticsearch.test.ESTestCase) TimeUnit(java.util.concurrent.TimeUnit)

Aggregations

ESTestCase (org.elasticsearch.test.ESTestCase)2 TimeUnit (java.util.concurrent.TimeUnit)1 SearchRequest (org.elasticsearch.action.search.SearchRequest)1 TaskId (org.elasticsearch.tasks.TaskId)1