Search in sources :

Example 51 with GitMaterial

use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method shouldNotBlowUpReportErrorIfAnAttemptIsMadeToInsertOnlyDuplicateModificationsForAGivenMaterial.

@Test
public void shouldNotBlowUpReportErrorIfAnAttemptIsMadeToInsertOnlyDuplicateModificationsForAGivenMaterial() {
    final MaterialInstance materialInstance = repo.findOrCreateFrom(new GitMaterial(UUID.randomUUID().toString(), "branch"));
    final ArrayList<Modification> firstSetOfModifications = getModifications(3);
    transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            repo.saveModifications(materialInstance, firstSetOfModifications);
            return null;
        }
    });
    Modifications firstSetOfModificationsFromDb = repo.getModificationsFor(materialInstance, Pagination.pageByNumber(1, 10, 10));
    assertThat(firstSetOfModificationsFromDb.size(), is(3));
    for (Modification modification : firstSetOfModifications) {
        assertThat(firstSetOfModificationsFromDb.containsRevisionFor(modification), is(true));
    }
    final ArrayList<Modification> secondSetOfModificationsContainingAllDuplicateRevisions = getModifications(3);
    transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            repo.saveModifications(materialInstance, secondSetOfModificationsContainingAllDuplicateRevisions);
            return null;
        }
    });
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) TransactionStatus(org.springframework.transaction.TransactionStatus) PackageMaterialInstance(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance) PluggableSCMMaterialInstance(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance) SvnMaterialInstance(com.thoughtworks.go.domain.materials.svn.SvnMaterialInstance) Test(org.junit.Test)

Example 52 with GitMaterial

use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method shouldRemoveDuplicatesBeforeInsertingModifications.

@Test
public void shouldRemoveDuplicatesBeforeInsertingModifications() {
    final MaterialInstance materialInstance = repo.findOrCreateFrom(new GitMaterial(UUID.randomUUID().toString(), "branch"));
    final ArrayList<Modification> firstSetOfModifications = getModifications(3);
    transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            repo.saveModifications(materialInstance, firstSetOfModifications);
            return null;
        }
    });
    Modifications firstSetOfModificationsFromDb = repo.getModificationsFor(materialInstance, Pagination.pageByNumber(1, 10, 10));
    assertThat(firstSetOfModificationsFromDb.size(), is(3));
    for (Modification modification : firstSetOfModifications) {
        assertThat(firstSetOfModificationsFromDb.containsRevisionFor(modification), is(true));
    }
    final ArrayList<Modification> secondSetOfModificationsContainingDuplicateRevisions = getModifications(4);
    transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            repo.saveModifications(materialInstance, secondSetOfModificationsContainingDuplicateRevisions);
            return null;
        }
    });
    Modifications secondSetOfModificationsFromDb = repo.getModificationsFor(materialInstance, Pagination.pageByNumber(1, 10, 10));
    assertThat(secondSetOfModificationsFromDb.size(), is(4));
    for (final Modification fromPreviousCycle : firstSetOfModificationsFromDb) {
        Modification modification = secondSetOfModificationsFromDb.stream().filter(new Predicate<Modification>() {

            @Override
            public boolean test(Modification item) {
                return item.getId() == fromPreviousCycle.getId();
            }
        }).findFirst().orElse(null);
        assertThat(modification, is(notNullValue()));
    }
    for (Modification modification : secondSetOfModificationsContainingDuplicateRevisions) {
        assertThat(secondSetOfModificationsFromDb.containsRevisionFor(modification), is(true));
    }
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) TransactionStatus(org.springframework.transaction.TransactionStatus) PackageMaterialInstance(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance) PluggableSCMMaterialInstance(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance) SvnMaterialInstance(com.thoughtworks.go.domain.materials.svn.SvnMaterialInstance) Test(org.junit.Test)

Example 53 with GitMaterial

use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method shouldBeAbleToHandleLargeNumberOfModifications.

// Slow test - takes ~1 min to run. Will remove if it causes issues. - Jyoti
@Test
public void shouldBeAbleToHandleLargeNumberOfModifications() {
    final MaterialInstance materialInstance = repo.findOrCreateFrom(new GitMaterial(UUID.randomUUID().toString(), "branch"));
    int count = 10000;
    final ArrayList<Modification> firstSetOfModifications = getModifications(count);
    transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            repo.saveModifications(materialInstance, firstSetOfModifications);
            return null;
        }
    });
    assertThat(repo.getTotalModificationsFor(materialInstance), is(new Long(count)));
    final ArrayList<Modification> secondSetOfModifications = getModifications(count + 1);
    transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            repo.saveModifications(materialInstance, secondSetOfModifications);
            return null;
        }
    });
    assertThat(repo.getTotalModificationsFor(materialInstance), is(new Long(count + 1)));
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) TransactionStatus(org.springframework.transaction.TransactionStatus) PackageMaterialInstance(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance) PluggableSCMMaterialInstance(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance) SvnMaterialInstance(com.thoughtworks.go.domain.materials.svn.SvnMaterialInstance) Test(org.junit.Test)

Example 54 with GitMaterial

use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.

the class FaninDependencyResolutionTest method shouldPickTheRightRevisionsWhenMaterialIsRemovedAndPutBack.

@Test
public void shouldPickTheRightRevisionsWhenMaterialIsRemovedAndPutBack() {
    GitMaterial git1 = u.wf(new GitMaterial("git1-url"), "git-folder1");
    GitMaterial git2 = u.wf(new GitMaterial("git2-url"), "git-folder2");
    GitMaterial git3 = u.wf(new GitMaterial("git3-url"), "git-folder3");
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("P1", u.m(git1), u.m(git2));
    ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("P2", u.m(git2));
    ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("P3", u.m(p1), u.m(p2), u.m(git1));
    ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWith("P4", u.m(p3), u.m(git2));
    u.checkinInOrder(git1, "git1_1");
    u.checkinInOrder(git2, "git2_1");
    String p1_1 = u.runAndPass(p1, "git1_1", "git2_1");
    String p2_1 = u.runAndPass(p2, "git2_1");
    String p3_1 = u.runAndPass(p3, p1_1, p2_1, "git1_1");
    String p4_1 = u.runAndPass(p4, p3_1, "git2_1");
    u.checkinInOrder(git1, "git1_2");
    u.checkinInOrder(git2, "git2_2");
    String p1_2 = u.runAndPass(p1, "git1_2", "git2_2");
    String p2_2 = u.runAndPass(p2, "git2_2");
    String p3_2 = u.runAndPass(p3, p1_2, p2_2, "git1_2");
    String p4_2 = u.runAndPass(p4, p3_2, "git2_2");
    configHelper.setMaterialConfigForPipeline("P2", git3.config());
    CruiseConfig cruiseConfig = goConfigDao.load();
    p2 = new ScheduleTestUtil.AddedPipeline(cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("P2")), p2.material);
    u.checkinInOrder(git1, "git1_3");
    u.checkinInOrder(git2, "git2_3");
    u.checkinInOrder(git3, "git3_1");
    String p1_3 = u.runAndPass(p1, "git1_3", "git2_3");
    String p2_3 = u.runAndPass(p2, "git3_1");
    String p3_3 = u.runAndPass(p3, p1_3, p2_3, "git1_3");
    // check wat happens to p4
    MaterialRevisions given = u.mrs(new MaterialRevision[] { u.mr(git2, true, "git2_3"), u.mr(p3, true, p3_3) });
    MaterialRevisions expected = u.mrs(new MaterialRevision[] { u.mr(git2, true, "git2_3"), u.mr(p3, true, p3_3) });
    MaterialRevisions finalRevisions = getRevisionsBasedOnDependencies(p4, cruiseConfig, given);
    assertThat(finalRevisions, is(expected));
    // bring back git2 in p2
    configHelper.setMaterialConfigForPipeline("P2", git2.config());
    cruiseConfig = goConfigDao.load();
    p2 = new ScheduleTestUtil.AddedPipeline(cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("P2")), p2.material);
    // check wat happend to p4
    given = u.mrs(u.mr(git2, true, "git2_3"), u.mr(p3, true, p3_3));
    expected = u.mrs(new MaterialRevision[] { u.mr(git2, true, "git2_3"), u.mr(p3, true, p3_3) });
    finalRevisions = getRevisionsBasedOnDependencies(p4, cruiseConfig, given);
    assertThat(finalRevisions, is(expected));
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 55 with GitMaterial

use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.

the class FaninDependencyResolutionTest method shouldRestoreMaterialNamesBasedOnMaterialConfig.

@Test
public void shouldRestoreMaterialNamesBasedOnMaterialConfig() throws Exception {
    /*
            g -> up   -> down
                 +-> mid -+
         */
    GitMaterial git = u.wf(new GitMaterial("git"), "folder1");
    u.checkinInOrder(git, "g1");
    ScheduleTestUtil.AddedPipeline up = u.saveConfigWith("up", u.m(git));
    ScheduleTestUtil.MaterialDeclaration upForMid = u.m(up);
    ((DependencyMaterial) upForMid.material).setName(new CaseInsensitiveString("up-for-mid"));
    ScheduleTestUtil.AddedPipeline mid = u.saveConfigWith("mid", upForMid);
    ScheduleTestUtil.MaterialDeclaration upForDown = u.m(up);
    ((DependencyMaterial) upForDown.material).setName(new CaseInsensitiveString("up-for-down"));
    ScheduleTestUtil.AddedPipeline down = u.saveConfigWith("down", u.m(mid), upForDown);
    CruiseConfig cruiseConfig = goConfigDao.load();
    String up_1 = u.runAndPass(up, "g1");
    String mid_1 = u.runAndPass(mid, up_1);
    String down_1 = u.runAndPass(down, mid_1, up_1);
    MaterialRevisions given = u.mrs(u.mr(mid, false, mid_1), u.mr(up, false, up_1));
    MaterialRevisions revisionsBasedOnDependencies = getRevisionsBasedOnDependencies(down, cruiseConfig, given);
    for (MaterialRevision revisionsBasedOnDependency : revisionsBasedOnDependencies) {
        DependencyMaterial dependencyPipeline = (DependencyMaterial) revisionsBasedOnDependency.getMaterial();
        if (dependencyPipeline.getPipelineName().equals(new CaseInsensitiveString("up"))) {
            assertThat(dependencyPipeline.getName(), is(new CaseInsensitiveString("up-for-down")));
        }
    }
    assertThat(revisionsBasedOnDependencies, is(given));
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) Test(org.junit.Test)

Aggregations

GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)146 Test (org.junit.Test)137 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)70 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)55 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)33 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)31 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)20 ValueStreamMapPresentationModel (com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel)20 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)19 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)13 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)11 Modification (com.thoughtworks.go.domain.materials.Modification)11 File (java.io.File)11 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)10 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)10 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)10 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)10 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)9 Material (com.thoughtworks.go.domain.materials.Material)8 Materials (com.thoughtworks.go.config.materials.Materials)7