use of org.springframework.transaction.TransactionStatus 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 = ListUtil.find(secondSetOfModificationsFromDb, new ListUtil.Condition() {
@Override
public <T> boolean isMet(T item) {
Modification modification = (Modification) item;
return modification.getId() == fromPreviousCycle.getId();
}
});
assertThat(modification, is(notNullValue()));
}
for (Modification modification : secondSetOfModificationsContainingDuplicateRevisions) {
assertThat(secondSetOfModificationsFromDb.containsRevisionFor(modification), is(true));
}
}
use of org.springframework.transaction.TransactionStatus in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldAllowSavingModificationsIfRevisionsAcrossDifferentMaterialsHappenToBeSame.
@Test
public void shouldAllowSavingModificationsIfRevisionsAcrossDifferentMaterialsHappenToBeSame() {
final MaterialInstance materialInstance1 = repo.findOrCreateFrom(new GitMaterial(UUID.randomUUID().toString(), "branch"));
final MaterialInstance materialInstance2 = repo.findOrCreateFrom(new GitMaterial(UUID.randomUUID().toString(), "branch"));
final ArrayList<Modification> modificationsForFirstMaterial = getModifications(3);
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
repo.saveModifications(materialInstance1, modificationsForFirstMaterial);
return null;
}
});
assertThat(repo.getModificationsFor(materialInstance1, Pagination.pageByNumber(1, 10, 10)).size(), is(3));
final ArrayList<Modification> modificationsForSecondMaterial = getModifications(3);
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
repo.saveModifications(materialInstance2, modificationsForSecondMaterial);
return null;
}
});
Modifications modificationsFromDb = repo.getModificationsFor(materialInstance2, Pagination.pageByNumber(1, 10, 10));
assertThat(modificationsFromDb.size(), is(3));
for (Modification modification : modificationsForSecondMaterial) {
assertThat(modificationsFromDb.containsRevisionFor(modification), is(true));
}
}
use of org.springframework.transaction.TransactionStatus 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)));
}
use of org.springframework.transaction.TransactionStatus in project gocd by gocd.
the class DatabaseAccessHelper method addRevisionsWithModifications.
public MaterialRevision addRevisionsWithModifications(Material material, Modification... modifications) {
final MaterialRevision revision = filterUnsaved(new MaterialRevision(material, modifications));
if (revision.getModifications().isEmpty()) {
return revision;
}
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
materialRepository.saveMaterialRevision(revision);
}
});
return revision;
}
use of org.springframework.transaction.TransactionStatus in project gocd by gocd.
the class DatabaseAccessHelper method saveRevs.
public void saveRevs(final MaterialRevisions materialRevisions) {
final MaterialRevisions unsavedRevisions = new MaterialRevisions();
for (MaterialRevision materialRevision : materialRevisions) {
unsavedRevisions.addRevision(filterUnsaved(materialRevision));
}
if (unsavedRevisions.isEmpty()) {
return;
}
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
materialRepository.save(unsavedRevisions);
}
});
}
Aggregations