Search in sources :

Example 61 with StorageException

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);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IntBlob(com.google.gerrit.server.notedb.IntBlob) RevWalk(org.eclipse.jgit.revwalk.RevWalk) StorageException(com.google.gerrit.exceptions.StorageException)

Example 62 with StorageException

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();
}
Also used : Inject(com.google.inject.Inject) ArrayList(java.util.ArrayList) ExternalIdFactory(com.google.gerrit.server.account.externalids.ExternalIdFactory) AccountsUpdate(com.google.gerrit.server.account.AccountsUpdate) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) Sequences(com.google.gerrit.server.notedb.Sequences) StorageException(com.google.gerrit.exceptions.StorageException) Account(com.google.gerrit.entities.Account) Test(org.junit.Test) TestPlugin(com.google.gerrit.acceptance.TestPlugin) Truth.assertThat(com.google.common.truth.Truth.assertThat) ExternalIdUpsertPreprocessor(com.google.gerrit.server.account.externalids.ExternalIdUpsertPreprocessor) Provider(com.google.inject.Provider) List(java.util.List) LightweightPluginDaemonTest(com.google.gerrit.acceptance.LightweightPluginDaemonTest) ServerInitiated(com.google.gerrit.server.ServerInitiated) ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Exports(com.google.gerrit.extensions.annotations.Exports) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) Repository(org.eclipse.jgit.lib.Repository) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) AbstractModule(com.google.inject.AbstractModule) Singleton(com.google.inject.Singleton) Account(com.google.gerrit.entities.Account) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) StorageException(com.google.gerrit.exceptions.StorageException) Test(org.junit.Test) LightweightPluginDaemonTest(com.google.gerrit.acceptance.LightweightPluginDaemonTest)

Example 63 with StorageException

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");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StorageException(com.google.gerrit.exceptions.StorageException) Test(org.junit.Test)

Example 64 with StorageException

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);
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) TestRepository(org.eclipse.jgit.junit.TestRepository) StorageException(com.google.gerrit.exceptions.StorageException) Test(org.junit.Test)

Example 65 with StorageException

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;
}
Also used : AccountAttribute(com.google.gerrit.server.data.AccountAttribute) UserIdentity(com.google.gerrit.entities.UserIdentity) PatchSet(com.google.gerrit.entities.PatchSet) IOException(java.io.IOException) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput) DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException) PatchSetAttribute(com.google.gerrit.server.data.PatchSetAttribute) StorageException(com.google.gerrit.exceptions.StorageException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

StorageException (com.google.gerrit.exceptions.StorageException)153 IOException (java.io.IOException)68 Change (com.google.gerrit.entities.Change)47 ObjectId (org.eclipse.jgit.lib.ObjectId)37 Repository (org.eclipse.jgit.lib.Repository)33 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)30 PatchSet (com.google.gerrit.entities.PatchSet)29 RevCommit (org.eclipse.jgit.revwalk.RevCommit)28 ArrayList (java.util.ArrayList)25 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)24 Project (com.google.gerrit.entities.Project)22 Ref (org.eclipse.jgit.lib.Ref)22 ChangeData (com.google.gerrit.server.query.change.ChangeData)21 RevWalk (org.eclipse.jgit.revwalk.RevWalk)21 Account (com.google.gerrit.entities.Account)20 Inject (com.google.inject.Inject)19 Map (java.util.Map)19 Test (org.junit.Test)19 List (java.util.List)18 BranchNameKey (com.google.gerrit.entities.BranchNameKey)17