From a70fe45d1dca708c8d33d7269ebee1cbb2e7f6bc Mon Sep 17 00:00:00 2001 From: wxd-gaming <492794628@qq.com> Date: Fri, 8 Aug 2025 10:29:33 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/logbus/PostLoginLogTest.java | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/wxdgaming.spring.logcenter/src/test/java/logbus/PostLoginLogTest.java b/wxdgaming.spring.logcenter/src/test/java/logbus/PostLoginLogTest.java index f6e811f..64874d5 100644 --- a/wxdgaming.spring.logcenter/src/test/java/logbus/PostLoginLogTest.java +++ b/wxdgaming.spring.logcenter/src/test/java/logbus/PostLoginLogTest.java @@ -5,10 +5,13 @@ import com.alibaba.fastjson.JSONObject; import org.junit.jupiter.api.RepeatedTest; import org.springframework.boot.test.context.SpringBootTest; import wxdgaming.spring.boot.core.CoreConfiguration; +import wxdgaming.spring.boot.core.chatset.StringUtils; import wxdgaming.spring.boot.core.collection.MapOf; +import wxdgaming.spring.boot.core.format.HexId; import wxdgaming.spring.boot.net.httpclient.HttpClientConfiguration; import wxdgaming.spring.boot.net.httpclient.HttpRequestPost; import wxdgaming.spring.boot.net.httpclient.HttpResponse; +import wxdgaming.spring.logcenter.bean.LogEntity; import java.util.ArrayList; import java.util.concurrent.TimeUnit; @@ -26,31 +29,31 @@ import java.util.concurrent.locks.LockSupport; ) public class PostLoginLogTest { + static final HexId hexId = new HexId(1); @RepeatedTest(10) public void login() { - JSONObject jsonObject = MapOf.newJSONObject(); - jsonObject.put("uid", System.nanoTime()); - jsonObject.put("createTime", System.currentTimeMillis()); - jsonObject.put("logType", "login"); - jsonObject.put("json", MapOf.newJSONObject().fluentPut("account", "wxd-gaming")); + LogEntity logEntity = new LogEntity(); + logEntity.setUid(hexId.newId()); + logEntity.setCreateTime(System.currentTimeMillis()); + logEntity.setLogType("login"); + logEntity.putJson("account", StringUtils.randomString(8)); HttpRequestPost httpRequestPost = HttpRequestPost.of("http://localhost:8888/api/log/push"); - httpRequestPost.setJson(jsonObject); + httpRequestPost.setJson(logEntity.toJSONString()); HttpResponse execute = httpRequestPost.execute(); System.out.println(execute.bodyString()); } - @RepeatedTest(10000) + @RepeatedTest(1000) public void loginList() { - ArrayList list = new ArrayList<>(); + ArrayList list = new ArrayList<>(); for (int i = 0; i < 1000; i++) { - JSONObject jsonObject = MapOf.newJSONObject(); - jsonObject.put("uid", System.nanoTime()); - jsonObject.put("createTime", System.currentTimeMillis()); - jsonObject.put("logType", "login"); - jsonObject.put("json", MapOf.newJSONObject().fluentPut("account", "wxd-gaming")); - - list.add(jsonObject); + LogEntity logEntity = new LogEntity(); + logEntity.setUid(hexId.newId()); + logEntity.setCreateTime(System.currentTimeMillis()); + logEntity.setLogType("login"); + logEntity.putJson("account", StringUtils.randomString(8)); + list.add(logEntity); } HttpRequestPost httpRequestPost = HttpRequestPost.of("http://localhost:8888/api/log/pushlist"); httpRequestPost.setJson(JSON.toJSONString(list)); @@ -62,13 +65,13 @@ public class PostLoginLogTest { @RepeatedTest(10) public void logout() { - JSONObject jsonObject = MapOf.newJSONObject(); - jsonObject.put("uid", System.nanoTime()); - jsonObject.put("createTime", System.currentTimeMillis()); - jsonObject.put("logType", "logout"); - jsonObject.put("json", MapOf.newJSONObject().fluentPut("account", "wxd-gaming")); + LogEntity logEntity = new LogEntity(); + logEntity.setUid(hexId.newId()); + logEntity.setCreateTime(System.currentTimeMillis()); + logEntity.setLogType("logout"); + logEntity.putJson("account", StringUtils.randomString(8)); HttpRequestPost httpRequestPost = HttpRequestPost.of("http://localhost:8888/api/log/push"); - httpRequestPost.setJson(jsonObject); + httpRequestPost.setJson(logEntity.toJSONString()); HttpResponse execute = httpRequestPost.execute(); System.out.println(execute.bodyString()); }