Search in sources :

Example 1 with TestOccurrencesCachedInfo

use of jetbrains.buildServer.server.rest.data.problem.TestOccurrencesCachedInfo in project teamcity-rest by JetBrains.

the class TestOccurrenceRequest method getTestOccurrences.

/**
 * Experimental, the requests and results returned will change in future versions!
 *
 * @param locatorText
 * @param uriInfo
 * @param request
 * @return
 */
@GET
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get all test occurrences.", nickname = "getAllTestOccurrences")
public TestOccurrences getTestOccurrences(@ApiParam(format = LocatorName.TEST_OCCURRENCE) @QueryParam("locator") String locatorText, @QueryParam("fields") String fields, @Context UriInfo uriInfo, @Context HttpServletRequest request) {
    TestOccurrencesCachedInfo info = myTestOccurrenceFinder.tryGetCachedInfo(locatorText, fields);
    if (info.getShortStatistics() != null) {
        if (info.filteringRequired()) {
            // We need a locator as getLocator(String) calls locator.isFullyProcessed() which breaks everything
            Locator locator1 = Locator.createPotentiallyEmptyLocator(locatorText);
            // Due to reasons, in composite builds MultiTestRun.getBuild() will return different build than specified in the locator.
            // At the time of writing this, the returned build will be one of the non-composite snapshot dependencies.
            // We are okay with it as we account for a BUILD dimension when retrieving short statistics in the first place.
            // However, let's skip filtering as it will filter out legitimate results.
            locator1.markUsed(Collections.singleton(TestOccurrenceFinder.BUILD));
            ItemFilter<STestRun> filter = myTestOccurrenceFinder.getFilter(locator1);
            PagingItemFilter<STestRun> pagingFilter = myTestOccurrenceFinder.getPagingFilter(locator1, filter);
            FilterItemProcessor<STestRun> processor = new FilterItemProcessor<>(pagingFilter);
            info.getShortStatistics().getFailedTestsIncludingMuted().forEach(processor::processItem);
            PagedSearchResult<STestRun> pagedResult = new PagedSearchResult<>(processor.getResult(), pagingFilter.getStart(), pagingFilter.getCount(), processor.getProcessedItemsCount(), pagingFilter.getLookupLimit(), pagingFilter.isLookupLimitReached(), pagingFilter.getLastProcessedItem());
            return new TestOccurrences(pagedResult.myEntries, null, uriInfo == null ? null : uriInfo.getRequestUri().toString(), uriInfo == null ? null : new PagerData(uriInfo.getRequestUriBuilder(), request.getContextPath(), pagedResult, locatorText, "locator"), new Fields(fields), myBeanContext);
        }
        return new TestOccurrences(null, info.getShortStatistics(), null, null, new Fields(fields), myBeanContext);
    }
    final PagedSearchResult<STestRun> result = myTestOccurrenceFinder.getItems(locatorText);
    return new TestOccurrences(result.myEntries, null, uriInfo == null ? null : uriInfo.getRequestUri().toString(), uriInfo == null ? null : new PagerData(uriInfo.getRequestUriBuilder(), request.getContextPath(), result, locatorText, "locator"), new Fields(fields), myBeanContext);
}
Also used : TestOccurrencesCachedInfo(jetbrains.buildServer.server.rest.data.problem.TestOccurrencesCachedInfo) ServiceLocator(jetbrains.buildServer.ServiceLocator) Fields(jetbrains.buildServer.server.rest.model.Fields) TestOccurrences(jetbrains.buildServer.server.rest.model.problem.TestOccurrences) STestRun(jetbrains.buildServer.serverSide.STestRun) PagerData(jetbrains.buildServer.server.rest.model.PagerData) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 TestOccurrencesCachedInfo (jetbrains.buildServer.server.rest.data.problem.TestOccurrencesCachedInfo)1 Fields (jetbrains.buildServer.server.rest.model.Fields)1 PagerData (jetbrains.buildServer.server.rest.model.PagerData)1 TestOccurrences (jetbrains.buildServer.server.rest.model.problem.TestOccurrences)1 STestRun (jetbrains.buildServer.serverSide.STestRun)1