Skip to content

Commit 084dac6

Browse files
authored
Merge pull request #1 from appulse-projects/develop
Add server sub-project
2 parents 18da879 + 8e50631 commit 084dac6

File tree

54 files changed

+2674
-63
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2674
-63
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,3 @@ nb-configuration.xml
112112
log*.txt*
113113
.DS_Store
114114
.vscode/
115-
116-
# Secure incomplete sub-projects
117-
server/

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ deploy:
3737
- "client/target/client-$project_version.jar"
3838
- "client/target/client-$project_version-javadoc.jar"
3939
- "client/target/client-$project_version-sources.jar"
40+
- "server/target/server-$project_version.jar"
41+
- "server/target/server-$project_version-javadoc.jar"
42+
- "server/target/server-$project_version-sources.jar"
4043
skip_cleanup: true
4144
on:
4245
tags: true

CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,25 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
## [Unreleased]
1111

12-
- Add EPMD server.
1312
- Add more unit and integration tests.
1413

14+
## [0.3.0](https://github.com/appulse-projects/epmd-java/releases/tag/0.3.0) - 2018-01-31
15+
16+
### Added
17+
18+
- EPMD server sub-project.
19+
- Server test.
20+
21+
### Changed
22+
23+
- [Core]: registration result returns creation 0 in case of failure.
24+
- [Client]: set connection read timeout (connection_timeout * 2).
25+
1526
## [0.2.2](https://github.com/appulse-projects/epmd-java/releases/tag/0.2.2) - 2018-01-29
1627

1728
### Added
1829

19-
- Add EPMD client.
30+
- EPMD client sub-project.
2031
- Serialization/Deserialization exceptions in `Core`.
2132

2233
### Changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Overview
22

33
[![build_status](https://travis-ci.org/appulse-projects/epmd-java.svg?branch=master)](https://travis-ci.org/appulse-projects/epmd-java)
4-
[![maven_central](https://maven-badges.herokuapp.com/maven-central/io.appulse.epmd.java/core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.appulse.epmd.java/core)
4+
[![maven_central](https://maven-badges.herokuapp.com/maven-central/io.appulse/epmd-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.appulse/epmd-java)
55

66
This is the set of projects, which implementing EPMD server and client.
77

88
- [Core description](./core/README.md)
99
- [Client description](./client/README.md)
10+
- [Server description](./server/README.md)
1011

1112
## Development
1213

client/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Include the dependency to your project's pom.xml file:
1414
<dependency>
1515
<groupId>io.appulse.epmd.java</groupId>
1616
<artifactId>client</artifactId>
17-
<version>0.2.2</version>
17+
<version>0.3.0</version>
1818
</dependency>
1919
...
2020
</dependencies>
@@ -23,7 +23,7 @@ Include the dependency to your project's pom.xml file:
2323
or Gradle:
2424

2525
```groovy
26-
compile 'io.appulse.epmd.java:client:0.2.2'
26+
compile 'io.appulse.epmd.java:client:0.3.0'
2727
```
2828

2929
### Create client

client/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ limitations under the License.
2525
<parent>
2626
<groupId>io.appulse</groupId>
2727
<artifactId>epmd-java</artifactId>
28-
<version>0.2.2</version>
28+
<version>0.3.0</version>
2929
</parent>
3030

3131
<groupId>io.appulse.epmd.java</groupId>
@@ -43,7 +43,7 @@ limitations under the License.
4343
<dependency>
4444
<groupId>org.testcontainers</groupId>
4545
<artifactId>testcontainers</artifactId>
46-
<version>1.5.1</version>
46+
<version>1.6.0</version>
4747
<scope>test</scope>
4848
</dependency>
4949
</dependencies>

client/src/main/java/io/appulse/epmd/java/client/Connection.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static java.util.concurrent.TimeUnit.SECONDS;
2020
import static lombok.AccessLevel.PRIVATE;
2121

22-
import java.io.ByteArrayOutputStream;
2322
import java.io.Closeable;
2423
import java.io.IOException;
2524
import java.net.InetAddress;
@@ -30,6 +29,7 @@
3029
import io.appulse.epmd.java.core.mapper.deserializer.MessageDeserializer;
3130
import io.appulse.epmd.java.core.mapper.serializer.MessageSerializer;
3231
import io.appulse.epmd.java.core.model.response.RegistrationResult;
32+
import io.appulse.utils.SocketUtils;
3333

3434
import lombok.NonNull;
3535
import lombok.RequiredArgsConstructor;
@@ -50,12 +50,15 @@ class Connection implements Closeable {
5050

5151
private static final int CONNECT_TIMEOUT;
5252

53+
private static final int READ_TIMEOUT;
54+
5355
private static final MessageSerializer SERIALIZER;
5456

5557
private static final MessageDeserializer DESERIALIZER;
5658

5759
static {
5860
CONNECT_TIMEOUT = (int) SECONDS.toMillis(5);
61+
READ_TIMEOUT = CONNECT_TIMEOUT * 2;
5962
SERIALIZER = new MessageSerializer();
6063
DESERIALIZER = new MessageDeserializer();
6164
}
@@ -89,8 +92,10 @@ public <T> T send (@NonNull Object request, @NonNull Class<T> responseType) thro
8992

9093
byte[] messageBytes;
9194
try {
92-
messageBytes = read(responseType);
93-
} catch (IOException ex) {
95+
messageBytes = responseType == RegistrationResult.class
96+
? SocketUtils.read(socket, 4)
97+
: SocketUtils.read(socket);
98+
} catch (Exception ex) {
9499
throw new EpmdConnectionException(ex);
95100
}
96101

@@ -129,6 +134,7 @@ private void connect () {
129134
try {
130135
socket.setTcpNoDelay(true);
131136
socket.connect(socketAddress, CONNECT_TIMEOUT);
137+
socket.setSoTimeout(READ_TIMEOUT);
132138
} catch (IOException ex) {
133139
val message = String.format("Couldn't connect to EPMD server (%s:%d), maybe it is down",
134140
address.toString(), port);
@@ -138,22 +144,4 @@ private void connect () {
138144

139145
log.debug("EPMD connection to {}:{} was established", address, port);
140146
}
141-
142-
private byte[] read (Class<?> responseType) throws IOException {
143-
val outputStream = new ByteArrayOutputStream(32);
144-
val buffer = new byte[32];
145-
146-
while (true) {
147-
val length = socket.getInputStream().read(buffer);
148-
if (length == -1) {
149-
break;
150-
}
151-
outputStream.write(buffer, 0, length);
152-
if (responseType == RegistrationResult.class) {
153-
break;
154-
}
155-
}
156-
157-
return outputStream.toByteArray();
158-
}
159147
}

client/src/main/java/io/appulse/epmd/java/client/EpmdClient.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.appulse.epmd.java.core.model.request.GetEpmdDump;
3131
import io.appulse.epmd.java.core.model.request.Kill;
3232
import io.appulse.epmd.java.core.model.request.Registration;
33+
import io.appulse.epmd.java.core.model.request.Stop;
3334
import io.appulse.epmd.java.core.model.response.EpmdDump;
3435
import io.appulse.epmd.java.core.model.response.KillResult;
3536
import io.appulse.epmd.java.core.model.response.RegistrationResult;
@@ -84,6 +85,7 @@ public EpmdClient (@NonNull InetAddress address, int port) {
8485
nodesLocatorService = new NodesLocatorService(address, port);
8586
this.address = address;
8687
this.port = port;
88+
log.debug("Instantiated EPMD client to '{}:{}'", address, port);
8789
}
8890

8991
public int register (String name, int nodePort, NodeType type, Protocol protocol, Version low, Version high) {
@@ -100,23 +102,23 @@ public int register (String name, int nodePort, NodeType type, Protocol protocol
100102
}
101103

102104
public int register (@NonNull Registration request) {
103-
log.debug("Registering: {}", request.getName());
105+
log.debug("Registering: '{}'", request.getName());
104106
val connection = getLocalConnection();
105107

106108
RegistrationResult response;
107109
try {
108110
response = connection.send(request, RegistrationResult.class);
109111
} catch (Exception ex) {
110-
log.error("{} wasn't registered successfully", request.getName());
112+
log.error("'{}' wasn't registered successfully", request.getName());
111113
throw new EpmdRegistrationException(ex);
112114
}
113115

114116
if (!response.isOk()) {
115-
log.error("{} wasn't registered successfully", request.getName());
117+
log.error("'{}' wasn't registered successfully", request.getName());
116118
throw new EpmdRegistrationException();
117119
}
118120

119-
log.info("{} was registered successfully", request.getName());
121+
log.info("'{}' was registered successfully", request.getName());
120122
return response.getCreation();
121123
}
122124

@@ -127,6 +129,12 @@ public List<EpmdDump.NodeDump> dumpAll () {
127129
}
128130
}
129131

132+
public void stop (@NonNull String node) {
133+
try (val connection = new Connection(address, port)) {
134+
connection.send(new Stop(node));
135+
}
136+
}
137+
130138
/**
131139
* This request kills the running EPMD server.
132140
*
@@ -194,7 +202,7 @@ private static int getDefaultPort () {
194202
} catch (NumberFormatException | SecurityException ex) {
195203
throw new RuntimeException(ex);
196204
}
197-
log.debug("Default EPMD port is: {}", port);
205+
log.debug("Default EPMD port is: '{}'", port);
198206
return port;
199207
}
200208
}

client/src/test/java/io/appulse/epmd/java/client/LocalEpmdClientTest.java

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import static lombok.AccessLevel.PRIVATE;
2424
import static org.assertj.core.api.Assertions.assertThat;
2525
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
26+
import static io.appulse.epmd.java.core.model.response.EpmdDump.NodeDump.Status.OLD_OR_UNUSED;
2627

2728
import io.appulse.epmd.java.client.exception.EpmdConnectionException;
29+
import io.appulse.epmd.java.client.exception.EpmdRegistrationException;
2830
import io.appulse.epmd.java.client.util.CheckLocalEpmdExists;
2931
import io.appulse.epmd.java.client.util.LocalEpmdHelper;
3032
import io.appulse.epmd.java.client.util.TestNamePrinter;
@@ -103,15 +105,20 @@ public void register () throws Exception {
103105
});
104106
}
105107

106-
// @Test
107-
public void connectionBroken () {
108-
LocalEpmdHelper.kill();
109-
110-
assertThat(LocalEpmdHelper.isRunning())
111-
.isFalse();
108+
@Test
109+
public void invalidRegistration () {
110+
try (EpmdClient client2 = new EpmdClient(8091)) {
111+
assertThatExceptionOfType(EpmdRegistrationException.class)
112+
.isThrownBy(() -> client2.register("popa", 8971, R3_ERLANG, TCP, R6, R6));
113+
}
114+
}
112115

113-
assertThatExceptionOfType(EpmdConnectionException.class)
114-
.isThrownBy(() -> client.lookup("popa"));
116+
@Test
117+
public void connectionBroken () {
118+
try (EpmdClient client2 = new EpmdClient(8091)) {
119+
assertThatExceptionOfType(EpmdConnectionException.class)
120+
.isThrownBy(() -> client2.lookup("popa"));
121+
}
115122
}
116123

117124
@Test
@@ -147,6 +154,26 @@ public void dumpAll () {
147154
});
148155
}
149156

157+
// @Test
158+
public void stop () {
159+
client.register("stopped", 19028, R3_ERLANG, TCP, R6, R6);
160+
161+
client.stop("stopped");
162+
163+
val nodes = client.dumpAll();
164+
assertThat(nodes)
165+
.isNotEmpty();
166+
167+
val node = nodes.stream()
168+
.filter(it -> "stopped".equals(it.getName()))
169+
.findFirst()
170+
.orElse(null);
171+
172+
assertThat(node)
173+
.isNotNull()
174+
.extracting("status").isEqualTo(OLD_OR_UNUSED);
175+
}
176+
150177
@Test
151178
public void kill () {
152179
assertThat(client.kill())

client/src/test/java/io/appulse/epmd/java/client/util/LocalEpmdHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static void run () {
5555
kill();
5656
}
5757

58-
val builder = new ProcessBuilder("epmd", "-daemon");
58+
val builder = new ProcessBuilder("epmd", "-daemon", "-relaxed_command_check");
5959
val process = builder.start();
6060
if (!process.waitFor(1, MINUTES)) {
6161
process.destroy();

0 commit comments

Comments
 (0)