use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class CheckMergeabilityIT method checkAlreadyMergedCommit.
@Test
public void checkAlreadyMergedCommit() throws Exception {
ObjectId c0 = testRepo.branch("HEAD").commit().insertChangeId().message("first commit").add("a.txt", "a contents ").create();
testRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/master")).call();
testRepo.branch("HEAD").commit().insertChangeId().message("second commit").add("b.txt", "b contents ").create();
testRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/master")).call();
assertCommitMerged("master", c0.getName(), "");
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class CheckMergeabilityIT method checkContentMergedCommit.
@Test
public void checkContentMergedCommit() throws Exception {
testRepo.branch("HEAD").commit().insertChangeId().message("first commit").add("a.txt", "a contents ").create();
testRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/master")).call();
// create a change, and cherrypick into master
PushOneCommit.Result cId = createChange();
RevCommit commitId = cId.getCommit();
CherryPickInput cpi = new CherryPickInput();
cpi.destination = "master";
cpi.message = "cherry pick the commit";
ChangeApi orig = gApi.changes().id(cId.getChangeId());
ChangeApi cherry = orig.current().cherryPick(cpi);
cherry.current().review(ReviewInput.approve());
cherry.current().submit();
ObjectId remoteId = getRemoteHead();
assertThat(remoteId).isNotEqualTo(commitId);
assertContentMerged("master", commitId.getName(), "recursive");
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class NoteDbOnlyIT method noRetryOnLockFailureWithoutAtomicUpdates.
@Test
public void noRetryOnLockFailureWithoutAtomicUpdates() throws Exception {
assume().that(notesMigration.fuseUpdates()).isFalse();
PushOneCommit.Result r = createChange();
Change.Id id = r.getChange().getId();
String master = "refs/heads/master";
ObjectId initial;
try (Repository repo = repoManager.openRepository(project)) {
initial = repo.exactRef(master).getObjectId();
}
AtomicInteger updateRepoCalledCount = new AtomicInteger();
AtomicInteger updateChangeCalledCount = new AtomicInteger();
AtomicInteger afterUpdateReposCalledCount = new AtomicInteger();
try {
retryHelper.execute(batchUpdateFactory -> {
try (BatchUpdate bu = newBatchUpdate(batchUpdateFactory)) {
bu.addOp(id, new UpdateRefAndAddMessageOp(updateRepoCalledCount, updateChangeCalledCount));
bu.execute(new ConcurrentWritingListener(afterUpdateReposCalledCount));
}
return null;
});
assert_().fail("expected RestApiException");
} catch (RestApiException e) {
// Expected.
}
assertThat(updateRepoCalledCount.get()).isEqualTo(1);
assertThat(afterUpdateReposCalledCount.get()).isEqualTo(1);
assertThat(updateChangeCalledCount.get()).isEqualTo(0);
// updateChange was never called, so no message was ever added.
assertThat(getMessages(id)).doesNotContain(UpdateRefAndAddMessageOp.CHANGE_MESSAGE);
try (Repository repo = repoManager.openRepository(project)) {
// Op lost the race, so the other writer's commit happened first. Op didn't retry, because the
// ref updates weren't atomic, so it didn't throw LockFailureException on failure.
assertThat(commitMessages(repo, initial, repo.exactRef(master).getObjectId())).containsExactly(ConcurrentWritingListener.MSG_PREFIX + "1");
}
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class NoteDbOnlyIT method updateChangeFailureRollsBackRefUpdate.
@Test
public void updateChangeFailureRollsBackRefUpdate() throws Exception {
assume().that(notesMigration.fuseUpdates()).isTrue();
PushOneCommit.Result r = createChange();
Change.Id id = r.getChange().getId();
String master = "refs/heads/master";
String backup = "refs/backup/master";
ObjectId master1 = getRef(master).get();
assertThat(getRef(backup)).isEmpty();
// Toy op that copies the value of refs/heads/master to refs/backup/master.
BatchUpdateOp backupMasterOp = new BatchUpdateOp() {
ObjectId newId;
@Override
public void updateRepo(RepoContext ctx) throws IOException {
ObjectId oldId = ctx.getRepoView().getRef(backup).orElse(ObjectId.zeroId());
newId = ctx.getRepoView().getRef(master).get();
ctx.addRefUpdate(oldId, newId, backup);
}
@Override
public boolean updateChange(ChangeContext ctx) {
ctx.getUpdate(ctx.getChange().currentPatchSetId()).setChangeMessage("Backed up master branch to " + newId.name());
return true;
}
};
try (BatchUpdate bu = newBatchUpdate(batchUpdateFactory)) {
bu.addOp(id, backupMasterOp);
bu.execute();
}
// Ensure backupMasterOp worked.
assertThat(getRef(backup)).hasValue(master1);
assertThat(getMessages(id)).contains("Backed up master branch to " + master1.name());
// Advance master by submitting the change.
gApi.changes().id(id.get()).current().review(ReviewInput.approve());
gApi.changes().id(id.get()).current().submit();
ObjectId master2 = getRef(master).get();
assertThat(master2).isNotEqualTo(master1);
int msgCount = getMessages(id).size();
try (BatchUpdate bu = newBatchUpdate(batchUpdateFactory)) {
// This time, we attempt to back up master, but we fail during updateChange.
bu.addOp(id, backupMasterOp);
String msg = "Change is bad";
bu.addOp(id, new BatchUpdateOp() {
@Override
public boolean updateChange(ChangeContext ctx) throws ResourceConflictException {
throw new ResourceConflictException(msg);
}
});
try {
bu.execute();
assert_().fail("expected ResourceConflictException");
} catch (ResourceConflictException e) {
assertThat(e).hasMessageThat().isEqualTo(msg);
}
}
// If updateChange hadn't failed, backup would have been updated to master2.
assertThat(getRef(backup)).hasValue(master1);
assertThat(getMessages(id)).hasSize(msgCount);
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class NoteDbOnlyIT method retryOnLockFailureWithAtomicUpdates.
@Test
public void retryOnLockFailureWithAtomicUpdates() throws Exception {
assume().that(notesMigration.fuseUpdates()).isTrue();
PushOneCommit.Result r = createChange();
Change.Id id = r.getChange().getId();
String master = "refs/heads/master";
ObjectId initial;
try (Repository repo = repoManager.openRepository(project)) {
((InMemoryRepository) repo).setPerformsAtomicTransactions(true);
initial = repo.exactRef(master).getObjectId();
}
AtomicInteger updateRepoCalledCount = new AtomicInteger();
AtomicInteger updateChangeCalledCount = new AtomicInteger();
AtomicInteger afterUpdateReposCalledCount = new AtomicInteger();
String result = retryHelper.execute(batchUpdateFactory -> {
try (BatchUpdate bu = newBatchUpdate(batchUpdateFactory)) {
bu.addOp(id, new UpdateRefAndAddMessageOp(updateRepoCalledCount, updateChangeCalledCount));
bu.execute(new ConcurrentWritingListener(afterUpdateReposCalledCount));
}
return "Done";
});
assertThat(result).isEqualTo("Done");
assertThat(updateRepoCalledCount.get()).isEqualTo(2);
assertThat(afterUpdateReposCalledCount.get()).isEqualTo(2);
assertThat(updateChangeCalledCount.get()).isEqualTo(2);
List<String> messages = getMessages(id);
assertThat(Iterables.getLast(messages)).isEqualTo(UpdateRefAndAddMessageOp.CHANGE_MESSAGE);
assertThat(Collections.frequency(messages, UpdateRefAndAddMessageOp.CHANGE_MESSAGE)).isEqualTo(1);
try (Repository repo = repoManager.openRepository(project)) {
// Op lost the race, so the other writer's commit happened first. Then op retried and wrote
// its commit with the other writer's commit as parent.
assertThat(commitMessages(repo, initial, repo.exactRef(master).getObjectId())).containsExactly(ConcurrentWritingListener.MSG_PREFIX + "1", UpdateRefAndAddMessageOp.COMMIT_MESSAGE).inOrder();
}
}
Aggregations