use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class PackageMaterialUpdaterTest method shouldNotUpdateMaterialInstanceWhenConfigHas_NOT_Changed.
@Test
public void shouldNotUpdateMaterialInstanceWhenConfigHas_NOT_Changed() throws Exception {
PackageMaterial material = MaterialsMother.packageMaterial();
MaterialInstance materialInstance = material.createMaterialInstance();
File file = new File("random");
Modifications modifications = new Modifications();
materialUpdater.insertLatestOrNewModifications(material, materialInstance, file, modifications);
verify(materialRepository, never()).saveOrUpdate(Matchers.<MaterialInstance>any());
verify(scmMaterialUpdater).insertLatestOrNewModifications(material, materialInstance, file, modifications);
}
use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class PluggableSCMMaterialUpdaterTest method shouldNotUpdateMaterialInstanceWhenConfigHas_NOT_Changed.
@Test
public void shouldNotUpdateMaterialInstanceWhenConfigHas_NOT_Changed() throws Exception {
PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
MaterialInstance materialInstance = material.createMaterialInstance();
File file = new File("random");
Modifications modifications = new Modifications();
materialUpdater.insertLatestOrNewModifications(material, materialInstance, file, modifications);
verify(materialRepository, never()).saveOrUpdate(Matchers.<MaterialInstance>any());
verify(scmMaterialUpdater).insertLatestOrNewModifications(material, materialInstance, file, modifications);
}
use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class PluggableSCMMaterialInstanceTest method shouldTestEqualsBasedOnConfiguration.
@Test
public void shouldTestEqualsBasedOnConfiguration() {
PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial("scm-id", "scm-name", ConfigurationPropertyMother.create("key1", false, "value1"));
MaterialInstance materialInstance = material.createMaterialInstance();
MaterialInstance materialInstanceCopy = material.createMaterialInstance();
material.getScmConfig().getConfiguration().add(ConfigurationPropertyMother.create("key2", false, "value2"));
MaterialInstance newMaterialInstance = material.createMaterialInstance();
assertThat(materialInstance, is(materialInstanceCopy));
assertThat(materialInstance, is(not(newMaterialInstance)));
}
use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class MaterialDatabaseUpdater method updateMaterialWithNewRevisions.
void updateMaterialWithNewRevisions(Material material) {
Materials materials = new Materials();
materialExpansionService.expandForHistory(material, materials);
for (Material expanded : materials) {
MaterialInstance expandedInstance = materialRepository.findMaterialInstance(expanded);
File expandedFolder = folderFor(expanded);
if (expandedInstance == null) {
addNewMaterialWithModifications(expandedFolder, expanded, updater(expanded));
} else {
insertLatestOrNewModifications(expanded, expandedInstance, expandedFolder, updater(expanded));
}
}
}
use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class MaterialDatabaseUpdater method updateMaterial.
public void updateMaterial(final Material material) throws Exception {
String materialMutex = mutexForMaterial(material);
HealthStateScope scope = HealthStateScope.forMaterial(material);
try {
MaterialInstance materialInstance = materialRepository.findMaterialInstance(material);
if (materialInstance == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("[Material Update] Material repository not found, creating with latest revision from %s", material));
}
synchronized (materialMutex) {
if (materialRepository.findMaterialInstance(material) == null) {
transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) throws Exception {
initializeMaterialWithLatestRevision(material);
return null;
}
});
}
}
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("[Material Update] Existing material repository, fetching new revisions from %s in flyweight %s", material, materialInstance.getFlyweightName()));
}
synchronized (materialMutex) {
transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) throws Exception {
updateMaterialWithNewRevisions(material);
return null;
}
});
}
}
healthService.removeByScope(scope);
} catch (Exception e) {
String message = "Modification check failed for material: " + material.getLongDescription();
String errorDescription = e.getMessage() == null ? "Unknown error" : e.getMessage();
healthService.update(ServerHealthState.error(message, errorDescription, HealthStateType.general(scope)));
LOGGER.warn(String.format("[Material Update] %s", message), e);
throw e;
}
}
Aggregations