DynamicSet: Store names of plugins who bound the items
For the items in DynamicItem and DynamicMap we are storing the name of the plugin which has bound the item. Do the same for items in DynamicSet so that we can provide items from DynamicSet by plugin. Being able to get the name of the plugin that has bound the item is useful for logging and debugging. Change-Id: I990afdc117e18f8544ca376788ce0f35bb1c2ec5 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
		@@ -63,6 +63,7 @@ public class EventRecorder {
 | 
			
		||||
 | 
			
		||||
    eventListenerRegistration =
 | 
			
		||||
        eventListeners.add(
 | 
			
		||||
            "gerrit",
 | 
			
		||||
            new UserScopedEventListener() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public void onEvent(Event e) {
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,12 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.extensions.registration;
 | 
			
		||||
 | 
			
		||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
 | 
			
		||||
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
 | 
			
		||||
import static java.util.Comparator.naturalOrder;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.ImmutableSet;
 | 
			
		||||
import com.google.common.collect.ImmutableSortedSet;
 | 
			
		||||
import com.google.inject.Binder;
 | 
			
		||||
import com.google.inject.Key;
 | 
			
		||||
import com.google.inject.Provider;
 | 
			
		||||
@@ -39,6 +45,24 @@ import java.util.concurrent.atomic.AtomicReference;
 | 
			
		||||
 * singleton and non-singleton members.
 | 
			
		||||
 */
 | 
			
		||||
public class DynamicSet<T> implements Iterable<T> {
 | 
			
		||||
  public static class Entry<T> {
 | 
			
		||||
    private final String pluginName;
 | 
			
		||||
    private final Provider<T> provider;
 | 
			
		||||
 | 
			
		||||
    private Entry(String pluginName, Provider<T> provider) {
 | 
			
		||||
      this.pluginName = pluginName;
 | 
			
		||||
      this.provider = provider;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getPluginName() {
 | 
			
		||||
      return pluginName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Provider<T> getProvider() {
 | 
			
		||||
      return provider;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Declare a singleton {@code DynamicSet<T>} with a binder.
 | 
			
		||||
   *
 | 
			
		||||
@@ -129,12 +153,12 @@ public class DynamicSet<T> implements Iterable<T> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static <T> DynamicSet<T> emptySet() {
 | 
			
		||||
    return new DynamicSet<>(Collections.<AtomicReference<Provider<T>>>emptySet());
 | 
			
		||||
    return new DynamicSet<>(Collections.<AtomicReference<NamedProvider<T>>>emptySet());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private final CopyOnWriteArrayList<AtomicReference<Provider<T>>> items;
 | 
			
		||||
  private final CopyOnWriteArrayList<AtomicReference<NamedProvider<T>>> items;
 | 
			
		||||
 | 
			
		||||
  DynamicSet(Collection<AtomicReference<Provider<T>>> base) {
 | 
			
		||||
  DynamicSet(Collection<AtomicReference<NamedProvider<T>>> base) {
 | 
			
		||||
    items = new CopyOnWriteArrayList<>(base);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -144,17 +168,33 @@ public class DynamicSet<T> implements Iterable<T> {
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public Iterator<T> iterator() {
 | 
			
		||||
    final Iterator<AtomicReference<Provider<T>>> itr = items.iterator();
 | 
			
		||||
    Iterator<Entry<T>> entryIterator = entryIterator();
 | 
			
		||||
    return new Iterator<T>() {
 | 
			
		||||
      private T next;
 | 
			
		||||
      @Override
 | 
			
		||||
      public boolean hasNext() {
 | 
			
		||||
        return entryIterator.hasNext();
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public T next() {
 | 
			
		||||
        Entry<T> next = entryIterator.next();
 | 
			
		||||
        return next != null ? next.getProvider().get() : null;
 | 
			
		||||
      }
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public Iterator<Entry<T>> entryIterator() {
 | 
			
		||||
    final Iterator<AtomicReference<NamedProvider<T>>> itr = items.iterator();
 | 
			
		||||
    return new Iterator<Entry<T>>() {
 | 
			
		||||
      private Entry<T> next;
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public boolean hasNext() {
 | 
			
		||||
        while (next == null && itr.hasNext()) {
 | 
			
		||||
          Provider<T> p = itr.next().get();
 | 
			
		||||
          NamedProvider<T> p = itr.next().get();
 | 
			
		||||
          if (p != null) {
 | 
			
		||||
            try {
 | 
			
		||||
              next = p.get();
 | 
			
		||||
              next = new Entry<>(p.pluginName, p.impl);
 | 
			
		||||
            } catch (RuntimeException e) {
 | 
			
		||||
              // TODO Log failed member of DynamicSet.
 | 
			
		||||
            }
 | 
			
		||||
@@ -164,9 +204,9 @@ public class DynamicSet<T> implements Iterable<T> {
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public T next() {
 | 
			
		||||
      public Entry<T> next() {
 | 
			
		||||
        if (hasNext()) {
 | 
			
		||||
          T result = next;
 | 
			
		||||
          Entry<T> result = next;
 | 
			
		||||
          next = null;
 | 
			
		||||
          return result;
 | 
			
		||||
        }
 | 
			
		||||
@@ -198,13 +238,29 @@ public class DynamicSet<T> implements Iterable<T> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Add one new element to the set.
 | 
			
		||||
   * Get the names of all running plugins supplying this type.
 | 
			
		||||
   *
 | 
			
		||||
   * @param item the item to add to the collection. Must not be null.
 | 
			
		||||
   * @return handle to remove the item at a later point in time.
 | 
			
		||||
   * @return sorted set of active plugins that supply at least one item.
 | 
			
		||||
   */
 | 
			
		||||
  public RegistrationHandle add(T item) {
 | 
			
		||||
    return add(Providers.of(item));
 | 
			
		||||
  public ImmutableSortedSet<String> plugins() {
 | 
			
		||||
    return items
 | 
			
		||||
        .stream()
 | 
			
		||||
        .map(i -> i.get().pluginName)
 | 
			
		||||
        .collect(toImmutableSortedSet(naturalOrder()));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get the items exported by a single plugin.
 | 
			
		||||
   *
 | 
			
		||||
   * @param pluginName name of the plugin.
 | 
			
		||||
   * @return items exported by a plugin.
 | 
			
		||||
   */
 | 
			
		||||
  public ImmutableSet<Provider<T>> byPlugin(String pluginName) {
 | 
			
		||||
    return items
 | 
			
		||||
        .stream()
 | 
			
		||||
        .filter(i -> i.get().pluginName.equals(pluginName))
 | 
			
		||||
        .map(i -> i.get().impl)
 | 
			
		||||
        .collect(toImmutableSet());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
@@ -213,13 +269,24 @@ public class DynamicSet<T> implements Iterable<T> {
 | 
			
		||||
   * @param item the item to add to the collection. Must not be null.
 | 
			
		||||
   * @return handle to remove the item at a later point in time.
 | 
			
		||||
   */
 | 
			
		||||
  public RegistrationHandle add(Provider<T> item) {
 | 
			
		||||
    final AtomicReference<Provider<T>> ref = new AtomicReference<>(item);
 | 
			
		||||
  public RegistrationHandle add(String pluginName, T item) {
 | 
			
		||||
    return add(pluginName, Providers.of(item));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Add one new element to the set.
 | 
			
		||||
   *
 | 
			
		||||
   * @param item the item to add to the collection. Must not be null.
 | 
			
		||||
   * @return handle to remove the item at a later point in time.
 | 
			
		||||
   */
 | 
			
		||||
  public RegistrationHandle add(String pluginName, Provider<T> item) {
 | 
			
		||||
    final AtomicReference<NamedProvider<T>> ref =
 | 
			
		||||
        new AtomicReference<>(new NamedProvider<>(item, pluginName));
 | 
			
		||||
    items.add(ref);
 | 
			
		||||
    return new RegistrationHandle() {
 | 
			
		||||
      @Override
 | 
			
		||||
      public void remove() {
 | 
			
		||||
        if (ref.compareAndSet(item, null)) {
 | 
			
		||||
        if (ref.compareAndSet(ref.get(), null)) {
 | 
			
		||||
          items.remove(ref);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
@@ -229,6 +296,7 @@ public class DynamicSet<T> implements Iterable<T> {
 | 
			
		||||
  /**
 | 
			
		||||
   * Add one new element that may be hot-replaceable in the future.
 | 
			
		||||
   *
 | 
			
		||||
   * @param pluginName unique name of the plugin providing the item.
 | 
			
		||||
   * @param key unique description from the item's Guice binding. This can be later obtained from
 | 
			
		||||
   *     the registration handle to facilitate matching with the new equivalent instance during a
 | 
			
		||||
   *     hot reload.
 | 
			
		||||
@@ -236,18 +304,19 @@ public class DynamicSet<T> implements Iterable<T> {
 | 
			
		||||
   * @return a handle that can remove this item later, or hot-swap the item without it ever leaving
 | 
			
		||||
   *     the collection.
 | 
			
		||||
   */
 | 
			
		||||
  public ReloadableRegistrationHandle<T> add(Key<T> key, Provider<T> item) {
 | 
			
		||||
    AtomicReference<Provider<T>> ref = new AtomicReference<>(item);
 | 
			
		||||
  public ReloadableRegistrationHandle<T> add(String pluginName, Key<T> key, Provider<T> item) {
 | 
			
		||||
    AtomicReference<NamedProvider<T>> ref =
 | 
			
		||||
        new AtomicReference<>(new NamedProvider<>(item, pluginName));
 | 
			
		||||
    items.add(ref);
 | 
			
		||||
    return new ReloadableHandle(ref, key, item);
 | 
			
		||||
    return new ReloadableHandle(ref, key, ref.get());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private class ReloadableHandle implements ReloadableRegistrationHandle<T> {
 | 
			
		||||
    private final AtomicReference<Provider<T>> ref;
 | 
			
		||||
    private final AtomicReference<NamedProvider<T>> ref;
 | 
			
		||||
    private final Key<T> key;
 | 
			
		||||
    private final Provider<T> item;
 | 
			
		||||
    private final NamedProvider<T> item;
 | 
			
		||||
 | 
			
		||||
    ReloadableHandle(AtomicReference<Provider<T>> ref, Key<T> key, Provider<T> item) {
 | 
			
		||||
    ReloadableHandle(AtomicReference<NamedProvider<T>> ref, Key<T> key, NamedProvider<T> item) {
 | 
			
		||||
      this.ref = ref;
 | 
			
		||||
      this.key = key;
 | 
			
		||||
      this.item = item;
 | 
			
		||||
@@ -267,8 +336,9 @@ public class DynamicSet<T> implements Iterable<T> {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ReloadableHandle replace(Key<T> newKey, Provider<T> newItem) {
 | 
			
		||||
      if (ref.compareAndSet(item, newItem)) {
 | 
			
		||||
        return new ReloadableHandle(ref, newKey, newItem);
 | 
			
		||||
      NamedProvider<T> n = new NamedProvider<>(newItem, item.pluginName);
 | 
			
		||||
      if (ref.compareAndSet(item, n)) {
 | 
			
		||||
        return new ReloadableHandle(ref, newKey, n);
 | 
			
		||||
      }
 | 
			
		||||
      return null;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -38,16 +38,17 @@ class DynamicSetProvider<T> implements Provider<DynamicSet<T>> {
 | 
			
		||||
    return new DynamicSet<>(find(injector, type));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static <T> List<AtomicReference<Provider<T>>> find(Injector src, TypeLiteral<T> type) {
 | 
			
		||||
  private static <T> List<AtomicReference<NamedProvider<T>>> find(
 | 
			
		||||
      Injector src, TypeLiteral<T> type) {
 | 
			
		||||
    List<Binding<T>> bindings = src.findBindingsByType(type);
 | 
			
		||||
    int cnt = bindings != null ? bindings.size() : 0;
 | 
			
		||||
    if (cnt == 0) {
 | 
			
		||||
      return Collections.emptyList();
 | 
			
		||||
    }
 | 
			
		||||
    List<AtomicReference<Provider<T>>> r = new ArrayList<>(cnt);
 | 
			
		||||
    List<AtomicReference<NamedProvider<T>>> r = new ArrayList<>(cnt);
 | 
			
		||||
    for (Binding<T> b : bindings) {
 | 
			
		||||
      if (b.getKey().getAnnotation() != null) {
 | 
			
		||||
        r.add(new AtomicReference<>(b.getProvider()));
 | 
			
		||||
        r.add(new AtomicReference<>(new NamedProvider<>(b.getProvider(), PluginName.GERRIT)));
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return r;
 | 
			
		||||
 
 | 
			
		||||
@@ -107,7 +107,7 @@ public class PrivateInternals_DynamicTypes {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static List<RegistrationHandle> attachSets(
 | 
			
		||||
      Injector src, Map<TypeLiteral<?>, DynamicSet<?>> sets) {
 | 
			
		||||
      Injector src, String pluginName, Map<TypeLiteral<?>, DynamicSet<?>> sets) {
 | 
			
		||||
    if (src == null || sets == null || sets.isEmpty()) {
 | 
			
		||||
      return Collections.emptyList();
 | 
			
		||||
    }
 | 
			
		||||
@@ -123,7 +123,7 @@ public class PrivateInternals_DynamicTypes {
 | 
			
		||||
 | 
			
		||||
        for (Binding<Object> b : bindings(src, type)) {
 | 
			
		||||
          if (b.getKey().getAnnotation() != null) {
 | 
			
		||||
            handles.add(set.add(b.getKey(), b.getProvider()));
 | 
			
		||||
            handles.add(set.add(pluginName, b.getKey(), b.getProvider()));
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
@@ -174,7 +174,7 @@ public class PrivateInternals_DynamicTypes {
 | 
			
		||||
        handles = new ArrayList<>(4);
 | 
			
		||||
        Injector parent = self.getParent();
 | 
			
		||||
        while (parent != null) {
 | 
			
		||||
          handles.addAll(attachSets(self, dynamicSetsOf(parent)));
 | 
			
		||||
          handles.addAll(attachSets(self, PluginName.GERRIT, dynamicSetsOf(parent)));
 | 
			
		||||
          handles.addAll(attachMaps(self, PluginName.GERRIT, dynamicMapsOf(parent)));
 | 
			
		||||
          parent = parent.getParent();
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -76,7 +76,7 @@ public abstract class AllRequestFilter implements Filter {
 | 
			
		||||
        // synchronized.
 | 
			
		||||
        if (!initializedFilters.contains(filter)) {
 | 
			
		||||
          filter.init(filterConfig);
 | 
			
		||||
          initializedFilters.add(filter);
 | 
			
		||||
          initializedFilters.add("gerrit", filter);
 | 
			
		||||
        }
 | 
			
		||||
      } else {
 | 
			
		||||
        ret = false;
 | 
			
		||||
@@ -89,7 +89,7 @@ public abstract class AllRequestFilter implements Filter {
 | 
			
		||||
      initializedFilters = new DynamicSet<>();
 | 
			
		||||
      for (AllRequestFilter filter : filtersToCleanUp) {
 | 
			
		||||
        if (filters.contains(filter)) {
 | 
			
		||||
          initializedFilters.add(filter);
 | 
			
		||||
          initializedFilters.add("gerrit", filter);
 | 
			
		||||
        } else {
 | 
			
		||||
          filter.destroy();
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -281,7 +281,8 @@ public class PluginGuiceEnvironment {
 | 
			
		||||
 | 
			
		||||
  private void attachSet(
 | 
			
		||||
      Map<TypeLiteral<?>, DynamicSet<?>> sets, @Nullable Injector src, Plugin plugin) {
 | 
			
		||||
    for (RegistrationHandle h : PrivateInternals_DynamicTypes.attachSets(src, sets)) {
 | 
			
		||||
    for (RegistrationHandle h :
 | 
			
		||||
        PrivateInternals_DynamicTypes.attachSets(src, plugin.getName(), sets)) {
 | 
			
		||||
      plugin.add(h);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@@ -434,7 +435,7 @@ public class PluginGuiceEnvironment {
 | 
			
		||||
          oi.remove();
 | 
			
		||||
          replace(newPlugin, h2, b);
 | 
			
		||||
        } else {
 | 
			
		||||
          newPlugin.add(set.add(b.getKey(), b.getProvider()));
 | 
			
		||||
          newPlugin.add(set.add(newPlugin.getName(), b.getKey(), b.getProvider()));
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -151,6 +151,7 @@ final class StreamEvents extends BaseCommand {
 | 
			
		||||
    stdout = toPrintWriter(out);
 | 
			
		||||
    eventListenerRegistration =
 | 
			
		||||
        eventListeners.add(
 | 
			
		||||
            "gerrit",
 | 
			
		||||
            new UserScopedEventListener() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public void onEvent(Event event) {
 | 
			
		||||
 
 | 
			
		||||
@@ -39,7 +39,7 @@ public class TestGroupBackendTest extends AbstractDaemonTest {
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void universalGroupBackendHandlesTestGroup() throws Exception {
 | 
			
		||||
    RegistrationHandle registrationHandle = groupBackends.add(testGroupBackend);
 | 
			
		||||
    RegistrationHandle registrationHandle = groupBackends.add("gerrit", testGroupBackend);
 | 
			
		||||
    try {
 | 
			
		||||
      assertThat(universalGroupBackend.handles(testUUID)).isTrue();
 | 
			
		||||
    } finally {
 | 
			
		||||
 
 | 
			
		||||
@@ -230,7 +230,7 @@ public class AccountIT extends AbstractDaemonTest {
 | 
			
		||||
  @Before
 | 
			
		||||
  public void addAccountIndexEventCounter() {
 | 
			
		||||
    accountIndexedCounter = new AccountIndexedCounter();
 | 
			
		||||
    accountIndexEventCounterHandle = accountIndexedListeners.add(accountIndexedCounter);
 | 
			
		||||
    accountIndexEventCounterHandle = accountIndexedListeners.add("gerrit", accountIndexedCounter);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @After
 | 
			
		||||
@@ -243,7 +243,7 @@ public class AccountIT extends AbstractDaemonTest {
 | 
			
		||||
  @Before
 | 
			
		||||
  public void addRefUpdateCounter() {
 | 
			
		||||
    refUpdateCounter = new RefUpdateCounter();
 | 
			
		||||
    refUpdateCounterHandle = refUpdateListeners.add(refUpdateCounter);
 | 
			
		||||
    refUpdateCounterHandle = refUpdateListeners.add("gerrit", refUpdateCounter);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @After
 | 
			
		||||
@@ -532,6 +532,7 @@ public class AccountIT extends AbstractDaemonTest {
 | 
			
		||||
        accountOperations.newAccount().preferredEmail("foo@deactivatable.com").create();
 | 
			
		||||
    RegistrationHandle registrationHandle =
 | 
			
		||||
        accountActivationValidationListeners.add(
 | 
			
		||||
            "gerrit",
 | 
			
		||||
            new AccountActivationValidationListener() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public void validateActivation(AccountState account) throws ValidationException {
 | 
			
		||||
 
 | 
			
		||||
@@ -203,7 +203,7 @@ public class ChangeIT extends AbstractDaemonTest {
 | 
			
		||||
  @Before
 | 
			
		||||
  public void addChangeIndexedCounter() {
 | 
			
		||||
    changeIndexedCounter = new ChangeIndexedCounter();
 | 
			
		||||
    changeIndexedCounterHandle = changeIndexedListeners.add(changeIndexedCounter);
 | 
			
		||||
    changeIndexedCounterHandle = changeIndexedListeners.add("gerrit", changeIndexedCounter);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @After
 | 
			
		||||
@@ -2599,6 +2599,7 @@ public class ChangeIT extends AbstractDaemonTest {
 | 
			
		||||
    PushOneCommit.Result change = createChange();
 | 
			
		||||
    RegistrationHandle handle =
 | 
			
		||||
        changeMessageModifiers.add(
 | 
			
		||||
            "gerrit",
 | 
			
		||||
            new ChangeMessageModifier() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public String onSubmit(
 | 
			
		||||
 
 | 
			
		||||
@@ -1298,7 +1298,7 @@ public class GroupsIT extends AbstractDaemonTest {
 | 
			
		||||
 | 
			
		||||
    GroupIndexedCounter groupIndexedCounter = new GroupIndexedCounter();
 | 
			
		||||
    RegistrationHandle groupIndexEventCounterHandle =
 | 
			
		||||
        groupIndexedListeners.add(groupIndexedCounter);
 | 
			
		||||
        groupIndexedListeners.add("gerrit", groupIndexedCounter);
 | 
			
		||||
    try {
 | 
			
		||||
      // Running the reindexer right after startup should not need to reindex any group since
 | 
			
		||||
      // reindexing was already done on startup.
 | 
			
		||||
@@ -1355,7 +1355,7 @@ public class GroupsIT extends AbstractDaemonTest {
 | 
			
		||||
 | 
			
		||||
    GroupIndexedCounter groupIndexedCounter = new GroupIndexedCounter();
 | 
			
		||||
    RegistrationHandle groupIndexEventCounterHandle =
 | 
			
		||||
        groupIndexedListeners.add(groupIndexedCounter);
 | 
			
		||||
        groupIndexedListeners.add("gerrit", groupIndexedCounter);
 | 
			
		||||
    try {
 | 
			
		||||
      // No group indexing happened on startup. All groups should be reindexed now.
 | 
			
		||||
      slaveGroupIndexer.run();
 | 
			
		||||
 
 | 
			
		||||
@@ -68,7 +68,7 @@ public class ProjectIT extends AbstractDaemonTest {
 | 
			
		||||
  @Before
 | 
			
		||||
  public void addProjectIndexedCounter() {
 | 
			
		||||
    projectIndexedCounter = new ProjectIndexedCounter();
 | 
			
		||||
    projectIndexedCounterHandle = projectIndexedListeners.add(projectIndexedCounter);
 | 
			
		||||
    projectIndexedCounterHandle = projectIndexedListeners.add("gerrit", projectIndexedCounter);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @After
 | 
			
		||||
 
 | 
			
		||||
@@ -920,6 +920,7 @@ public class RevisionIT extends AbstractDaemonTest {
 | 
			
		||||
    CountDownLatch reindexed = new CountDownLatch(1);
 | 
			
		||||
    RegistrationHandle handle =
 | 
			
		||||
        changeIndexedListeners.add(
 | 
			
		||||
            "gerrit",
 | 
			
		||||
            new ChangeIndexedListener() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public void onChangeIndexed(String projectName, int id) {
 | 
			
		||||
@@ -1086,6 +1087,7 @@ public class RevisionIT extends AbstractDaemonTest {
 | 
			
		||||
    WebLinkInfo expectedWebLinkInfo = new WebLinkInfo("foo", "imageUrl", "url");
 | 
			
		||||
    RegistrationHandle handle =
 | 
			
		||||
        patchSetLinks.add(
 | 
			
		||||
            "gerrit",
 | 
			
		||||
            new PatchSetWebLink() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public WebLinkInfo getPatchSetWebLink(String projectName, String commit) {
 | 
			
		||||
 
 | 
			
		||||
@@ -52,9 +52,10 @@ public class TraceIT extends AbstractDaemonTest {
 | 
			
		||||
  public void setup() {
 | 
			
		||||
    projectCreationListener = new TraceValidatingProjectCreationValidationListener();
 | 
			
		||||
    projectCreationListenerRegistrationHandle =
 | 
			
		||||
        projectCreationValidationListeners.add(projectCreationListener);
 | 
			
		||||
        projectCreationValidationListeners.add("gerrit", projectCreationListener);
 | 
			
		||||
    commitValidationListener = new TraceValidatingCommitValidationListener();
 | 
			
		||||
    commitValidationRegistrationHandle = commitValidationListeners.add(commitValidationListener);
 | 
			
		||||
    commitValidationRegistrationHandle =
 | 
			
		||||
        commitValidationListeners.add("gerrit", commitValidationListener);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @After
 | 
			
		||||
 
 | 
			
		||||
@@ -1324,7 +1324,7 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
 | 
			
		||||
 | 
			
		||||
  protected void addOnSubmitValidationListener(OnSubmitValidationListener listener) {
 | 
			
		||||
    assertThat(onSubmitValidatorHandle).isNull();
 | 
			
		||||
    onSubmitValidatorHandle = onSubmitValidationListeners.add(listener);
 | 
			
		||||
    onSubmitValidatorHandle = onSubmitValidationListeners.add("gerrit", listener);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private String getLatestDiff(Repository repo) throws Exception {
 | 
			
		||||
 
 | 
			
		||||
@@ -331,7 +331,7 @@ public class ActionsIT extends AbstractDaemonTest {
 | 
			
		||||
    assertThat(origActions.get("abandon").label).isEqualTo("Abandon");
 | 
			
		||||
 | 
			
		||||
    Visitor v = new Visitor();
 | 
			
		||||
    visitorHandle = actionVisitors.add(v);
 | 
			
		||||
    visitorHandle = actionVisitors.add("gerrit", v);
 | 
			
		||||
 | 
			
		||||
    Map<String, ActionInfo> newActions =
 | 
			
		||||
        gApi.changes().id(id).get(EnumSet.of(ListChangesOption.CHANGE_ACTIONS)).actions;
 | 
			
		||||
@@ -380,7 +380,7 @@ public class ActionsIT extends AbstractDaemonTest {
 | 
			
		||||
    assertThat(origActions.get("rebase").label).isEqualTo("Rebase");
 | 
			
		||||
 | 
			
		||||
    Visitor v = new Visitor();
 | 
			
		||||
    visitorHandle = actionVisitors.add(v);
 | 
			
		||||
    visitorHandle = actionVisitors.add("gerrit", v);
 | 
			
		||||
 | 
			
		||||
    // Test different codepaths within ActionJson...
 | 
			
		||||
    // ...via revision API.
 | 
			
		||||
@@ -443,7 +443,7 @@ public class ActionsIT extends AbstractDaemonTest {
 | 
			
		||||
    assertThat(origActions.get("description").label).isEqualTo("Edit Description");
 | 
			
		||||
 | 
			
		||||
    Visitor v = new Visitor();
 | 
			
		||||
    visitorHandle = actionVisitors.add(v);
 | 
			
		||||
    visitorHandle = actionVisitors.add("gerrit", v);
 | 
			
		||||
 | 
			
		||||
    // Unlike for the current revision, actions for old revisions are only available via the
 | 
			
		||||
    // revision API.
 | 
			
		||||
 
 | 
			
		||||
@@ -97,6 +97,7 @@ public class SubmitByCherryPickIT extends AbstractSubmit {
 | 
			
		||||
    PushOneCommit.Result change = createChange();
 | 
			
		||||
    RegistrationHandle handle =
 | 
			
		||||
        changeMessageModifiers.add(
 | 
			
		||||
            "gerrit",
 | 
			
		||||
            new ChangeMessageModifier() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public String onSubmit(
 | 
			
		||||
 
 | 
			
		||||
@@ -87,6 +87,7 @@ public class SubmitByRebaseAlwaysIT extends AbstractSubmitByRebase {
 | 
			
		||||
 | 
			
		||||
    RegistrationHandle handle =
 | 
			
		||||
        changeMessageModifiers.add(
 | 
			
		||||
            "gerrit",
 | 
			
		||||
            new ChangeMessageModifier() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public String onSubmit(
 | 
			
		||||
 
 | 
			
		||||
@@ -89,6 +89,7 @@ public class AccessIT extends AbstractDaemonTest {
 | 
			
		||||
  public void webLink() throws Exception {
 | 
			
		||||
    RegistrationHandle handle =
 | 
			
		||||
        fileHistoryWebLinkDynamicSet.add(
 | 
			
		||||
            "gerrit",
 | 
			
		||||
            new FileHistoryWebLink() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public WebLinkInfo getFileHistoryWebLink(
 | 
			
		||||
@@ -111,6 +112,7 @@ public class AccessIT extends AbstractDaemonTest {
 | 
			
		||||
  public void webLinkNoRefsMetaConfig() throws Exception {
 | 
			
		||||
    RegistrationHandle handle =
 | 
			
		||||
        fileHistoryWebLinkDynamicSet.add(
 | 
			
		||||
            "gerrit",
 | 
			
		||||
            new FileHistoryWebLink() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public WebLinkInfo getFileHistoryWebLink(
 | 
			
		||||
 
 | 
			
		||||
@@ -76,6 +76,7 @@ public class CommentAddedEventIT extends AbstractDaemonTest {
 | 
			
		||||
 | 
			
		||||
    eventListenerRegistration =
 | 
			
		||||
        source.add(
 | 
			
		||||
            "gerrit",
 | 
			
		||||
            new CommentAddedListener() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public void onCommentAdded(Event event) {
 | 
			
		||||
 
 | 
			
		||||
@@ -610,7 +610,7 @@ public class OnlineNoteDbMigrationIT extends AbstractDaemonTest {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void addListener(NotesMigrationStateListener listener) {
 | 
			
		||||
    addedListeners.add(listeners.add(listener));
 | 
			
		||||
    addedListeners.add(listeners.add("gerrit", listener));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private ImmutableSortedSet<String> getObjectFiles(Project.NameKey project) throws Exception {
 | 
			
		||||
 
 | 
			
		||||
@@ -82,6 +82,7 @@ public class CustomLabelIT extends AbstractDaemonTest {
 | 
			
		||||
 | 
			
		||||
    eventListenerRegistration =
 | 
			
		||||
        source.add(
 | 
			
		||||
            "gerrit",
 | 
			
		||||
            new CommentAddedListener() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public void onCommentAdded(Event event) {
 | 
			
		||||
 
 | 
			
		||||
@@ -50,7 +50,7 @@ public abstract class AbstractIndexTests extends AbstractDaemonTest {
 | 
			
		||||
  @Before
 | 
			
		||||
  public void addChangeIndexedCounter() {
 | 
			
		||||
    changeIndexedCounter = new ChangeIndexedCounter();
 | 
			
		||||
    changeIndexedCounterHandle = changeIndexedListeners.add(changeIndexedCounter);
 | 
			
		||||
    changeIndexedCounterHandle = changeIndexedListeners.add("gerrit", changeIndexedCounter);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @After
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ public class SshTraceIT extends AbstractDaemonTest {
 | 
			
		||||
  public void setup() {
 | 
			
		||||
    projectCreationListener = new TraceValidatingProjectCreationValidationListener();
 | 
			
		||||
    projectCreationListenerRegistrationHandle =
 | 
			
		||||
        projectCreationValidationListeners.add(projectCreationListener);
 | 
			
		||||
        projectCreationValidationListeners.add("gerrit", projectCreationListener);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @After
 | 
			
		||||
 
 | 
			
		||||
@@ -15,9 +15,12 @@
 | 
			
		||||
package com.google.gerrit.extensions.registration;
 | 
			
		||||
 | 
			
		||||
import static com.google.common.truth.Truth.assertThat;
 | 
			
		||||
import static java.util.stream.Collectors.toSet;
 | 
			
		||||
 | 
			
		||||
import com.google.inject.Key;
 | 
			
		||||
import com.google.inject.Provider;
 | 
			
		||||
import com.google.inject.util.Providers;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
public class DynamicSetTest {
 | 
			
		||||
@@ -40,7 +43,7 @@ public class DynamicSetTest {
 | 
			
		||||
  @Test
 | 
			
		||||
  public void containsTrueWithSingleElement() throws Exception {
 | 
			
		||||
    DynamicSet<Integer> ds = new DynamicSet<>();
 | 
			
		||||
    ds.add(2);
 | 
			
		||||
    ds.add("gerrit", 2);
 | 
			
		||||
 | 
			
		||||
    assertThat(ds.contains(2)).isTrue(); // See above comment about ds.contains
 | 
			
		||||
  }
 | 
			
		||||
@@ -48,7 +51,7 @@ public class DynamicSetTest {
 | 
			
		||||
  @Test
 | 
			
		||||
  public void containsFalseWithSingleElement() throws Exception {
 | 
			
		||||
    DynamicSet<Integer> ds = new DynamicSet<>();
 | 
			
		||||
    ds.add(2);
 | 
			
		||||
    ds.add("gerrit", 2);
 | 
			
		||||
 | 
			
		||||
    assertThat(ds.contains(3)).isFalse(); // See above comment about ds.contains
 | 
			
		||||
  }
 | 
			
		||||
@@ -56,8 +59,8 @@ public class DynamicSetTest {
 | 
			
		||||
  @Test
 | 
			
		||||
  public void containsTrueWithTwoElements() throws Exception {
 | 
			
		||||
    DynamicSet<Integer> ds = new DynamicSet<>();
 | 
			
		||||
    ds.add(2);
 | 
			
		||||
    ds.add(4);
 | 
			
		||||
    ds.add("gerrit", 2);
 | 
			
		||||
    ds.add("gerrit", 4);
 | 
			
		||||
 | 
			
		||||
    assertThat(ds.contains(4)).isTrue(); // See above comment about ds.contains
 | 
			
		||||
  }
 | 
			
		||||
@@ -65,8 +68,8 @@ public class DynamicSetTest {
 | 
			
		||||
  @Test
 | 
			
		||||
  public void containsFalseWithTwoElements() throws Exception {
 | 
			
		||||
    DynamicSet<Integer> ds = new DynamicSet<>();
 | 
			
		||||
    ds.add(2);
 | 
			
		||||
    ds.add(4);
 | 
			
		||||
    ds.add("gerrit", 2);
 | 
			
		||||
    ds.add("gerrit", 4);
 | 
			
		||||
 | 
			
		||||
    assertThat(ds.contains(3)).isFalse(); // See above comment about ds.contains
 | 
			
		||||
  }
 | 
			
		||||
@@ -74,12 +77,12 @@ public class DynamicSetTest {
 | 
			
		||||
  @Test
 | 
			
		||||
  public void containsDynamic() throws Exception {
 | 
			
		||||
    DynamicSet<Integer> ds = new DynamicSet<>();
 | 
			
		||||
    ds.add(2);
 | 
			
		||||
    ds.add("gerrit", 2);
 | 
			
		||||
 | 
			
		||||
    Key<Integer> key = Key.get(Integer.class);
 | 
			
		||||
    ReloadableRegistrationHandle<Integer> handle = ds.add(key, Providers.of(4));
 | 
			
		||||
    ReloadableRegistrationHandle<Integer> handle = ds.add("gerrit", key, Providers.of(4));
 | 
			
		||||
 | 
			
		||||
    ds.add(6);
 | 
			
		||||
    ds.add("gerrit", 6);
 | 
			
		||||
 | 
			
		||||
    // At first, 4 is contained.
 | 
			
		||||
    assertThat(ds.contains(4)).isTrue(); // See above comment about ds.contains
 | 
			
		||||
@@ -90,4 +93,49 @@ public class DynamicSetTest {
 | 
			
		||||
    // And now 4 should no longer be contained.
 | 
			
		||||
    assertThat(ds.contains(4)).isFalse(); // See above comment about ds.contains
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void plugins() {
 | 
			
		||||
    DynamicSet<Integer> ds = new DynamicSet<>();
 | 
			
		||||
    ds.add("foo", 1);
 | 
			
		||||
    ds.add("bar", 2);
 | 
			
		||||
    ds.add("bar", 3);
 | 
			
		||||
 | 
			
		||||
    assertThat(ds.plugins()).containsExactly("bar", "foo").inOrder();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void byPlugin() {
 | 
			
		||||
    DynamicSet<Integer> ds = new DynamicSet<>();
 | 
			
		||||
    ds.add("foo", 1);
 | 
			
		||||
    ds.add("bar", 2);
 | 
			
		||||
    ds.add("bar", 3);
 | 
			
		||||
 | 
			
		||||
    assertThat(ds.byPlugin("foo").stream().map(Provider::get).collect(toSet())).containsExactly(1);
 | 
			
		||||
    assertThat(ds.byPlugin("bar").stream().map(Provider::get).collect(toSet()))
 | 
			
		||||
        .containsExactly(2, 3);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void entryIterator() {
 | 
			
		||||
    DynamicSet<Integer> ds = new DynamicSet<>();
 | 
			
		||||
    ds.add("foo", 1);
 | 
			
		||||
    ds.add("bar", 2);
 | 
			
		||||
    ds.add("bar", 3);
 | 
			
		||||
 | 
			
		||||
    Iterator<DynamicSet.Entry<Integer>> entryIterator = ds.entryIterator();
 | 
			
		||||
    DynamicSet.Entry<Integer> next = entryIterator.next();
 | 
			
		||||
    assertThat(next.getPluginName()).isEqualTo("foo");
 | 
			
		||||
    assertThat(next.getProvider().get()).isEqualTo(1);
 | 
			
		||||
 | 
			
		||||
    next = entryIterator.next();
 | 
			
		||||
    assertThat(next.getPluginName()).isEqualTo("bar");
 | 
			
		||||
    assertThat(next.getProvider().get()).isEqualTo(2);
 | 
			
		||||
 | 
			
		||||
    next = entryIterator.next();
 | 
			
		||||
    assertThat(next.getPluginName()).isEqualTo("bar");
 | 
			
		||||
    assertThat(next.getProvider().get()).isEqualTo(3);
 | 
			
		||||
 | 
			
		||||
    assertThat(entryIterator.hasNext()).isFalse();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -76,7 +76,7 @@ public class AllRequestFilterFilterProxyTest {
 | 
			
		||||
   */
 | 
			
		||||
  private ReloadableRegistrationHandle<AllRequestFilter> addFilter(AllRequestFilter filter) {
 | 
			
		||||
    Key<AllRequestFilter> key = Key.get(AllRequestFilter.class);
 | 
			
		||||
    return filters.add(key, Providers.of(filter));
 | 
			
		||||
    return filters.add("gerrit", key, Providers.of(filter));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,7 @@ public class UniversalGroupBackendTest extends GerritBaseTests {
 | 
			
		||||
    user = createNiceMock(IdentifiedUser.class);
 | 
			
		||||
    replay(user);
 | 
			
		||||
    backends = new DynamicSet<>();
 | 
			
		||||
    backends.add(new SystemGroupBackend(new Config()));
 | 
			
		||||
    backends.add("gerrit", new SystemGroupBackend(new Config()));
 | 
			
		||||
    backend = new UniversalGroupBackend(backends);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -123,7 +123,7 @@ public class UniversalGroupBackendTest extends GerritBaseTests {
 | 
			
		||||
    replay(member, notMember, backend);
 | 
			
		||||
 | 
			
		||||
    backends = new DynamicSet<>();
 | 
			
		||||
    backends.add(backend);
 | 
			
		||||
    backends.add("gerrit", backend);
 | 
			
		||||
    backend = new UniversalGroupBackend(backends);
 | 
			
		||||
 | 
			
		||||
    GroupMembership checker = backend.membershipsOf(member);
 | 
			
		||||
 
 | 
			
		||||
@@ -586,7 +586,7 @@ public class Schema_166_to_167_WithGroupsInReviewDbTest {
 | 
			
		||||
    AccountGroup group = createInReviewDb("group");
 | 
			
		||||
 | 
			
		||||
    TestGroupBackend testGroupBackend = new TestGroupBackend();
 | 
			
		||||
    backends.add(testGroupBackend);
 | 
			
		||||
    backends.add("gerrit", testGroupBackend);
 | 
			
		||||
    AccountGroup.UUID subgroupUuid = testGroupBackend.create("test").getGroupUUID();
 | 
			
		||||
    assertThat(groupBackend.handles(subgroupUuid)).isTrue();
 | 
			
		||||
    addSubgroupsInReviewDb(group.getId(), subgroupUuid);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user