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;
}
});
}
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));
}
}
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)));
}
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));
}
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));
}
Aggregations