File tree Expand file tree Collapse file tree 5 files changed +45
-2
lines changed
main/java/io/github/protocol/mdtp/server
test/java/io/github/protocol/mdtp/server Expand file tree Collapse file tree 5 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 1818 java-version : ' 17'
1919 distribution : ' temurin'
2020 - name : unit tests
21- run : mvn -B clean test
21+ run : mvn -B clean test; mvn -B validate
2222 - name : Upload coverage to Codecov
2323 uses : codecov/codecov-action@v4
2424 env :
Original file line number Diff line number Diff line change 1717 <artifactId >mdtp-common</artifactId >
1818 <version >${project.version} </version >
1919 </dependency >
20+ <dependency >
21+ <groupId >io.github.protocol-laboratory</groupId >
22+ <artifactId >mdtp-client</artifactId >
23+ <version >${project.version} </version >
24+ </dependency >
2025 <dependency >
2126 <groupId >io.netty</groupId >
2227 <artifactId >netty-handler</artifactId >
Original file line number Diff line number Diff line change 11package io .github .protocol .mdtp .server ;
22
33import io .netty .bootstrap .ServerBootstrap ;
4+ import io .netty .channel .Channel ;
45import io .netty .channel .ChannelFuture ;
56import io .netty .channel .ChannelInitializer ;
67import io .netty .channel .EventLoopGroup ;
@@ -21,6 +22,8 @@ public class MdtpServer implements Closeable {
2122
2223 private EventLoopGroup ioGroup ;
2324
25+ private Channel channel ;
26+
2427 public MdtpServer (MdtpServerConfig config ) {
2528 this .config = config ;
2629 }
@@ -44,13 +47,21 @@ protected void initChannel(SocketChannel socketChannel) throws Exception {
4447 });
4548 ChannelFuture channelFuture = serverBootstrap .bind ().sync ();
4649 if (channelFuture .isSuccess ()) {
50+ this .channel = channelFuture .channel ();
4751 log .info ("mdtp server started" );
4852 } else {
4953 log .error ("mdtp server start failed" , channelFuture .cause ());
5054 throw new Exception ("mdtp server start failed" , channelFuture .cause ());
5155 }
5256 }
5357
58+ public int listenPort () {
59+ if (this .channel != null && this .channel .localAddress () instanceof InetSocketAddress ) {
60+ return ((InetSocketAddress ) this .channel .localAddress ()).getPort ();
61+ }
62+ return -1 ;
63+ }
64+
5465 @ Override
5566 public void close () throws IOException {
5667 if (this .acceptorGroup != null ) {
Original file line number Diff line number Diff line change 1+ package io .github .protocol .mdtp .server ;
2+
3+ import io .github .protocol .mdtp .client .MdtpClient ;
4+ import io .github .protocol .mdtp .client .MdtpClientConfig ;
5+ import org .junit .jupiter .api .Test ;
6+
7+ public class MdtpConnectTest {
8+ @ Test
9+ public void mdtpConnect () throws Exception {
10+ MdtpServerConfig mdtpServerConfig = new MdtpServerConfig ().host ("localhost" ).port (0 );
11+ MdtpServer mdtpServer = new MdtpServer (mdtpServerConfig );
12+ mdtpServer .start ();
13+ MdtpClientConfig mdtpClientConfig = new MdtpClientConfig ().host ("localhost" ).port (mdtpServer .listenPort ());
14+ MdtpClient mdtpClient = new MdtpClient (mdtpClientConfig );
15+ mdtpClient .start ();
16+ mdtpClient .close ();
17+ mdtpServer .close ();
18+ }
19+ }
Original file line number Diff line number Diff line change 2121 <maven .compiler.target>17</maven .compiler.target>
2222 <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
2323 <src .dir>src/main/java</src .dir>
24+ <jacoco .overall.exec>${maven.multiModuleProjectDirectory} /target/jacoco/jacoco.exec</jacoco .overall.exec>
2425 <!-- dependency -->
2526 <junit .version>5.11.0</junit .version>
2627 <log4j .version>2.20.0</log4j .version>
99100 <groupId >org.jacoco</groupId >
100101 <artifactId >jacoco-maven-plugin</artifactId >
101102 <version >${jacoco-maven-plugin.version} </version >
103+ <configuration >
104+ <destFile >${jacoco.overall.exec} </destFile >
105+ <dataFile >${jacoco.overall.exec} </dataFile >
106+ </configuration >
102107 <executions >
103108 <execution >
104109 <id >prepare-agent</id >
110+ <configuration >
111+ <append >true</append >
112+ </configuration >
105113 <goals >
106114 <goal >prepare-agent</goal >
107115 </goals >
108116 </execution >
109117 <execution >
110118 <id >report</id >
111- <phase >test </phase >
119+ <phase >validate </phase >
112120 <goals >
113121 <goal >report</goal >
114122 </goals >
You can’t perform that action at this time.
0 commit comments