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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
### Fixed
- Issue [#319](https://github.com/reportportal/client-java/issues/319): RP client threw exception on Launch finish if the Launch wasn't started, by @HardNorth

## [5.4.12]
### Added
Expand Down
57 changes: 26 additions & 31 deletions src/main/java/com/epam/reportportal/service/LaunchImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,56 +357,45 @@ public TemplateConfiguration getTemplateConfiguration() {
return templateConfiguration;
}

private void truncateName(@Nonnull final StartRQ rq, int limit) {
if (rq.getName() == null || rq.getName().isEmpty()) {
return;
@Nullable
private String sanitizeField(@Nullable final String field, int limit) {
if (field == null || field.isEmpty()) {
return field;
}

String name = rq.getName();
ListenerParameters params = getParameters();
String myField = field;
if (params.isReplaceBinaryCharacters()) {
name = cleanBinaryCharacters(name);
rq.setName(name);
myField = cleanBinaryCharacters(field);
if (myField == null || myField.isEmpty()) {
return field;
}
}

if (!params.isTruncateFields()) {
return;
return myField;
}
rq.setName(truncateString(name, limit, params.getTruncateReplacement()));
return truncateString(myField, limit, params.getTruncateReplacement());
}

@Nullable
private String truncateDescription(@Nullable String description, int maxLength) {
if (description == null || description.isEmpty()) {
return description;
}

ListenerParameters params = getParameters();
String myDescription = description;
if (params.isReplaceBinaryCharacters()) {
myDescription = cleanBinaryCharacters(myDescription);
}

if (!params.isTruncateFields()) {
return myDescription;
}
return truncateString(myDescription, maxLength, params.getTruncateReplacement());
private void truncateName(@Nonnull final StartRQ rq, int limit) {
rq.setName(sanitizeField(rq.getName(), limit));
}

private void truncateDescription(@Nonnull StartLaunchRQ rq) {
rq.setDescription(truncateDescription(rq.getDescription(), MAX_LAUNCH_DESCRIPTION_LENGTH));
rq.setDescription(sanitizeField(rq.getDescription(), MAX_LAUNCH_DESCRIPTION_LENGTH));
}

private void truncateDescription(@Nonnull StartTestItemRQ rq) {
rq.setDescription(truncateDescription(rq.getDescription(), MAX_DESCRIPTION_LENGTH));
rq.setDescription(sanitizeField(rq.getDescription(), MAX_DESCRIPTION_LENGTH));
}

private void truncateDescription(@Nonnull FinishExecutionRQ rq) {
rq.setDescription(truncateDescription(rq.getDescription(), MAX_LAUNCH_DESCRIPTION_LENGTH));
rq.setDescription(sanitizeField(rq.getDescription(), MAX_LAUNCH_DESCRIPTION_LENGTH));
}

private void truncateDescription(@Nonnull FinishTestItemRQ rq) {
rq.setDescription(truncateDescription(rq.getDescription(), MAX_DESCRIPTION_LENGTH));
rq.setDescription(sanitizeField(rq.getDescription(), MAX_DESCRIPTION_LENGTH));
}

private void applyNameFormat(@Nonnull StartTestItemRQ rq) {
Expand Down Expand Up @@ -646,10 +635,16 @@ protected void completeLogEmitter() {
if (logEmitter.hasComplete()) {
return;
}
// To ensure we sent all logs post one message (for the case when there were no logs at all) and wait for it to be sent
// Use blocking get, since we are at the end of the flow and Maybe.map(..) will be stopped by system exit
String launchUUID = getLaunch().blockingGet();
String launchUUID;
try {
// Use blocking get, since we are at the end of the flow and Maybe.map(..) will be stopped by system exit
launchUUID = getLaunch().blockingGet();
} catch (Throwable e) {
LOGGER.error("Unable to finish the Launch", e);
return; // Nothing to finish, we are unable to even start the Launch
}
int logBatchesSent = loggingSubscriber.getProcessedCount();
// To ensure we sent all logs post one message (for the case when there were no logs at all) and wait for it to be sent
emitLog(StaticStructuresUtils.getLastLogRQ(launchUUID));
logEmitter.onComplete();
Waiter waiter = new Waiter("Wait for last log batch sent").duration(getParameters().getReportingTimeout(), TimeUnit.SECONDS)
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/com/epam/reportportal/service/LaunchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

import static com.epam.reportportal.test.TestUtils.*;
import static com.epam.reportportal.util.test.CommonUtils.shutdownExecutorService;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.endsWith;
Expand Down Expand Up @@ -663,6 +664,16 @@ public void launch_should_not_throw_exceptions_or_hang_if_finished_and_started_a
verify(rpClient, times(1)).finishTestItem(same(id.blockingGet()), any());
}

@Test
public void launch_should_not_throw_exception_if_launch_start_failed_on_finish() {
when(rpClient.startLaunch(any(StartLaunchRQ.class))).thenReturn(Maybe.error(new IllegalStateException("Unable to start launch")));
Launch launch = createLaunch();
launch.start();

assertDoesNotThrow(() -> launch.finish(standardLaunchFinishRequest()));
verify(rpClient, never()).log(anyList());
}

@Test
public void test_noop_launch_not_null() {
assertThat(Launch.NOOP_LAUNCH, notNullValue());
Expand Down
Loading