Merge branch 'stable-3.4' into stable-3.5

* stable-3.4:
  Allow replication of hidden projects
  Fix ApplyObjectIT flaky test

Change-Id: I55e95db567140e9a440647886d1b33d947cefde6
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java
index 0ebbf91..f75ea7b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java
@@ -318,13 +318,6 @@
                         ref);
                     throw new NoSuchProjectException(project);
                   }
-                  if (!projectState.get().statePermitsRead()) {
-                    repLog.warn(
-                        "NOT scheduling replication {}:{} because project is not readable",
-                        project,
-                        ref);
-                    return false;
-                  }
                   if (!shouldReplicate(projectState.get(), userProvider.get())) {
                     return false;
                   }
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md
index 22b52e7..73c5c05 100644
--- a/src/main/resources/Documentation/about.md
+++ b/src/main/resources/Documentation/about.md
@@ -16,6 +16,10 @@
 group that is granted the 'Pull Replication' capability (provided
 by this plugin) or the 'Administrate Server' capability.
 
+When replicating hidden projects, the pull replication user needs to have
+the 'Administrate Server' capability or being added as the owner of each
+individual project that is supposed to be replicated.
+
 Change Indexing
 --------
 
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index b85aeb6..65b03b8 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -80,6 +80,21 @@
 
 	Default is 1024.
 
+cache.projects.refreshAfterWrite
+:	The Gerrit configuration of the `projects` cache, as [documented](/Documentation/config-gerrit.html#cache.name.refreshAfterWrite)
+
+	Needs to be set to a relatively low value (e.g. 1 min) for allowing the
+	project settings cache to be kept relatively up-to-date (e.g. within 1 mins)
+	with the incoming replication tasks updating it.
+
+cache.project_list.refreshAfterWrite
+:	The Gerrit configuration of the `project_list` cache, as [documented](/Documentation/config-gerrit.html#cache.name.refreshAfterWrite)
+
+	Needs to be set to a relatively low value (e.g. 5 min) for allowing the
+	creation, removal and hiding of projects performed by incoming
+	replication tasks to be reflected relavitely soon (e.g. within 5 mins)
+	in the list of projects.
+
 File `@PLUGIN@.config`
 -------------------------
 
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/fetch/ApplyObjectIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/fetch/ApplyObjectIT.java
index 161830b..c75d32a 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/fetch/ApplyObjectIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/fetch/ApplyObjectIT.java
@@ -77,12 +77,15 @@
     Result pushResult = createChange();
     String refName = RefNames.changeMetaRef(pushResult.getChange().getId());
 
-    Optional<RevisionData> revisionData =
-        reader.read(
-            Project.nameKey(testRepoProjectName), pushResult.getCommit().toObjectId(), refName, 0);
-
     RefSpec refSpec = new RefSpec(refName);
-    objectUnderTest.apply(project, refSpec, toArray(revisionData));
+    Optional<RevisionData> revisionData;
+    NameKey testRepoKey = Project.nameKey(testRepoProjectName);
+
+    try (Repository repo = repoManager.openRepository(testRepoKey)) {
+      revisionData = reader.read(testRepoKey, repo.exactRef(refName).getObjectId(), refName, 0);
+      objectUnderTest.apply(project, refSpec, toArray(revisionData));
+    }
+
     try (Repository repo = repoManager.openRepository(project);
         TestRepository<Repository> testRepo = new TestRepository<>(repo); ) {
       Optional<RevisionData> newRevisionData =