Skip to content

Commit 23b6fde

Browse files
committed
1.2.5 update cluster creation utils for JS support
1 parent 8ab017d commit 23b6fde

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

src/main/java/nats/io/ClusterInsert.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,13 @@ public ClusterInsert(ClusterNode node, String[] configInserts) {
2121
this.node = node;
2222
this.configInserts = configInserts == null || configInserts.length == 0 ? null : configInserts;
2323
}
24+
25+
@Override
26+
public String toString() {
27+
StringBuilder sb = new StringBuilder();
28+
for (String s : configInserts) {
29+
sb.append(s).append("\r\n");
30+
}
31+
return sb.toString();
32+
}
2433
}

src/main/java/nats/io/NatsRunnerUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public abstract class NatsRunnerUtils {
3939
public static final String DEFAULT_CLUSTER_NAME = "cluster";
4040
public static final String DEFAULT_SERVER_NAME_PREFIX = "server";
4141

42+
public static String DEFAULT_HOST = "127.0.0.1";
43+
public static int DEFAULT_PORT_START = 4220;
44+
public static int DEFAULT_LISTEN_START = 4230;
45+
public static int DEFAULT_MONITOR_START = 4280;
46+
4247
private NatsRunnerUtils() {}
4348

4449
/**
@@ -207,11 +212,6 @@ public static List<ClusterInsert> createClusterInserts(int count, String cluster
207212
return createClusterInserts(createNodes(count, clusterName, serverNamePrefix, monitor, jsStoreDirBase));
208213
}
209214

210-
public static String DEFAULT_HOST = "127.0.0.1";
211-
public static int DEFAULT_PORT_START = 4220;
212-
public static int DEFAULT_LISTEN_START = 4230;
213-
public static int DEFAULT_MONITOR_START = 4280;
214-
215215
public static void defaultHost(String defaultHost) {
216216
DEFAULT_HOST = defaultHost;
217217
}

src/test/java/nats/io/NatsClusterTest.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
// limitations under the License.
1313
package nats.io;
1414

15-
import nl.jqno.equalsverifier.EqualsVerifier;
1615
import org.junit.jupiter.api.Test;
1716

18-
import java.util.ArrayList;
1917
import java.util.Collections;
2018
import java.util.List;
2119

22-
import static nats.io.NatsRunnerUtils.DEFAULT_CLUSTER_NAME;
23-
import static nats.io.NatsRunnerUtils.createClusterInserts;
20+
import static nats.io.NatsRunnerUtils.*;
2421
import static org.junit.jupiter.api.Assertions.assertTrue;
2522

2623
public class NatsClusterTest extends TestBase {
@@ -29,24 +26,17 @@ public class NatsClusterTest extends TestBase {
2926
public void testCreateCluster() throws Exception {
3027
_testCreateCluster(createClusterInserts());
3128
_testCreateCluster(createClusterInserts(3));
32-
List<ClusterInsert> clusterInserts = createClusterInserts(3);
29+
}
3330

34-
List<ClusterNode> nodes = new ArrayList<>();
31+
private void _testCreateCluster(List<ClusterInsert> clusterInserts) throws Exception {
3532
for (ClusterInsert ci : clusterInserts) {
36-
nodes.add(new ClusterNode(ci.node.clusterName, ci.node.serverName, ci.node.port, ci.node.listen));
33+
String s = ci.toString();
34+
assertTrue(s.contains("port:" + ci.node.port));
35+
assertTrue(s.contains("server_name=" + DEFAULT_SERVER_NAME_PREFIX));
36+
assertTrue(s.contains("listen: " + DEFAULT_HOST + ":" + ci.node.listen));
37+
assertTrue(s.contains("name: " + DEFAULT_CLUSTER_NAME));
3738
}
38-
_testCreateCluster(NatsRunnerUtils.createClusterInserts(nodes));
39-
40-
EqualsVerifier.simple().forClass(ClusterInsert.class).verify();
4139

42-
ClusterInsert ci = clusterInserts.get(0);
43-
String s = ci.toString();
44-
assertTrue(s.contains("port:" + ci.node.port));
45-
assertTrue(s.contains("listen:" + ci.node.host + ":" + ci.node.listen));
46-
assertTrue(s.contains("name: " + DEFAULT_CLUSTER_NAME));
47-
}
48-
49-
private void _testCreateCluster(List<ClusterInsert> clusterInserts) throws Exception {
5040
ClusterInsert ci0 = clusterInserts.get(0);
5141
ClusterInsert ci1 = clusterInserts.get(1);
5242
ClusterInsert ci2 = clusterInserts.get(2);

0 commit comments

Comments
 (0)