diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8531e775..635594d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,24 +13,30 @@ jobs: strategy: fail-fast: false matrix: - java: [7, 8, 11] + java: [8, 11] steps: - uses: actions/checkout@v2 - - name: Install Maven 3.8.x (instead of 3.9.x) - run: | - MAVEN_VERSION=3.8.9 - wget https://downloads.apache.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz - tar xzvf apache-maven-$MAVEN_VERSION-bin.tar.gz - sudo mv apache-maven-$MAVEN_VERSION /opt/maven - sudo rm -f /usr/bin/mvn # Remove existing symbolic link if it exists - sudo ln -s /opt/maven/bin/mvn /usr/bin/mvn # Create new symbolic link - +# - name: Install Maven 3.8.x (instead of 3.9.x) +# run: | +# MAVEN_VERSION=3.8.9 +# wget https://downloads.apache.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz +# tar xzvf apache-maven-$MAVEN_VERSION-bin.tar.gz +# sudo mv apache-maven-$MAVEN_VERSION /opt/maven +# sudo rm -f /usr/bin/mvn # Remove existing symbolic link if it exists +# sudo ln -s /opt/maven/bin/mvn /usr/bin/mvn # Create new symbolic link + +# - name: Setup java +# uses: actions/setup-java@v1 +# with: +# java-version: ${{ matrix.java }} - name: Setup java - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: java-version: ${{ matrix.java }} + distribution: 'zulu' + cache: 'maven' - name: Cache Maven packages uses: actions/cache@v4 @@ -45,4 +51,4 @@ jobs: node-version: 14.x - name: Run the Maven verify phase - run: mvn verify -Dgpg.skip=true + run: mvn verify -Dgpg.skip=true --no-transfer-progress diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..0097e79a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,49 @@ +name: Publish to Maven Central + +on: + release: + types: [created] + workflow_dispatch: + inputs: + version: + description: 'Version to publish' + required: false + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 8 + uses: actions/setup-java@v4 + with: + java-version: '8' + distribution: 'zulu' + cache: 'maven' + server-id: central + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.SIGNING_KEY }} + gpg-passphrase: SIGNING_PASSWORD + + - name: Set version (if provided) + if: github.event.inputs.version != '' + run: | + mvn versions:set -DnewVersion=${{ github.event.inputs.version }} -DgenerateBackupPoms=false + + - name: Build and publish + env: + MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + run: | + mvn clean deploy \ + --no-transfer-progress \ + --batch-mode \ +# -DskipTests \ +# -Dgpg.keyname=${{ secrets.SIGNING_KEY_ID }} \ +# -Dgpg.passphrase=${{ secrets.SIGNING_PASSWORD }} \ +# -Dgpg.pinentry-mode=loopback \ \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3d8fb065..3527a89d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,18 +1,21 @@ - + 4.0.0 - io.socket + io.github.robinpcrd socket.io-client - 2.2.0-SNAPSHOT + 2.2.0 jar socket.io-client - Socket.IO Client Library for Java - https://github.com/socketio/socket.io-client-java + Socket.IO Client Library for Java (Fork) + https://github.com/RobinPcrd/socket.io-client-java + github @@ -27,9 +30,9 @@ - https://github.com/socketio/socket.io-client-java - scm:git:https://github.com/socketio/socket.io-client-java.git - scm:git:https://github.com/socketio/socket.io-client-java.git + https://github.com/RobinPcrd/socket.io-client-java + scm:git:https://github.com/RobinPcrd/socket.io-client-java.git + scm:git:https://github.com/RobinPcrd/socket.io-client-java.git HEAD @@ -39,8 +42,14 @@ Naoyuki Kanezawa naoyuki.kanezawa@gmail.com + + robinpcrd + Robin Picard + robin.picard.dev@gmail.com + + - 3.0.4 + 3.6.3 @@ -89,16 +99,18 @@ + @@ -129,6 +141,12 @@ + + + --pinentry-mode + loopback + + org.apache.maven.plugins @@ -167,17 +185,19 @@ deploy + org.codehaus.mojo exec-maven-plugin @@ -247,6 +267,17 @@ true + + org.sonatype.central + central-publishing-maven-plugin + 0.6.0 + true + + central + true + uploaded + + diff --git a/src/test/java/io/socket/client/Connection.java b/src/test/java/io/socket/client/Connection.java index 7d7fd4ca..f270a31b 100644 --- a/src/test/java/io/socket/client/Connection.java +++ b/src/test/java/io/socket/client/Connection.java @@ -18,61 +18,88 @@ public abstract class Connection { final static int TIMEOUT = 7_000; final static int PORT = 3000; + final static int NO_RECOVERY_PORT = 3001; private Process serverProcess; + private Process noRecoveryServerProcess; private ExecutorService serverService; - private Future serverOutput; - private Future serverError; + private Future serverOutput; + private Future serverError; + private Future noRecoveryServerOutput; + private Future noRecoveryServerError; @Before public void startServer() throws IOException, InterruptedException { - logger.fine("Starting server ..."); + logger.fine("Starting servers..."); + // Start main server final CountDownLatch latch = new CountDownLatch(1); - serverProcess = Runtime.getRuntime().exec( - String.format("node src/test/resources/server.js %s", nsp()), createEnv()); + serverProcess = startServerProcess("node src/test/resources/server.js %s", PORT); serverService = Executors.newCachedThreadPool(); - serverOutput = serverService.submit(new Runnable() { - @Override - public void run() { - BufferedReader reader = new BufferedReader( - new InputStreamReader(serverProcess.getInputStream())); - String line; - try { - line = reader.readLine(); - latch.countDown(); - do { - logger.fine("SERVER OUT: " + line); - } while ((line = reader.readLine()) != null); - } catch (IOException e) { - logger.warning(e.getMessage()); - } + serverOutput = startServerOutput(serverProcess, "MAIN", latch); + serverError = startServerError(serverProcess, "MAIN"); + + // Start no-recovery server + final CountDownLatch noRecoveryLatch = new CountDownLatch(1); + noRecoveryServerProcess = startServerProcess("node src/test/resources/server_no_recovery.js %s", NO_RECOVERY_PORT); + noRecoveryServerOutput = startServerOutput(noRecoveryServerProcess, "NO_RECOVERY", noRecoveryLatch); + noRecoveryServerError = startServerError(noRecoveryServerProcess, "NO_RECOVERY"); + + // Wait for both servers to start + latch.await(3000, TimeUnit.MILLISECONDS); + noRecoveryLatch.await(3000, TimeUnit.MILLISECONDS); + } + + private Process startServerProcess(String script, int port) throws IOException { + return Runtime.getRuntime().exec(String.format(script, nsp()), createEnv(port)); + } + + private Future startServerOutput(Process process, String serverName, CountDownLatch latch) { + return serverService.submit(() -> { + BufferedReader reader = new BufferedReader( + new InputStreamReader(process.getInputStream())); + String line; + try { + line = reader.readLine(); + latch.countDown(); + do { + logger.fine(serverName + " SERVER OUT: " + line); + } while ((line = reader.readLine()) != null); + } catch (IOException e) { + logger.warning(e.getMessage()); } }); - serverError = serverService.submit(new Runnable() { - @Override - public void run() { - BufferedReader reader = new BufferedReader( - new InputStreamReader(serverProcess.getErrorStream())); - String line; - try { - while ((line = reader.readLine()) != null) { - logger.fine("SERVER ERR: " + line); - } - } catch (IOException e) { - logger.warning(e.getMessage()); + } + + private Future startServerError(Process process, String serverName) { + return serverService.submit(() -> { + BufferedReader reader = new BufferedReader( + new InputStreamReader(process.getErrorStream())); + String line; + try { + while ((line = reader.readLine()) != null) { + logger.fine(serverName + " SERVER ERR: " + line); } + } catch (IOException e) { + logger.warning(e.getMessage()); } }); - latch.await(3000, TimeUnit.MILLISECONDS); } @After public void stopServer() throws InterruptedException { - logger.fine("Stopping server ..."); + logger.fine("Stopping servers..."); + + // Stop main server serverProcess.destroy(); serverOutput.cancel(false); serverError.cancel(false); + + // Stop no-recovery server + noRecoveryServerProcess.destroy(); + noRecoveryServerOutput.cancel(false); + noRecoveryServerError.cancel(false); + serverService.shutdown(); serverService.awaitTermination(3000, TimeUnit.MILLISECONDS); } @@ -90,11 +117,16 @@ Socket client(IO.Options opts) { } Socket client(String path, IO.Options opts) { - return IO.socket(URI.create(uri() + path), opts); + int port = opts.port != -1 ? opts.port : PORT; + return IO.socket(URI.create(uri(port) + path), opts); } URI uri() { - return URI.create("http://localhost:" + PORT); + return uri(PORT); + } + + URI uri(int port) { + return URI.create("http://localhost:" + port); } String nsp() { @@ -108,9 +140,13 @@ IO.Options createOptions() { } String[] createEnv() { + return createEnv(PORT); + } + + String[] createEnv(int port) { Map env = new HashMap<>(System.getenv()); env.put("DEBUG", "socket.io:*"); - env.put("PORT", String.valueOf(PORT)); + env.put("PORT", String.valueOf(port)); String[] _env = new String[env.size()]; int i = 0; for (String key : env.keySet()) { @@ -118,6 +154,5 @@ String[] createEnv() { i++; } return _env; - } } diff --git a/src/test/java/io/socket/client/SocketTest.java b/src/test/java/io/socket/client/SocketTest.java index 210e5f81..88bd141f 100644 --- a/src/test/java/io/socket/client/SocketTest.java +++ b/src/test/java/io/socket/client/SocketTest.java @@ -117,12 +117,7 @@ public void shouldChangeSocketIdUponReconnection() throws InterruptedException { IO.Options opts = createOptions(); opts.forceNew = true; - try { - JSONObject auth = new JSONObject(); - auth.put("noRecovery", true); - opts.auth = auth; - } catch (JSONException ignored) { - } + opts.port = Connection.NO_RECOVERY_PORT; socket = client(opts); socket.once(Socket.EVENT_CONNECT, new Emitter.Listener() { diff --git a/src/test/java/io/socket/client/executions/ConnectionFailure.java b/src/test/java/io/socket/client/executions/ConnectionFailure.java index a4feb267..e818c3cf 100644 --- a/src/test/java/io/socket/client/executions/ConnectionFailure.java +++ b/src/test/java/io/socket/client/executions/ConnectionFailure.java @@ -10,8 +10,7 @@ public class ConnectionFailure { public static void main(String[] args) throws URISyntaxException { - int port = Integer.parseInt(System.getenv("PORT")); - port++; + int port = 60_000; IO.Options options = new IO.Options(); options.forceNew = true; options.reconnection = false; diff --git a/src/test/resources/server.js b/src/test/resources/server.js index 333c5dfd..cfad86fb 100644 --- a/src/test/resources/server.js +++ b/src/test/resources/server.js @@ -22,14 +22,6 @@ var port = process.env.PORT || 3000; var nsp = process.argv[2] || '/'; var slice = Array.prototype.slice; -// Disable recovery on demand -io.use((socket, next) => { - if (socket.handshake.auth?.noRecovery === true) { - socket.handshake.auth._pid = 'invalid-' + Date.now(); - } - next(); -}); - const fooNsp = io.of('/foo'); fooNsp.on('connection', (socket) => { diff --git a/src/test/resources/server_no_recovery.js b/src/test/resources/server_no_recovery.js new file mode 100644 index 00000000..4262eeb8 --- /dev/null +++ b/src/test/resources/server_no_recovery.js @@ -0,0 +1,31 @@ +var fs = require('fs'); + +var server; +if (process.env.SSL) { + server = require('https').createServer({ + key: fs.readFileSync(__dirname + '/key.pem'), + cert: fs.readFileSync(__dirname + '/cert.pem') + }); +} else { + server = require('http').createServer(); +} + +// Create server without connection state recovery +var io = require('socket.io')(server, { + pingInterval: 2000 +}); + +var port = process.env.PORT || 3001; // Different port to avoid conflicts +var nsp = process.argv[2] || '/'; + +server.listen(port, () => { + console.log(`Test server without recovery running on port ${port}`); +}); + +io.of(nsp).on('connection', (socket) => { + console.log(`New connection: ${socket.id}`); + + socket.on('disconnect', () => { + console.log(`Client disconnected: ${socket.id}`); + }); +}); \ No newline at end of file