From f910d598dc4a3ceba7abb932557cc5afff148a9a Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 14 Nov 2024 17:03:45 +0300 Subject: [PATCH 1/9] `rp.launch.uuid.creation.skip` configuration properties to control Launch start on provided UUID --- CHANGELOG.md | 2 + README.md | 9 +++ README_TEMPLATE.md | 58 +++++++++------ .../listeners/ListenerParameters.java | 74 +++++++++---------- .../epam/reportportal/service/LaunchImpl.java | 24 +++--- .../reportportal/service/ReportPortal.java | 45 ++++++----- .../utils/properties/ListenerProperty.java | 6 +- 7 files changed, 125 insertions(+), 93 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5a0193e..6a2f9e19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## [Unreleased] +### Added +- `rp.launch.uuid.creation.skip` configuration properties to control Launch start on provided UUID, by @HardNorth ## [5.2.20] ### Fixed diff --git a/README.md b/README.md index 8013076b..418d4e43 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,15 @@ etc. | rp.truncation.item.name.limit | Integer | Default: `1024`
Maximum item names length before truncation. | | rp.truncation.attribute.limit | Integer | Default: `128`
Maximum attribute key and value limit (counts separately) | +### Bug Tracking System parameters + +| **Property name** | **Type** | **Description** | +|-------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| rp.bts.project | String | Bug Tracking System Project name to use along with `@ExternalIssue` annotation. Should be the same as in corresponding integration. | +| rp.bts.url | String | Bug Tracking System base URL. Should be the same as in corresponding integration. | +| rp.bts.issue.url | String | Bug Tracking System URL Pattern for Issues. Use {issue_id} and {bts_project} placeholders to mark a place where to put Issue ID and Bug Tracking System Project name. | +| rp.bts.issue.fail | Boolean | Default: `true`
Fail tests marked with `@Issue` annotation if they passed. Designed to not miss the moment when the issue got fixed but test is still marked by annotation. | + ## Proxy configuration ReportPortal supports 2 options for setting Proxy configuration: diff --git a/README_TEMPLATE.md b/README_TEMPLATE.md index 96806176..d6f92efd 100644 --- a/README_TEMPLATE.md +++ b/README_TEMPLATE.md @@ -84,30 +84,31 @@ value will be used. ### Common parameters -| **Property name** | **Type** | **Description** | **Required** | -|-----------------------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------| -| rp.endpoint | String | URL of web service, where requests should be send | Yes | -| rp.api.key | String | Api token of user | Yes | -| rp.launch | String | A unique name of Launch (Run). Based on that name a history of runs will be created for particular name | Yes | -| rp.project | String | Project name to identify scope | Yes | -| rp.launch.uuid | String | A unique Launch UUID to which the whole test execution will be uploaded. No new launch will be created if the property specified. | No | -| rp.launch.uuid.print | Boolean | Enables printing Launch UUID on test run start. Default `False`. | No | -| rp.launch.uuid.print.output | Enum | Launch UUID print output. Default `stdout`. Possible values: `stderr`, `stdout`. | No | -| rp.enable | Boolean | Enable/Disable logging to ReportPortal: rp.enable=true - enable log to RP server. Any other value means 'false': rp.enable=false - disable log to RP server. If parameter is absent in properties file then automation project results will be posted on RP. | No | -| rp.description | String | Launch description | No | -| rp.attributes | String | Set of attributes for specifying additional meta information for current launch. Format: key:value;value;build:12345-6. Attributes should be separated by “;”, keys and values - “:”. | No | -| rp.reporting.async | Boolean | Enables asynchronous reporting. Available values - `true` (by default) or `false`. Supported only in 5+ version. | No | -| rp.reporting.callback | Boolean | Enables [callback reporting](https://github.com/reportportal/client-java/wiki/Callback-reporting-usefulness). Available values - `true` or `false`(by default). Supported only in 5+ vesion | No | -| rp.rerun | Boolean | Enables [rerun mode](https://github.com/reportportal/documentation/blob/master/src/md/src/DevGuides/rerun.md). Available values - `true` or `false`(by default). Supported only in 5+ version | No | -| rp.rerun.of | String | Specifies UUID of launch that has to be rerun. | No | -| rp.convertimage | Boolean | Colored log images can be converted to grayscale for reducing image size. Values: ‘true’ – will be converted. Any other value means ‘false’. | No | -| rp.mode | Enum | ReportPortal provides possibility to specify visibility of executing launch. Currently two modes are supported: DEFAULT - all users from project can see this launch; DEBUG - all users except of Customer role can see this launch (in debug sub tab). Note: for all java based clients (TestNG, Junit) mode will be set automatically to "DEFAULT" if it is not specified. | No | -| rp.skipped.issue | Boolean | ReportPortal provides feature to mark skipped tests as not 'To Investigate' items on WS side. Parameter could be equal boolean values:
  • `true` - skipped tests considered as issues and will be marked as 'To Investigate' on ReportPortal.
  • `false` - skipped tests will not be marked as 'To Investigate' on application. | No | -| rp.batch.size.logs | Integer | Put logs into batches of specified size in order to rise up performance and reduce number of requests to server. Default = 10 | No | -| rp.batch.payload.limit | Long | Limit batches by payload size to avoid request rejection due to server limitations. | No | -| rp.rx.buffer.size | Integer | Internal queue size for log processing, increase this value along with log batch size if you see not all your logs passing to server. Default = 128 | No | -| rp.keystore.resource | String | Put your JKS file into resources and specify path to it | No | -| rp.keystore.password | String | Access password for JKS (certificate storage) package, mentioned above
    | No | +| **Property name** | **Type** | **Description** | **Required** | +|-------------------------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------| +| rp.endpoint | String | URL of web service, where requests should be send | Yes | +| rp.api.key | String | Api token of user | Yes | +| rp.launch | String | A unique name of Launch (Run). Based on that name a history of runs will be created for particular name | Yes | +| rp.project | String | Project name to identify scope | Yes | +| rp.launch.uuid | String | A unique Launch UUID to which the whole test execution will be uploaded. | No | +| rp.launch.uuid.creation.skip | Boolean | Do not create new launch and report to predefined Launch provided by UUID above. Default `true`. | No | +| rp.launch.uuid.print | Boolean | Enables printing Launch UUID on test run start. Default `false`. | No | +| rp.launch.uuid.print.output | Enum | Launch UUID print output. Default `stdout`. Possible values: `stderr`, `stdout`. | No | +| rp.enable | Boolean | Enable/Disable logging to ReportPortal: rp.enable=true - enable log to RP server. Any other value means 'false': rp.enable=false - disable log to RP server. If parameter is absent in properties file then automation project results will be posted on RP. | No | +| rp.description | String | Launch description | No | +| rp.attributes | String | Set of attributes for specifying additional meta information for current launch. Format: key:value;value;build:12345-6. Attributes should be separated by “;”, keys and values - “:”. | No | +| rp.reporting.async | Boolean | Enables asynchronous reporting. Available values - `true` (by default) or `false`. Supported only in 5+ version. | No | +| rp.reporting.callback | Boolean | Enables [callback reporting](https://github.com/reportportal/client-java/wiki/Callback-reporting-usefulness). Available values - `true` or `false`(by default). Supported only in 5+ vesion | No | +| rp.rerun | Boolean | Enables [rerun mode](https://github.com/reportportal/documentation/blob/master/src/md/src/DevGuides/rerun.md). Available values - `true` or `false`(by default). Supported only in 5+ version | No | +| rp.rerun.of | String | Specifies UUID of launch that has to be rerun. | No | +| rp.convertimage | Boolean | Colored log images can be converted to grayscale for reducing image size. Values: ‘true’ – will be converted. Any other value means ‘false’. | No | +| rp.mode | Enum | ReportPortal provides possibility to specify visibility of executing launch. Currently two modes are supported: DEFAULT - all users from project can see this launch; DEBUG - all users except of Customer role can see this launch (in debug sub tab). Note: for all java based clients (TestNG, Junit) mode will be set automatically to "DEFAULT" if it is not specified. | No | +| rp.skipped.issue | Boolean | ReportPortal provides feature to mark skipped tests as not 'To Investigate' items on WS side. Parameter could be equal boolean values:
  • `true` - skipped tests considered as issues and will be marked as 'To Investigate' on ReportPortal.
  • `false` - skipped tests will not be marked as 'To Investigate' on application. | No | +| rp.batch.size.logs | Integer | Put logs into batches of specified size in order to rise up performance and reduce number of requests to server. Default = 10 | No | +| rp.batch.payload.limit | Long | Limit batches by payload size to avoid request rejection due to server limitations. | No | +| rp.rx.buffer.size | Integer | Internal queue size for log processing, increase this value along with log batch size if you see not all your logs passing to server. Default = 128 | No | +| rp.keystore.resource | String | Put your JKS file into resources and specify path to it | No | +| rp.keystore.password | String | Access password for JKS (certificate storage) package, mentioned above
    | No | Launch name sets once before first execution, because in common launch parts are fixed for a long time. By keeping the same launch name we will know a fixed list of suites behind it. That will allow us to have a history trend. On Report @@ -156,6 +157,15 @@ etc. | rp.truncation.item.name.limit | Integer | Default: `1024`
    Maximum item names length before truncation. | | rp.truncation.attribute.limit | Integer | Default: `128`
    Maximum attribute key and value limit (counts separately) | +### Bug Tracking System parameters + +| **Property name** | **Type** | **Description** | +|-------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| rp.bts.project | String | Bug Tracking System Project name to use along with `@ExternalIssue` annotation. Should be the same as in corresponding integration. | +| rp.bts.url | String | Bug Tracking System base URL. Should be the same as in corresponding integration. | +| rp.bts.issue.url | String | Bug Tracking System URL Pattern for Issues. Use {issue_id} and {bts_project} placeholders to mark a place where to put Issue ID and Bug Tracking System Project name. | +| rp.bts.issue.fail | Boolean | Default: `true`
    Fail tests marked with `@Issue` annotation if they passed. Designed to not miss the moment when the issue got fixed but test is still marked by annotation. | + ## Proxy configuration ReportPortal supports 2 options for setting Proxy configuration: diff --git a/src/main/java/com/epam/reportportal/listeners/ListenerParameters.java b/src/main/java/com/epam/reportportal/listeners/ListenerParameters.java index dedbdc1f..fb61be20 100644 --- a/src/main/java/com/epam/reportportal/listeners/ListenerParameters.java +++ b/src/main/java/com/epam/reportportal/listeners/ListenerParameters.java @@ -71,6 +71,7 @@ public class ListenerParameters implements Cloneable { // Due to shortcoming of payload calculation mechanism this value is set to 65 million of bytes rather than 65 megabytes public static final long DEFAULT_BATCH_PAYLOAD_LIMIT = 65 * 1000 * 1000; + public static final boolean DEFAULT_LAUNCH_CREATION_SKIP = true; public static final boolean DEFAULT_LAUNCH_UUID_PRINT = false; public static final String DEFAULT_LAUNCH_UUID_OUTPUT = "stdout"; @@ -122,6 +123,7 @@ public class ListenerParameters implements Cloneable { private String truncateReplacement; private int attributeLengthLimit; + private boolean isLaunchUuidCreationSkip; private boolean printLaunchUuid; private PrintStream printLaunchUuidOutput; @@ -155,10 +157,12 @@ private static ChronoUnit toChronoUnit(@Nonnull TimeUnit t) { @Nullable private static Duration getDurationProperty(@Nonnull PropertiesLoader properties, @Nonnull ListenerProperty value, @Nonnull ListenerProperty unit) { - return ofNullable(properties.getProperty(value)).map(Long::parseLong).map(t -> Duration.of(t, - ofNullable(properties.getProperty(unit)).map(u -> toChronoUnit(TimeUnit.valueOf(u))) - .orElse(ChronoUnit.MILLIS) - )).orElse(null); + return ofNullable(properties.getProperty(value)).map(Long::parseLong) + .map(t -> Duration.of( + t, + ofNullable(properties.getProperty(unit)).map(u -> toChronoUnit(TimeUnit.valueOf(u))).orElse(ChronoUnit.MILLIS) + )) + .orElse(null); } /** @@ -200,8 +204,8 @@ public ListenerParameters() { this.attributeLengthLimit = DEFAULT_TRUNCATE_ATTRIBUTE_LIMIT; this.printLaunchUuid = DEFAULT_LAUNCH_UUID_PRINT; - this.printLaunchUuidOutput = - OutputTypes.valueOf(DEFAULT_LAUNCH_UUID_OUTPUT.toUpperCase(Locale.ROOT)).getOutput(); + this.printLaunchUuidOutput = OutputTypes.valueOf(DEFAULT_LAUNCH_UUID_OUTPUT.toUpperCase(Locale.ROOT)).getOutput(); + this.isLaunchUuidCreationSkip = DEFAULT_LAUNCH_CREATION_SKIP; this.btsIssueFail = DEFAULT_BTS_ISSUE_FAIL; } @@ -213,8 +217,7 @@ public ListenerParameters() { */ public ListenerParameters(PropertiesLoader properties) { this.description = properties.getProperty(DESCRIPTION); - this.apiKey = ofNullable(properties.getProperty(API_KEY, properties.getProperty(UUID))).map(String::trim) - .orElse(null); + this.apiKey = ofNullable(properties.getProperty(API_KEY, properties.getProperty(UUID))).map(String::trim).orElse(null); this.baseUrl = properties.getProperty(BASE_URL) != null ? properties.getProperty(BASE_URL).trim() : null; this.proxyUrl = properties.getProperty(HTTP_PROXY_URL); this.proxyUser = properties.getProperty(HTTP_PROXY_USER); @@ -222,19 +225,14 @@ public ListenerParameters(PropertiesLoader properties) { this.httpLogging = properties.getPropertyAsBoolean(HTTP_LOGGING, DEFAULT_HTTP_LOGGING); this.httpCallTimeout = getDurationProperty(properties, HTTP_CALL_TIMEOUT_VALUE, HTTP_CALL_TIMEOUT_UNIT); - this.httpConnectTimeout = getDurationProperty(properties, - HTTP_CONNECT_TIMEOUT_VALUE, - HTTP_CONNECT_TIMEOUT_UNIT - ); + this.httpConnectTimeout = getDurationProperty(properties, HTTP_CONNECT_TIMEOUT_VALUE, HTTP_CONNECT_TIMEOUT_UNIT); this.httpReadTimeout = getDurationProperty(properties, HTTP_READ_TIMEOUT_VALUE, HTTP_READ_TIMEOUT_UNIT); this.httpWriteTimeout = getDurationProperty(properties, HTTP_WRITE_TIMEOUT_VALUE, HTTP_WRITE_TIMEOUT_UNIT); - this.projectName = - properties.getProperty(PROJECT_NAME) != null ? properties.getProperty(PROJECT_NAME).trim() : null; + this.projectName = properties.getProperty(PROJECT_NAME) != null ? properties.getProperty(PROJECT_NAME).trim() : null; this.launchName = properties.getProperty(LAUNCH_NAME); this.launchUuid = properties.getProperty(LAUNCH_UUID); - this.attributes = Collections.unmodifiableSet(AttributeParser.parseAsSet(properties.getProperty( - LAUNCH_ATTRIBUTES))); + this.attributes = Collections.unmodifiableSet(AttributeParser.parseAsSet(properties.getProperty(LAUNCH_ATTRIBUTES))); this.launchRunningMode = parseLaunchMode(properties.getProperty(MODE)); this.enable = properties.getPropertyAsBoolean(ENABLE, DEFAULT_ENABLE); this.isSkippedAnIssue = properties.getPropertyAsBoolean(SKIPPED_AS_ISSUE, DEFAULT_SKIP_ISSUE); @@ -250,32 +248,25 @@ public ListenerParameters(PropertiesLoader properties) { this.rerunOf = properties.getProperty(RERUN_OF); this.asyncReporting = properties.getPropertyAsBoolean(ASYNC_REPORTING, DEFAULT_ASYNC_REPORTING); - this.callbackReportingEnabled = properties.getPropertyAsBoolean(CALLBACK_REPORTING_ENABLED, - DEFAULT_CALLBACK_REPORTING_ENABLED - ); + this.callbackReportingEnabled = properties.getPropertyAsBoolean(CALLBACK_REPORTING_ENABLED, DEFAULT_CALLBACK_REPORTING_ENABLED); this.ioPoolSize = properties.getPropertyAsInt(IO_POOL_SIZE, DEFAULT_IO_POOL_SIZE); // client join parameters clientJoin = properties.getPropertyAsBoolean(CLIENT_JOIN_MODE, DEFAULT_CLIENT_JOIN); - clientJoinMode = LaunchIdLockMode.valueOf(properties.getProperty(CLIENT_JOIN_MODE_VALUE, - DEFAULT_CLIENT_JOIN_MODE - )); + clientJoinMode = LaunchIdLockMode.valueOf(properties.getProperty(CLIENT_JOIN_MODE_VALUE, DEFAULT_CLIENT_JOIN_MODE)); lockPortNumber = properties.getPropertyAsInt(CLIENT_JOIN_LOCK_PORT, DEFAULT_CLIENT_JOIN_LOCK_PORT); lockFileName = properties.getProperty(FILE_LOCK_NAME, DEFAULT_LOCK_FILE_NAME); syncFileName = properties.getProperty(FILE_SYNC_NAME, DEFAULT_SYNC_FILE_NAME); - clientJoinTimeout = ofNullable(properties.getProperty(CLIENT_JOIN_TIMEOUT_VALUE)) - .map(t -> TimeUnit.valueOf(properties.getProperty(CLIENT_JOIN_TIMEOUT_UNIT, + clientJoinTimeout = ofNullable(properties.getProperty(CLIENT_JOIN_TIMEOUT_VALUE)).map(t -> TimeUnit.valueOf(properties.getProperty(CLIENT_JOIN_TIMEOUT_UNIT, DEFAULT_CLIENT_JOIN_TIMEOUT_UNIT )).toMillis(Long.parseLong(t))) .orElse(DEFAULT_CLIENT_JOIN_TIMEOUT); - lockWaitTimeout = ofNullable(properties.getProperty(CLIENT_JOIN_LOCK_TIMEOUT_VALUE)) - .map(t -> TimeUnit.valueOf(properties.getProperty(CLIENT_JOIN_LOCK_TIMEOUT_UNIT, + lockWaitTimeout = ofNullable(properties.getProperty(CLIENT_JOIN_LOCK_TIMEOUT_VALUE)).map(t -> TimeUnit.valueOf(properties.getProperty(CLIENT_JOIN_LOCK_TIMEOUT_UNIT, DEFAULT_CLIENT_JOIN_LOCK_TIMEOUT_UNIT )).toMillis(Long.parseLong(t))) .orElse(DEFAULT_FILE_WAIT_TIMEOUT); - clientJoinLaunchTimeout = ofNullable(properties.getProperty(CLIENT_JOIN_LAUNCH_TIMEOUT_VALUE)) - .map(t -> TimeUnit.valueOf(properties.getProperty(CLIENT_JOIN_LAUNCH_TIMEOUT_UNIT, + clientJoinLaunchTimeout = ofNullable(properties.getProperty(CLIENT_JOIN_LAUNCH_TIMEOUT_VALUE)).map(t -> TimeUnit.valueOf(properties.getProperty(CLIENT_JOIN_LAUNCH_TIMEOUT_UNIT, DEFAULT_CLIENT_JOIN_LAUNCH_TIMEOUT_UNIT )).toMillis(Long.parseLong(t))) .orElse(DEFAULT_CLIENT_JOIN_LAUNCH_TIMEOUT); @@ -283,19 +274,13 @@ public ListenerParameters(PropertiesLoader properties) { this.rxBufferSize = properties.getPropertyAsInt(RX_BUFFER_SIZE, DEFAULT_RX_BUFFER_SIZE); this.truncateFields = properties.getPropertyAsBoolean(TRUNCATE_FIELDS, DEFAULT_TRUNCATE); - this.truncateItemNamesLimit = properties.getPropertyAsInt(TRUNCATE_ITEM_NAME_LIMIT, - DEFAULT_TRUNCATE_ITEM_NAMES_LIMIT); + this.truncateItemNamesLimit = properties.getPropertyAsInt(TRUNCATE_ITEM_NAME_LIMIT, DEFAULT_TRUNCATE_ITEM_NAMES_LIMIT); this.truncateReplacement = properties.getProperty(TRUNCATE_REPLACEMENT, DEFAULT_TRUNCATE_REPLACEMENT); - this.attributeLengthLimit = properties.getPropertyAsInt(TRUNCATE_ATTRIBUTE_LIMIT, - DEFAULT_TRUNCATE_ATTRIBUTE_LIMIT); + this.attributeLengthLimit = properties.getPropertyAsInt(TRUNCATE_ATTRIBUTE_LIMIT, DEFAULT_TRUNCATE_ATTRIBUTE_LIMIT); this.printLaunchUuid = properties.getPropertyAsBoolean(LAUNCH_UUID_PRINT, DEFAULT_LAUNCH_UUID_PRINT); - this.printLaunchUuidOutput = - OutputTypes.valueOf( - properties - .getProperty(LAUNCH_UUID_PRINT_OUTPUT, DEFAULT_LAUNCH_UUID_OUTPUT) - .toUpperCase(Locale.ROOT) - ).getOutput(); + this.printLaunchUuidOutput = OutputTypes.valueOf(properties.getProperty(LAUNCH_UUID_PRINT_OUTPUT, DEFAULT_LAUNCH_UUID_OUTPUT) + .toUpperCase(Locale.ROOT)).getOutput(); this.btsProjectId = properties.getProperty(BTS_PROJECT); this.btsUrl = properties.getProperty(BTS_URL); @@ -380,6 +365,14 @@ public void setLaunchUuid(@Nullable String launchUuid) { this.launchUuid = launchUuid; } + public boolean isLaunchUuidCreationSkip() { + return isLaunchUuidCreationSkip; + } + + public void setLaunchUuidCreationSkip(boolean launchUuidCreationSkip) { + isLaunchUuidCreationSkip = launchUuidCreationSkip; + } + public boolean isPrintLaunchUuid() { return printLaunchUuid; } @@ -590,9 +583,7 @@ public void setHttpLogging(boolean httpLogging) { } public int getRxBufferSize() { - return ofNullable(System.getProperty("rx2.buffer-size")).map(Integer::valueOf) - .map(s -> Math.max(1, s)) - .orElse(rxBufferSize); + return ofNullable(System.getProperty("rx2.buffer-size")).map(Integer::valueOf).map(s -> Math.max(1, s)).orElse(rxBufferSize); } public void setRxBufferSize(int size) { @@ -743,6 +734,7 @@ public String toString() { sb.append(", projectName='").append(projectName).append('\''); sb.append(", launchName='").append(launchName).append('\''); sb.append(", launchUuid='").append(launchUuid).append('\''); + sb.append(", launchUuidCreationSkip='").append(isLaunchUuidCreationSkip).append('\''); sb.append(", printLaunchUuid='").append(printLaunchUuid).append('\''); sb.append(", printLaunchUuidOutput='").append(printLaunchUuidOutput).append('\''); sb.append(", launchRunningMode=").append(launchRunningMode); diff --git a/src/main/java/com/epam/reportportal/service/LaunchImpl.java b/src/main/java/com/epam/reportportal/service/LaunchImpl.java index c9f4564d..e02f17a7 100644 --- a/src/main/java/com/epam/reportportal/service/LaunchImpl.java +++ b/src/main/java/com/epam/reportportal/service/LaunchImpl.java @@ -77,11 +77,13 @@ public class LaunchImpl extends Launch { && ErrorType.FINISH_ITEM_NOT_ALLOWED.equals(((ReportPortalException) throwable).getError().getErrorType())) || INTERNAL_CLIENT_EXCEPTION_PREDICATE.test(throwable); - private static final RetryWithDelay DEFAULT_REQUEST_RETRY = new RetryWithDelay(INTERNAL_CLIENT_EXCEPTION_PREDICATE, + private static final RetryWithDelay DEFAULT_REQUEST_RETRY = new RetryWithDelay( + INTERNAL_CLIENT_EXCEPTION_PREDICATE, DEFAULT_RETRY_COUNT, TimeUnit.SECONDS.toMillis(DEFAULT_RETRY_TIMEOUT) ); - private static final RetryWithDelay TEST_ITEM_FINISH_REQUEST_RETRY = new RetryWithDelay(TEST_ITEM_FINISH_RETRY_PREDICATE, + private static final RetryWithDelay TEST_ITEM_FINISH_REQUEST_RETRY = new RetryWithDelay( + TEST_ITEM_FINISH_RETRY_PREDICATE, ITEM_FINISH_MAX_RETRIES, TimeUnit.SECONDS.toMillis(ITEM_FINISH_RETRY_TIMEOUT) ); @@ -127,10 +129,12 @@ protected LaunchImpl(@Nonnull final ReportPortalClient reportPortalClient, @Nonn }).subscribeOn(getScheduler()).cache(); //noinspection ResultOfMethodCallIgnored - launchPromise.subscribe(rs -> emitter.onSuccess(rs.getId()), t -> { - LOG_ERROR.accept(t); - emitter.onComplete(); - }); + launchPromise.subscribe( + rs -> emitter.onSuccess(rs.getId()), t -> { + LOG_ERROR.accept(t); + emitter.onComplete(); + } + ); }).cache(); projectSettings = ofNullable(getClient().getProjectSettings()).map(settings -> settings.subscribeOn(getScheduler()).cache()) .orElse(Maybe.empty()); @@ -213,14 +217,16 @@ private Set truncateAttributes(@Nullable final Set limit && keyLength > replacement.length()) { - updated = new ItemAttributesRQ(updated.getKey().substring(0, limit - replacement.length()) + replacement, + updated = new ItemAttributesRQ( + updated.getKey().substring(0, limit - replacement.length()) + replacement, updated.getValue(), updated.isSystem() ); } int valueLength = ofNullable(updated.getValue()).map(String::length).orElse(0); if (valueLength > limit && valueLength > replacement.length()) { - updated = new ItemAttributesRQ(updated.getKey(), + updated = new ItemAttributesRQ( + updated.getKey(), updated.getValue().substring(0, limit - replacement.length()) + replacement, updated.isSystem() ); @@ -275,7 +281,7 @@ public Maybe start() { public void finish(final FinishExecutionRQ request) { QUEUE.getOrCompute(launch).addToQueue(LaunchLoggingContext.complete()); Completable finish = Completable.concat(QUEUE.getOrCompute(launch).getChildren()); - if (StringUtils.isBlank(getParameters().getLaunchUuid())) { + if (StringUtils.isBlank(getParameters().getLaunchUuid()) || !getParameters().isLaunchUuidCreationSkip()) { FinishExecutionRQ rq = clonePojo(request, FinishExecutionRQ.class); truncateAttributes(rq); finish = finish.andThen(launch.map(id -> getClient().finishLaunch(id, rq) diff --git a/src/main/java/com/epam/reportportal/service/ReportPortal.java b/src/main/java/com/epam/reportportal/service/ReportPortal.java index 684d736e..90467475 100644 --- a/src/main/java/com/epam/reportportal/service/ReportPortal.java +++ b/src/main/java/com/epam/reportportal/service/ReportPortal.java @@ -55,7 +55,10 @@ import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.util.*; -import java.util.concurrent.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; @@ -118,34 +121,42 @@ public Launch newLaunch(@Nonnull StartLaunchRQ rq) { return Launch.NOOP_LAUNCH; } - if (StringUtils.isNotBlank(parameters.getLaunchUuid())) { - // a Launch UUID specified, use it and do not start a new Launch - return new LaunchImpl(rpClient, parameters, Maybe.just(parameters.getLaunchUuid()), executor); + StartLaunchRQ rqCopy = clonePojo(rq, StartLaunchRQ.class); + String launchUuid = parameters.getLaunchUuid(); + boolean launchUuidSet = StringUtils.isNotBlank(launchUuid); + if (launchUuidSet) { + if (parameters.isLaunchUuidCreationSkip()) { + // a Launch UUID specified, but we should skip its creation + return new LaunchImpl(rpClient, parameters, Maybe.just(launchUuid), executor); + } else { + // a Launch UUID specified, but we should create a new Launch with it + rqCopy.setUuid(launchUuid); + } } if (launchIdLock == null) { // do not use multi-client mode - return new LaunchImpl(rpClient, parameters, rq, executor); + return new LaunchImpl(rpClient, parameters, rqCopy, executor); } final String instanceUuid = UUID.randomUUID().toString(); final String uuid = launchIdLock.obtainLaunchUuid(instanceUuid); if (uuid == null) { // timeout locking on file or interrupted, anyway it should be logged already - // we continue to operate normally, since this flag is set by default and we shouldn't fail launches because of it - return new LaunchImpl(rpClient, parameters, rq, executor); + // we continue to operate normally, since this flag is set by default, and we shouldn't fail launches because of it + return new LaunchImpl(rpClient, parameters, rqCopy, executor); } if (instanceUuid.equals(uuid)) { - // We got our own UUID as launch UUID, that means we are primary launch. - StartLaunchRQ rqCopy = clonePojo(rq, StartLaunchRQ.class); - rqCopy.setUuid(uuid); + // We got our own instance UUID, that means we are primary launch. + if (!launchUuidSet) { + // If we got Launch UUID from parameters, we should use it, otherwise we should use instance UUID as Launch UUID + rqCopy.setUuid(instanceUuid); + } return new PrimaryLaunch(rpClient, parameters, rqCopy, executor, launchIdLock, instanceUuid); } else { - Maybe launch = Maybe.create(emitter -> { - emitter.onSuccess(uuid); - emitter.onComplete(); - }); + // If we got Launch UUID from parameters, we should use it, otherwise we should use obtained UUID as a Secondary Launch + Maybe launch = launchUuidSet ? Maybe.just(launchUuid) : Maybe.just(uuid); return new SecondaryLaunch(rpClient, parameters, launch, executor, launchIdLock, instanceUuid); } } @@ -495,12 +506,10 @@ protected Retrofit buildRestEndpoint(@Nonnull final ListenerParameters parameter builder.baseUrl(baseUrl); } catch (NoSuchMethodError e) { throw new InternalReportPortalClientException( - "Unable to initialize OkHttp client. " - + "ReportPortal client supports OkHttp version 3.11.0 as minimum.\n" + "Unable to initialize OkHttp client. ReportPortal client supports OkHttp version 3.11.0 as minimum.\n" + "Please update OkHttp dependency.\n" + "Besides this usually happens due to old selenium-java version (it overrides our dependency), " - + "please use selenium-java 3.141.0 as minimum.", - e + + "please use selenium-java 3.141.0 as minimum.", e ); } return builder.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.from(executor))) diff --git a/src/main/java/com/epam/reportportal/utils/properties/ListenerProperty.java b/src/main/java/com/epam/reportportal/utils/properties/ListenerProperty.java index 522d661e..c482cc7a 100644 --- a/src/main/java/com/epam/reportportal/utils/properties/ListenerProperty.java +++ b/src/main/java/com/epam/reportportal/utils/properties/ListenerProperty.java @@ -58,9 +58,13 @@ public enum ListenerProperty { PROJECT_NAME("rp.project", true), LAUNCH_NAME("rp.launch", true), /** - * Do not create new launch and use predefined Launch UUID. + * Use predefined Launch UUID. */ LAUNCH_UUID("rp.launch.uuid", false), + /** + * Do not create new launch and report to predefined Launch UUID. + */ + LAUNCH_UUID_CREATION_SKIP("rp.launch.uuid.creation.skip", false), /** * Print Launch UUID after start in a format: `ReportPortal Launch UUID: {UUID}`. */ From f950d001126123c6f949d5354755f963a34f0627 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 14 Nov 2024 17:41:50 +0300 Subject: [PATCH 2/9] Fix property set and add a test --- .../listeners/ListenerParameters.java | 5 +- .../service/ReportPortalTest.java | 71 ++++++++++++++++--- 2 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/epam/reportportal/listeners/ListenerParameters.java b/src/main/java/com/epam/reportportal/listeners/ListenerParameters.java index fb61be20..cdea3458 100644 --- a/src/main/java/com/epam/reportportal/listeners/ListenerParameters.java +++ b/src/main/java/com/epam/reportportal/listeners/ListenerParameters.java @@ -90,7 +90,6 @@ public class ListenerParameters implements Cloneable { private Duration httpWriteTimeout; private String projectName; private String launchName; - private String launchUuid; private Mode launchRunningMode; private Set attributes; private Boolean enable; @@ -123,6 +122,7 @@ public class ListenerParameters implements Cloneable { private String truncateReplacement; private int attributeLengthLimit; + private String launchUuid; private boolean isLaunchUuidCreationSkip; private boolean printLaunchUuid; private PrintStream printLaunchUuidOutput; @@ -231,7 +231,6 @@ public ListenerParameters(PropertiesLoader properties) { this.projectName = properties.getProperty(PROJECT_NAME) != null ? properties.getProperty(PROJECT_NAME).trim() : null; this.launchName = properties.getProperty(LAUNCH_NAME); - this.launchUuid = properties.getProperty(LAUNCH_UUID); this.attributes = Collections.unmodifiableSet(AttributeParser.parseAsSet(properties.getProperty(LAUNCH_ATTRIBUTES))); this.launchRunningMode = parseLaunchMode(properties.getProperty(MODE)); this.enable = properties.getPropertyAsBoolean(ENABLE, DEFAULT_ENABLE); @@ -278,6 +277,8 @@ public ListenerParameters(PropertiesLoader properties) { this.truncateReplacement = properties.getProperty(TRUNCATE_REPLACEMENT, DEFAULT_TRUNCATE_REPLACEMENT); this.attributeLengthLimit = properties.getPropertyAsInt(TRUNCATE_ATTRIBUTE_LIMIT, DEFAULT_TRUNCATE_ATTRIBUTE_LIMIT); + this.launchUuid = properties.getProperty(LAUNCH_UUID); + this.isLaunchUuidCreationSkip = properties.getPropertyAsBoolean(LAUNCH_UUID_CREATION_SKIP, DEFAULT_LAUNCH_CREATION_SKIP); this.printLaunchUuid = properties.getPropertyAsBoolean(LAUNCH_UUID_PRINT, DEFAULT_LAUNCH_UUID_PRINT); this.printLaunchUuidOutput = OutputTypes.valueOf(properties.getProperty(LAUNCH_UUID_PRINT_OUTPUT, DEFAULT_LAUNCH_UUID_OUTPUT) .toUpperCase(Locale.ROOT)).getOutput(); diff --git a/src/test/java/com/epam/reportportal/service/ReportPortalTest.java b/src/test/java/com/epam/reportportal/service/ReportPortalTest.java index e232eda0..116921b6 100644 --- a/src/test/java/com/epam/reportportal/service/ReportPortalTest.java +++ b/src/test/java/com/epam/reportportal/service/ReportPortalTest.java @@ -111,11 +111,13 @@ public void verify_proxy_parameter_works() throws Exception { assertThat(client, notNullValue()); Exception error = null; try { - SocketUtils.ServerCallable serverCallable = new SocketUtils.ServerCallable(server, + SocketUtils.ServerCallable serverCallable = new SocketUtils.ServerCallable( + server, Collections.emptyMap(), "files/simple_response.txt" ); - Pair, Response> result = SocketUtils.executeServerCallable(serverCallable, + Pair, Response> result = SocketUtils.executeServerCallable( + serverCallable, () -> client.newCall(new Request.Builder().url(baseUrl).build()).execute() ); assertThat(result.getValue().code(), equalTo(200)); @@ -147,11 +149,13 @@ public void verify_proxy_credential_works() throws Exception { assertThat(client, notNullValue()); Exception error = null; try { - SocketUtils.ServerCallable serverCallable = new SocketUtils.ServerCallable(server, + SocketUtils.ServerCallable serverCallable = new SocketUtils.ServerCallable( + server, Collections.emptyMap(), Arrays.asList("files/proxy_auth_response.txt", "files/simple_response.txt") ); - Pair, Response> proxyAuth = SocketUtils.executeServerCallable(serverCallable, + Pair, Response> proxyAuth = SocketUtils.executeServerCallable( + serverCallable, () -> client.newCall(new Request.Builder().url(baseUrl).build()).execute() ); assertThat(proxyAuth.getValue().code(), equalTo(200)); @@ -198,7 +202,8 @@ private static Pair, T> executeWithClosingOnException(ExecutorS private static Pair, StartLaunchRS> executeWithClosing(ExecutorService clientExecutor, ServerSocket ss, SocketUtils.ServerCallable serverCallable, Callable clientCallable) throws Exception { - Pair, StartLaunchRS> result = executeWithClosingOnException(clientExecutor, + Pair, StartLaunchRS> result = executeWithClosingOnException( + clientExecutor, ss, () -> SocketUtils.executeServerCallable(serverCallable, clientCallable) ); @@ -259,7 +264,8 @@ public void verify_rp_client_http_logging() throws Exception { ExecutorService clientExecutor = Executors.newSingleThreadExecutor(); ReportPortalClient rpClient = ReportPortal.builder().buildClient(ReportPortalClient.class, parameters, clientExecutor); - SocketUtils.ServerCallable serverCallable = new SocketUtils.ServerCallable(ss, + SocketUtils.ServerCallable serverCallable = new SocketUtils.ServerCallable( + ss, Collections.emptyMap(), Collections.singletonList("files/simple_response.txt") ); @@ -334,20 +340,63 @@ public void verify_launch_uuid_parameter_handling() { Maybe launchMaybe = launch.start(); assertThat(launchMaybe.blockingGet(), equalTo(launchUuid)); - //noinspection ReactiveStreamsUnusedPublisher - launch.startTestItem(TestUtils.standardStartSuiteRequest()); + //noinspection ResultOfMethodCallIgnored + launch.startTestItem(TestUtils.standardStartSuiteRequest()).blockingGet(); + + verify(rpClient, after(1000).times(0)).startLaunch(any(StartLaunchRQ.class)); + + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(rpClient).startTestItem(startCaptor.capture()); + + StartTestItemRQ startItem = startCaptor.getValue(); + assertThat(startItem.getLaunchUuid(), equalTo(launchUuid)); + + launch.finish(TestUtils.standardLaunchFinishRequest()); + + verify(rpClient, after(1000).times(0)).finishLaunch(anyString(), any(FinishExecutionRQ.class)); + } catch (RuntimeException e) { + error = e; + } + CommonUtils.shutdownExecutorService(executor); + if (error != null) { + throw error; + } + } + + @Test + public void verify_launch_uuid_creation_skip_parameter_handling() { + simulateStartLaunchResponse(rpClient); + simulateStartTestItemResponse(rpClient); + + String launchUuid = "test-launch-uuid"; + ListenerParameters listenerParameters = TestUtils.standardParameters(); + listenerParameters.setLaunchUuid(launchUuid); + listenerParameters.setLaunchUuidCreationSkip(false); + + ExecutorService executor = Executors.newSingleThreadExecutor(); + RuntimeException error = null; + + try { + ReportPortal rp = ReportPortal.create(rpClient, listenerParameters, executor); + + Launch launch = rp.newLaunch(standardLaunchRequest(listenerParameters)); + Maybe launchMaybe = launch.start(); + assertThat(launchMaybe.blockingGet(), equalTo(launchUuid)); + + //noinspection ResultOfMethodCallIgnored + launch.startTestItem(TestUtils.standardStartSuiteRequest()).blockingGet(); - verify(rpClient, timeout(1000).times(0)).startLaunch(any(StartLaunchRQ.class)); + verify(rpClient, timeout(1000).times(1)).startLaunch(any(StartLaunchRQ.class)); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(rpClient, timeout(1000)).startTestItem(startCaptor.capture()); + verify(rpClient).startTestItem(startCaptor.capture()); StartTestItemRQ startItem = startCaptor.getValue(); assertThat(startItem.getLaunchUuid(), equalTo(launchUuid)); launch.finish(TestUtils.standardLaunchFinishRequest()); - verify(rpClient, timeout(1000).times(0)).finishLaunch(anyString(), any(FinishExecutionRQ.class)); + verify(rpClient, timeout(1000).times(1)).finishLaunch(eq(launchUuid), any(FinishExecutionRQ.class)); } catch (RuntimeException e) { error = e; } From ef853994157aed648dac7a71747faf31144f47a9 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 14 Nov 2024 17:50:49 +0300 Subject: [PATCH 3/9] Replace `rp.uuid` with `rp.api.key` --- src/test/resources/property-test/default-required.properties | 2 +- src/test/resources/property-test/http-timeout-unit.properties | 2 +- src/test/resources/property-test/http-timeout.properties | 2 +- src/test/resources/property-test/launch-print-false.properties | 2 +- .../resources/property-test/launch-print-true-stderr.properties | 2 +- src/test/resources/property-test/launch-print-true.properties | 2 +- .../resources/property-test/lock-wait-client_lock.properties | 2 +- .../property-test/lock-wait-client_lock_no_time_unit.properties | 2 +- .../property-test/lock-wait-client_lock_override.properties | 2 +- src/test/resources/property-test/utf-demo.properties | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/resources/property-test/default-required.properties b/src/test/resources/property-test/default-required.properties index 44d3da82..627207b2 100644 --- a/src/test/resources/property-test/default-required.properties +++ b/src/test/resources/property-test/default-required.properties @@ -1,4 +1,4 @@ rp.endpoint=http://localhost:8080 rp.project=default_personal rp.launch=launch -rp.uuid=uuid +rp.api.key=uuid diff --git a/src/test/resources/property-test/http-timeout-unit.properties b/src/test/resources/property-test/http-timeout-unit.properties index f65d3c3b..f58bd5a6 100644 --- a/src/test/resources/property-test/http-timeout-unit.properties +++ b/src/test/resources/property-test/http-timeout-unit.properties @@ -1,7 +1,7 @@ rp.endpoint=http://localhost:8080 rp.project=default_personal rp.launch=launch -rp.uuid=uuid +rp.api.key=uuid rp.http.timeout.call.value=1000000 rp.http.timeout.call.unit=NANOSECONDS rp.http.timeout.connect.value=1000000 diff --git a/src/test/resources/property-test/http-timeout.properties b/src/test/resources/property-test/http-timeout.properties index a8dde2eb..4d8963e5 100644 --- a/src/test/resources/property-test/http-timeout.properties +++ b/src/test/resources/property-test/http-timeout.properties @@ -1,7 +1,7 @@ rp.endpoint=http://localhost:8080 rp.project=default_personal rp.launch=launch -rp.uuid=uuid +rp.api.key=uuid rp.http.timeout.call.value=100000 rp.http.timeout.connect.value=100000 rp.http.timeout.read.value=100000 diff --git a/src/test/resources/property-test/launch-print-false.properties b/src/test/resources/property-test/launch-print-false.properties index 7c67b9ff..e16b5606 100644 --- a/src/test/resources/property-test/launch-print-false.properties +++ b/src/test/resources/property-test/launch-print-false.properties @@ -1,5 +1,5 @@ rp.endpoint=http://localhost:8080 rp.project=default_personal rp.launch=launch -rp.uuid=uuid +rp.api.key=uuid rp.launch.uuid.print=false diff --git a/src/test/resources/property-test/launch-print-true-stderr.properties b/src/test/resources/property-test/launch-print-true-stderr.properties index a763a195..5fc3f85e 100644 --- a/src/test/resources/property-test/launch-print-true-stderr.properties +++ b/src/test/resources/property-test/launch-print-true-stderr.properties @@ -1,6 +1,6 @@ rp.endpoint=http://localhost:8080 rp.project=default_personal rp.launch=launch -rp.uuid=uuid +rp.api.key=uuid rp.launch.uuid.print=true rp.launch.uuid.print.output=stderr diff --git a/src/test/resources/property-test/launch-print-true.properties b/src/test/resources/property-test/launch-print-true.properties index a8ddad40..cd8331bd 100644 --- a/src/test/resources/property-test/launch-print-true.properties +++ b/src/test/resources/property-test/launch-print-true.properties @@ -1,5 +1,5 @@ rp.endpoint=http://localhost:8080 rp.project=default_personal rp.launch=launch -rp.uuid=uuid +rp.api.key=uuid rp.launch.uuid.print=true diff --git a/src/test/resources/property-test/lock-wait-client_lock.properties b/src/test/resources/property-test/lock-wait-client_lock.properties index 2e806e10..b02f07ec 100644 --- a/src/test/resources/property-test/lock-wait-client_lock.properties +++ b/src/test/resources/property-test/lock-wait-client_lock.properties @@ -1,6 +1,6 @@ rp.endpoint=http://localhost:8080 rp.project=default_personal rp.launch=launch -rp.uuid=uuid +rp.api.key=uuid rp.client.join.lock.timeout.value=17 rp.client.join.lock.timeout.unit=SECONDS diff --git a/src/test/resources/property-test/lock-wait-client_lock_no_time_unit.properties b/src/test/resources/property-test/lock-wait-client_lock_no_time_unit.properties index 4d9c7f8f..5c5e34cb 100644 --- a/src/test/resources/property-test/lock-wait-client_lock_no_time_unit.properties +++ b/src/test/resources/property-test/lock-wait-client_lock_no_time_unit.properties @@ -1,5 +1,5 @@ rp.endpoint=http://localhost:8080 rp.project=default_personal rp.launch=launch -rp.uuid=uuid +rp.api.key=uuid rp.client.join.lock.timeout.value=21 diff --git a/src/test/resources/property-test/lock-wait-client_lock_override.properties b/src/test/resources/property-test/lock-wait-client_lock_override.properties index cef4392f..08a03ed9 100644 --- a/src/test/resources/property-test/lock-wait-client_lock_override.properties +++ b/src/test/resources/property-test/lock-wait-client_lock_override.properties @@ -1,7 +1,7 @@ rp.endpoint=http://localhost:8080 rp.project=default_personal rp.launch=launch -rp.uuid=uuid +rp.api.key=uuid rp.client.join.file.wait.timeout.ms=15223 rp.client.join.lock.timeout.value=19 rp.client.join.lock.timeout.unit=SECONDS diff --git a/src/test/resources/property-test/utf-demo.properties b/src/test/resources/property-test/utf-demo.properties index df3786c6..ec96306d 100644 --- a/src/test/resources/property-test/utf-demo.properties +++ b/src/test/resources/property-test/utf-demo.properties @@ -1,5 +1,5 @@ rp.endpoint=https://onliner.by rp.project=project rp.launch=launch -rp.uuid=uuid +rp.api.key=uuid utf8=привет мир! \ No newline at end of file From 26d2ddf29299a77a4ff5d1bad24505641d057f8a Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 14 Nov 2024 17:51:17 +0300 Subject: [PATCH 4/9] Add a test --- .../reportportal/listeners/ListenerParametersTest.java | 9 +++++++++ .../property-test/launch-uuid-create.properties | 6 ++++++ 2 files changed, 15 insertions(+) create mode 100644 src/test/resources/property-test/launch-uuid-create.properties diff --git a/src/test/java/com/epam/reportportal/listeners/ListenerParametersTest.java b/src/test/java/com/epam/reportportal/listeners/ListenerParametersTest.java index 3397ec43..11d1f3d6 100644 --- a/src/test/java/com/epam/reportportal/listeners/ListenerParametersTest.java +++ b/src/test/java/com/epam/reportportal/listeners/ListenerParametersTest.java @@ -210,4 +210,13 @@ public void verify_launch_uuid_print(String propertyFile, boolean expectedEnable assertThat(listenerParameters.isPrintLaunchUuid(), equalTo(expectedEnabled)); assertThat(listenerParameters.getPrintLaunchUuidOutput(), sameInstance(expectedPrintStream)); } + + @Test + public void verify_launch_uuid_with_creation() { + PropertiesLoader properties = PropertiesLoader.load("property-test/launch-uuid-create.properties"); + ListenerParameters listenerParameters = new ListenerParameters(properties); + + assertEquals("test-uuid", listenerParameters.getLaunchUuid()); + assertFalse(listenerParameters.isLaunchUuidCreationSkip()); + } } diff --git a/src/test/resources/property-test/launch-uuid-create.properties b/src/test/resources/property-test/launch-uuid-create.properties new file mode 100644 index 00000000..64137737 --- /dev/null +++ b/src/test/resources/property-test/launch-uuid-create.properties @@ -0,0 +1,6 @@ +rp.endpoint=http://localhost:8080 +rp.project=default_personal +rp.launch=launch +rp.api.key=uuid +rp.launch.uuid=test-uuid +rp.launch.uuid.creation.skip=false From 9a363746769877479e80fe55bb370ccaf27401cb Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 14 Nov 2024 18:05:25 +0300 Subject: [PATCH 5/9] Test fixes --- .../service/step/DefaultStepReporter.java | 13 ++++++++----- .../service/step/StepReporter.java | 18 ++++++++++-------- .../service/step/ManualNestedStepTest.java | 12 ++++++++---- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/epam/reportportal/service/step/DefaultStepReporter.java b/src/main/java/com/epam/reportportal/service/step/DefaultStepReporter.java index d9cba68e..230b9783 100644 --- a/src/main/java/com/epam/reportportal/service/step/DefaultStepReporter.java +++ b/src/main/java/com/epam/reportportal/service/step/DefaultStepReporter.java @@ -193,20 +193,23 @@ private void failParents() { * @param status finish status */ @Override - public void finishPreviousStep(@Nullable ItemStatus status) { - finishPreviousStepInternal(status).ifPresent(e -> { + @Nonnull + public Maybe finishPreviousStep(@Nullable ItemStatus status) { + return finishPreviousStepInternal(status).map(e -> { if (ItemStatus.FAILED.name().equalsIgnoreCase(e.getFinishTestItemRQ().getStatus())) { failParents(); } - }); + return e.getItemId(); + }).orElse(Maybe.empty()); } /** * Finish current step started by any of #sendStep methods. */ @Override - public void finishPreviousStep() { - finishPreviousStep(null); + @Nonnull + public Maybe finishPreviousStep() { + return finishPreviousStep(null); } @Override diff --git a/src/main/java/com/epam/reportportal/service/step/StepReporter.java b/src/main/java/com/epam/reportportal/service/step/StepReporter.java index b1e4ef0d..04ccf965 100644 --- a/src/main/java/com/epam/reportportal/service/step/StepReporter.java +++ b/src/main/java/com/epam/reportportal/service/step/StepReporter.java @@ -66,9 +66,11 @@ public interface StepReporter { void sendStep(@Nonnull ItemStatus status, @Nonnull String name, @Nullable Throwable throwable, @Nullable File... files); - void finishPreviousStep(@Nullable ItemStatus status); + @Nonnull + Maybe finishPreviousStep(@Nullable ItemStatus status); - void finishPreviousStep(); + @Nonnull + Maybe finishPreviousStep(); @Nonnull Maybe startNestedStep(@Nonnull StartTestItemRQ startStepRequest); @@ -134,15 +136,13 @@ class StepEntry { private final Date timestamp; private final FinishTestItemRQ finishTestItemRQ; - public StepEntry(@Nonnull Maybe itemId, @Nonnull Date stepStartTime, - @Nonnull FinishTestItemRQ finishTestItemRQ) { + public StepEntry(@Nonnull Maybe itemId, @Nonnull Date stepStartTime, @Nonnull FinishTestItemRQ finishTestItemRQ) { this.itemId = itemId; this.timestamp = stepStartTime; this.finishTestItemRQ = finishTestItemRQ; } - public StepEntry(@Nonnull Maybe itemId, - @Nonnull FinishTestItemRQ finishTestItemRQ) { + public StepEntry(@Nonnull Maybe itemId, @Nonnull FinishTestItemRQ finishTestItemRQ) { this(itemId, Calendar.getInstance().getTime(), finishTestItemRQ); } @@ -193,9 +193,11 @@ public void sendStep(@Nonnull ItemStatus status, @Nonnull String name, @Nullable @Override public void sendStep(@Nonnull ItemStatus status, @Nonnull String name, @Nullable Throwable throwable, @Nullable File... files) {} @Override - public void finishPreviousStep(@Nullable ItemStatus status) {} + @Nonnull + public Maybe finishPreviousStep(@Nullable ItemStatus status) {return Maybe.empty();} @Override - public void finishPreviousStep() {} + @Nonnull + public Maybe finishPreviousStep() {return Maybe.empty();} @Override @Nonnull public Maybe startNestedStep(@Nonnull StartTestItemRQ startStepRequest) {return Maybe.empty();} diff --git a/src/test/java/com/epam/reportportal/service/step/ManualNestedStepTest.java b/src/test/java/com/epam/reportportal/service/step/ManualNestedStepTest.java index 3911a0f2..b9bc58ea 100644 --- a/src/test/java/com/epam/reportportal/service/step/ManualNestedStepTest.java +++ b/src/test/java/com/epam/reportportal/service/step/ManualNestedStepTest.java @@ -162,7 +162,8 @@ public void verify_failed_nested_step_marks_parent_test_as_failed_nested_finish( sr.sendStep(ItemStatus.FAILED, stepName); verify(client, timeout(1000)).startTestItem(eq(testMethodUuid), any()); - sr.finishPreviousStep(); + //noinspection ResultOfMethodCallIgnored + sr.finishPreviousStep().blockingGet(); ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); verify(client, timeout(1000)).finishTestItem(eq(nestedSteps.get(0)), finishStepCaptor.capture()); @@ -182,7 +183,8 @@ public void verify_failed_nested_finish_step_marks_parent_test_as_failed_nested_ sr.sendStep(stepName); verify(client, timeout(1000)).startTestItem(eq(testMethodUuid), any()); - sr.finishPreviousStep(ItemStatus.FAILED); + //noinspection ResultOfMethodCallIgnored + sr.finishPreviousStep(ItemStatus.FAILED).blockingGet(); ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); verify(client, timeout(1000)).finishTestItem(eq(nestedSteps.get(0)), finishStepCaptor.capture()); @@ -364,7 +366,8 @@ public void verify_nested_step_manual_failure_set() { String logMessage = "Test message"; sr.sendStep(stepName, logMessage); sr.setStepStatus(ItemStatus.FAILED); - sr.finishPreviousStep(); + //noinspection ResultOfMethodCallIgnored + sr.finishPreviousStep().blockingGet(); verify(client, timeout(1000)).startTestItem(eq(testMethodUuid), any(StartTestItemRQ.class)); ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); @@ -386,7 +389,8 @@ public void verify_nested_step_manual_failure_set_overrides_any_other_status() { String logMessage = "Test message"; sr.sendStep(ItemStatus.PASSED, stepName, logMessage); sr.setStepStatus(ItemStatus.PASSED); - sr.finishPreviousStep(ItemStatus.FAILED); + //noinspection ResultOfMethodCallIgnored + sr.finishPreviousStep(ItemStatus.FAILED).blockingGet(); verify(client, timeout(1000)).startTestItem(eq(testMethodUuid), any(StartTestItemRQ.class)); ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); From 6eb310e28239a903b424370d873c24c1034edbc5 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 15 Nov 2024 10:53:41 +0300 Subject: [PATCH 6/9] Minor warning fix --- src/main/java/com/epam/reportportal/service/LaunchImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/epam/reportportal/service/LaunchImpl.java b/src/main/java/com/epam/reportportal/service/LaunchImpl.java index e02f17a7..839a90c5 100644 --- a/src/main/java/com/epam/reportportal/service/LaunchImpl.java +++ b/src/main/java/com/epam/reportportal/service/LaunchImpl.java @@ -470,6 +470,7 @@ public Maybe finishTestItem(final Maybe item, fin FinishTestItemRQ rq = clonePojo(request, FinishTestItemRQ.class); truncateAttributes(rq); + //noinspection ReactiveStreamsUnusedPublisher getStepReporter().finishPreviousStep(ofNullable(rq.getStatus()).map(ItemStatus::valueOf).orElse(null)); ItemStatus status = ofNullable(rq.getStatus()).map(ItemStatus::valueOf).orElse(null); From 703b44522574db713b86f9beaa917d2227117880 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 15 Nov 2024 10:53:57 +0300 Subject: [PATCH 7/9] Add Launch UUID test and refactoring --- .../service/ReportPortalClientJoinTest.java | 132 ++++++++---------- 1 file changed, 56 insertions(+), 76 deletions(-) diff --git a/src/test/java/com/epam/reportportal/service/ReportPortalClientJoinTest.java b/src/test/java/com/epam/reportportal/service/ReportPortalClientJoinTest.java index b5caa945..1c00a75e 100644 --- a/src/test/java/com/epam/reportportal/service/ReportPortalClientJoinTest.java +++ b/src/test/java/com/epam/reportportal/service/ReportPortalClientJoinTest.java @@ -30,10 +30,7 @@ import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; import io.reactivex.Maybe; import io.reactivex.Scheduler; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Consumer; import okhttp3.OkHttpClient; -import org.awaitility.Awaitility; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -110,34 +107,8 @@ private static Maybe getLaunchResponse(String id) { } private static void simulateGetLaunchResponse(final ReportPortalClient client) { - when(client.getLaunchByUuid(anyString())).then((Answer>) invocation -> getLaunchResponse( - invocation.getArgument(0).toString())); - } - - private static class StringConsumer implements Consumer { - private volatile String result; - - @Override - public void accept(String s) { - result = s; - } - - public String getResult() { - return result; - } - } - - private static String getId(Maybe stringMaybe) { - final StringConsumer consumer = new StringConsumer(); - Disposable disposable = stringMaybe.subscribe(consumer); - try { - return Awaitility.await("Waiting for reactivex consumer") - .pollInterval(2, TimeUnit.MILLISECONDS) - .atMost(10, TimeUnit.SECONDS) - .until(consumer::getResult, Matchers.notNullValue()); - } finally { - disposable.dispose(); - } + when(client.getLaunchByUuid(anyString())).then((Answer>) invocation -> getLaunchResponse(invocation.getArgument( + 0).toString())); } private static List createLaunchesNoStart(int num, ReportPortalClient rpClient, ListenerParameters params, @@ -151,15 +122,14 @@ private static List createLaunchesNoStart(int num, ReportPortalClient rp return result; } - private static List createLaunchesNoGetLaunch(int num, ReportPortalClient rpClient, - ListenerParameters params, LaunchIdLock launchIdLock, ExecutorService executor) { + private static List createLaunchesNoGetLaunch(int num, ReportPortalClient rpClient, ListenerParameters params, + LaunchIdLock launchIdLock, ExecutorService executor) { simulateStartLaunchResponse(rpClient); return createLaunchesNoStart(num, rpClient, params, launchIdLock, executor); } - private static List createLaunches(@SuppressWarnings("SameParameterValue") int num, - ReportPortalClient rpClient, ListenerParameters params, LaunchIdLock launchIdLock, - ExecutorService executor) { + private static List createLaunches(@SuppressWarnings("SameParameterValue") int num, ReportPortalClient rpClient, + ListenerParameters params, LaunchIdLock launchIdLock, ExecutorService executor) { simulateGetLaunchResponse(rpClient); return createLaunchesNoGetLaunch(num, rpClient, params, launchIdLock, executor); } @@ -168,30 +138,26 @@ private static List createLaunches(@SuppressWarnings("SameParameterValue public void test_two_launches_have_correct_class_names() { List launches = createLaunchesNoStart(2, rpClient, paramSupplier.get(), launchIdLock, executor); - assertThat( - launches.get(0).getClass().getCanonicalName(), - Matchers.equalTo(PrimaryLaunch.class.getCanonicalName()) - ); - assertThat( - launches.get(1).getClass().getCanonicalName(), - Matchers.equalTo(SecondaryLaunch.class.getCanonicalName()) - ); + assertThat(launches.get(0).getClass().getCanonicalName(), Matchers.equalTo(PrimaryLaunch.class.getCanonicalName())); + assertThat(launches.get(1).getClass().getCanonicalName(), Matchers.equalTo(SecondaryLaunch.class.getCanonicalName())); } @Test + @SuppressWarnings("ResultOfMethodCallIgnored") public void test_two_launches_call_start_launch_only_once() { List launches = createLaunches(2, rpClient, paramSupplier.get(), launchIdLock, executor); - launches.get(0).start(); - launches.get(1).start(); + launches.get(0).start().blockingGet(); + launches.get(1).start().blockingGet(); verify(launchIdLock, times(2)).obtainLaunchUuid(ArgumentMatchers.anyString()); - verify(rpClient, after(WAIT_TIMEOUT).times(1)).startLaunch(any(StartLaunchRQ.class)); + verify(rpClient, times(1)).startLaunch(any(StartLaunchRQ.class)); } @Test public void test_primary_launch_start_launch_request() { List launches = createLaunchesNoGetLaunch(1, rpClient, paramSupplier.get(), launchIdLock, executor); - launches.get(0).start(); + //noinspection ResultOfMethodCallIgnored + launches.get(0).start().blockingGet(); ArgumentCaptor passedUuid = ArgumentCaptor.forClass(String.class); verify(launchIdLock, timeout(WAIT_TIMEOUT).times(1)).obtainLaunchUuid(passedUuid.capture()); @@ -208,10 +174,10 @@ public void test_primary_launch_start_launch_request() { public void test_two_launches_have_same_uuid() { List launches = createLaunches(2, rpClient, paramSupplier.get(), launchIdLock, executor); - String firstUuid = getId(launches.get(0).start()); - String secondUuid = getId(launches.get(1).start()); + String firstStart = launches.get(0).start().blockingGet(); + String secondStart = launches.get(1).start().blockingGet(); - assertThat(firstUuid, equalTo(secondUuid)); + assertThat(secondStart, equalTo(firstStart)); } private static FinishExecutionRQ standardLaunchFinish() { @@ -222,15 +188,13 @@ private static FinishExecutionRQ standardLaunchFinish() { } @Test + @SuppressWarnings("ReactiveStreamsUnusedPublisher") public void test_only_primary_launch_finish_launch_on_rp() { List launches = createLaunches(2, rpClient, paramSupplier.get(), launchIdLock, executor); launches.get(0).start(); launches.get(1).start(); - when(rpClient.finishLaunch( - any(), - any(FinishExecutionRQ.class) - )).thenReturn(Maybe.just(new OperationCompletionRS())); + when(rpClient.finishLaunch(any(), any(FinishExecutionRQ.class))).thenReturn(Maybe.just(new OperationCompletionRS())); launches.get(0).finish(standardLaunchFinish()); launches.get(1).finish(standardLaunchFinish()); @@ -288,6 +252,7 @@ private static Maybe standardItemResponse(String id) { } @Test + @SuppressWarnings("ReactiveStreamsUnusedPublisher") public void test_rp_client_sends_correct_start_item_for_secondary_launch() { List launches = createLaunches(2, rpClient, paramSupplier.get(), launchIdLock, executor); launches.get(0).start(); @@ -296,22 +261,22 @@ public void test_rp_client_sends_correct_start_item_for_secondary_launch() { String itemUuid = UUID.randomUUID().toString(); simulateStartItemResponse(rpClient, itemUuid); Maybe rs = launches.get(1).startTestItem(standardItemRequest()); - String testItemId = getId(rs); - assertThat(testItemId, equalTo(itemUuid)); + assertThat(rs.blockingGet(), equalTo(itemUuid)); } @Test public void test_secondary_launch_call_get_launch_by_uuid() { List launches = createLaunchesNoStart(2, rpClient, paramSupplier.get(), launchIdLock, executor); simulateGetLaunchResponse(rpClient); - launches.get(1).start(); + //noinspection ResultOfMethodCallIgnored + launches.get(1).start().blockingGet(); ArgumentCaptor obtainUuids = ArgumentCaptor.forClass(String.class); verify(launchIdLock, timeout(WAIT_TIMEOUT).times(2)).obtainLaunchUuid(obtainUuids.capture()); ArgumentCaptor sentUuid = ArgumentCaptor.forClass(String.class); - verify(rpClient, after(WAIT_TIMEOUT * 2).times(1)).getLaunchByUuid(sentUuid.capture()); + verify(rpClient, times(1)).getLaunchByUuid(sentUuid.capture()); assertThat(sentUuid.getValue(), equalTo(obtainUuids.getAllValues().get(0))); } @@ -320,19 +285,18 @@ private static Maybe getLaunchErrorResponse() { return Maybe.error(new ReportPortalException(404, "Launch not found", new ErrorRS())); } - private static void simulateGetLaunchByUuidResponse(ReportPortalClient client) { + private static void simulateGetLaunchErrorResponse(ReportPortalClient client) { Answer> errorAnswer = invocation -> getLaunchErrorResponse(); when(client.getLaunchByUuid(anyString())).then(errorAnswer) .then(errorAnswer) - .then((Answer>) invocation -> getLaunchResponse(invocation.getArgument(0) - .toString())); + .then((Answer>) invocation -> getLaunchResponse(invocation.getArgument(0).toString())); } @Test public void test_secondary_launch_awaits_get_launch_by_uuid_correct_response_for_v1() { int num = 2; simulateObtainLaunchUuidResponse(launchIdLock); - simulateGetLaunchByUuidResponse(rpClient); + simulateGetLaunchErrorResponse(rpClient); ListenerParameters p = paramSupplier.get(); p.setAsyncReporting(false); List launches = new ArrayList<>(num); @@ -340,6 +304,7 @@ public void test_secondary_launch_awaits_get_launch_by_uuid_correct_response_for ReportPortal rp = new ReportPortal(rpClient, executor, p, launchIdLock); launches.add(rp.newLaunch(standardLaunchRequest(p))); } + //noinspection ReactiveStreamsUnusedPublisher launches.get(1).start(); verify(launchIdLock, timeout(WAIT_TIMEOUT).times(2)).obtainLaunchUuid(anyString()); @@ -357,10 +322,11 @@ public void test_secondary_launch_does_not_await_get_launch_by_uuid_correct_resp ReportPortal rp = new ReportPortal(rpClient, executor, p, launchIdLock); launches.add(rp.newLaunch(standardLaunchRequest(p))); } - launches.get(1).start(); + //noinspection ResultOfMethodCallIgnored + launches.get(1).start().blockingGet(); verify(launchIdLock, timeout(WAIT_TIMEOUT).times(2)).obtainLaunchUuid(anyString()); - verify(rpClient, after(WAIT_TIMEOUT * 3).times(0)).getLaunchByUuid(anyString()); + verify(rpClient, times(0)).getLaunchByUuid(anyString()); } @Test @@ -415,19 +381,11 @@ public void test_secondary_launch_updates_its_instance_periodically() { public void test_primary_launch_waits_for_secondary_finish() { String secondaryLaunchUuid = UUID.randomUUID().toString(); - Launch primaryLaunch = createLaunchesNoGetLaunch( - 1, - rpClient, - paramSupplier.get(), - launchIdLock, - executor - ).iterator().next(); + Launch primaryLaunch = createLaunchesNoGetLaunch(1, rpClient, paramSupplier.get(), launchIdLock, executor).iterator().next(); assertThat(primaryLaunch, notNullValue()); when(launchIdLock.getLiveInstanceUuids()).thenReturn(Collections.singletonList(secondaryLaunchUuid)); - when(rpClient.finishLaunch( - any(), - any(FinishExecutionRQ.class) - )).thenReturn(Maybe.just(new OperationCompletionRS())); + when(rpClient.finishLaunch(any(), any(FinishExecutionRQ.class))).thenReturn(Maybe.just(new OperationCompletionRS())); + //noinspection ReactiveStreamsUnusedPublisher primaryLaunch.start(); Thread finishThread = new Thread(() -> primaryLaunch.finish(standardLaunchFinish())); @@ -442,4 +400,26 @@ public void test_primary_launch_waits_for_secondary_finish() { verify(launchIdLock, atLeast(1)).getLiveInstanceUuids(); assertThat(finishThread.isAlive(), equalTo(Boolean.FALSE)); } + + @Test + @SuppressWarnings("ResultOfMethodCallIgnored") + public void test_launches_uses_passed_launch_uuid() { + String launchUuid = UUID.randomUUID().toString(); + ListenerParameters params = paramSupplier.get(); + params.setLaunchUuid(launchUuid); + params.setLaunchUuidCreationSkip(false); + List launches = createLaunchesNoStart(2, rpClient, params, launchIdLock, executor); + simulateStartLaunchResponse(rpClient); + simulateGetLaunchResponse(rpClient); + launches.get(0).start().blockingGet(); + launches.get(1).start().blockingGet(); + + ArgumentCaptor launchStart = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(rpClient, times(1)).startLaunch(launchStart.capture()); + assertThat(launchStart.getValue().getUuid(), equalTo(launchUuid)); + + ArgumentCaptor secondaryUuid = ArgumentCaptor.forClass(String.class); + verify(rpClient, times(1)).getLaunchByUuid(secondaryUuid.capture()); + assertThat(secondaryUuid.getValue(), equalTo(launchUuid)); + } } From aace1e6de313971a61e2d2c52c0a649e6cbd104c Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 15 Nov 2024 12:10:57 +0300 Subject: [PATCH 8/9] Fix test --- .../statistics/StatisticsServiceTest.java | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/src/test/java/com/epam/reportportal/service/statistics/StatisticsServiceTest.java b/src/test/java/com/epam/reportportal/service/statistics/StatisticsServiceTest.java index 1acb8c32..ea6a89b1 100644 --- a/src/test/java/com/epam/reportportal/service/statistics/StatisticsServiceTest.java +++ b/src/test/java/com/epam/reportportal/service/statistics/StatisticsServiceTest.java @@ -34,6 +34,7 @@ import org.mockito.Mock; import retrofit2.Response; +import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Collections; @@ -42,7 +43,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.hamcrest.Matchers.matchesRegex; import static org.mockito.Mockito.any; import static org.mockito.Mockito.*; @@ -67,7 +67,6 @@ protected Statistics getStatistics() { private static final String SEMANTIC_VERSION_PATTERN = "(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?"; - @Mock private StatisticsApiClient httpClient; @@ -84,7 +83,10 @@ protected Statistics getStatistics() { private ListenerParameters parameters; private void stubSend() { - when(statistics.send(any())).thenReturn(Maybe.create(e -> e.onSuccess(Response.success(ResponseBody.create("", MediaType.get("text/plain")))))); + when(statistics.send(any())).thenReturn(Maybe.create(e -> e.onSuccess(Response.success(ResponseBody.create( + "", + MediaType.get("text/plain") + ))))); } @BeforeEach @@ -98,10 +100,7 @@ public void setup() { public void test_statistics_send_event_with_agent() { stubSend(); StartLaunchRQ launchRq = TestUtils.standardLaunchRequest(parameters); - launchRq.setAttributes(Collections.singleton(new ItemAttributesRQ("agent", - "agent-java-testng|test-version-1", - true - ))); + launchRq.setAttributes(Collections.singleton(new ItemAttributesRQ("agent", "agent-java-testng|test-version-1", true))); service.sendEvent(launchMaybe, launchRq); service.close(); @@ -118,12 +117,13 @@ public void test_statistics_send_event_with_agent() { Map params = event.getParams(); assertThat(params.get(StatisticsService.CLIENT_NAME_PARAM), anyOf(equalTo("${name}"), equalTo("client-java"))); - assertThat(params.get(StatisticsService.CLIENT_VERSION_PARAM).toString(), anyOf(equalTo("${version}"), matchesRegex(SEMANTIC_VERSION_PATTERN))); + assertThat( + params.get(StatisticsService.CLIENT_VERSION_PARAM).toString(), + anyOf(equalTo("${version}"), matchesRegex(SEMANTIC_VERSION_PATTERN)) + ); assertThat(params.get(StatisticsService.AGENT_NAME_PARAM), equalTo("agent-java-testng")); assertThat(params.get(StatisticsService.AGENT_VERSION_PARAM), equalTo("test-version-1")); - assertThat(params.get(StatisticsService.INTERPRETER_PARAM), - equalTo("Java " + System.getProperty("java.version")) - ); + assertThat(params.get(StatisticsService.INTERPRETER_PARAM), equalTo("Java " + System.getProperty("java.version"))); } @Test @@ -147,12 +147,13 @@ public void test_statistics_send_event_no_agent_record() { Map params = event.getParams(); assertThat(params.get(StatisticsService.CLIENT_NAME_PARAM), anyOf(equalTo("${name}"), equalTo("client-java"))); - assertThat(params.get(StatisticsService.CLIENT_VERSION_PARAM).toString(), anyOf(equalTo("${version}"), matchesRegex(SEMANTIC_VERSION_PATTERN))); + assertThat( + params.get(StatisticsService.CLIENT_VERSION_PARAM).toString(), + anyOf(equalTo("${version}"), matchesRegex(SEMANTIC_VERSION_PATTERN)) + ); assertThat(params, not(hasKey(StatisticsService.AGENT_NAME_PARAM))); assertThat(params, not(hasKey(StatisticsService.AGENT_VERSION_PARAM))); - assertThat(params.get(StatisticsService.INTERPRETER_PARAM), - equalTo("Java " + System.getProperty("java.version")) - ); + assertThat(params.get(StatisticsService.INTERPRETER_PARAM), equalTo("Java " + System.getProperty("java.version"))); } @Test @@ -165,8 +166,8 @@ public void test_statistics_send_event_async() { @Test public void verify_service_sends_same_client_id() { - when(httpClient.send(anyString(), anyString(), anyString(), any(StatisticsItem.class))).thenReturn(Maybe.create( - e -> e.onSuccess(Response.success(ResponseBody.create("", MediaType.get("text/plain")))))); + when(httpClient.send(anyString(), anyString(), anyString(), any(StatisticsItem.class))).thenReturn(Maybe.create(e -> e.onSuccess( + Response.success(ResponseBody.create("", MediaType.get("text/plain")))))); String cid; try (StatisticsClient client = new StatisticsClient("id", "secret", httpClient)) { try (StatisticsService service = new StatisticsService(TestUtils.standardParameters(), client)) { @@ -179,8 +180,8 @@ public void verify_service_sends_same_client_id() { cid = item1.getClientId(); } StatisticsApiClient secondClient = mock(StatisticsApiClient.class); - when(secondClient.send(anyString(), anyString(), anyString(), any())).thenReturn(Maybe.create(e -> e.onSuccess( - Response.success(ResponseBody.create("", MediaType.get("text/plain")))))); + when(secondClient.send(anyString(), anyString(), anyString(), any())).thenReturn(Maybe.create(e -> e.onSuccess(Response.success( + ResponseBody.create("", MediaType.get("text/plain")))))); try (StatisticsClient client = new StatisticsClient("id", "secret", secondClient)) { try (StatisticsService service = new StatisticsService(TestUtils.standardParameters(), client)) { @@ -197,16 +198,19 @@ public void verify_service_sends_same_client_id() { } @Test - public void verify_service_sends_same_client_id_for_processes() - throws IOException, InterruptedException { - Process process = ProcessUtils.buildProcess(false, StatisticsIdsRunnable.class); + public void verify_service_sends_same_client_id_for_processes() throws IOException, InterruptedException { + Map homeProperty = Collections.singletonMap( + "user.home", + System.getProperty("user.dir") + File.separator + "same_client_id_test" + ); + Process process = ProcessUtils.buildProcess(false, StatisticsIdsRunnable.class, null, homeProperty); assertThat("Exit code should be '0'", process.waitFor(), equalTo(0)); String result = Utils.readInputStreamToString(process.getInputStream()); process.destroyForcibly(); Map values = Arrays.stream(result.split(System.lineSeparator())) .collect(Collectors.toMap(k -> k.substring(0, k.indexOf("=")), v -> v.substring(v.indexOf("=") + 1))); - Process process2 = ProcessUtils.buildProcess(false, StatisticsIdsRunnable.class); + Process process2 = ProcessUtils.buildProcess(false, StatisticsIdsRunnable.class, null, homeProperty); assertThat("Exit code should be '0'", process2.waitFor(), equalTo(0)); String result2 = Utils.readInputStreamToString(process2.getInputStream()); Map values2 = Arrays.stream(result2.split(System.lineSeparator())) From b346e03b4dac18e7f6f94e24547f2cd826eab379 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 15 Nov 2024 12:34:22 +0300 Subject: [PATCH 9/9] Fix test --- .../reportportal/service/ReportPortalClientJoinTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/epam/reportportal/service/ReportPortalClientJoinTest.java b/src/test/java/com/epam/reportportal/service/ReportPortalClientJoinTest.java index 1c00a75e..cbb7da7f 100644 --- a/src/test/java/com/epam/reportportal/service/ReportPortalClientJoinTest.java +++ b/src/test/java/com/epam/reportportal/service/ReportPortalClientJoinTest.java @@ -252,11 +252,11 @@ private static Maybe standardItemResponse(String id) { } @Test - @SuppressWarnings("ReactiveStreamsUnusedPublisher") + @SuppressWarnings({ "ResultOfMethodCallIgnored" }) public void test_rp_client_sends_correct_start_item_for_secondary_launch() { List launches = createLaunches(2, rpClient, paramSupplier.get(), launchIdLock, executor); - launches.get(0).start(); - launches.get(1).start(); + launches.get(0).start().blockingGet(); + launches.get(1).start().blockingGet(); String itemUuid = UUID.randomUUID().toString(); simulateStartItemResponse(rpClient, itemUuid);