Search in sources :

Example 91 with TimeValue

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

the class IndexSettingsTests method testRefreshInterval.

public void testRefreshInterval() {
    String refreshInterval = getRandomTimeString();
    IndexMetaData metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), refreshInterval).build());
    IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
    assertEquals(TimeValue.parseTimeValue(refreshInterval, new TimeValue(1, TimeUnit.DAYS), IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey()), settings.getRefreshInterval());
    String newRefreshInterval = getRandomTimeString();
    settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), newRefreshInterval).build()));
    assertEquals(TimeValue.parseTimeValue(newRefreshInterval, new TimeValue(1, TimeUnit.DAYS), IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey()), settings.getRefreshInterval());
}
Also used : HasToString.hasToString(org.hamcrest.object.HasToString.hasToString) StringContains.containsString(org.hamcrest.core.StringContains.containsString) TimeValue(org.elasticsearch.common.unit.TimeValue) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 92 with TimeValue

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

the class IndexSettingsTests method testGCDeletesSetting.

public void testGCDeletesSetting() {
    TimeValue gcDeleteSetting = new TimeValue(Math.abs(randomInt()), TimeUnit.MILLISECONDS);
    IndexMetaData metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), gcDeleteSetting.getStringRep()).build());
    IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
    assertEquals(TimeValue.parseTimeValue(gcDeleteSetting.getStringRep(), new TimeValue(1, TimeUnit.DAYS), IndexSettings.INDEX_GC_DELETES_SETTING.getKey()).getMillis(), settings.getGcDeletesInMillis());
    TimeValue newGCDeleteSetting = new TimeValue(Math.abs(randomInt()), TimeUnit.MILLISECONDS);
    settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), newGCDeleteSetting.getStringRep()).build()));
    assertEquals(TimeValue.parseTimeValue(newGCDeleteSetting.getStringRep(), new TimeValue(1, TimeUnit.DAYS), IndexSettings.INDEX_GC_DELETES_SETTING.getKey()).getMillis(), settings.getGcDeletesInMillis());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), randomBoolean() ? -1 : new TimeValue(-1, TimeUnit.MILLISECONDS)).build()));
    assertEquals(-1, settings.getGcDeletesInMillis());
}
Also used : TimeValue(org.elasticsearch.common.unit.TimeValue) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 93 with TimeValue

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

the class JvmGcMonitorServiceSettingsTests method execute.

private static void execute(Settings settings, TriFunction<Runnable, TimeValue, String, Cancellable> scheduler, Consumer<Throwable> consumer, boolean constructionShouldFail, Runnable asserts) throws InterruptedException {
    assert constructionShouldFail == (consumer != null);
    assert constructionShouldFail == (asserts == null);
    ThreadPool threadPool = null;
    try {
        threadPool = new TestThreadPool(JvmGcMonitorServiceSettingsTests.class.getCanonicalName()) {

            @Override
            public Cancellable scheduleWithFixedDelay(Runnable command, TimeValue interval, String name) {
                return scheduler.apply(command, interval, name);
            }
        };
        try {
            JvmGcMonitorService service = new JvmGcMonitorService(settings, threadPool);
            if (constructionShouldFail) {
                fail("construction of jvm gc service should have failed");
            }
            service.doStart();
            asserts.run();
            service.doStop();
        } catch (Exception t) {
            consumer.accept(t);
        }
    } finally {
        ThreadPool.terminate(threadPool, 30, TimeUnit.SECONDS);
    }
}
Also used : Cancellable(org.elasticsearch.threadpool.ThreadPool.Cancellable) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ThreadPool(org.elasticsearch.threadpool.ThreadPool) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 94 with TimeValue

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

the class RemoteRequestBuildersTests method testScrollParams.

public void testScrollParams() {
    TimeValue scroll = TimeValue.parseTimeValue(randomPositiveTimeValue(), "test");
    assertThat(scrollParams(scroll), hasEntry("scroll", scroll.toString()));
}
Also used : TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 95 with TimeValue

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

the class RemoteRequestBuildersTests method testInitialSearchParamsMisc.

public void testInitialSearchParamsMisc() {
    SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
    Version remoteVersion = Version.fromId(between(0, Version.CURRENT.id));
    TimeValue scroll = null;
    if (randomBoolean()) {
        scroll = TimeValue.parseTimeValue(randomPositiveTimeValue(), "test");
        searchRequest.scroll(scroll);
    }
    int size = between(0, Integer.MAX_VALUE);
    searchRequest.source().size(size);
    Boolean fetchVersion = null;
    if (randomBoolean()) {
        fetchVersion = randomBoolean();
        searchRequest.source().version(fetchVersion);
    }
    Map<String, String> params = initialSearchParams(searchRequest, remoteVersion);
    assertThat(params, scroll == null ? not(hasKey("scroll")) : hasEntry("scroll", scroll.toString()));
    assertThat(params, hasEntry("size", Integer.toString(size)));
    assertThat(params, fetchVersion == null || fetchVersion == true ? hasEntry("version", null) : not(hasEntry("version", null)));
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Version(org.elasticsearch.Version) Matchers.containsString(org.hamcrest.Matchers.containsString) TimeValue(org.elasticsearch.common.unit.TimeValue) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Aggregations

TimeValue (org.elasticsearch.common.unit.TimeValue)139 ClusterState (org.elasticsearch.cluster.ClusterState)26 IOException (java.io.IOException)24 CountDownLatch (java.util.concurrent.CountDownLatch)18 ArrayList (java.util.ArrayList)17 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)17 Settings (org.elasticsearch.common.settings.Settings)17 Supplier (org.apache.logging.log4j.util.Supplier)16 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 SearchResponse (org.elasticsearch.action.search.SearchResponse)15 AbstractRunnable (org.elasticsearch.common.util.concurrent.AbstractRunnable)13 Matchers.containsString (org.hamcrest.Matchers.containsString)13 Map (java.util.Map)12 TimeUnit (java.util.concurrent.TimeUnit)11 ThreadPool (org.elasticsearch.threadpool.ThreadPool)11 List (java.util.List)10 HashMap (java.util.HashMap)9 Iterator (java.util.Iterator)8 ExecutionException (java.util.concurrent.ExecutionException)8