Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ jobs:
runs-on: ubuntu-latest
env:
BUILD_TYPE: "PR"
nats_server_path: nats-server/main
steps:
- run: echo -e "PR Branch ${{ github.head_ref }}"
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Setup GO
uses: actions/setup-go@v2
- name: Check out repository code
uses: actions/checkout@v2
- name: Install Nats Server
run: chmod +x install-nats-server.sh && ./install-nats-server.sh
- name: Build and Test
run: chmod +x gradlew && ./gradlew test
- name: Check Docs
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/push_or_merge_to_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
BUILD_TYPE: "MERGE"
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
nats_server_path: nats-server/main
steps:
- run: echo -e "PUSH/MERGE to main"
- name: Set up JDK 8
Expand All @@ -20,6 +21,12 @@ jobs:
distribution: 'adopt'
- name: Check out repository code
uses: actions/checkout@v2
- name: Setup GO
uses: actions/setup-go@v2
- name: Check out repository code
uses: actions/checkout@v2
- name: Install Nats Server
run: chmod +x install-nats-server.sh && ./install-nats-server.sh
- name: Build and Test
run: chmod +x gradlew && ./gradlew clean test
- name: Publish
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ jobs:
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
nats_server_path: nats-server/main
steps:
- run: echo -e "RELEASE"
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Setup GO
uses: actions/setup-go@v2
- name: Check out repository code
uses: actions/checkout@v2
- name: Install Nats Server
run: chmod +x install-nats-server.sh && ./install-nats-server.sh
- name: Build and Test
run: chmod +x gradlew && ./gradlew clean test
- name: Publish
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id 'signing'
}

def jarVersion = "1.0.3"
def jarVersion = "1.0.4 "
group = 'io.nats'

def isPr = System.getenv("BUILD_TYPE") == "PR"
Expand Down
5 changes: 5 additions & 0 deletions install-nats-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
git clone https://github.com/nats-io/nats-server.git
cd nats-server
go build main.go
cd ..
nats-server/main -v%
18 changes: 9 additions & 9 deletions src/main/java/nats/io/NatsServerRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class NatsServerRunner implements AutoCloseable {

private static final Logger LOGGER = Logger.getLogger(NatsServerRunner.class.getName());

private final int port;
private final int _port;

private Process process;
private final String cmdLine;
Expand Down Expand Up @@ -232,7 +232,7 @@ public NatsServerRunner(String[] customArgs, int port, boolean debug) throws IOE
* @throws IOException thrown when the server cannot start
*/
public NatsServerRunner(int port, boolean debug, boolean jetstream, String configFilePath, String[] configInserts, String[] customArgs) throws IOException {
this.port = port <= 0 ? nextPort() : port;
_port = port <= 0 ? nextPort() : port;

List<String> cmd = new ArrayList<>();

Expand Down Expand Up @@ -260,9 +260,9 @@ public NatsServerRunner(int port, boolean debug, boolean jetstream, String confi
portMatcher.reset(line);

if (portMatcher.find()) {
line = line.replace(portMatcher.group(1), String.valueOf(port));
line = line.replace(portMatcher.group(1), String.valueOf(_port));
cmd.add("--port");
cmd.add(String.valueOf(port));
cmd.add(String.valueOf(_port));
}

writer.write(line);
Expand Down Expand Up @@ -292,7 +292,7 @@ public NatsServerRunner(int port, boolean debug, boolean jetstream, String confi
}
} else {
cmd.add("--port");
cmd.add(String.valueOf(port));
cmd.add(String.valueOf(_port));
}

if (jetstream) {
Expand All @@ -318,7 +318,7 @@ public NatsServerRunner(int port, boolean debug, boolean jetstream, String confi

process = pb.start();

NatsOutputLogger.logOutput(LOGGER, process, NATS_SERVER, port);
NatsOutputLogger.logOutput(LOGGER, process, NATS_SERVER, _port);

int tries = 10;
// wait at least 1x and maybe 10
Expand All @@ -331,7 +331,7 @@ public NatsServerRunner(int port, boolean debug, boolean jetstream, String confi
tries--;
} while (!process.isAlive() && tries > 0);

SocketAddress addr = new InetSocketAddress("localhost", port);
SocketAddress addr = new InetSocketAddress("localhost", _port);
SocketChannel socketChannel = SocketChannel.open();
socketChannel.configureBlocking(true);
boolean scanning = true;
Expand Down Expand Up @@ -361,7 +361,7 @@ public NatsServerRunner(int port, boolean debug, boolean jetstream, String confi
* @return the port number
*/
public int getPort() {
return port;
return _port;
}

/**
Expand All @@ -370,7 +370,7 @@ public int getPort() {
* @return the uri string
*/
public String getURI() {
return getURIForPort(port);
return getURIForPort(_port);
}

/**
Expand Down
12 changes: 10 additions & 2 deletions src/test/java/nats/io/NatsServerRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
package nats.io;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertTrue;

class NatsServerRunnerTest {

@Test
void testSomeLibraryMethod() {
public void testConnection() throws IOException, InterruptedException {
try (NatsServerRunner ts = new NatsServerRunner(false)) {
assertTrue(ts.getPort() > 0);
assertTrue(ts.getURI().startsWith("nats://localhost"));
}
}
}