Search in sources :

Example 1 with STestRun

use of jetbrains.buildServer.serverSide.STestRun in project teamcity-rest by JetBrains.

the class TestScopeTreeCollector method getSlicedTreeFromBuildPromotions.

@NotNull
public List<ScopeTree.Node<STestRun, TestCountersData>> getSlicedTreeFromBuildPromotions(@NotNull Stream<BuildPromotion> promotions, @NotNull Locator treeLocator) {
    treeLocator.addSupportedDimensions(NEW_FAILURE, SUBTREE_ROOT_ID);
    final String testRunsLocator = "build:%d,status:failure,muted:false,ignored:false" + (treeLocator.isAnyPresent(NEW_FAILURE) ? ",newFailure:" + treeLocator.getSingleDimensionValue(NEW_FAILURE) : "");
    Stream<STestRun> testRunStream = promotions.filter(promotion -> promotion.getAssociatedBuildId() != null).flatMap(promotion -> myTestOccurrenceFinder.getItems(String.format(testRunsLocator, promotion.getAssociatedBuildId())).myEntries.stream());
    Stream<TestScope> scopeStream = myScopeCollector.groupByClass(testRunStream, new TestScopeFilterImpl(Collections.emptyList(), ""));
    scopeStream = myScopeCollector.splitByBuildType(scopeStream);
    List<TestScope> scopes = scopeStream.collect(Collectors.toList());
    ScopeTree<STestRun, TestCountersData> tree = new ScopeTree<STestRun, TestCountersData>(TestScopeInfo.ROOT, new TestCountersData(), scopes);
    if (treeLocator.isAnyPresent(SUBTREE_ROOT_ID)) {
        String subTreeRootId = treeLocator.getSingleDimensionValue(SUBTREE_ROOT_ID);
        treeLocator.checkLocatorFullyProcessed();
        // noinspection ConstantConditions
        return tree.getFullNodeAndSlicedOrderedSubtree(subTreeRootId, DEFAULT_MAX_CHILDREN, STestRun.NEW_FIRST_NAME_COMPARATOR, SUPPORTED_ORDERS.getComparator(DEFAULT_NODE_ORDER_BY_NEW_FAILED_COUNT));
    }
    treeLocator.checkLocatorFullyProcessed();
    return tree.getSlicedOrderedTree(DEFAULT_MAX_CHILDREN, STestRun.NEW_FIRST_NAME_COMPARATOR, SUPPORTED_ORDERS.getComparator(DEFAULT_NODE_ORDER_BY_NEW_FAILED_COUNT));
}
Also used : LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) java.util(java.util) BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) STestRun(jetbrains.buildServer.serverSide.STestRun) Locator(jetbrains.buildServer.server.rest.data.Locator) Collectors(java.util.stream.Collectors) TestCountersData(jetbrains.buildServer.server.rest.data.problem.TestCountersData) jetbrains.buildServer.server.rest.data.problem.tree(jetbrains.buildServer.server.rest.data.problem.tree) Stream(java.util.stream.Stream) Orders(jetbrains.buildServer.server.rest.data.problem.Orders) TestOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder) NotNull(org.jetbrains.annotations.NotNull) PagerData(jetbrains.buildServer.server.rest.model.PagerData) STestRun(jetbrains.buildServer.serverSide.STestRun) TestCountersData(jetbrains.buildServer.server.rest.data.problem.TestCountersData) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with STestRun

use of jetbrains.buildServer.serverSide.STestRun in project teamcity-rest by JetBrains.

the class TestScopesCollector method getItems.

public Stream<TestScope> getItems(@NotNull Locator locator) {
    locator.addSupportedDimensions(SCOPE_TYPE, TEST_OCCURRENCES, ORDER_BY, PagerData.START, PagerData.COUNT);
    locator.addSupportedDimensions(TestScopeFilterImpl.SUPPORTED_DIMENSIONS);
    String scopeName = locator.getSingleDimensionValue(SCOPE_TYPE);
    if (scopeName == null || !SUPPORTED_SCOPES.contains(scopeName)) {
        throw new BadRequestException("Invalid scope. Only scopes " + String.join(",", SUPPORTED_SCOPES) + " are supported.");
    }
    TestScopeFilter filter = myTestScopeFilterProducer.createFromLocator(locator);
    Locator testOccurrencesLocator = new Locator(locator.getSingleDimensionValue(TEST_OCCURRENCES));
    if (!StringUtil.isEmpty(filter.getLocatorString()))
        testOccurrencesLocator.setDimension(TestOccurrenceFinder.SCOPE, filter.getLocatorString());
    PagedSearchResult<STestRun> items = myTestOccurrenceFinder.getItems(testOccurrencesLocator.getStringRepresentation());
    Stream<TestScope> scopes = groupByScope(items, filter, scopeName);
    if (locator.isAnyPresent(ORDER_BY)) {
        String orderDimension = locator.getSingleDimensionValue(ORDER_BY);
        // noinspection ConstantConditions
        scopes = scopes.sorted(SUPPORTED_ORDERS.getComparator(orderDimension));
    }
    if (locator.isAnyPresent(SPLIT_BY_BUILD_TYPE)) {
        Boolean split = locator.getSingleDimensionValueAsBoolean(SPLIT_BY_BUILD_TYPE);
        if (BooleanUtils.isTrue(split)) {
            scopes = splitByBuildType(scopes);
        }
    }
    return scopes;
}
Also used : Locator(jetbrains.buildServer.server.rest.data.Locator) STestRun(jetbrains.buildServer.serverSide.STestRun) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException)

Example 3 with STestRun

use of jetbrains.buildServer.serverSide.STestRun in project teamcity-rest by JetBrains.

the class TestOccurrence method getInvocations.

@XmlElement
@FieldStrategy(name = "invocations", defaultForShort = FieldRule.EXCLUDE, defaultForLong = FieldRule.EXCLUDE)
public TestOccurrences getInvocations() {
    return ValueWithDefault.decideDefault(myChecker.isIncluded("invocations", myFields), () -> {
        if (!(myTestRun instanceof MultiTestRun))
            return null;
        MultiTestRun multiTestRun = (MultiTestRun) myTestRun;
        Fields nestedField = myFields.getNestedField("invocations");
        PagingItemFilter<STestRun> pagingFilter = myTestOccurrenceFinder.getPagingInvocationsFilter(nestedField);
        FilterItemProcessor<STestRun> processor = new FilterItemProcessor<>(pagingFilter);
        multiTestRun.getTestRuns().forEach(processor::processItem);
        ArrayList<STestRun> filtered = processor.getResult();
        return new TestOccurrences(filtered, null, null, null, nestedField, myBeanContext);
    });
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) STestRun(jetbrains.buildServer.serverSide.STestRun) FilterItemProcessor(jetbrains.buildServer.server.rest.data.FilterItemProcessor) MultiTestRun(jetbrains.buildServer.serverSide.MultiTestRun) FieldStrategy(jetbrains.buildServer.server.rest.util.fieldInclusion.FieldStrategy) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 4 with STestRun

use of jetbrains.buildServer.serverSide.STestRun in project teamcity-rest by JetBrains.

the class TestScopes method getTestCounters.

@XmlElement(name = "testCounters")
public TestCounters getTestCounters() {
    return ValueWithDefault.decideDefault(myFields.isIncluded("testCounters"), () -> {
        Fields testCounters = myFields.getNestedField("testCounters");
        List<STestRun> runs = myTestScopes.stream().flatMap(scope -> scope.getTestRuns().stream()).collect(Collectors.toList());
        // Will just calculate all counters for simplicity
        TestCountersData data = new TestCountersData(runs);
        return new TestCounters(testCounters, data);
    });
}
Also used : XmlAttribute(javax.xml.bind.annotation.XmlAttribute) Fields(jetbrains.buildServer.server.rest.model.Fields) STestRun(jetbrains.buildServer.serverSide.STestRun) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) ValueWithDefault(jetbrains.buildServer.server.rest.util.ValueWithDefault) Collectors(java.util.stream.Collectors) TestCounters(jetbrains.buildServer.server.rest.model.problem.TestCounters) TestCountersData(jetbrains.buildServer.server.rest.data.problem.TestCountersData) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) XmlType(javax.xml.bind.annotation.XmlType) UriInfo(javax.ws.rs.core.UriInfo) ModelBaseType(jetbrains.buildServer.server.rest.swagger.annotations.ModelBaseType) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) ObjectType(jetbrains.buildServer.server.rest.swagger.constants.ObjectType) XmlElement(javax.xml.bind.annotation.XmlElement) PagerData(jetbrains.buildServer.server.rest.model.PagerData) Fields(jetbrains.buildServer.server.rest.model.Fields) STestRun(jetbrains.buildServer.serverSide.STestRun) TestCountersData(jetbrains.buildServer.server.rest.data.problem.TestCountersData) TestCounters(jetbrains.buildServer.server.rest.model.problem.TestCounters) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 5 with STestRun

use of jetbrains.buildServer.serverSide.STestRun 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

STestRun (jetbrains.buildServer.serverSide.STestRun)5 Fields (jetbrains.buildServer.server.rest.model.Fields)3 PagerData (jetbrains.buildServer.server.rest.model.PagerData)3 Collectors (java.util.stream.Collectors)2 XmlElement (javax.xml.bind.annotation.XmlElement)2 Locator (jetbrains.buildServer.server.rest.data.Locator)2 TestCountersData (jetbrains.buildServer.server.rest.data.problem.TestCountersData)2 NotNull (org.jetbrains.annotations.NotNull)2 ApiOperation (io.swagger.annotations.ApiOperation)1 java.util (java.util)1 List (java.util.List)1 Stream (java.util.stream.Stream)1 UriInfo (javax.ws.rs.core.UriInfo)1 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)1 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)1 XmlType (javax.xml.bind.annotation.XmlType)1 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 FilterItemProcessor (jetbrains.buildServer.server.rest.data.FilterItemProcessor)1 Orders (jetbrains.buildServer.server.rest.data.problem.Orders)1 TestOccurrenceFinder (jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder)1