Search in sources :

Example 1 with Fields

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);
}
Also used : Status(jetbrains.buildServer.messages.Status) TestOccurrence(jetbrains.buildServer.server.rest.model.problem.TestOccurrence) Fields(jetbrains.buildServer.server.rest.model.Fields) FieldInclusionChecker(jetbrains.buildServer.server.rest.util.fieldInclusion.FieldInclusionChecker) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Fields

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);
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) Test(org.testng.annotations.Test)

Example 3 with Fields

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);
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) Test(org.testng.annotations.Test)

Example 4 with Fields

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();
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) java.util(java.util) Test(org.testng.annotations.Test) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) SProjectFeatureDescriptor(jetbrains.buildServer.serverSide.SProjectFeatureDescriptor) StringUtils(org.apache.commons.lang3.StringUtils) Branch(jetbrains.buildServer.server.rest.model.build.Branch) Projects(jetbrains.buildServer.server.rest.model.project.Projects) Option(jetbrains.buildServer.util.Option) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) RestContext(jetbrains.buildServer.server.rest.data.RestContext) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) ProjectFeatureDescriptorFactory(jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory) MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) OperationRequestor(jetbrains.buildServer.vcs.OperationRequestor) BuildFinderTestBase(jetbrains.buildServer.server.rest.data.BuildFinderTestBase) Branches(jetbrains.buildServer.server.rest.model.build.Branches) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) BeforeMethod(org.testng.annotations.BeforeMethod) RepositoryStateData.createVersionState(jetbrains.buildServer.vcs.RepositoryStateData.createVersionState) Util.map(jetbrains.buildServer.util.Util.map) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTypeEx(jetbrains.buildServer.serverSide.BuildTypeEx) Pair(com.intellij.openapi.util.Pair) SProject(jetbrains.buildServer.serverSide.SProject) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) Projects(jetbrains.buildServer.server.rest.model.project.Projects) RestContext(jetbrains.buildServer.server.rest.data.RestContext) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Fields(jetbrains.buildServer.server.rest.model.Fields) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) Pair(com.intellij.openapi.util.Pair)

Example 5 with Fields

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

Aggregations

Fields (jetbrains.buildServer.server.rest.model.Fields)90 ApiOperation (io.swagger.annotations.ApiOperation)66 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)17 PagerData (jetbrains.buildServer.server.rest.model.PagerData)17 Test (org.testng.annotations.Test)13 ServiceLocator (jetbrains.buildServer.ServiceLocator)12 SUser (jetbrains.buildServer.users.SUser)10 NotNull (org.jetbrains.annotations.NotNull)10 SBuildAgent (jetbrains.buildServer.serverSide.SBuildAgent)9 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)8 ChangeStatus (jetbrains.buildServer.vcs.ChangeStatus)8 ChangeStatusProvider (jetbrains.buildServer.vcs.ChangeStatusProvider)8 SVcsModification (jetbrains.buildServer.vcs.SVcsModification)8 Locator (jetbrains.buildServer.server.rest.data.Locator)7 BuildType (jetbrains.buildServer.server.rest.model.buildType.BuildType)7 BeanContext (jetbrains.buildServer.server.rest.util.BeanContext)6 BuildPromotion (jetbrains.buildServer.serverSide.BuildPromotion)6 List (java.util.List)5 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)5 Collectors (java.util.stream.Collectors)4