liuxiaolong
2019-05-06 a7bed6b4cfecd61ec153818945f982c5bb796b98
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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));
 
    }
}