Search in sources :

Example 91 with TransactionCallback

use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.

the class JobInstanceSqlMapDaoIntegrationTest method savedJobForAgent.

private JobInstance savedJobForAgent(final String jobName, final String uuid, final boolean runOnAllAgents, final boolean runMultipleInstance) {
    return (JobInstance) transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus status) {
            JobInstance jobInstance = scheduled(jobName, new DateTime().plusMinutes(1).toDate());
            jobInstance.setRunOnAllAgents(runOnAllAgents);
            jobInstance.setRunMultipleInstance(runMultipleInstance);
            jobInstanceService.save(savedStage.getIdentifier(), stageId, jobInstance);
            jobInstance.changeState(JobState.Building);
            jobInstance.setAgentUuid(uuid);
            jobInstanceDao.updateStateAndResult(jobInstance);
            return jobInstance;
        }
    });
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) TransactionStatus(org.springframework.transaction.TransactionStatus) DateTime(org.joda.time.DateTime)

Example 92 with TransactionCallback

use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.

the class PluggableSCMMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModification.

@Test
public void shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModification() throws Exception {
    final PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    final MaterialInstance materialInstance = material.createMaterialInstance();
    materialRepository.saveOrUpdate(materialInstance);
    Map<String, String> data = new HashMap<>();
    data.put("k1", "v1");
    when(scmExtension.getLatestRevision(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class))).thenReturn(new MaterialPollResult(data, new SCMRevision()));
    mockSCMExtensionInPoller();
    scmMaterialUpdater = new ScmMaterialUpdater(materialRepository, materialChecker, subprocessExecutionContext, materialService);
    pluggableSCMMaterialUpdater = new PluggableSCMMaterialUpdater(materialRepository, scmMaterialUpdater, transactionTemplate);
    transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus transactionStatus) {
            pluggableSCMMaterialUpdater.insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications());
            return null;
        }
    });
    MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
    assertThat(actualInstance.getAdditionalDataMap(), is(data));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) HashMap(java.util.HashMap) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) TransactionStatus(org.springframework.transaction.TransactionStatus) Modifications(com.thoughtworks.go.domain.materials.Modifications) TransactionCallback(org.springframework.transaction.support.TransactionCallback) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 93 with TransactionCallback

use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method materialsShouldBeSerializable.

@Test
public void materialsShouldBeSerializable() throws Exception {
    SvnMaterial svnMaterial = MaterialsMother.svnMaterial();
    Modification modification = new Modification("user", "comment", "email", new Date(), "revision");
    modification.createModifiedFile("file1", "folder1", ModifiedAction.added);
    modification.createModifiedFile("file2", "folder2", ModifiedAction.deleted);
    final MaterialRevision materialRevision = new MaterialRevision(svnMaterial, modification);
    MaterialInstance materialInstance = (MaterialInstance) transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus status) {
            return repo.saveMaterialRevision(materialRevision);
        }
    });
    List<Modification> mods = repo.findMaterialRevisionsForMaterial(materialInstance.getId());
    List<Modification> deserialized = (List<Modification>) SerializationTester.serializeAndDeserialize(mods);
    assertThat(deserialized, is(mods));
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) TransactionStatus(org.springframework.transaction.TransactionStatus) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) P4MaterialInstance(com.thoughtworks.go.domain.materials.perforce.P4MaterialInstance) PackageMaterialInstance(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance) TfsMaterialInstance(com.thoughtworks.go.domain.materials.tfs.TfsMaterialInstance) HgMaterialInstance(com.thoughtworks.go.domain.materials.mercurial.HgMaterialInstance) PluggableSCMMaterialInstance(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance) SvnMaterialInstance(com.thoughtworks.go.domain.materials.svn.SvnMaterialInstance) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 94 with TransactionCallback

use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method shouldNotSaveAndClearCacheWhenThereAreNoNewModifications.

@Test
public void shouldNotSaveAndClearCacheWhenThereAreNoNewModifications() {
    final MaterialInstance materialInstance = repo.findOrCreateFrom(new GitMaterial(UUID.randomUUID().toString(), "branch"));
    String key = repo.materialModificationsWithPaginationKey(materialInstance);
    String subKey = repo.materialModificationsWithPaginationSubKey(Pagination.ONE_ITEM);
    goCache.put(key, subKey, new Modifications(new Modification()));
    transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus status) {
            repo.saveModifications(materialInstance, new ArrayList<>());
            return null;
        }
    });
    assertThat(goCache.get(key, subKey), is(notNullValue()));
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ArrayList(java.util.ArrayList) TransactionStatus(org.springframework.transaction.TransactionStatus) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) P4MaterialInstance(com.thoughtworks.go.domain.materials.perforce.P4MaterialInstance) PackageMaterialInstance(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance) TfsMaterialInstance(com.thoughtworks.go.domain.materials.tfs.TfsMaterialInstance) HgMaterialInstance(com.thoughtworks.go.domain.materials.mercurial.HgMaterialInstance) PluggableSCMMaterialInstance(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance) SvnMaterialInstance(com.thoughtworks.go.domain.materials.svn.SvnMaterialInstance) Test(org.junit.jupiter.api.Test)

Example 95 with TransactionCallback

use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method saveOneScmModification.

private MaterialRevision saveOneScmModification(final String revision, final Material original, final String user, final String filename, final String comment) {
    return (MaterialRevision) transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus status) {
            Modification modification = new Modification(user, comment, "email", new Date(), revision);
            modification.createModifiedFile(filename, "folder1", ModifiedAction.added);
            MaterialRevision originalRevision = new MaterialRevision(original, modification);
            repo.save(new MaterialRevisions(originalRevision));
            return originalRevision;
        }
    });
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) TransactionStatus(org.springframework.transaction.TransactionStatus) Date(java.util.Date)

Aggregations

TransactionCallback (org.springframework.transaction.support.TransactionCallback)100 TransactionStatus (org.springframework.transaction.TransactionStatus)75 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)16 Test (org.junit.jupiter.api.Test)14 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)10 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)10 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)9 PreparedStatement (java.sql.PreparedStatement)8 List (java.util.List)8 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)7 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)7 Modification (com.thoughtworks.go.domain.materials.Modification)7 PackageMaterialInstance (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance)7 PluggableSCMMaterialInstance (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance)7 Query (org.hibernate.Query)7 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)6 DbDialect (com.alibaba.otter.node.etl.common.db.dialect.DbDialect)6 Modifications (com.thoughtworks.go.domain.materials.Modifications)6 HgMaterialInstance (com.thoughtworks.go.domain.materials.mercurial.HgMaterialInstance)6