Search in sources :

Example 1 with PagedSearchResult

use of jetbrains.buildServer.server.rest.data.PagedSearchResult 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 2 with PagedSearchResult

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

the class ChangeRequest method getUniqueCommiters.

/**
 * Experimental support only!
 * @since 2021.1.1
 */
@GET
@Path("/{changeLocator}/commiters")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get unique commiters of the matching changes.", nickname = "getUniqueCommiters", hidden = true)
public Commiters getUniqueCommiters(@ApiParam(format = LocatorName.CHANGE) @PathParam("changeLocator") String changeLocator, @QueryParam("fields") String fields) {
    Locator patchedChangeLocator = Locator.createPotentiallyEmptyLocator(changeLocator);
    if (!patchedChangeLocator.isAnyPresent(PagerData.COUNT)) {
        String lookupLimit = TeamCityProperties.getProperty("rest.request.changes.committersLookupLimit", DEFAULT_CHANGES_LOOKUP_LIMIT_FOR_COMMITERS);
        patchedChangeLocator.setDimension(PagerData.COUNT, lookupLimit);
    }
    PagedSearchResult<SVcsModificationOrChangeDescriptor> changes = myChangeFinder.getItems(patchedChangeLocator.getStringRepresentation());
    List<CommiterData> commiters = ChangeUtil.getUniqueCommiters(changes.myEntries.stream().map(modOrDesc -> modOrDesc.getSVcsModification()));
    return new Commiters(commiters, new Fields(fields), myBeanContext);
}
Also used : CommiterData(jetbrains.buildServer.server.rest.data.change.CommiterData) Fields(jetbrains.buildServer.server.rest.model.Fields) Items(jetbrains.buildServer.server.rest.model.Items) BuildTypeFinder(jetbrains.buildServer.server.rest.data.BuildTypeFinder) BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) LocatorName(jetbrains.buildServer.server.rest.swagger.constants.LocatorName) Issues(jetbrains.buildServer.server.rest.model.issue.Issues) ApiParam(io.swagger.annotations.ApiParam) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) ArrayList(java.util.ArrayList) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ApiOperation(io.swagger.annotations.ApiOperation) ChangeStatusProvider(jetbrains.buildServer.vcs.ChangeStatusProvider) HttpServletRequest(javax.servlet.http.HttpServletRequest) CommiterData(jetbrains.buildServer.server.rest.data.change.CommiterData) TestScopeTreeCollector(jetbrains.buildServer.server.rest.data.problem.scope.TestScopeTreeCollector) ChangeFinder(jetbrains.buildServer.server.rest.data.ChangeFinder) UriBuilder(javax.ws.rs.core.UriBuilder) Api(io.swagger.annotations.Api) ProblemOccurrencesTree(jetbrains.buildServer.server.rest.model.problem.scope.ProblemOccurrencesTree) SBuildType(jetbrains.buildServer.serverSide.SBuildType) ChangeStatus(jetbrains.buildServer.vcs.ChangeStatus) PagerData(jetbrains.buildServer.server.rest.model.PagerData) TestScopeTree(jetbrains.buildServer.server.rest.model.problem.scope.TestScopeTree) TeamCityProperties(jetbrains.buildServer.serverSide.TeamCityProperties) Context(javax.ws.rs.core.Context) ServiceLocator(jetbrains.buildServer.ServiceLocator) ProblemOccurrencesTreeCollector(jetbrains.buildServer.server.rest.data.problem.scope.ProblemOccurrencesTreeCollector) StringUtil(com.intellij.openapi.util.text.StringUtil) Builds(jetbrains.buildServer.server.rest.model.build.Builds) ApiUrlBuilder(jetbrains.buildServer.server.rest.ApiUrlBuilder) Locator(jetbrains.buildServer.server.rest.data.Locator) Collectors(java.util.stream.Collectors) BeanFactory(jetbrains.buildServer.server.rest.util.BeanFactory) ChangeUtil(jetbrains.buildServer.server.rest.data.change.ChangeUtil) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Stream(java.util.stream.Stream) javax.ws.rs(javax.ws.rs) jetbrains.buildServer.server.rest.model.change(jetbrains.buildServer.server.rest.model.change) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) BuildTypes(jetbrains.buildServer.server.rest.model.buildType.BuildTypes) Entries(jetbrains.buildServer.server.rest.model.Entries) UriInfo(javax.ws.rs.core.UriInfo) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) SVcsModification(jetbrains.buildServer.vcs.SVcsModification) ServiceLocator(jetbrains.buildServer.ServiceLocator) Locator(jetbrains.buildServer.server.rest.data.Locator) Fields(jetbrains.buildServer.server.rest.model.Fields) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with PagedSearchResult

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

the class PagerDataTest method testSpecialSymbols.

@Test
public void testSpecialSymbols() throws URISyntaxException {
    List<String> items = new ArrayList<String>();
    PagedSearchResult<String> pagedResult = new PagedSearchResult<>(items, 5L, 3, null, 10L, true, null);
    UriBuilder uriBuilder = UriBuilder.fromUri(new URI("http://some.url:8111/teamcity/smth?locator=start:5,count:3,a:%25"));
    final PagerData pagerData = new PagerData(uriBuilder, "/teamcity", pagedResult, "start:5,count:3,a:(eight-[{~!@#$%^&*_+`=\\|'\";:/?,<.>]})", "locator");
    assertEquals("href is different", "/smth?locator=start:5,count:3,a:%25", pagerData.getHref());
    assertEquals("nextHref is different", (Object) "/smth?locator=a:(eight-%5B%7B%7E%21%40%23$%25%5E%26*_%2B%60%3D%5C%7C%27%22%3B:%2F%3F,%3C.%3E%5D%7D),count:3,lookupLimit:20,start:5", pagerData.getNextHref());
    assertEquals("prevHref is different", (Object) "/smth?locator=a:(eight-%5B%7B%7E%21%40%23$%25%5E%26*_%2B%60%3D%5C%7C%27%22%3B:%2F%3F,%3C.%3E%5D%7D),count:3,start:2", pagerData.getPrevHref());
}
Also used : ArrayList(java.util.ArrayList) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

PagedSearchResult (jetbrains.buildServer.server.rest.data.PagedSearchResult)3 ArrayList (java.util.ArrayList)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 Fields (jetbrains.buildServer.server.rest.model.Fields)2 BeanContext (jetbrains.buildServer.server.rest.util.BeanContext)2 Pair (com.intellij.openapi.util.Pair)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 URI (java.net.URI)1 java.util (java.util)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 javax.ws.rs (javax.ws.rs)1 Context (javax.ws.rs.core.Context)1 UriInfo (javax.ws.rs.core.UriInfo)1