Skip to content
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
<central-publishing-maven-plugin.version>0.7.0</central-publishing-maven-plugin.version>
<exec.maven.version>3.1.0</exec.maven.version>
<junit.version>5.14.2</junit.version>
<mockito-core.version>5.21.0</mockito-core.version>
<mockito-inline.version>5.2.0</mockito-inline.version>
<file.encoding>UTF-8</file.encoding>
</properties>

Expand Down Expand Up @@ -146,6 +148,24 @@
<classifier>runtime</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito-inline.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 2 additions & 2 deletions trpc-dependencies/trpc-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
<gson.version>2.8.9</gson.version>
<guava.version>32.1.3-jre</guava.version>
<httpclient.version>4.5.14</httpclient.version>
<httpclient5.version>5.4.1</httpclient5.version>
<httpclient5.version>5.3.1</httpclient5.version>
<httpcore.version>4.4.15</httpcore.version>
<httpcore5.version>5.2.1</httpcore5.version>
<httpcore5.version>5.2.5</httpcore5.version>
<hutool.all.version>5.8.28</hutool.all.version>
<jackson.version>2.15.0-rc2</jackson.version>
<jakarta.servlet.version>6.0.0</jakarta.servlet.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Tencent is pleased to support the open source community by making tRPC available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company.
* Copyright (C) 2023 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* If you have downloaded a copy of the tRPC source code from Tencent,
Expand All @@ -17,17 +17,17 @@
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

public class ExecutorDispatcherTest {

@Test
public void test() throws ServletException, IOException {
ExecutorDispatcher dispatcher = new ExecutorDispatcher();
HttpServletRequest req = PowerMockito.mock(HttpServletRequest.class);
PowerMockito.when(req.getLocalPort()).thenReturn(1024);
HttpServletResponse rsp = PowerMockito.mock(HttpServletResponse.class);
HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
Mockito.when(req.getLocalPort()).thenReturn(1024);
HttpServletResponse rsp = Mockito.mock(HttpServletResponse.class);
dispatcher.service(req, rsp);
org.mockito.Mockito.verify(rsp, times(1)).sendError(404,
"HttpExecutor is closed: port is:1024.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Tencent is pleased to support the open source community by making tRPC available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company.
* Copyright (C) 2023 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* If you have downloaded a copy of the tRPC source code from Tencent,
Expand All @@ -14,7 +14,7 @@
import static com.tencent.trpc.transport.http.common.Constants.HTTP2_SCHEME;
import static com.tencent.trpc.transport.http.common.Constants.KEYSTORE_PASS;
import static com.tencent.trpc.transport.http.common.Constants.KEYSTORE_PATH;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.tencent.trpc.core.common.config.ProtocolConfig;
import com.tencent.trpc.core.extension.ExtensionLoader;
Expand Down Expand Up @@ -43,10 +43,10 @@
import org.apache.hc.core5.http2.ssl.ConscryptClientTlsStrategy;
import org.apache.hc.core5.ssl.SSLContexts;
import org.eclipse.jetty.http.HttpStatus;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class JettyHttp2ServerTest {

Expand All @@ -56,7 +56,7 @@

private static CloseableHttpAsyncClient httpAsyncClient;

@BeforeClass
@BeforeAll

Check warning on line 59 in trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttp2ServerTest.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] reported by reviewdog 🐶 缺少 Javadoc 。 Raw Output: /github/workspace/./trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttp2ServerTest.java:59:5: info: 缺少 Javadoc 。 (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
public static void beforeClass() throws CertificateException, NoSuchAlgorithmException,
KeyStoreException, IOException, KeyManagementException {
ProtocolConfig protocolConfig = ProtocolConfig.newInstance();
Expand Down Expand Up @@ -109,7 +109,7 @@
httpAsyncClient.start();
}

@AfterClass
@AfterAll
public static void afterClass() {
if (httpServer != null) {
httpServer.open();
Expand Down Expand Up @@ -146,14 +146,14 @@
}
});
SimpleHttpResponse simpleHttpResponse = httpResponseFuture.get(2000, TimeUnit.MILLISECONDS);
Assert.assertNotEquals(null, simpleHttpResponse);
Assertions.assertNotEquals(null, simpleHttpResponse);
logger.error(simpleHttpResponse.getBodyText());
Assert.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol());
Assert.assertEquals(2, simpleHttpResponse.getVersion().getMajor());
Assertions.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol());
Assertions.assertEquals(2, simpleHttpResponse.getVersion().getMajor());
logger.info("response code is {}", simpleHttpResponse.getCode());
Assert.assertEquals(200, simpleHttpResponse.getCode());
Assertions.assertEquals(200, simpleHttpResponse.getCode());
logger.info("http response is: {}", simpleHttpResponse.getBodyText());
Assert.assertEquals("", simpleHttpResponse.getBodyText());
Assertions.assertEquals("", simpleHttpResponse.getBodyText());
}

@Test
Expand All @@ -178,14 +178,14 @@
}
});
SimpleHttpResponse simpleHttpResponse = httpResponseFuture.get(2000, TimeUnit.MILLISECONDS);
Assert.assertNotEquals(null, simpleHttpResponse);
Assertions.assertNotEquals(null, simpleHttpResponse);
logger.error(simpleHttpResponse.getBodyText());
Assert.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol());
Assert.assertEquals(2, simpleHttpResponse.getVersion().getMajor());
Assertions.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol());
Assertions.assertEquals(2, simpleHttpResponse.getVersion().getMajor());
logger.info("response code is {}", simpleHttpResponse.getCode());
Assert.assertEquals(404, simpleHttpResponse.getCode());
Assertions.assertEquals(404, simpleHttpResponse.getCode());
logger.info("http response is: {}", simpleHttpResponse.getBodyText());
Assert.assertEquals("", simpleHttpResponse.getBodyText());
Assertions.assertEquals("", simpleHttpResponse.getBodyText());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
package com.tencent.trpc.transport.http;

import static com.tencent.trpc.transport.http.common.Constants.HTTP2_SCHEME;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.tencent.trpc.core.common.config.ProtocolConfig;
import com.tencent.trpc.core.extension.ExtensionLoader;
Expand All @@ -34,10 +34,10 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.eclipse.jetty.http.HttpStatus;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class JettyHttp2cServerTest {

Expand All @@ -49,7 +49,7 @@

private static CloseableHttpClient httpClient;

@BeforeClass
@BeforeAll

Check warning on line 52 in trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttp2cServerTest.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] reported by reviewdog 🐶 缺少 Javadoc 。 Raw Output: /github/workspace/./trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttp2cServerTest.java:52:5: info: 缺少 Javadoc 。 (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
public static void beforeClass() {
ProtocolConfig protocolConfig = ProtocolConfig.newInstance();
protocolConfig.setIp("localhost");
Expand Down Expand Up @@ -88,7 +88,7 @@
httpClient = HttpClients.custom().build();
}

@AfterClass
@AfterAll
public static void afterClass() {
if (httpServer != null) {
httpServer.open();
Expand Down Expand Up @@ -125,14 +125,14 @@
}
});
SimpleHttpResponse simpleHttpResponse = httpResponseFuture.get(2000, TimeUnit.MILLISECONDS);
Assert.assertNotEquals(null, simpleHttpResponse);
Assertions.assertNotEquals(null, simpleHttpResponse);
logger.error(simpleHttpResponse.getBodyText());
Assert.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol());
Assert.assertEquals(2, simpleHttpResponse.getVersion().getMajor());
Assertions.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol());
Assertions.assertEquals(2, simpleHttpResponse.getVersion().getMajor());
logger.info("response code is {}", simpleHttpResponse.getCode());
Assert.assertEquals(200, simpleHttpResponse.getCode());
Assertions.assertEquals(200, simpleHttpResponse.getCode());
logger.info("http response is: {}", simpleHttpResponse.getBodyText());
Assert.assertEquals("", simpleHttpResponse.getBodyText());
Assertions.assertEquals("", simpleHttpResponse.getBodyText());
}

@Test
Expand All @@ -157,14 +157,14 @@
}
});
SimpleHttpResponse simpleHttpResponse = httpResponseFuture.get(2000, TimeUnit.MILLISECONDS);
Assert.assertNotEquals(null, simpleHttpResponse);
Assertions.assertNotEquals(null, simpleHttpResponse);
logger.error(simpleHttpResponse.getBodyText());
Assert.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol());
Assert.assertEquals(2, simpleHttpResponse.getVersion().getMajor());
Assertions.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol());
Assertions.assertEquals(2, simpleHttpResponse.getVersion().getMajor());
logger.info("response code is {}", simpleHttpResponse.getCode());
Assert.assertEquals(404, simpleHttpResponse.getCode());
Assertions.assertEquals(404, simpleHttpResponse.getCode());
logger.info("http response is: {}", simpleHttpResponse.getBodyText());
Assert.assertEquals("", simpleHttpResponse.getBodyText());
Assertions.assertEquals("", simpleHttpResponse.getBodyText());
}

@Test
Expand All @@ -175,10 +175,10 @@

int responseCode = httpResponse.getStatusLine().getStatusCode();
logger.info("response code is {}", responseCode);
Assert.assertEquals(responseCode, 200);
Assertions.assertEquals(responseCode, 200);

Assert.assertEquals(httpResponse.getProtocolVersion().getProtocol(), "HTTP");
Assert.assertEquals(httpResponse.getProtocolVersion().getMajor(), 1);
Assertions.assertEquals(httpResponse.getProtocolVersion().getProtocol(), "HTTP");
Assertions.assertEquals(httpResponse.getProtocolVersion().getMajor(), 1);

}

Expand All @@ -190,10 +190,10 @@

int responseCode = httpResponse.getStatusLine().getStatusCode();
logger.info("response code is {}", responseCode);
Assert.assertEquals(responseCode, 404);
Assertions.assertEquals(responseCode, 404);

Assert.assertEquals(httpResponse.getProtocolVersion().getProtocol(), "HTTP");
Assert.assertEquals(httpResponse.getProtocolVersion().getMajor(), 1);
Assertions.assertEquals(httpResponse.getProtocolVersion().getProtocol(), "HTTP");
Assertions.assertEquals(httpResponse.getProtocolVersion().getMajor(), 1);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Tencent is pleased to support the open source community by making tRPC available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company.
* Copyright (C) 2023 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* If you have downloaded a copy of the tRPC source code from Tencent,
Expand All @@ -14,7 +14,7 @@
import static com.tencent.trpc.transport.http.common.Constants.HTTP_SCHEME;
import static com.tencent.trpc.transport.http.common.Constants.KEYSTORE_PASS;
import static com.tencent.trpc.transport.http.common.Constants.KEYSTORE_PATH;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.tencent.trpc.core.common.config.ProtocolConfig;
import com.tencent.trpc.core.extension.ExtensionLoader;
Expand All @@ -40,13 +40,15 @@
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
import org.apache.hc.core5.concurrent.FutureCallback;
import org.apache.hc.core5.http2.HttpVersionPolicy;
import org.apache.hc.core5.http2.ssl.ConscryptClientTlsStrategy;
import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.apache.hc.core5.ssl.SSLContexts;
import org.apache.hc.core5.ssl.TrustStrategy;
import org.eclipse.jetty.http.HttpStatus;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class JettyHttpsServerTest {

Expand All @@ -56,7 +58,7 @@

private static CloseableHttpAsyncClient httpAsyncClient;

@BeforeClass
@BeforeAll

Check warning on line 61 in trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttpsServerTest.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] reported by reviewdog 🐶 缺少 Javadoc 。 Raw Output: /github/workspace/./trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttpsServerTest.java:61:5: info: 缺少 Javadoc 。 (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
public static void beforeClass() throws CertificateException, NoSuchAlgorithmException,
KeyStoreException, IOException, KeyManagementException {
ProtocolConfig protocolConfig = ProtocolConfig.newInstance();
Expand Down Expand Up @@ -97,19 +99,23 @@
String keyStorePath = String.valueOf(path);
String keyStorePass = "init234";
final SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(new File(keyStorePath), keyStorePass.toCharArray())
.loadTrustMaterial(new File(keyStorePath), keyStorePass.toCharArray(),
(TrustStrategy) (chain, authType) -> true)
.build();
final PoolingAsyncClientConnectionManager cm = PoolingAsyncClientConnectionManagerBuilder
.create().useSystemProperties()
.setTlsStrategy(new ConscryptClientTlsStrategy(sslContext))
.create()
.setTlsStrategy(ClientTlsStrategyBuilder.create()
.setSslContext(sslContext)
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.build())
.build();
httpAsyncClient = HttpAsyncClients.custom()
.setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_1).setConnectionManager(cm)
.build();
httpAsyncClient.start();
}

@AfterClass
@AfterAll
public static void afterClass() {
if (httpServer != null) {
httpServer.open();
Expand Down Expand Up @@ -146,14 +152,14 @@
}
});
SimpleHttpResponse simpleHttpResponse = httpResponseFuture.get(2000, TimeUnit.MILLISECONDS);
Assert.assertNotEquals(null, simpleHttpResponse);
Assertions.assertNotEquals(null, simpleHttpResponse);
logger.error(simpleHttpResponse.getBodyText());
Assert.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol());
Assert.assertEquals(1, simpleHttpResponse.getVersion().getMajor());
Assertions.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol());
Assertions.assertEquals(1, simpleHttpResponse.getVersion().getMajor());
logger.info("response code is {}", simpleHttpResponse.getCode());
Assert.assertEquals(200, simpleHttpResponse.getCode());
Assertions.assertEquals(200, simpleHttpResponse.getCode());
logger.info("http response is: {}", simpleHttpResponse.getBodyText());
Assert.assertEquals("", simpleHttpResponse.getBodyText());
Assertions.assertEquals("", simpleHttpResponse.getBodyText());
}

@Test
Expand All @@ -178,14 +184,14 @@
}
});
SimpleHttpResponse simpleHttpResponse = httpResponseFuture.get(2000, TimeUnit.MILLISECONDS);
Assert.assertNotEquals(null, simpleHttpResponse);
Assertions.assertNotEquals(null, simpleHttpResponse);
logger.error(simpleHttpResponse.getBodyText());
Assert.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol());
Assert.assertEquals(1, simpleHttpResponse.getVersion().getMajor());
Assertions.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol());
Assertions.assertEquals(1, simpleHttpResponse.getVersion().getMajor());
logger.info("response code is {}", simpleHttpResponse.getCode());
Assert.assertEquals(404, simpleHttpResponse.getCode());
Assertions.assertEquals(404, simpleHttpResponse.getCode());
logger.info("http response is: {}", simpleHttpResponse.getBodyText());
Assert.assertEquals("", simpleHttpResponse.getBodyText());
Assertions.assertEquals("", simpleHttpResponse.getBodyText());
}

}
Loading
Loading