Merge branch 'stable-2.13'

* stable-2.13:
  Rename change indexing servlet
  Rename OK to NO_CONTENT as the value is 204, not 200
  Add cache key to the evict request name
  Fix CacheEvictionIT test setup
  Remove the possibility of configuring number of threads to forward events

Change-Id: If17ba0ca23aaf410eeccfbeafb8d1520662e8e95
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/Configuration.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/Configuration.java
index 39bf9ca..19ffb16 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/Configuration.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/Configuration.java
@@ -42,7 +42,6 @@
   private final int maxTries;
   private final int retryInterval;
   private final int indexThreadPoolSize;
-  private final int eventThreadPoolSize;
   private final int cacheThreadPoolSize;
 
   @Inject
@@ -58,8 +57,6 @@
     retryInterval = getInt(cfg, "retryInterval", DEFAULT_RETRY_INTERVAL);
     indexThreadPoolSize =
         getInt(cfg, "indexThreadPoolSize", DEFAULT_THREAD_POOL_SIZE);
-    eventThreadPoolSize =
-        getInt(cfg, "eventThreadPoolSize", DEFAULT_THREAD_POOL_SIZE);
     cacheThreadPoolSize =
         getInt(cfg, "cacheThreadPoolSize", DEFAULT_THREAD_POOL_SIZE);
   }
@@ -107,10 +104,6 @@
     return indexThreadPoolSize;
   }
 
-  public int getEventThreadPoolSize() {
-    return eventThreadPoolSize;
-  }
-
   public int getCacheThreadPoolSize() {
     return cacheThreadPoolSize;
   }
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/event/EventExecutorProvider.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/event/EventExecutorProvider.java
index 95b595d..29af0ea 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/event/EventExecutorProvider.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/event/EventExecutorProvider.java
@@ -18,15 +18,13 @@
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
-import com.ericsson.gerrit.plugins.highavailability.Configuration;
 import com.ericsson.gerrit.plugins.highavailability.ExecutorProvider;
 
 @Singleton
 class EventExecutorProvider extends ExecutorProvider {
 
   @Inject
-  EventExecutorProvider(WorkQueue workQueue,
-      Configuration config) {
-    super(workQueue, config.getEventThreadPoolSize(), "Forward-stream-event");
+  EventExecutorProvider(WorkQueue workQueue) {
+    super(workQueue, 1, "Forward-stream-event");
   }
 }
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexRestApiServlet.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServlet.java
similarity index 96%
rename from src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexRestApiServlet.java
rename to src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServlet.java
index 0a6761e..0ed9bcc 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexRestApiServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServlet.java
@@ -42,10 +42,10 @@
 import javax.servlet.http.HttpServletResponse;
 
 @Singleton
-class IndexRestApiServlet extends HttpServlet {
+class IndexChangeRestApiServlet extends HttpServlet {
   private static final long serialVersionUID = -1L;
   private static final Logger logger =
-      LoggerFactory.getLogger(IndexRestApiServlet.class);
+      LoggerFactory.getLogger(IndexChangeRestApiServlet.class);
   private static final Map<Change.Id, AtomicInteger> changeIdLocks =
       new HashMap<>();
 
@@ -53,7 +53,7 @@
   private final SchemaFactory<ReviewDb> schemaFactory;
 
   @Inject
-  IndexRestApiServlet(ChangeIndexer indexer,
+  IndexChangeRestApiServlet(ChangeIndexer indexer,
       SchemaFactory<ReviewDb> schemaFactory) {
     this.indexer = indexer;
     this.schemaFactory = schemaFactory;
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java
index 4574026..fddec98 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java
@@ -65,7 +65,7 @@
   }
 
   private String buildIndexEndpoint(int changeId) {
-    return Joiner.on("/").join(pluginRelativePath, "index", changeId);
+    return Joiner.on("/").join(pluginRelativePath, "index/change", changeId);
   }
 
   @Override
@@ -84,7 +84,7 @@
 
   @Override
   public boolean evict(final String cacheName, final Object key) {
-    return new Request("evict for cache " + cacheName) {
+    return new Request("evict for cache " + cacheName + "[" + key + "]") {
       @Override
       HttpResult send() throws IOException {
         String json = GsonParser.toJson(cacheName, key);
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderServletModule.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderServletModule.java
index 71b9bf0..4b0157d 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderServletModule.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderServletModule.java
@@ -19,7 +19,7 @@
 public class RestForwarderServletModule extends HttpPluginModule {
   @Override
   protected void configureServlets() {
-    serveRegex("/index/\\d+$").with(IndexRestApiServlet.class);
+    serveRegex("/index/change/\\d+$").with(IndexChangeRestApiServlet.class);
     serve("/event").with(EventRestApiServlet.class);
     serve("/cache/*").with(CacheRestApiServlet.class);
   }
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 26af4ee..f894822 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -53,10 +53,6 @@
 :   Maximum number of threads used to send index events to the target instance.
     Defaults to 1.
 
-@PLUGIN@.eventThreadPoolSize
-:   Maximum number of threads used to send stream events to the target instance.
-    Defaults to 1.
-
 @PLUGIN@.cacheThreadPoolSize
 :   Maximum number of threads used to send cache evictions to the target instance.
     Defaults to 1.
\ No newline at end of file
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/ConfigurationTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/ConfigurationTest.java
index f9225c3..0cd3e4a 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/ConfigurationTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/ConfigurationTest.java
@@ -66,8 +66,6 @@
     assertThat(configuration.getRetryInterval()).isEqualTo(RETRY_INTERVAL);
     assertThat(configuration.getIndexThreadPoolSize())
         .isEqualTo(THREAD_POOL_SIZE);
-    assertThat(configuration.getEventThreadPoolSize())
-        .isEqualTo(THREAD_POOL_SIZE);
     assertThat(configuration.getCacheThreadPoolSize())
         .isEqualTo(THREAD_POOL_SIZE);
   }
@@ -83,7 +81,6 @@
     assertThat(configuration.getMaxTries()).isEqualTo(0);
     assertThat(configuration.getRetryInterval()).isEqualTo(0);
     assertThat(configuration.getIndexThreadPoolSize()).isEqualTo(0);
-    assertThat(configuration.getEventThreadPoolSize()).isEqualTo(0);
     assertThat(configuration.getCacheThreadPoolSize()).isEqualTo(0);
   }
 
@@ -107,7 +104,6 @@
     assertThat(configuration.getMaxTries()).isEqualTo(5);
     assertThat(configuration.getRetryInterval()).isEqualTo(1000);
     assertThat(configuration.getIndexThreadPoolSize()).isEqualTo(1);
-    assertThat(configuration.getEventThreadPoolSize()).isEqualTo(1);
     assertThat(configuration.getCacheThreadPoolSize()).isEqualTo(1);
   }
 
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionIT.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionIT.java
index caaf2d8..c11dac8 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionIT.java
@@ -76,7 +76,7 @@
       }
     });
     givenThat(post(urlEqualTo(flushRequest))
-        .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
+        .willReturn(aResponse().withStatus(HttpStatus.SC_NO_CONTENT)));
 
     adminSshSession
         .exec("gerrit flush-caches --cache " + Constants.PROJECT_LIST);
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/event/EventExecutorProviderTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/event/EventExecutorProviderTest.java
index 085ca0a..054a2e6 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/event/EventExecutorProviderTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/event/EventExecutorProviderTest.java
@@ -21,9 +21,6 @@
 
 import com.google.gerrit.server.git.WorkQueue;
 
-import com.ericsson.gerrit.plugins.highavailability.Configuration;
-import com.ericsson.gerrit.plugins.highavailability.event.EventExecutorProvider;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -39,13 +36,9 @@
   @Before
   public void setUp() throws Exception {
     WorkQueue workQueueMock = mock(WorkQueue.class);
-    when(workQueueMock.createQueue(4, "Forward-stream-event"))
+    when(workQueueMock.createQueue(1, "Forward-stream-event"))
         .thenReturn(executorMock);
-    Configuration configMock = mock(Configuration.class);
-    when(configMock.getEventThreadPoolSize()).thenReturn(4);
-
-    eventsExecutorProvider =
-        new EventExecutorProvider(workQueueMock, configMock);
+    eventsExecutorProvider = new EventExecutorProvider(workQueueMock);
   }
 
   @Test
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpResponseHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpResponseHandlerTest.java
index b612770..ee8f9b4 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpResponseHandlerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpResponseHandlerTest.java
@@ -30,7 +30,7 @@
 
 public class HttpResponseHandlerTest {
   private static final int ERROR = 400;
-  private static final int OK = 204;
+  private static final int NO_CONTENT = 204;
   private static final String EMPTY_ENTITY = "";
   private static final String ERROR_ENTITY = "Error";
 
@@ -43,7 +43,7 @@
 
   @Test
   public void testIsSuccessful() throws Exception {
-    HttpResponse response = setupMocks(OK, EMPTY_ENTITY);
+    HttpResponse response = setupMocks(NO_CONTENT, EMPTY_ENTITY);
     HttpResult result = handler.handleResponse(response);
     assertThat(result.isSuccessful()).isTrue();
     assertThat(result.getMessage()).isEmpty();
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpSessionTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpSessionTest.java
index 69a188c..7834cf0 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpSessionTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpSessionTest.java
@@ -41,7 +41,7 @@
   private static final int RETRY_INTERVAL = 250;
   private static final int TIMEOUT = 500;
   private static final int ERROR = 500;
-  private static final int OK = 204;
+  private static final int NO_CONTENT = 204;
   private static final int NOT_FOUND = 404;
   private static final int UNAUTHORIZED = 401;
 
@@ -80,7 +80,7 @@
   @Test
   public void testPostResponseOK() throws Exception {
     wireMockRule.givenThat(post(urlEqualTo(ENDPOINT))
-        .willReturn(aResponse().withStatus(OK)));
+        .willReturn(aResponse().withStatus(NO_CONTENT)));
 
     assertThat(httpSession.post(ENDPOINT).isSuccessful()).isTrue();
   }
@@ -88,14 +88,14 @@
   @Test
   public void testPostResponseWithContentOK() throws Exception {
     wireMockRule.givenThat(post(urlEqualTo(ENDPOINT))
-        .withRequestBody(equalTo(BODY)).willReturn(aResponse().withStatus(OK)));
+        .withRequestBody(equalTo(BODY)).willReturn(aResponse().withStatus(NO_CONTENT)));
     assertThat(httpSession.post(ENDPOINT, BODY).isSuccessful()).isTrue();
   }
 
   @Test
   public void testDeleteResponseOK() throws Exception {
     wireMockRule.givenThat(delete(urlEqualTo(ENDPOINT))
-        .willReturn(aResponse().withStatus(OK)));
+        .willReturn(aResponse().withStatus(NO_CONTENT)));
 
     assertThat(httpSession.delete(ENDPOINT).isSuccessful()).isTrue();
   }
@@ -129,7 +129,7 @@
         .willReturn(aResponse().withStatus(ERROR)));
     wireMockRule.givenThat(post(urlEqualTo(ENDPOINT)).inScenario(RETRY_AT_ERROR)
         .whenScenarioStateIs(REQUEST_MADE)
-        .willReturn(aResponse().withStatus(OK)));
+        .willReturn(aResponse().withStatus(NO_CONTENT)));
 
     assertThat(httpSession.post(ENDPOINT).isSuccessful()).isTrue();
   }
@@ -151,7 +151,7 @@
         .willReturn(aResponse().withStatus(ERROR).withFixedDelay(TIMEOUT / 2)));
     wireMockRule.givenThat(post(urlEqualTo(ENDPOINT)).inScenario(RETRY_AT_DELAY)
         .whenScenarioStateIs(REQUEST_MADE)
-        .willReturn(aResponse().withStatus(OK)));
+        .willReturn(aResponse().withStatus(NO_CONTENT)));
 
     assertThat(httpSession.post(ENDPOINT).isSuccessful()).isTrue();
   }
@@ -169,7 +169,7 @@
         .willReturn(aResponse().withFixedDelay(TIMEOUT)));
     wireMockRule.givenThat(post(urlEqualTo(ENDPOINT)).inScenario(RETRY_AT_DELAY)
         .whenScenarioStateIs(THIRD_TRY)
-        .willReturn(aResponse().withStatus(OK)));
+        .willReturn(aResponse().withStatus(NO_CONTENT)));
 
     assertThat(httpSession.post(ENDPOINT).isSuccessful()).isTrue();
   }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServletTest.java
similarity index 95%
rename from src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexRestApiServletTest.java
rename to src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServletTest.java
index 3aa7009..0f2f1d5 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServletTest.java
@@ -47,7 +47,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 @RunWith(MockitoJUnitRunner.class)
-public class IndexRestApiServletTest {
+public class IndexChangeRestApiServletTest {
   private static final boolean CHANGE_EXISTS = true;
   private static final boolean CHANGE_DOES_NOT_EXIST = false;
   private static final boolean DO_NOT_THROW_IO_EXCEPTION = false;
@@ -68,7 +68,7 @@
   private HttpServletResponse rsp;
   private Change.Id id;
   private Change change;
-  private IndexRestApiServlet indexRestApiServlet;
+  private IndexChangeRestApiServlet indexRestApiServlet;
 
   @BeforeClass
   public static void setup() {
@@ -77,9 +77,9 @@
 
   @Before
   public void setUpMocks() {
-    indexRestApiServlet = new IndexRestApiServlet(indexer, schemaFactory);
+    indexRestApiServlet = new IndexChangeRestApiServlet(indexer, schemaFactory);
     id = Change.Id.parse(CHANGE_NUMBER);
-    when(req.getPathInfo()).thenReturn("/index/" + CHANGE_NUMBER);
+    when(req.getPathInfo()).thenReturn("/index/change/" + CHANGE_NUMBER);
     change = new Change(null, id, null, null, TimeUtil.nowTs());
   }
 
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java
index 72e2462..2c65f84 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java
@@ -45,7 +45,7 @@
   //Index
   private static final int CHANGE_NUMBER = 1;
   private static final String DELETE_OP = "delete";
-  private static final String INDEX_OP = "index";
+  private static final String INDEX_OP = "index/change";
 
   //Evict cache
   private static final String EMPTY_JSON = "{}";