测试HttpsClient,RestTemplate,WebClitnt性能的方法
程序员文章站
2022-05-31 16:09:56
...
public static void main(String[] args) throws SSLException { RequestEntity requestEntity = new RequestEntity(); requestEntity.setUserId("dsds"); requestEntity.setRegion("dasrjasl"); requestEntity.setProductType("fdsfgsf"); List<String> ids = new ArrayList<>(); ids.add("132354"); ids.add("rewwtrwetr"); requestEntity.setProductsId(ids); String keyClockToken = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJLQ0FzQUVYYzVPSkRWb3RuS1hFX01Gc2FiSkc5NlRvbWJyY1VoSVRUaTVBIn0.eyJqdGkiOiI2YTZjODBmMS02OGFhLTRiMWUtOGE1NS01M2I4YjQ3YmFjYTEiLCJleHAiOjE1MzgzMDU0NjIsIm5iZiI6MCwiaWF0IjoxNTM4MjY5NDYyLCJpc3MiOiJodHRwczovLzEwLjExMC4yMi4xMy9hdXRoL3JlYWxtcy9waWNwIiwiYXVkIjoiYnNzLWNsaWVudCIsInN1YiI6ImJkN2VlNTc4LTNkMjYtNGVmYy05N2VkLWM1NzYzMjVjZjk1YSIsInR5cCI6IkJlYXJlciIsImF6cCI6ImJzcy1jbGllbnQiLCJhdXRoX3RpbWUiOjAsInNlc3Npb25fc3RhdGUiOiJlOTg1OGMxZi0zOGFlLTQzNDgtYTMzNS0wN2VlNTAxNGQ5MDciLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbIioiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbInVtYV9hdXRob3JpemF0aW9uIiwidm1fYXRvbWFwaSIsInVzZXIiXX0sInJlc291cmNlX2FjY2VzcyI6eyJ2bS1hdG9tYXBpIjp7InJvbGVzIjpbInVtYV9wcm90ZWN0aW9uIiwidm1fYXRvbWFwaSJdfSwiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19fSwicHJvamVjdCI6ImppbmRlbmdrZTIiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJqaW5kZW5na2UiLCJwcm9qZWN0aWQiOiJmYzZiM2YwMi0wNzNiLTRkYTgtYmQ1ZS0xYzUzZDkxZGRiNjAiLCJlbWFpbCI6ImppbmRlbmdrZUBpbnNwdXIuY29tIn0.CduWvtxitubXiD_CIO-HywIMw6OChV7Q7WsUzrCEEi787V-Rhyx0v6x3-e60LUY7gSQ_qzNd-Q8S9-kK2ozhcauMDDPx0a6FcruCVBniqJs04QVi2b4XDpxxWkZi4V63K2RKu1YYmCVmMEMNe9N5SIzBuiUZKU2UpXXsZE8QHzO5myD1_QDddNtHIKvcVc_oNAaXtm44C9TjldpM5Q5ZRencFXvtxKLugi05RhG-zfIdPFpVBpldfd-nlGFtV_8F4J75oEr0Dj_rDXKKe0nR03uRXFbUYBuwx2BtmucsR2GFBycWc3-aHBSovIkELe4xOCXwypGnIaf3L6aiMGZqOw"; /* HttpServletRequest request = RequestHolder.getRequest(); String keyClockToken = request.getHeader("Authorization");*/ long start0 = System.currentTimeMillis(); HttpsClient.doPostJson(GET_SERVERS_FEE_DATA.getValue(), JSONObject.toJSONString(requestEntity)); long end0 = System.currentTimeMillis(); System.out.println("时间---0:" +(end0-start0)); HttpHeaders getHeader = HttpEntityAndHeaderUtil.getHeader(); getHeader.add("Authorization", keyClockToken); long start1 = System.currentTimeMillis(); HttpEntity httpEntity = new HttpEntity(JSONObject.toJSONString(requestEntity), getHeader); ResponseEntity<ReturnEntity> responseEntity = RestTemplate() .exchange(GET_SERVERS_FEE_DATA.getValue(), HttpMethod.POST, httpEntity, ReturnEntity.class); long end1 = System.currentTimeMillis(); System.out.println("时间---1:" +(end1-start1)); System.out.println(responseEntity.getBody()); Map<String,String> map = new HashMap<>(); map.put(HEADER_CONTENT_TYPE.getValue(), CONTENT_TYPE_JSON.getValue()); map.put("Authorization", keyClockToken); long start2 = System.currentTimeMillis(); ReturnEntity ret = MyWebClitntUtil.post(requestEntity, GET_SERVERS_FEE_DATA.getValue(),map, ReturnEntity.class); long end2 = System.currentTimeMillis(); System.out.println("时间---2:" +(end2-start2)); System.out.println(ret); } 已隐藏部分细节
推荐阅读
-
python 字典(dict)遍历的四种方法性能测试报告
-
编写Go程序对Nginx服务器进行性能测试的方法
-
关于电脑性能测试的常见的几大方法分享
-
Python实现测试磁盘性能的方法
-
性能测试 查看Android APP 帧数FPS的方法
-
使用性能测试nGrinder无法创建ngrinder-monitor监控问题的解决方法
-
测试Flash Player 11.3/AIR3.3提供的bitmapData.encode方法的性能
-
测试Flash Player 11.3/AIR3.3提供的bitmapData.encode方法的性能
-
关于电脑性能测试的常见的几大方法分享
-
通过sysbench工具实现MySQL数据库的性能测试的方法