|
|
@@ -0,0 +1,84 @@
|
|
|
+package com.uas.platform.b2c.common.gor;
|
|
|
+
|
|
|
+import com.uas.platform.core.util.HttpUtil;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Random;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 测试模拟发起请求<br/>
|
|
|
+ * 用于测试Gor流量复制
|
|
|
+ * @author suntg
|
|
|
+ * @date 2018年5月8日17:26:46
|
|
|
+ */
|
|
|
+public class GorTest {
|
|
|
+
|
|
|
+// private static String HOST_URL = "http://localhost:20210/article";
|
|
|
+
|
|
|
+ private static String HOST_URL = "http://192.168.253.6:20218/article";
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ generalTest();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 集成测试
|
|
|
+ */
|
|
|
+ public static void generalTest() {
|
|
|
+ int i = 0, getCount = 0, postCount = 0;
|
|
|
+ while (i < 10000) {
|
|
|
+ Random random = new Random();
|
|
|
+ // 随机事件,50-150ms
|
|
|
+ int timer = 50 + random.nextInt(100);
|
|
|
+ // 随机类型,1 get请求,2 post请求
|
|
|
+ int type = 1 + random.nextInt(2);
|
|
|
+ switch (type) {
|
|
|
+ case 1 :
|
|
|
+ testGetApi();
|
|
|
+ System.out.println("i: " + i + ", send get request.");
|
|
|
+ getCount ++;
|
|
|
+ break;
|
|
|
+ case 2 :
|
|
|
+ testPostApi();
|
|
|
+ System.out.println("i: " + i + ", send post request.");
|
|
|
+ postCount ++;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Thread.sleep(timer);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ System.out.println(i + " requests send, " + getCount + " getRequest, " + postCount + " postRequest.");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发起get请求
|
|
|
+ */
|
|
|
+ public static void testGetApi() {
|
|
|
+ try {
|
|
|
+ HttpUtil.sendGetRequest(HOST_URL, null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发起post请求
|
|
|
+ */
|
|
|
+ public static void testPostApi() {
|
|
|
+ try {
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ // 生成随机的字符串
|
|
|
+ String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ params.put("content", uuid);
|
|
|
+ HttpUtil.sendPostRequest(HOST_URL, params, false, false);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|