Search in sources :

Example 11 with ScmMaterial

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

the class MaterialDatabaseUpdaterIntegrationTest method shouldNotThrowUpWhenSameMaterialIsBeingUpdatedByMultipleThreads.

@Test
public void shouldNotThrowUpWhenSameMaterialIsBeingUpdatedByMultipleThreads() throws Exception {
    final ScmMaterial material = new GitMaterial(testRepo.projectRepositoryUrl());
    final List<Exception> threadOneExceptions = new ArrayList();
    final List<Exception> threadTwoExceptions = new ArrayList();
    Thread updateThread1 = new Thread() {

        @Override
        public void run() {
            try {
                updater.updateMaterial(material);
            } catch (Exception e) {
                threadOneExceptions.add(e);
            }
        }
    };
    Thread updateThread2 = new Thread() {

        @Override
        public void run() {
            try {
                updater.updateMaterial(material);
            } catch (Exception e) {
                threadTwoExceptions.add(e);
            }
        }
    };
    updateThread1.start();
    updateThread2.start();
    updateThread1.join();
    updateThread2.join();
    if (!threadOneExceptions.isEmpty()) {
        throw threadOneExceptions.get(0);
    }
    if (!threadTwoExceptions.isEmpty()) {
        throw threadTwoExceptions.get(0);
    }
    assertThat("transaction template executeWithExceptionHandling should be invoked only once", transactionTemplateWithInvocationCount.invocationCount, is(1));
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ArrayList(java.util.ArrayList) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) Test(org.junit.Test)

Example 12 with ScmMaterial

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

the class FanInPerformanceTest method shouldTestFanInForMesh.

@Test(timeout = 240000)
@RunIf(value = DatabaseChecker.class, arguments = { DatabaseChecker.H2 })
public void shouldTestFanInForMesh() throws Exception {
    int numberOfNodesPerLevel = 10;
    int numberOfLevels = 10;
    int numberOfInstancesForUpstream = 1;
    ScmMaterial svn = u.wf((ScmMaterial) MaterialsMother.defaultMaterials().get(0), "folder1");
    String[] svn_revs = { "svn_1" };
    u.checkinInOrder(svn, svn_revs);
    PipelineConfig upstreamConfig = graphGenerator.createPipelineWithInstances("upstream", new ArrayList<>(), numberOfInstancesForUpstream);
    PipelineConfig currentConfig = graphGenerator.createMesh(upstreamConfig, "current", "up", numberOfInstancesForUpstream, numberOfNodesPerLevel, numberOfLevels);
    List<MaterialRevision> revisions = new ArrayList<>();
    revisions.add(u.mr(svn, true, "svn_1"));
    for (int i = 1; i <= numberOfNodesPerLevel; i++) {
        String pipelineName = String.format("pipeline_%s_%d_%d", "up", numberOfLevels, i);
        revisions.add(u.mr(new DependencyMaterial(new CaseInsensitiveString(pipelineName), new CaseInsensitiveString("stage")), true, pipelineName + "/1/stage/1"));
    }
    MaterialRevisions given = new MaterialRevisions(revisions);
    long start = System.currentTimeMillis();
    MaterialRevisions finalRevisions = getRevisionsBasedOnDependencies(currentConfig.name(), configHelper.currentConfig(), given);
    long timeTaken = (System.currentTimeMillis() - start) / 1000;
    assertThat(String.format("Fan-in took %ds. Should have finished in 10s.", timeTaken), timeTaken, Matchers.lessThan(10l));
    assertThat(finalRevisions, is(given));
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) ArrayList(java.util.ArrayList) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 13 with ScmMaterial

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

the class MaterialRevisions method updateToCommand.

public BuildCommand updateToCommand(String baseDir) {
    List<BuildCommand> commands = new ArrayList<>();
    for (MaterialRevision revision : revisions) {
        Material material = revision.getMaterial();
        if (material instanceof ScmMaterial) {
            if (material instanceof GitMaterial) {
                GitMaterialUpdater updater = new GitMaterialUpdater((GitMaterial) material);
                commands.add(updater.updateTo(baseDir, revision.toRevisionContext()));
            } else {
                commands.add(BuildCommand.fail("%s Material is not supported for new build command agent", material.getTypeForDisplay()));
            }
        }
    }
    return BuildCommand.compose(commands);
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ArrayList(java.util.ArrayList) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) GitMaterialUpdater(com.thoughtworks.go.domain.materials.git.GitMaterialUpdater) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)

Example 14 with ScmMaterial

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

the class PipelineSqlMapDaoIntegrationTest method shouldPersistMaterialsWithRealPassword.

@Test
public void shouldPersistMaterialsWithRealPassword() throws SQLException {
    MaterialRevisions materialRevisions = new MaterialRevisions();
    addRevision(materialRevisions, MaterialsMother.svnMaterial("http://username:password@localhost"));
    addRevision(materialRevisions, MaterialsMother.hgMaterial("http://username:password@localhost"));
    addRevision(materialRevisions, new GitMaterial("git://username:password@localhost"));
    addRevision(materialRevisions, new P4Material("localhost:1666", "view"));
    BuildCause buildCause = BuildCause.createManualForced(materialRevisions, Username.ANONYMOUS);
    Pipeline pipeline = new Pipeline("Test", buildCause);
    save(pipeline);
    Pipeline loaded = pipelineDao.mostRecentPipeline("Test");
    Materials materials = loaded.getMaterials();
    for (Material material : materials) {
        assertThat(((ScmMaterial) material).getUrl(), not(containsString("******")));
    }
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) Materials(com.thoughtworks.go.config.materials.Materials) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) MaterialsMother.svnMaterial(com.thoughtworks.go.helper.MaterialsMother.svnMaterial) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) Material(com.thoughtworks.go.domain.materials.Material) P4Material(com.thoughtworks.go.config.materials.perforce.P4Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) P4Material(com.thoughtworks.go.config.materials.perforce.P4Material) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 15 with ScmMaterial

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

the class SCMDependencyNodeTest method addMaterialRevisionShouldNotAllowDuplicates.

@Test
public void addMaterialRevisionShouldNotAllowDuplicates() {
    ScmMaterial gitMaterial = MaterialsMother.gitMaterial("/url/for/repo");
    List<Modification> modifications = ModificationsMother.multipleModificationList();
    SCMDependencyNode node = new SCMDependencyNode("nodeID", "nodeName", "GIT");
    node.addMaterialRevision(new MaterialRevision(gitMaterial, modifications));
    node.addMaterialRevision(new MaterialRevision(gitMaterial, modifications));
    assertThat(node.getMaterialRevisions().size(), is(1));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Test(org.junit.Test)

Aggregations

ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)26 Test (org.junit.Test)24 Modification (com.thoughtworks.go.domain.materials.Modification)6 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)5 MaterialUpdateMessageMatcher.matchMaterialUpdateMessage (com.thoughtworks.go.helper.MaterialUpdateMessageMatcher.matchMaterialUpdateMessage)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 PackageMaterialInstance (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance)4 PluggableSCMMaterialInstance (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance)4 SvnMaterialInstance (com.thoughtworks.go.domain.materials.svn.SvnMaterialInstance)4 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)3 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 RunIf (com.googlecode.junit.ext.RunIf)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)2 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)2 PipelineLabel (com.thoughtworks.go.domain.label.PipelineLabel)2 Material (com.thoughtworks.go.domain.materials.Material)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2