use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class NoteDbSchemaVersionManager method init.
public void init() throws IOException {
try (Repository repo = repoManager.openRepository(allProjectsName);
RevWalk rw = new RevWalk(repo)) {
Optional<IntBlob> old = IntBlob.parse(repo, REFS_VERSION, rw);
if (old.isPresent()) {
throw new StorageException(String.format("Expected no old version for %s, found %s", REFS_VERSION, old.get().value()));
}
IntBlob.store(repo, rw, allProjectsName, REFS_VERSION, old.map(IntBlob::id).orElse(ObjectId.zeroId()), NoteDbSchemaVersions.LATEST, GitReferenceUpdated.DISABLED);
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class ExternalIdNotesUpsertPreprocessorIT method blockUpsert.
@Test
public void blockUpsert() throws Exception {
Account.Id id = Account.id(sequences.nextAccountId());
ExternalId extId = extIdFactory.create("foo", "bar", id);
testPreprocessor.throwException = true;
StorageException e = assertThrows(StorageException.class, () -> accountsUpdateProvider.get().insert("test", id, u -> u.addExternalId(extId)));
assertThat(e).hasMessageThat().contains("upsert not good");
assertThat(testPreprocessor.upserted).isEmpty();
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class RepoSequenceTest method failAfterRetryerGivesUp.
@Test
public void failAfterRetryerGivesUp() throws Exception {
AtomicInteger bgCounter = new AtomicInteger(1234);
RepoSequence s = newSequence("id", 1, 10, () -> writeBlob("id", Integer.toString(bgCounter.getAndAdd(1000))), RetryerBuilder.<ImmutableList<Integer>>newBuilder().withStopStrategy(StopStrategies.stopAfterAttempt(3)).build());
StorageException thrown = assertThrows(StorageException.class, () -> s.next());
assertThat(thrown).hasMessageThat().contains("Failed to update refs/sequences/id: LOCK_FAILURE");
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class RepoSequenceTest method failOnWrongType.
@Test
public void failOnWrongType() throws Exception {
try (Repository repo = repoManager.openRepository(project);
TestRepository<Repository> tr = new TestRepository<>(repo)) {
tr.branch(RefNames.REFS_SEQUENCES + "id").commit().create();
StorageException e = assertThrows(StorageException.class, () -> newSequence("id", 1, 3).next());
assertThat(e.getCause()).isInstanceOf(IncorrectObjectTypeException.class);
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class EventFactory method asPatchSetAttribute.
/**
* Create a PatchSetAttribute for the given patchset suitable for serialization to JSON.
*/
public PatchSetAttribute asPatchSetAttribute(RevWalk revWalk, Change change, PatchSet patchSet) {
PatchSetAttribute p = new PatchSetAttribute();
p.revision = patchSet.commitId().name();
p.number = patchSet.number();
p.ref = patchSet.refName();
p.uploader = asAccountAttribute(patchSet.uploader());
p.createdOn = patchSet.createdOn().getEpochSecond();
PatchSet.Id pId = patchSet.id();
try {
p.parents = new ArrayList<>();
RevCommit c = revWalk.parseCommit(ObjectId.fromString(p.revision));
for (RevCommit parent : c.getParents()) {
p.parents.add(parent.name());
}
UserIdentity author = emails.toUserIdentity(c.getAuthorIdent());
if (author.getAccount() == null) {
p.author = new AccountAttribute();
p.author.email = author.getEmail();
p.author.name = author.getName();
p.author.username = "";
} else {
p.author = asAccountAttribute(author.getAccount());
}
Map<String, FileDiffOutput> modifiedFiles = diffOperations.listModifiedFilesAgainstParent(change.getProject(), patchSet.commitId(), /* parentNum= */
0, DiffOptions.DEFAULTS);
for (FileDiffOutput fileDiff : modifiedFiles.values()) {
p.sizeDeletions += fileDiff.deletions();
p.sizeInsertions += fileDiff.insertions();
}
p.kind = changeKindCache.getChangeKind(change, patchSet);
} catch (IOException | StorageException e) {
logger.atSevere().withCause(e).log("Cannot load patch set data for %s", patchSet.id());
} catch (DiffNotAvailableException e) {
logger.atSevere().withCause(e).log("Cannot get size information for %s.", pId);
}
return p;
}
Aggregations