WebRequest
This commit is contained in:
@@ -11,8 +11,8 @@ import org.redkale.boot.Application;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
import org.redkale.net.AsyncIOGroup;
|
||||
import org.redkale.net.http.HttpServer;
|
||||
import org.redkale.net.http.HttpSimpleClient;
|
||||
import org.redkale.net.http.HttpSimpleRequest;
|
||||
import org.redkale.net.http.WebClient;
|
||||
import org.redkale.net.http.WebRequest;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
|
||||
/**
|
||||
@@ -43,10 +43,10 @@ public class HttpSimpleClientTest {
|
||||
//Utility.sleep(50000);
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
asyncGroup.start();
|
||||
HttpSimpleClient client = HttpSimpleClient.create(asyncGroup);
|
||||
WebClient client = WebClient.create(asyncGroup);
|
||||
InetSocketAddress addr = new InetSocketAddress("127.0.0.1", port);
|
||||
{
|
||||
HttpSimpleRequest req = HttpSimpleRequest.createPostPath("/test").param("id", 100);
|
||||
WebRequest req = WebRequest.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.createPostPath("/test").param("id", index);
|
||||
WebRequest req = WebRequest.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.createPostPath("/test").param("id", index);
|
||||
WebRequest req = WebRequest.createPostPath("/test").param("id", index);
|
||||
client.sendAsync(addr, req).whenComplete((v, t) -> {
|
||||
cdl.countDown();
|
||||
System.out.println("输出: " + new String((byte[]) v.getResult()));
|
||||
|
||||
@@ -6,9 +6,9 @@ package org.redkale.test.http;
|
||||
import java.lang.reflect.Field;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.redkale.mq.spi.HttpSimpleRequestCoder;
|
||||
import org.redkale.mq.spi.WebRequestCoder;
|
||||
import org.redkale.net.client.ClientRequest;
|
||||
import org.redkale.net.http.HttpSimpleRequest;
|
||||
import org.redkale.net.http.WebRequest;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -28,10 +28,10 @@ public class RequestCoderTest {
|
||||
|
||||
@Test
|
||||
public void run1() throws Exception {
|
||||
HttpSimpleRequest req1 = HttpSimpleRequest.createPostPath("/aaa");
|
||||
WebRequest req1 = WebRequest.createPostPath("/aaa");
|
||||
System.out.println("simpleRequest1: " + req1);
|
||||
byte[] bytes = HttpSimpleRequestCoder.getInstance().encode(req1);
|
||||
HttpSimpleRequest req2 = HttpSimpleRequestCoder.getInstance().decode(bytes);
|
||||
byte[] bytes = WebRequestCoder.getInstance().encode(req1);
|
||||
WebRequest req2 = WebRequestCoder.getInstance().decode(bytes);
|
||||
Field timeFiedl = ClientRequest.class.getDeclaredField("createTime");
|
||||
timeFiedl.setAccessible(true);
|
||||
timeFiedl.set(req2, req1.getCreateTime());
|
||||
@@ -41,12 +41,12 @@ public class RequestCoderTest {
|
||||
|
||||
@Test
|
||||
public void run2() throws Exception {
|
||||
HttpSimpleRequest req1 = HttpSimpleRequest.createPostPath("/aaa");
|
||||
WebRequest req1 = WebRequest.createPostPath("/aaa");
|
||||
req1.addHeader("X-aaa", "aaa");
|
||||
req1.param("bean", "{}");
|
||||
System.out.println("simpleRequest1: " + req1);
|
||||
byte[] bytes = HttpSimpleRequestCoder.getInstance().encode(req1);
|
||||
HttpSimpleRequest req2 = HttpSimpleRequestCoder.getInstance().decode(bytes);
|
||||
byte[] bytes = WebRequestCoder.getInstance().encode(req1);
|
||||
WebRequest req2 = WebRequestCoder.getInstance().decode(bytes);
|
||||
Field timeFiedl = ClientRequest.class.getDeclaredField("createTime");
|
||||
timeFiedl.setAccessible(true);
|
||||
timeFiedl.set(req2, req1.getCreateTime());
|
||||
@@ -56,14 +56,14 @@ public class RequestCoderTest {
|
||||
|
||||
@Test
|
||||
public void run3() throws Exception {
|
||||
HttpSimpleRequest req1 = HttpSimpleRequest.createPostPath("/aaa");
|
||||
WebRequest req1 = WebRequest.createPostPath("/aaa");
|
||||
req1.addHeader("X-aaa", "aaa");
|
||||
req1.addHeader("X-bbb", "bbb1");
|
||||
req1.addHeader("X-bbb", "bbb2");
|
||||
req1.param("bean", "{}");
|
||||
System.out.println("simpleRequest1: " + req1);
|
||||
byte[] bytes = HttpSimpleRequestCoder.getInstance().encode(req1);
|
||||
HttpSimpleRequest req2 = HttpSimpleRequestCoder.getInstance().decode(bytes);
|
||||
byte[] bytes = WebRequestCoder.getInstance().encode(req1);
|
||||
WebRequest req2 = WebRequestCoder.getInstance().decode(bytes);
|
||||
Field timeFiedl = ClientRequest.class.getDeclaredField("createTime");
|
||||
timeFiedl.setAccessible(true);
|
||||
timeFiedl.set(req2, req1.getCreateTime());
|
||||
|
||||
Reference in New Issue
Block a user