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


Java TimeValue.timeValueSeconds方法代码示例

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


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

示例1: testSimpleRetry

import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public void testSimpleRetry() throws Exception {
    FailThenSuccessBackoffTransport fakeTransport =
            new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 3);

    MockGoogleCredential credential = RetryHttpInitializerWrapper.newMockCredentialBuilder()
            .build();
    MockSleeper mockSleeper = new MockSleeper();

    RetryHttpInitializerWrapper retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, mockSleeper,
        TimeValue.timeValueSeconds(5));

    Compute client = new Compute.Builder(fakeTransport, new JacksonFactory(), null)
            .setHttpRequestInitializer(retryHttpInitializerWrapper)
            .setApplicationName("test")
            .build();

    HttpRequest request = client.getRequestFactory().buildRequest("Get", new GenericUrl("http://elasticsearch.com"), null);
    HttpResponse response = request.execute();

    assertThat(mockSleeper.getCount(), equalTo(3));
    assertThat(response.getStatusCode(), equalTo(200));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:RetryHttpInitializerWrapperTests.java

示例2: getTimeValue

import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
/**
 * Returns TimeValue based on the given interval
 * Interval can be in minutes, seconds, mili seconds
 */
public static TimeValue getTimeValue(String interval, String defaultValue) {
    TimeValue timeValue = null;
    String timeInterval = interval != null ? interval : defaultValue;
    logger.trace("Time interval is [{}] ", timeInterval);
    if (timeInterval != null) {
        Integer time = Integer.valueOf(timeInterval.substring(0, timeInterval.length() - 1));
        String unit = timeInterval.substring(timeInterval.length() - 1);
        UnitEnum unitEnum = UnitEnum.fromString(unit);
        switch (unitEnum) {
            case MINUTE:
                timeValue = TimeValue.timeValueMinutes(time);
                break;
            case SECOND:
                timeValue = TimeValue.timeValueSeconds(time);
                break;
            case MILI_SECOND:
                timeValue = TimeValue.timeValueMillis(time);
                break;
            default:
                logger.error("Unit is incorrect, please check the Time Value unit: " + unit);
        }
    }
    return timeValue;
}
 
开发者ID:cognitree,项目名称:flume-elasticsearch-sink,代码行数:29,代码来源:Util.java

示例3: testSameAlias

import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public void testSameAlias() throws Exception {
    logger.info("--> creating index [test]");
    assertAcked(prepareCreate("test").addMapping("type", "name", "type=text"));
    ensureGreen();

    logger.info("--> creating alias1 ");
    assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1")));
    TimeValue timeout = TimeValue.timeValueSeconds(2);
    logger.info("--> recreating alias1 ");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1").setTimeout(timeout)));
    assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));

    logger.info("--> modifying alias1 to have a filter");
    stopWatch.start();
    assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1", termQuery("name", "foo")).setTimeout(timeout)));
    assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));

    logger.info("--> recreating alias1 with the same filter");
    stopWatch.start();
    assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1", termQuery("name", "foo")).setTimeout(timeout)));
    assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));

    logger.info("--> recreating alias1 with a different filter");
    stopWatch.start();
    assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1", termQuery("name", "bar")).setTimeout(timeout)));
    assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));

    logger.info("--> verify that filter was updated");
    AliasMetaData aliasMetaData = ((AliasOrIndex.Alias) internalCluster().clusterService().state().metaData().getAliasAndIndexLookup().get("alias1")).getFirstAliasMetaData();
    assertThat(aliasMetaData.getFilter().toString(), equalTo("{\"term\":{\"name\":{\"value\":\"bar\",\"boost\":1.0}}}"));

    logger.info("--> deleting alias1");
    stopWatch.start();
    assertAcked((admin().indices().prepareAliases().removeAlias("test", "alias1").setTimeout(timeout)));
    assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));


}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:IndexAliasesIT.java

示例4: green

import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
/**
 * Waits for cluster to attain green state.
 */
public void green() {

  if(!USE_EXTERNAL_ES5){
    TimeValue timeout = TimeValue.timeValueSeconds(30);

    final org.elasticsearch.client.Client c = nodes[0].client();
    ClusterHealthResponse actionGet = c.admin().cluster()
            .health(Requests.clusterHealthRequest()
                .timeout(timeout)
                .waitForGreenStatus()
                .waitForEvents(Priority.LANGUID)
                .waitForRelocatingShards(0)).actionGet();

    if (actionGet.isTimedOut()) {
      logger.info("--> timed out waiting for cluster green state.\n{}\n{}",
              c.admin().cluster().prepareState().get().getState().prettyPrint(),
              c.admin().cluster().preparePendingClusterTasks().get().prettyPrint());
      fail("timed out waiting for cluster green state");
    }

    Assert.assertTrue(actionGet.getStatus().compareTo(ClusterHealthStatus.GREEN) == 0);

    NodesInfoResponse actionInfoGet = c.admin().cluster().nodesInfo(Requests.nodesInfoRequest().all()).actionGet();
    for (NodeInfo node : actionInfoGet) {
      Version nodeVersion = node.getVersion();
      if (version == null) {
        version = nodeVersion;
      } else {
        if (!nodeVersion.equals(version)) {
          logger.debug("Nodes in elasticsearch cluster have inconsistent versions.");
        }
      }
      if (nodeVersion.before(version)) {
        version = nodeVersion;
      }
    }
  }

}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:43,代码来源:ElasticsearchCluster.java

示例5: expectedTimeToHeal

import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
@Override
public TimeValue expectedTimeToHeal() {
    return TimeValue.timeValueSeconds(0);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:NoOpDisruptionScheme.java

示例6: testResolveTimeout

import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public void testResolveTimeout() throws InterruptedException {
    final Logger logger = mock(Logger.class);
    final NetworkService networkService = new NetworkService(Settings.EMPTY, Collections.emptyList());
    final CountDownLatch latch = new CountDownLatch(1);
    final Transport transport = new MockTcpTransport(
        Settings.EMPTY,
        threadPool,
        BigArrays.NON_RECYCLING_INSTANCE,
        new NoneCircuitBreakerService(),
        new NamedWriteableRegistry(Collections.emptyList()),
        networkService,
        Version.CURRENT) {

        @Override
        public BoundTransportAddress boundAddress() {
            return new BoundTransportAddress(
                new TransportAddress[]{new TransportAddress(InetAddress.getLoopbackAddress(), 9500)},
                new TransportAddress(InetAddress.getLoopbackAddress(), 9500)
            );
        }

        @Override
        public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws UnknownHostException {
            if ("hostname1".equals(address)) {
                return new TransportAddress[]{new TransportAddress(TransportAddress.META_ADDRESS, 9300)};
            } else if ("hostname2".equals(address)) {
                try {
                    latch.await();
                    return new TransportAddress[]{new TransportAddress(TransportAddress.META_ADDRESS, 9300)};
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            } else {
                throw new UnknownHostException(address);
            }
        }

    };
    closeables.push(transport);

    final TransportService transportService =
        new TransportService(Settings.EMPTY, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> null, null);
    closeables.push(transportService);
    final TimeValue resolveTimeout = TimeValue.timeValueSeconds(randomIntBetween(1, 3));
    try {
        final List<DiscoveryNode> discoveryNodes = TestUnicastZenPing.resolveHostsLists(
            executorService,
            logger,
            Arrays.asList("hostname1", "hostname2"),
            1,
            transportService,
            "test+",
            resolveTimeout);

        assertThat(discoveryNodes, hasSize(1));
        verify(logger).trace(
            "resolved host [{}] to {}", "hostname1",
            new TransportAddress[]{new TransportAddress(TransportAddress.META_ADDRESS, 9300)});
        verify(logger).warn("timed out after [{}] resolving host [{}]", resolveTimeout, "hostname2");
        verifyNoMoreInteractions(logger);
    } finally {
        latch.countDown();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:65,代码来源:UnicastZenPingTests.java

示例7: testCancellationOfScrollSearchesOnFollowupRequests

import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public void testCancellationOfScrollSearchesOnFollowupRequests() throws Exception {

        List<ScriptedBlockPlugin> plugins = initBlockFactory();
        indexTestData();

        // Disable block so the first request would pass
        disableBlocks(plugins);

        logger.info("Executing search");
        TimeValue keepAlive = TimeValue.timeValueSeconds(5);
        SearchResponse searchResponse = client().prepareSearch("test")
            .setScroll(keepAlive)
            .setSize(2)
            .setQuery(
                scriptQuery(new Script(
                    ScriptType.INLINE, "native", NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, Collections.emptyMap())))
            .get();

        assertNotNull(searchResponse.getScrollId());

        // Enable block so the second request would block
        for (ScriptedBlockPlugin plugin : plugins) {
            plugin.scriptedBlockFactory.reset();
            plugin.scriptedBlockFactory.enableBlock();
        }

        String scrollId = searchResponse.getScrollId();
        logger.info("Executing scroll with id {}", scrollId);
        ListenableActionFuture<SearchResponse> scrollResponse = client().prepareSearchScroll(searchResponse.getScrollId())
            .setScroll(keepAlive).execute();

        awaitForBlock(plugins);
        cancelSearch(SearchScrollAction.NAME);
        disableBlocks(plugins);

        SearchResponse response = ensureSearchWasCancelled(scrollResponse);
        if (response != null) {
            // The response didn't fail completely - update scroll id
            scrollId = response.getScrollId();
        }
        logger.info("Cleaning scroll with id {}", scrollId);
        client().prepareClearScroll().addScrollId(scrollId).get();
    }
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:44,代码来源:SearchCancellationIT.java

示例8: BlockingClusterStateListener

import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public BlockingClusterStateListener(ClusterService clusterService, String blockOn, String countOn, Priority passThroughPriority) {
    // Waiting for the 70 seconds here to make sure that the last check at 65 sec mark in assertBusyPendingTasks has a chance
    // to finish before we timeout on the cluster state block. Otherwise the last check in assertBusyPendingTasks kicks in
    // after the cluster state block clean up takes place and it's assert doesn't reflect the actual failure
    this(clusterService, blockOn, countOn, passThroughPriority, TimeValue.timeValueSeconds(70));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:AbstractSnapshotIntegTestCase.java

示例9: client

import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public synchronized Compute client() {
    if (refreshInterval != null && refreshInterval.millis() != 0) {
        if (client != null &&
            (refreshInterval.millis() < 0 || (System.currentTimeMillis() - lastRefresh) < refreshInterval.millis())) {
            if (logger.isTraceEnabled()) logger.trace("using cache to retrieve client");
            return client;
        }
        lastRefresh = System.currentTimeMillis();
    }

    try {
        gceJsonFactory = new JacksonFactory();

        logger.info("starting GCE discovery service");
        // Forcing Google Token API URL as set in GCE SDK to
        //      http://metadata/computeMetadata/v1/instance/service-accounts/default/token
        // See https://developers.google.com/compute/docs/metadata#metadataserver
        String tokenServerEncodedUrl = GceMetadataService.GCE_HOST.get(settings) +
            "/computeMetadata/v1/instance/service-accounts/default/token";
        ComputeCredential credential = new ComputeCredential.Builder(getGceHttpTransport(), gceJsonFactory)
            .setTokenServerEncodedUrl(tokenServerEncodedUrl)
            .build();

        // hack around code messiness in GCE code
        // TODO: get this fixed
        Access.doPrivilegedIOException(credential::refreshToken);

        logger.debug("token [{}] will expire in [{}] s", credential.getAccessToken(), credential.getExpiresInSeconds());
        if (credential.getExpiresInSeconds() != null) {
            refreshInterval = TimeValue.timeValueSeconds(credential.getExpiresInSeconds() - 1);
        }


        Compute.Builder builder = new Compute.Builder(getGceHttpTransport(), gceJsonFactory, null).setApplicationName(VERSION)
            .setRootUrl(GCE_ROOT_URL.get(settings));

        if (RETRY_SETTING.exists(settings)) {
            TimeValue maxWait = MAX_WAIT_SETTING.get(settings);
            RetryHttpInitializerWrapper retryHttpInitializerWrapper;

            if (maxWait.getMillis() > 0) {
                retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, maxWait);
            } else {
                retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential);
            }
            builder.setHttpRequestInitializer(retryHttpInitializerWrapper);

        } else {
            builder.setHttpRequestInitializer(credential);
        }

        this.client = builder.build();
    } catch (Exception e) {
        logger.warn("unable to start GCE discovery service", e);
        throw new IllegalArgumentException("unable to start GCE discovery service", e);
    }

    return this.client;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:60,代码来源:GceInstancesServiceImpl.java

示例10: defaultValue

import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
@Override
public TimeValue defaultValue() {
    return TimeValue.timeValueSeconds(5);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:5,代码来源:CrateTableSettings.java


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