use of jetbrains.buildServer.server.rest.model.Fields in project teamcity-rest by JetBrains.
the class TestOccurrenceFinder method tryGetCachedInfo.
/**
* Checks whether response can be built only using ShortStatistics without fetching test occurrences given locator and fields. If so, get this statistics.
* In addition, check if test runs in a returned statistics require filtering.
* @return ShortStatistics with a post filtering flag if there is enough data to produce the response, TestOccurrencesCachedInfo.empty() otherwise.
*/
@NotNull
public TestOccurrencesCachedInfo tryGetCachedInfo(@Nullable final String locatorText, @Nullable final String fieldsText) {
if (locatorText == null || fieldsText == null)
return TestOccurrencesCachedInfo.empty();
Locator locator = Locator.locator(locatorText);
Fields fields = new Fields(fieldsText);
boolean postFilteringRequired = false;
boolean needsActualOccurrence = fields.isIncluded("testOccurrence", false, false);
if (needsActualOccurrence) {
Status status = Util.resolveNull(locator.lookupSingleDimensionValue(STATUS), TestOccurrence::getStatusFromPosted);
if (status == null || status != Status.FAILURE) {
return TestOccurrencesCachedInfo.empty();
}
Fields occurrenceFields = fields.getNestedField("testOccurrence");
FieldInclusionChecker checker = FieldInclusionChecker.getForClass(TestOccurrence.class);
if (!FASTPATH_ALLOWED_FIELDS.containsAll(checker.getAllPotentiallyIncludedFields(occurrenceFields))) {
return TestOccurrencesCachedInfo.empty();
}
// let's just do it always if we need items
postFilteringRequired = true;
}
String buildDimension = locator.getSingleDimensionValue(BUILD);
if (buildDimension == null)
return TestOccurrencesCachedInfo.empty();
if (locator.getSingleDimensionValueAsStrictBoolean(EXPAND_INVOCATIONS, false)) {
// Expand invocations requires additional logic
return TestOccurrencesCachedInfo.empty();
}
List<BuildPromotion> buildPromotions = myBuildFinder.getBuilds(null, buildDimension).myEntries;
if (buildPromotions.size() != 1) {
// If there is not a single build to the criteria,
return TestOccurrencesCachedInfo.empty();
}
SBuild build = buildPromotions.get(0).getAssociatedBuild();
if (build == null)
return TestOccurrencesCachedInfo.empty();
// let's not construct a filter if we already know that we want to filter anyways
if (!postFilteringRequired) {
// If any kind of filter is defined then post filtering is necessary
MultiCheckerFilter<STestRun> filter = (MultiCheckerFilter<STestRun>) getFilter(locator);
// Personal builds filter is always there
postFilteringRequired = filter.getSubFiltersCount() > 1;
}
return new TestOccurrencesCachedInfo(build.getShortStatistics(), postFilteringRequired);
}
use of jetbrains.buildServer.server.rest.model.Fields in project teamcity-rest by JetBrains.
the class TestOccurrenceFieldsTest method testAll.
@Test
public void testAll() {
Fields defaults = Fields.ALL;
Set<String> result = myChecker.getAllPotentiallyIncludedFields(defaults);
checkSame(Arrays.asList("id", "name", "status", "ignored", "duration", "runOrder", "newFailure", "muted", "currentlyMuted", "currentlyInvestigated", "href", "ignoreDetails", "details", "test", "mute", "build", "firstFailed", "nextFixed", "invocations", "metadata", "logAnchor"), result);
}
use of jetbrains.buildServer.server.rest.model.Fields in project teamcity-rest by JetBrains.
the class TestOccurrenceFieldsTest method testShort.
@Test
public void testShort() {
Fields defaults = new Fields("$short");
Set<String> result = myChecker.getAllPotentiallyIncludedFields(defaults);
checkSame(Arrays.asList("id", "name", "status", "ignored", "duration", "muted", "currentlyMuted", "currentlyInvestigated", "href"), result);
}
use of jetbrains.buildServer.server.rest.model.Fields in project teamcity-rest by JetBrains.
the class ProjectRequestTest method memoryTest.
// @Test
public void memoryTest() throws InterruptedException {
final ProjectRequest request = new ProjectRequest();
request.setInTests(myProjectFinder, myBranchFinder, myBeanContext);
final String locator = "archived:false,affectedProject:_Root";
final String fields = "count,project(id,internalId,name,parentProjectId,archived,readOnlyUI,buildTypes(buildType(id,paused,internalId,projectId,name,type,description)),description)";
Queue<Pair<Integer, ProjectEx>> q = new ArrayDeque<>();
q.add(new Pair<>(0, myProject));
final int max = 2;
final int children = 4;
int counter = 0;
while (!q.isEmpty()) {
Pair<Integer, ProjectEx> p = q.poll();
String prefix = "Bt" + StringUtils.repeat('a', 10 * p.getFirst());
for (int i = 0; i < children; i++) {
ProjectEx c = myFixture.createProject("z-" + p.first + "-" + counter++, p.second);
if (p.first < max) {
q.add(new Pair<>(p.first + 1, c));
}
for (int j = 0; j < children * 4; j++) c.createBuildType(prefix + j);
}
}
System.out.println(counter + " projects created.");
Thread[] ts = new Thread[100];
for (int i = 0; i < ts.length; i++) {
final int threadIdx = i;
ts[i] = new Thread(() -> {
new RestContext(z -> null).run(() -> {
for (int j = 0; j < 100; j++) {
final PagedSearchResult<SProject> result = myProjectFinder.getItems(locator);
Projects projects = new Projects(result.myEntries, null, new Fields(fields), myBeanContext);
projects.projects.stream().flatMap(p -> p.buildTypes.buildTypes.stream()).forEach(bt -> {
bt.getId();
bt.isPaused();
bt.getInternalId();
bt.getProjectId();
bt.getName();
bt.getType();
bt.getDescription();
});
System.out.println(String.format("Finished %d requests in thread %d", j, threadIdx));
}
return null;
});
});
ts[i].start();
}
for (Thread t : ts) t.join();
}
use of jetbrains.buildServer.server.rest.model.Fields 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);
});
}
Aggregations