Class LaunchImpl

  • Direct Known Subclasses:
    AbstractJoinedLaunch

    public class LaunchImpl
    extends Launch
    Asynchronous Launch object implementation, which uses reactive framework to handle launch events. It accepts and returns promises of items' IDs and launch ID, and handle actual requests to ReportPortal under the hood.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void completeIssues​(Issue issue)
      Lookup for the Issue Type locator in project settings and fill missed external issue fields based on properties.
      protected void completeLogEmitter()
      Finalizes the batched log emitter ensuring the last batch is sent before completing.
      protected io.reactivex.Scheduler createScheduler​(java.util.concurrent.ExecutorService executorService)
      Creates or reuses an RxJava Scheduler backed by the provided executor.
      io.reactivex.Maybe<java.lang.String> createVirtualItem()
      Creates a virtual test item in ReportPortal.
      protected io.reactivex.Completable createVirtualItemCompletable()
      Creates a Completable that polls for completion of all virtual items.
      void finish​(FinishExecutionRQ request)
      Finishes launch in ReportPortal.
      io.reactivex.Maybe<OperationCompletionRS> finishTestItem​(io.reactivex.Maybe<java.lang.String> item, FinishTestItemRQ request)
      Finishes Test Item in ReportPortal asynchronously (non-blocking).
      java.util.concurrent.ExecutorService getExecutor()
      Returns a current executor which is used to process launch events such as requests and responses.
      io.reactivex.Maybe<java.lang.String> getLaunch()
      Returns current launch UUID promise as Maybe, empty if the launch is not started.
      io.reactivex.Scheduler getScheduler()
      Returns a current Scheduler which is used to process launch events such as requests and responses.
      void log​(SaveLogRQ rq)
      Logs message to the ReportPortal Launch.
      void log​(io.reactivex.Maybe<java.lang.String> logItemUuid, java.util.function.Function<java.lang.String,​SaveLogRQ> logSupplier)
      Logs message to the ReportPortal Launch.
      void log​(java.util.function.Function<java.lang.String,​SaveLogRQ> logSupplier)
      Logs message to the ReportPortal Launch.
      io.reactivex.Maybe<java.lang.String> start()
      Starts new launch in ReportPortal asynchronously (non-blocking).
      protected io.reactivex.Maybe<java.lang.String> start​(boolean statistics)
      Starts the launch asynchronously on first subscription.
      io.reactivex.Maybe<java.lang.String> startTestItem​(StartTestItemRQ request)
      Starts new root test item in ReportPortal asynchronously (non-blocking).
      io.reactivex.Maybe<java.lang.String> startTestItem​(io.reactivex.Maybe<java.lang.String> parentId, StartTestItemRQ request)
      Starts new test item in ReportPortal asynchronously (non-blocking).
      io.reactivex.Maybe<java.lang.String> startTestItem​(io.reactivex.Maybe<java.lang.String> parentId, io.reactivex.Maybe<java.lang.String> retryOf, StartTestItemRQ rq)
      Starts new test item in ReportPortal asynchronously (non-blocking), ensure provided retry item ID starts first.
      io.reactivex.Maybe<java.lang.String> startVirtualTestItem​(io.reactivex.Maybe<java.lang.String> virtualItem, StartTestItemRQ rq)
      Starts new test item in ReportPortal asynchronously (non-blocking) and populates the provided virtual item with the real item ID.
      io.reactivex.Maybe<java.lang.String> startVirtualTestItem​(io.reactivex.Maybe<java.lang.String> parentId, io.reactivex.Maybe<java.lang.String> virtualItem, StartTestItemRQ rq)
      Starts new test item in ReportPortal asynchronously (non-blocking) and populates the provided virtual item with the real item ID.
      boolean useMicroseconds()
      Determines whether timestamps should use microsecond precision based on the ReportPortal server version.
      protected void waitForCompletable​(io.reactivex.Completable... completableTasks)
      Executes completion tasks with a timeout.
      protected void waitForItemsCompletion​(io.reactivex.Completable itemCompletable)
      Waits for completion of all test items including virtual ones and log emitters.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DISABLE_PROPERTY

        public static final java.lang.String DISABLE_PROPERTY
        Environment variable name to disable analytics
        See Also:
        Constant Field Values
      • MICROSECONDS_MIN_VERSION

        public static final java.lang.String MICROSECONDS_MIN_VERSION
        See Also:
        Constant Field Values
      • CUSTOM_AGENT

        public static final java.lang.String CUSTOM_AGENT
        Default Agent name for cases where real name is not known.
        See Also:
        Constant Field Values
      • virtualItems

        protected final java.util.Map<io.reactivex.Maybe<java.lang.String>,​io.reactivex.subjects.PublishSubject<java.lang.String>> virtualItems
        Mapping between virtual item Maybes and their emitters
      • virtualItemDisposables

        protected final java.util.Queue<io.reactivex.disposables.Disposable> virtualItemDisposables
        Collection of disposables from virtual item subscriptions
      • logCompletables

        protected final java.util.Queue<io.reactivex.Completable> logCompletables
      • apiInfo

        protected final io.reactivex.Maybe<ApiInfo> apiInfo
    • Constructor Detail

      • LaunchImpl

        protected LaunchImpl​(@Nonnull
                             ReportPortalClient reportPortalClient,
                             @Nonnull
                             ListenerParameters parameters,
                             @Nonnull
                             StartLaunchRQ rq,
                             @Nonnull
                             java.util.concurrent.ExecutorService executorService,
                             @Nonnull
                             LoggingSubscriber loggingSubscriber)
        Constructs a LaunchImpl that starts a new launch on first use and configures a batched log emitter.
        Parameters:
        reportPortalClient - the client used to communicate with ReportPortal
        parameters - the agent listener parameters
        rq - launch start request used to initialize the launch
        executorService - executor used to schedule reactive operations
        loggingSubscriber - subscriber which receives batched log upload results
        Throws:
        InternalReportPortalClientException - if the provided executor is already shut down
      • LaunchImpl

        protected LaunchImpl​(@Nonnull
                             ReportPortalClient reportPortalClient,
                             @Nonnull
                             ListenerParameters parameters,
                             @Nonnull
                             StartLaunchRQ rq,
                             @Nonnull
                             java.util.concurrent.ExecutorService executorService)
        Convenience constructor which uses a default LoggingSubscriber for batched log uploads.
        Parameters:
        reportPortalClient - the client used to communicate with ReportPortal
        parameters - the agent listener parameters
        rq - launch start request used to initialize the launch
        executorService - executor used to schedule reactive operations
      • LaunchImpl

        protected LaunchImpl​(@Nonnull
                             ReportPortalClient reportPortalClient,
                             @Nonnull
                             ListenerParameters parameters,
                             @Nonnull
                             io.reactivex.Maybe<java.lang.String> launchMaybe,
                             @Nonnull
                             java.util.concurrent.ExecutorService executorService)
        Constructs a LaunchImpl using an already created launch ID promise. No new launch will be started by this instance.
        Parameters:
        reportPortalClient - the client used to communicate with ReportPortal
        parameters - the agent listener parameters
        launchMaybe - an existing launch ID promise to be used by this instance
        executorService - executor used to schedule reactive operations
        Throws:
        InternalReportPortalClientException - if the provided executor is already shut down
    • Method Detail

      • createScheduler

        protected io.reactivex.Scheduler createScheduler​(java.util.concurrent.ExecutorService executorService)
        Creates or reuses an RxJava Scheduler backed by the provided executor. Ensures a single scheduler per executor instance.
        Parameters:
        executorService - the executor to back the scheduler
        Returns:
        a scheduler mapped to the provided executor
      • useMicroseconds

        public boolean useMicroseconds()
        Determines whether timestamps should use microsecond precision based on the ReportPortal server version. Versions greater than or equal to 5.13.2 support microseconds.

        The value is computed once and cached for subsequent calls.

        Specified by:
        useMicroseconds in class Launch
        Returns:
        true if server version greater or equal 5.13.2, otherwise false
      • getExecutor

        public java.util.concurrent.ExecutorService getExecutor()
        Returns a current executor which is used to process launch events such as requests and responses.
        Returns:
        an ExecutorService
      • getScheduler

        public io.reactivex.Scheduler getScheduler()
        Returns a current Scheduler which is used to process launch events such as requests and responses.
        Returns:
        an Scheduler
      • getLaunch

        @Nonnull
        public io.reactivex.Maybe<java.lang.String> getLaunch()
        Returns current launch UUID promise as Maybe, empty if the launch is not started.
        Specified by:
        getLaunch in class Launch
        Returns:
        Launch UUID promise.
      • start

        @Nonnull
        protected io.reactivex.Maybe<java.lang.String> start​(boolean statistics)
        Starts the launch asynchronously on first subscription. Subsequent calls do not start the launch again due to internal caching.
        Parameters:
        statistics - whether to send analytics events for the launch
        Returns:
        a Maybe that emits the launch UUID once available
      • start

        @Nonnull
        public io.reactivex.Maybe<java.lang.String> start()
        Starts new launch in ReportPortal asynchronously (non-blocking). Does NOT start the same launch twice.
        Specified by:
        start in class Launch
        Returns:
        Launch ID promise.
      • createVirtualItemCompletable

        protected io.reactivex.Completable createVirtualItemCompletable()
        Creates a Completable that polls for completion of all virtual items. This method recursively checks if all virtual items have been populated with real IDs. If there are still virtual items pending, it schedules another check after a 100ms delay. When all virtual items are processed (the virtualItems map is empty), it completes.
        Returns:
        A Completable that completes when all virtual items are processed
      • waitForCompletable

        protected void waitForCompletable​(io.reactivex.Completable... completableTasks)
        Executes completion tasks with a timeout.
        Parameters:
        completableTasks - Completable tasks to execute
      • waitForItemsCompletion

        protected void waitForItemsCompletion​(@Nullable
                                              io.reactivex.Completable itemCompletable)
        Waits for completion of all test items including virtual ones and log emitters. This method ensures all test results are properly reported to ReportPortal before the launch completes. It uses the timeout defined in the parameters to prevent indefinite waiting.
        Parameters:
        itemCompletable - A completable representing the test items to be completed before finishing the launch
      • completeLogEmitter

        protected void completeLogEmitter()
        Finalizes the batched log emitter ensuring the last batch is sent before completing. Blocks within the configured reporting timeout while waiting for the final batch to be processed.
      • finish

        public void finish​(@Nonnull
                           FinishExecutionRQ request)
        Finishes launch in ReportPortal. Blocks until all items are reported correctly.
        Specified by:
        finish in class Launch
        Parameters:
        request - Launch finish request.
      • startTestItem

        @Nonnull
        public io.reactivex.Maybe<java.lang.String> startTestItem​(StartTestItemRQ request)
        Starts new root test item in ReportPortal asynchronously (non-blocking).
        Specified by:
        startTestItem in class Launch
        Parameters:
        request - Item start request.
        Returns:
        Test Item ID promise.
      • startTestItem

        @Nonnull
        public io.reactivex.Maybe<java.lang.String> startTestItem​(io.reactivex.Maybe<java.lang.String> parentId,
                                                                  StartTestItemRQ request)
        Starts new test item in ReportPortal asynchronously (non-blocking).
        Specified by:
        startTestItem in class Launch
        Parameters:
        parentId - Promise of parent item ID.
        request - Item start request.
        Returns:
        Test Item ID promise
      • startTestItem

        @Nonnull
        public io.reactivex.Maybe<java.lang.String> startTestItem​(io.reactivex.Maybe<java.lang.String> parentId,
                                                                  io.reactivex.Maybe<java.lang.String> retryOf,
                                                                  StartTestItemRQ rq)
        Starts new test item in ReportPortal asynchronously (non-blocking), ensure provided retry item ID starts first. Also sets flags retry: true and retryOf: {retryOf argument value}.
        Specified by:
        startTestItem in class Launch
        Parameters:
        parentId - Promise of parent item ID.
        retryOf - Previous item ID promise, which is retried.
        rq - Item start request.
        Returns:
        Promise of Test Item ID.
      • createVirtualItem

        @Nonnull
        public io.reactivex.Maybe<java.lang.String> createVirtualItem()
        Creates a virtual test item in ReportPortal. Virtual items are used as temporary placeholders until they are populated with real item IDs. This is useful for scenarios where item creation order needs to be decoupled from test execution order.
        Specified by:
        createVirtualItem in class Launch
        Returns:
        Virtual test item ID promise that will be populated with a real ID later
      • startVirtualTestItem

        @Nonnull
        public io.reactivex.Maybe<java.lang.String> startVirtualTestItem​(io.reactivex.Maybe<java.lang.String> virtualItem,
                                                                         StartTestItemRQ rq)
        Starts new test item in ReportPortal asynchronously (non-blocking) and populates the provided virtual item with the real item ID.
        Specified by:
        startVirtualTestItem in class Launch
        Parameters:
        virtualItem - Virtual item ID promise to populate with real ID.
        rq - Item start rq.
        Returns:
        Real Test Item ID promise.
      • startVirtualTestItem

        @Nonnull
        public io.reactivex.Maybe<java.lang.String> startVirtualTestItem​(io.reactivex.Maybe<java.lang.String> parentId,
                                                                         io.reactivex.Maybe<java.lang.String> virtualItem,
                                                                         StartTestItemRQ rq)
        Starts new test item in ReportPortal asynchronously (non-blocking) and populates the provided virtual item with the real item ID.
        Specified by:
        startVirtualTestItem in class Launch
        Parameters:
        parentId - Promise of parent item ID.
        virtualItem - Virtual item ID promise to populate with real ID.
        rq - Item start request.
        Returns:
        Real Test Item ID promise.
      • completeIssues

        protected void completeIssues​(@Nonnull
                                      Issue issue)
        Lookup for the Issue Type locator in project settings and fill missed external issue fields based on properties.
        Parameters:
        issue - Issue to complete
      • finishTestItem

        @Nonnull
        public io.reactivex.Maybe<OperationCompletionRS> finishTestItem​(io.reactivex.Maybe<java.lang.String> item,
                                                                        FinishTestItemRQ request)
        Finishes Test Item in ReportPortal asynchronously (non-blocking). Schedules finish after success of all child items.
        Specified by:
        finishTestItem in class Launch
        Parameters:
        item - Item ID promise.
        request - Item finish request.
        Returns:
        Promise of Test Item finish response.
      • log

        public void log​(@Nonnull
                        SaveLogRQ rq)
        Logs message to the ReportPortal Launch.
        Specified by:
        log in class Launch
        Parameters:
        rq - Log request.
      • log

        public void log​(@Nonnull
                        java.util.function.Function<java.lang.String,​SaveLogRQ> logSupplier)
        Logs message to the ReportPortal Launch.
        Specified by:
        log in class Launch
        Parameters:
        logSupplier - Log Message Factory. Argument of the function will be actual launch UUID.
      • log

        public void log​(@Nonnull
                        io.reactivex.Maybe<java.lang.String> logItemUuid,
                        @Nonnull
                        java.util.function.Function<java.lang.String,​SaveLogRQ> logSupplier)
        Logs message to the ReportPortal Launch.
        Specified by:
        log in class Launch
        Parameters:
        logItemUuid - Test Item ID promise
        logSupplier - Log Message Factory. Argument of the function will be actual launch UUID.