Search in sources :

Example 1 with RetryerBuilder

use of com.github.rholder.retry.RetryerBuilder in project gerrit by GerritCodeReview.

the class ExternalIdIT method failAfterRetryerGivesUp.

@Test
public void failAfterRetryerGivesUp() throws Exception {
    ExternalId.Key[] extIdsKeys = { ExternalId.Key.create("foo", "foo"), ExternalId.Key.create("bar", "bar"), ExternalId.Key.create("baz", "baz") };
    final AtomicInteger bgCounter = new AtomicInteger(0);
    ExternalIdsUpdate update = new ExternalIdsUpdate(repoManager, allUsers, metricMaker, externalIds, new DisabledExternalIdCache(), serverIdent.get(), serverIdent.get(), () -> {
        try {
            extIdsUpdate.create().insert(ExternalId.create(extIdsKeys[bgCounter.getAndAdd(1)], admin.id));
        } catch (IOException | ConfigInvalidException | OrmException e) {
        // Ignore, the successful insertion of the external ID is asserted later
        }
    }, RetryerBuilder.<RefsMetaExternalIdsUpdate>newBuilder().retryIfException(e -> e instanceof LockFailureException).withStopStrategy(StopStrategies.stopAfterAttempt(extIdsKeys.length)).build());
    assertThat(bgCounter.get()).isEqualTo(0);
    try {
        update.insert(ExternalId.create(ExternalId.Key.create("abc", "abc"), admin.id));
        fail("expected LockFailureException");
    } catch (LockFailureException e) {
    // Ignore, expected
    }
    assertThat(bgCounter.get()).isEqualTo(extIdsKeys.length);
    for (ExternalId.Key extIdKey : extIdsKeys) {
        assertThat(externalIds.get(extIdKey)).isNotNull();
    }
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) TypeToken(com.google.gson.reflect.TypeToken) OrmException(com.google.gwtorm.server.OrmException) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) OBJ_BLOB(org.eclipse.jgit.lib.Constants.OBJ_BLOB) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) Retryer(com.github.rholder.retry.Retryer) RetryerBuilder(com.github.rholder.retry.RetryerBuilder) Inject(com.google.inject.Inject) RestResponse(com.google.gerrit.acceptance.RestResponse) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BlockStrategy(com.github.rholder.retry.BlockStrategy) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Config(org.eclipse.jgit.lib.Config) SCHEME_USERNAME(com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USERNAME) ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) AuthException(com.google.gerrit.extensions.restapi.AuthException) Assert.fail(org.junit.Assert.fail) SCHEME_UUID(com.google.gerrit.server.account.externalids.ExternalId.SCHEME_UUID) NoteMap(org.eclipse.jgit.notes.NoteMap) CheckAccountExternalIdsInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountExternalIdsInput) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) Permission(com.google.gerrit.common.data.Permission) ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo) Set(java.util.Set) ExternalIds(com.google.gerrit.server.account.externalids.ExternalIds) List(java.util.List) StopStrategies(com.github.rholder.retry.StopStrategies) RefNames(com.google.gerrit.reviewdb.client.RefNames) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) MetricMaker(com.google.gerrit.metrics.MetricMaker) ExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate) GitUtil.fetch(com.google.gerrit.acceptance.GitUtil.fetch) Iterables(com.google.common.collect.Iterables) Status(org.eclipse.jgit.transport.RemoteRefUpdate.Status) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) OrmDuplicateKeyException(com.google.gwtorm.server.OrmDuplicateKeyException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RefsMetaExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate.RefsMetaExternalIdsUpdate) LockFailureException(com.google.gerrit.server.git.LockFailureException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DisabledExternalIdCache(com.google.gerrit.server.account.externalids.DisabledExternalIdCache) ImmutableList(com.google.common.collect.ImmutableList) AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo) Account(com.google.gerrit.reviewdb.client.Account) ConsistencyCheckInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput) GitUtil.pushHead(com.google.gerrit.acceptance.GitUtil.pushHead) TestRepository(org.eclipse.jgit.junit.TestRepository) Sandboxed(com.google.gerrit.acceptance.Sandboxed) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ExternalIdReader(com.google.gerrit.server.account.externalids.ExternalIdReader) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) SCHEME_MAILTO(com.google.gerrit.server.account.externalids.ExternalId.SCHEME_MAILTO) MutableInteger(org.eclipse.jgit.util.MutableInteger) ObjectId(org.eclipse.jgit.lib.ObjectId) TransportException(org.eclipse.jgit.api.errors.TransportException) Collectors.toList(java.util.stream.Collectors.toList) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RefsMetaExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate.RefsMetaExternalIdsUpdate) ExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate) RefsMetaExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate.RefsMetaExternalIdsUpdate) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) IOException(java.io.IOException) LockFailureException(com.google.gerrit.server.git.LockFailureException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OrmException(com.google.gwtorm.server.OrmException) DisabledExternalIdCache(com.google.gerrit.server.account.externalids.DisabledExternalIdCache) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

BlockStrategy (com.github.rholder.retry.BlockStrategy)1 Retryer (com.github.rholder.retry.Retryer)1 RetryerBuilder (com.github.rholder.retry.RetryerBuilder)1 StopStrategies (com.github.rholder.retry.StopStrategies)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 GitUtil.fetch (com.google.gerrit.acceptance.GitUtil.fetch)1 GitUtil.pushHead (com.google.gerrit.acceptance.GitUtil.pushHead)1 RestResponse (com.google.gerrit.acceptance.RestResponse)1 Sandboxed (com.google.gerrit.acceptance.Sandboxed)1 GlobalCapability (com.google.gerrit.common.data.GlobalCapability)1 Permission (com.google.gerrit.common.data.Permission)1 ConsistencyCheckInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo)1 ConsistencyProblemInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo)1 ConsistencyCheckInput (com.google.gerrit.extensions.api.config.ConsistencyCheckInput)1 CheckAccountExternalIdsInput (com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountExternalIdsInput)1 AccountExternalIdInfo (com.google.gerrit.extensions.common.AccountExternalIdInfo)1