Skip to content

Commit

Permalink
Merge pull request #11 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth authored Jan 15, 2025
2 parents c0549b5 + bb60937 commit e8b8e32
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
java-version: '8'

- name: Setup git credentials
uses: oleksiyrudenko/gha-git-credentials@v2.1.1
uses: oleksiyrudenko/gha-git-credentials@v2-latest
with:
name: 'reportportal.io'
email: '[email protected]'
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
### Fixed
- Handle of client exceptions in `SocketUtils.executeServerCallable` method, by @HardNorth
### Changed
- Dependencies updated to latest versions, by @HardNorth

## [0.0.6]
### Removed
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ java {
compileTestJava.options.encoding = "UTF-8"

dependencies {
compileOnly 'io.reactivex.rxjava2:rxjava:2.2.10'
compileOnly 'io.reactivex.rxjava2:rxjava:2.2.21'
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
compileOnly 'org.apache.commons:commons-lang3:3.11'
compileOnly 'org.apache.commons:commons-io:1.3.2'
compileOnly 'org.apache.commons:commons-lang3:3.17.0'
compileOnly 'commons-io:commons-io:2.18.0'

implementation 'org.hamcrest:hamcrest-core:2.2'
implementation('org.awaitility:awaitility:4.0.2') {
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/com/epam/reportportal/util/test/SocketUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public List<String> call() throws Exception {
results.add(builder.toString());
String rs = ofNullable(getClass().getClassLoader().getResourceAsStream(responseFile)).flatMap(stream -> {
try {
String responseStr = IOUtils.toString(stream);
String responseStr = IOUtils.toString(stream, StandardCharsets.UTF_8);
for (String k : model.keySet()) {
responseStr = responseStr.replace("{" + k + "}", model.get(k).toString());
}
Expand All @@ -85,8 +85,7 @@ public List<String> call() throws Exception {
return empty();
}
}).orElseThrow(() -> new IOException("Unable to read file: " + responseFile));
IOUtils.write(rs, s.getOutputStream());

IOUtils.write(rs, s.getOutputStream(), StandardCharsets.UTF_8);
}
return results;
}
Expand All @@ -99,14 +98,22 @@ public static ServerSocket getServerSocketOnFreePort() throws IOException {

public static <T> Pair<List<String>, T> executeServerCallable(ServerCallable srvCall, Callable<T> clientCallable, long timeoutSeconds)
throws Exception {
ExecutorService clientExecutor = Executors.newSingleThreadExecutor();
ExecutorService serverExecutor = Executors.newSingleThreadExecutor();
Future<List<String>> future = serverExecutor.submit(srvCall);
T rs = clientCallable.call();
Future<List<String>> serverFuture = serverExecutor.submit(srvCall);
Future<T> clientFuture = clientExecutor.submit(clientCallable);

Pair<List<String>, T> result;
try {
return Pair.of(future.get(timeoutSeconds, TimeUnit.SECONDS), rs);
} finally {
result = Pair.of(serverFuture.get(timeoutSeconds, TimeUnit.SECONDS), clientFuture.get(timeoutSeconds, TimeUnit.SECONDS));
} catch (TimeoutException e) {
CommonUtils.shutdownExecutorService(clientExecutor);
CommonUtils.shutdownExecutorService(serverExecutor);
throw e;
}
CommonUtils.shutdownExecutorService(clientExecutor);
CommonUtils.shutdownExecutorService(serverExecutor);
return result;
}

public static <T> Pair<List<String>, T> executeServerCallable(ServerCallable srvCall, Callable<T> clientCallable) throws Exception {
Expand Down

0 comments on commit e8b8e32

Please sign in to comment.