HttpSimpleClient优化

This commit is contained in:
redkale
2023-11-30 15:40:09 +08:00
parent f0e53d4a8e
commit c25001c5e4
10 changed files with 174 additions and 102 deletions

View File

@@ -46,7 +46,7 @@ public class HttpSimpleClientTest {
HttpSimpleClient client = HttpSimpleClient.create(asyncGroup);
InetSocketAddress addr = new InetSocketAddress("127.0.0.1", port);
{
HttpSimpleRequest req = HttpSimpleRequest.createPath("/test").param("id", 100);
HttpSimpleRequest req = HttpSimpleRequest.createPostPath("/test").param("id", 100);
System.out.println(client.getAsync("http://127.0.0.1:" + port + req.getPath() + "?id=100").join());
System.out.println(client.sendAsync(addr, req).join());
}
@@ -55,7 +55,7 @@ public class HttpSimpleClientTest {
final CountDownLatch cdl = new CountDownLatch(count);
for (int i = 100; i < 100 + count; i++) {
final int index = i;
HttpSimpleRequest req = HttpSimpleRequest.createPath("/test").param("id", index);
HttpSimpleRequest req = HttpSimpleRequest.createPostPath("/test").param("id", index);
client.getAsync("http://127.0.0.1:" + port + req.getPath() + "?id=" + index).whenComplete((v, t) -> {
cdl.countDown();
Assertions.assertEquals("ok-" + index, new String((byte[]) v.getResult()));
@@ -68,7 +68,7 @@ public class HttpSimpleClientTest {
final CountDownLatch cdl = new CountDownLatch(count);
for (int i = 100; i < 100 + count; i++) {
final int index = i;
HttpSimpleRequest req = HttpSimpleRequest.createPath("/test").param("id", index);
HttpSimpleRequest req = HttpSimpleRequest.createPostPath("/test").param("id", index);
client.sendAsync(addr, req).whenComplete((v, t) -> {
cdl.countDown();
System.out.println("输出: " + new String((byte[]) v.getResult()));

View File

@@ -28,7 +28,7 @@ public class RequestCoderTest {
@Test
public void run1() throws Exception {
HttpSimpleRequest req1 = HttpSimpleRequest.createPath("/aaa");
HttpSimpleRequest req1 = HttpSimpleRequest.createPostPath("/aaa");
System.out.println("simpleRequest1: " + req1);
byte[] bytes = HttpSimpleRequestCoder.getInstance().encode(req1);
HttpSimpleRequest req2 = HttpSimpleRequestCoder.getInstance().decode(bytes);
@@ -41,7 +41,7 @@ public class RequestCoderTest {
@Test
public void run2() throws Exception {
HttpSimpleRequest req1 = HttpSimpleRequest.createPath("/aaa");
HttpSimpleRequest req1 = HttpSimpleRequest.createPostPath("/aaa");
req1.addHeader("X-aaa", "aaa");
req1.param("bean", "{}");
System.out.println("simpleRequest1: " + req1);
@@ -56,7 +56,7 @@ public class RequestCoderTest {
@Test
public void run3() throws Exception {
HttpSimpleRequest req1 = HttpSimpleRequest.createPath("/aaa");
HttpSimpleRequest req1 = HttpSimpleRequest.createPostPath("/aaa");
req1.addHeader("X-aaa", "aaa");
req1.addHeader("X-bbb", "bbb1");
req1.addHeader("X-bbb", "bbb2");