Search in sources :

Example 1 with RemoteCollection

use of org.jboss.pnc.client.RemoteCollection in project pnc by project-ncl.

the class GroupConfigurationEndpointTest method testConcurrentGet.

/**
 * reproducer for NCL-3552
 */
@Test
public void testConcurrentGet() throws RemoteResourceException {
    GroupConfigurationClient client = new GroupConfigurationClient(RestClientConfiguration.asUser());
    Map<Integer, RemoteCollection<BuildConfiguration>> responseMap = new HashMap<>();
    String gcId = "100";
    ExecutorService executorService = MDCExecutors.newFixedThreadPool(2);
    executorService.execute(() -> {
        logger.info("Making 1st request ...");
        RemoteCollection<BuildConfiguration> configurations = null;
        try {
            configurations = client.getBuildConfigs(gcId);
        } catch (RemoteResourceException e) {
        // detected with null in responseMap
        }
        logger.info("1st done.");
        responseMap.put(1, configurations);
    });
    executorService.execute(() -> {
        logger.info("Making 2nd request ...");
        RemoteCollection<BuildConfiguration> configurations = null;
        try {
            configurations = client.getBuildConfigs(gcId);
        } catch (RemoteResourceException e) {
        // detected with null in responseMap
        }
        logger.info("2nd done.");
        responseMap.put(2, configurations);
    });
    try {
        executorService.awaitTermination(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        executorService.shutdownNow();
        throw new AssertionError("Requests were not completed in given timeout.", e);
    }
    assertThat(responseMap).containsKeys(1, 2).doesNotContainValue(null);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) HashMap(java.util.HashMap) ExecutorService(java.util.concurrent.ExecutorService) GroupConfigurationClient(org.jboss.pnc.client.GroupConfigurationClient) RemoteCollection(org.jboss.pnc.client.RemoteCollection) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 2 with RemoteCollection

use of org.jboss.pnc.client.RemoteCollection in project bacon by project-ncl.

the class PncBuilderTest method getCountOfBuildConfigsForGroupBuild.

@Test
void getCountOfBuildConfigsForGroupBuild() throws Exception {
    Map<String, BuildConfigurationRef> buildConfigurations = new HashMap<>();
    BuildConfigurationRef bc1 = easyRandom.nextObject(BuildConfigurationRef.class);
    BuildConfigurationRef bc2 = easyRandom.nextObject(BuildConfigurationRef.class);
    BuildConfigurationRef bc3 = easyRandom.nextObject(BuildConfigurationRef.class);
    buildConfigurations.put(bc1.getName(), bc1);
    buildConfigurations.put(bc2.getName(), bc2);
    buildConfigurations.put(bc3.getName(), bc3);
    String groupConfigurationId = "5";
    String groupBuildId = "1";
    GroupConfiguration gc = GroupConfiguration.builder().id(groupConfigurationId).buildConfigs(buildConfigurations).build();
    GroupBuild gb = GroupBuild.builder().id(groupBuildId).groupConfig(gc).build();
    when(groupBuildClient.getSpecific(groupBuildId)).thenReturn(gb);
    when(groupConfigurationClient.getBuildConfigs(groupConfigurationId)).thenReturn(new RemoteCollection<BuildConfiguration>() {

        @Override
        public int size() {
            return buildConfigurations.size();
        }

        @Override
        public Collection<BuildConfiguration> getAll() {
            return null;
        }

        @Override
        public Iterator<BuildConfiguration> iterator() {
            return null;
        }
    });
    try (PncBuilder builder = new PncBuilder(groupBuildClient, groupConfigurationClient)) {
        assertEquals(buildConfigurations.size(), builder.getCountOfBuildConfigsForGroupBuild(groupBuildId));
    }
}
Also used : BuildConfigurationRef(org.jboss.pnc.dto.BuildConfigurationRef) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) HashMap(java.util.HashMap) GroupBuild(org.jboss.pnc.dto.GroupBuild) Iterator(java.util.Iterator) Collection(java.util.Collection) RemoteCollection(org.jboss.pnc.client.RemoteCollection) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) Test(org.junit.jupiter.api.Test)

Example 3 with RemoteCollection

use of org.jboss.pnc.client.RemoteCollection in project pnc by project-ncl.

the class ProductMilestoneEndpointTest method shouldGetMilestoneRelease.

@Test
public void shouldGetMilestoneRelease() throws IOException, RemoteResourceException {
    // given
    ProductClient productClient = new ProductClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<Product> products = productClient.getAll(Optional.empty(), Optional.of("name==\"" + PNC_PRODUCT_NAME + "\""));
    Product product = products.iterator().next();
    Map<String, ProductVersionRef> productVersions = product.getProductVersions();
    Optional<ProductVersionRef> productVersion = productVersions.values().stream().filter(pv -> pv.getVersion().equals(DatabaseDataInitializer.PNC_PRODUCT_VERSION_1)).findAny();
    ProductVersionClient productVersionClient = new ProductVersionClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<ProductMilestone> milestones = productVersionClient.getMilestones(productVersion.get().getId(), Optional.empty(), Optional.of("version==\"" + PNC_PRODUCT_MILESTONE3 + "\""));
    ProductMilestone milestone = milestones.iterator().next();
    ProductMilestoneClient milestoneClient = new ProductMilestoneClient(RestClientConfiguration.asAnonymous());
    // when
    RemoteCollection<ProductMilestoneCloseResult> milestoneReleases = milestoneClient.getCloseResults(milestone.getId(), null);
    // then
    Assert.assertEquals(3, milestoneReleases.size());
    // make sure the result is ordered by date
    Instant previous = Instant.EPOCH;
    for (Iterator<ProductMilestoneCloseResult> iter = milestoneReleases.iterator(); iter.hasNext(); ) {
        ProductMilestoneCloseResult next = iter.next();
        logger.debug("MilestoneRelease id: {}, StartingDate: {}.", next.getId(), next.getStartingDate());
        Assert.assertTrue("Wong milestone releases order.", next.getStartingDate().isAfter(previous));
        previous = next.getStartingDate();
    }
    // when
    ProductMilestoneCloseParameters filter = new ProductMilestoneCloseParameters();
    filter.setLatest(true);
    RemoteCollection<ProductMilestoneCloseResult> latestMilestoneRelease = milestoneClient.getCloseResults(milestone.getId(), filter);
    // then
    Assert.assertEquals(1, latestMilestoneRelease.getAll().size());
    // the latest one in demo data has status SUCCEEDED
    Assert.assertEquals(MilestoneCloseStatus.SUCCEEDED, latestMilestoneRelease.iterator().next().getStatus());
}
Also used : BeforeClass(org.junit.BeforeClass) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) ProductClient(org.jboss.pnc.client.ProductClient) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) RemoteCollection(org.jboss.pnc.client.RemoteCollection) ContainerTest(org.jboss.pnc.test.category.ContainerTest) ClientException(org.jboss.pnc.client.ClientException) ProductMilestoneCloseParameters(org.jboss.pnc.rest.api.parameters.ProductMilestoneCloseParameters) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ProductMilestone(org.jboss.pnc.dto.ProductMilestone) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) Deployments(org.jboss.pnc.integration.setup.Deployments) PNC_PRODUCT_MILESTONE3(org.jboss.pnc.demo.data.DatabaseDataInitializer.PNC_PRODUCT_MILESTONE3) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ValidationResponse(org.jboss.pnc.dto.response.ValidationResponse) ValidationErrorType(org.jboss.pnc.enums.ValidationErrorType) DatabaseDataInitializer(org.jboss.pnc.demo.data.DatabaseDataInitializer) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) Product(org.jboss.pnc.dto.Product) ProductMilestoneClient(org.jboss.pnc.client.ProductMilestoneClient) Test(org.junit.Test) IOException(java.io.IOException) Artifact(org.jboss.pnc.dto.Artifact) VersionValidationRequest(org.jboss.pnc.dto.requests.validation.VersionValidationRequest) Category(org.junit.experimental.categories.Category) Instant(java.time.Instant) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient) Build(org.jboss.pnc.dto.Build) PNC_PRODUCT_NAME(org.jboss.pnc.demo.data.DatabaseDataInitializer.PNC_PRODUCT_NAME) Deployment(org.jboss.arquillian.container.test.api.Deployment) ProductMilestoneCloseResult(org.jboss.pnc.dto.ProductMilestoneCloseResult) ProductVersionRef(org.jboss.pnc.dto.ProductVersionRef) ProductVersion(org.jboss.pnc.dto.ProductVersion) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) Optional(java.util.Optional) Assert(org.junit.Assert) MilestoneCloseStatus(org.jboss.pnc.enums.MilestoneCloseStatus) ProductMilestone(org.jboss.pnc.dto.ProductMilestone) ProductMilestoneClient(org.jboss.pnc.client.ProductMilestoneClient) Instant(java.time.Instant) Product(org.jboss.pnc.dto.Product) ProductVersionRef(org.jboss.pnc.dto.ProductVersionRef) ProductMilestoneCloseParameters(org.jboss.pnc.rest.api.parameters.ProductMilestoneCloseParameters) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient) ProductClient(org.jboss.pnc.client.ProductClient) ProductMilestoneCloseResult(org.jboss.pnc.dto.ProductMilestoneCloseResult) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 4 with RemoteCollection

use of org.jboss.pnc.client.RemoteCollection in project pnc by project-ncl.

the class SCMRepositoryEndpointTest method testGetBuildConfigurationForARepository.

@Test
public void testGetBuildConfigurationForARepository() throws ClientException {
    BuildConfigurationClient buildConfigurationClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
    SCMRepository scmRepository = repositoryClient.getAll(null, null).iterator().next();
    Iterator<BuildConfiguration> allConfigsIterator = buildConfigurationClient.getAll().iterator();
    BuildConfiguration buildConfiguration1 = allConfigsIterator.next().toBuilder().scmRepository(scmRepository).build();
    BuildConfiguration buildConfiguration2 = allConfigsIterator.next().toBuilder().scmRepository(scmRepository).build();
    buildConfigurationClient.update(buildConfiguration1.getId(), buildConfiguration1);
    buildConfigurationClient.update(buildConfiguration2.getId(), buildConfiguration2);
    RemoteCollection<BuildConfiguration> buildConfigs = repositoryClient.getBuildConfigs(scmRepository.getId());
    assertThat(buildConfigs).usingElementComparatorIgnoringFields("modificationTime", "creationUser", "modificationUser").contains(buildConfiguration1, buildConfiguration2).allSatisfy((bc -> scmRepository.equals(bc.getScmRepository())));
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) ClientErrorException(javax.ws.rs.ClientErrorException) RemoteCollection(org.jboss.pnc.client.RemoteCollection) CreateAndSyncSCMRequest(org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest) ContainerTest(org.jboss.pnc.test.category.ContainerTest) ClientException(org.jboss.pnc.client.ClientException) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BadRequestException(javax.ws.rs.BadRequestException) Deployments(org.jboss.pnc.integration.setup.Deployments) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) SCMRepositoryClient(org.jboss.pnc.client.SCMRepositoryClient) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) SCMRepository(org.jboss.pnc.dto.SCMRepository) Ignore(org.junit.Ignore) Deployment(org.jboss.arquillian.container.test.api.Deployment) Condition(org.assertj.core.api.Condition) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) SCMRepository(org.jboss.pnc.dto.SCMRepository) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

RemoteCollection (org.jboss.pnc.client.RemoteCollection)4 Iterator (java.util.Iterator)3 RemoteResourceException (org.jboss.pnc.client.RemoteResourceException)3 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)3 ContainerTest (org.jboss.pnc.test.category.ContainerTest)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 BadRequestException (javax.ws.rs.BadRequestException)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 Deployment (org.jboss.arquillian.container.test.api.Deployment)2 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)2 Arquillian (org.jboss.arquillian.junit.Arquillian)2 ClientException (org.jboss.pnc.client.ClientException)2 Deployments (org.jboss.pnc.integration.setup.Deployments)2 RestClientConfiguration (org.jboss.pnc.integration.setup.RestClientConfiguration)2 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)2 Category (org.junit.experimental.categories.Category)2 RunWith (org.junit.runner.RunWith)2 Logger (org.slf4j.Logger)2