package com.cloud.attendance.utils; import com.alibaba.fastjson.JSONObject; import com.cloud.common.utils.RestTemplateUtil; import lombok.extern.log4j.Log4j; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @Log4j @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class TestRestEs { @Autowired private RestTemplateUtil restTemplate; @Test public void test1() throws Exception { String json = "{\"size\":10000,\"query\": {\"match_all\": {}}}"; JSONObject jsonParams = JSONObject.parseObject(json); long start = System.currentTimeMillis(); log.info("开始时间"+start); String post = restTemplate.post("http://192.168.1.203:9200/videopersons/_search?scroll=1m", jsonParams, MediaType.APPLICATION_JSON_UTF8, false); long end = System.currentTimeMillis(); log.info("结束时间"+end); log.info("用时:"+(end-start)); } }