Skip to content

Commit e0708da

Browse files
pj-25claude
andcommitted
build: restore Maven build, add end-to-end echo tests and CI; rewrite README
- remove duplicate junit-jupiter declaration (POM failed to load) - declare JSERVER -> JConnection dependency (was IDE-only) + aggregator pom - EchoRoundTripTest: real server on ephemeral port, ordering + pause/resume - disable manual JConnectionTest (needs external server on :5656) - README: problem, design, trade-offs, known limitations, run instructions Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e31cfa8 commit e0708da

8 files changed

Lines changed: 197 additions & 258 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: build
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- uses: actions/setup-java@v4
9+
with: { distribution: temurin, java-version: '17', cache: maven }
10+
- run: mvn -B -f JSC/pom.xml test

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@
2020

2121
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2222
hs_err_pid*
23+
24+
# Maven build output
25+
target/

‎JSC/JConnection/pom.xml‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,35 @@
77
<groupId>org.example</groupId>
88
<artifactId>JConnection</artifactId>
99
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<junit.version>5.10.2</junit.version>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
</properties>
15+
1016
<build>
1117
<plugins>
1218
<plugin>
1319
<groupId>org.apache.maven.plugins</groupId>
1420
<artifactId>maven-compiler-plugin</artifactId>
21+
<version>3.13.0</version>
1522
<configuration>
1623
<source>8</source>
1724
<target>8</target>
1825
</configuration>
1926
</plugin>
27+
<plugin>
28+
<groupId>org.apache.maven.plugins</groupId>
29+
<artifactId>maven-surefire-plugin</artifactId>
30+
<version>3.2.5</version>
31+
</plugin>
2032
</plugins>
2133
</build>
2234
<dependencies>
2335
<dependency>
2436
<groupId>org.junit.jupiter</groupId>
2537
<artifactId>junit-jupiter</artifactId>
26-
<version>RELEASE</version>
27-
<scope>test</scope>
28-
</dependency>
29-
<dependency>
30-
<groupId>org.junit.jupiter</groupId>
31-
<artifactId>junit-jupiter</artifactId>
32-
<version>RELEASE</version>
38+
<version>${junit.version}</version>
3339
<scope>test</scope>
3440
</dependency>
3541
</dependencies>

‎JSC/JConnection/src/test/java/jsc/jConnection/JConnectionTest.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44

55

6+
@org.junit.jupiter.api.Disabled("Manual: needs EchoServer running on :5656. Automated coverage: JSERVER EchoRoundTripTest")
67
class JConnectionTest {
78

89
JConnection jConnection;

‎JSC/JSERVER/pom.xml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,44 @@
77
<groupId>org.example</groupId>
88
<artifactId>JSERVER</artifactId>
99
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<junit.version>5.10.2</junit.version>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
</properties>
15+
1016
<build>
1117
<plugins>
1218
<plugin>
1319
<groupId>org.apache.maven.plugins</groupId>
1420
<artifactId>maven-compiler-plugin</artifactId>
21+
<version>3.13.0</version>
1522
<configuration>
1623
<source>8</source>
1724
<target>8</target>
1825
</configuration>
1926
</plugin>
27+
<plugin>
28+
<groupId>org.apache.maven.plugins</groupId>
29+
<artifactId>maven-surefire-plugin</artifactId>
30+
<version>3.2.5</version>
31+
</plugin>
2032
</plugins>
2133
</build>
2234

35+
<dependencies>
36+
<dependency>
37+
<groupId>org.example</groupId>
38+
<artifactId>JConnection</artifactId>
39+
<version>1.0-SNAPSHOT</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.junit.jupiter</groupId>
43+
<artifactId>junit-jupiter</artifactId>
44+
<version>${junit.version}</version>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
2349

2450
</project>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package jsc.jServer;
2+
3+
import jsc.jConnection.JConnection;
4+
import org.junit.jupiter.api.AfterEach;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.util.concurrent.BlockingQueue;
9+
import java.util.concurrent.LinkedBlockingQueue;
10+
import java.util.concurrent.TimeUnit;
11+
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
15+
/** End-to-end: real JServer on an ephemeral port, real JConnection client, messages echoed back in order. */
16+
class EchoRoundTripTest {
17+
18+
public static class Echo extends JRequestManager {
19+
@Override
20+
public void accept(String req) { write(req); }
21+
}
22+
23+
private JServer server;
24+
private JConnection client;
25+
private final BlockingQueue<String> received = new LinkedBlockingQueue<>();
26+
27+
@BeforeEach
28+
void setUp() throws Exception {
29+
server = new JServer(0, Echo.class); // port 0 = OS picks a free port
30+
Thread t = new Thread(server::start, "jserver");
31+
t.setDaemon(true);
32+
t.start();
33+
client = new JConnection("127.0.0.1", server.getServerSocket().getLocalPort(), received::add);
34+
client.run();
35+
}
36+
37+
@AfterEach
38+
void tearDown() {
39+
client.close();
40+
server.setRunning(false);
41+
server.close();
42+
}
43+
44+
@Test
45+
void echoesMessagesInOrder() throws Exception {
46+
String[] msgs = {"hello", "1/2~3>4;5,6", "unicode ✓"};
47+
for (String m : msgs) client.write(m);
48+
for (String m : msgs) assertEquals(m, received.poll(5, TimeUnit.SECONDS));
49+
}
50+
51+
@Test
52+
void pausedReadHoldsMessagesUntilResume() throws Exception {
53+
client.write("before");
54+
assertEquals("before", received.poll(5, TimeUnit.SECONDS));
55+
client.setReadInterrupt(true);
56+
client.write("m1");
57+
client.write("m2");
58+
client.write("m3");
59+
Thread.sleep(500);
60+
// The pause is checked before each blocking readUTF(), so a read already in flight
61+
// can still deliver one message (documented limitation); the rest must be held.
62+
int leaked = received.size();
63+
assertTrue(leaked <= 1, "at most one in-flight message may arrive while paused, got " + leaked);
64+
client.setReadInterrupt(false);
65+
for (String m : new String[]{"m1", "m2", "m3"}) assertEquals(m, received.poll(5, TimeUnit.SECONDS));
66+
}
67+
}

‎JSC/pom.xml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Aggregator so `mvn test` builds JConnection first, then JSERVER (which depends on it). -->
3+
<project xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<groupId>org.example</groupId>
8+
<artifactId>JSC</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>pom</packaging>
11+
<modules>
12+
<module>JConnection</module>
13+
<module>JSERVER</module>
14+
</modules>
15+
</project>

0 commit comments

Comments
 (0)