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));
}
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;
}
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);
});
}
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);
});
}
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);
}
Aggregations