Merge branch 'stable-2.10'
* stable-2.10:
Remove unused import and method
Fix type conversion warning
Replace deprecated HTTP.UTF_8 with StandardCharsets.UTF_8
Build with API version 2.10
Change-Id: I3dca8f8af8f11fbf3a657fe011c1f60f734b1985
diff --git a/pom.xml b/pom.xml
index f5cbd4a..540f32d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,7 @@
<groupId>com.googlesource.gerrit.plugins.its</groupId>
<artifactId>its-rtc</artifactId>
<packaging>jar</packaging>
- <version>2.10</version>
+ <version>2.11-SNAPSHOT</version>
<name>Gerrit Code Review - IBM Rational Team Concert support</name>
<url>http://maven.apache.org</url>
<properties>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/InitRTC.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/InitRTC.java
index 24dc5ba..f4647a7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/InitRTC.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/InitRTC.java
@@ -14,11 +14,11 @@
package com.googlesource.gerrit.plugins.hooks.rtc;
import com.google.gerrit.extensions.annotations.PluginName;
-import com.google.gerrit.pgm.init.AllProjectsConfig;
-import com.google.gerrit.pgm.init.AllProjectsNameOnInitProvider;
-import com.google.gerrit.pgm.init.InitFlags;
-import com.google.gerrit.pgm.init.Section;
-import com.google.gerrit.pgm.util.ConsoleUI;
+import com.google.gerrit.pgm.init.api.AllProjectsConfig;
+import com.google.gerrit.pgm.init.api.AllProjectsNameOnInitProvider;
+import com.google.gerrit.pgm.init.api.InitFlags;
+import com.google.gerrit.pgm.init.api.Section;
+import com.google.gerrit.pgm.init.api.ConsoleUI;
import com.google.inject.Inject;
import com.google.inject.Singleton;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/RTCModule.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/RTCModule.java
index 78cb4c6..fc27dbd 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/RTCModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/RTCModule.java
@@ -21,7 +21,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gerrit.common.ChangeListener;
+import com.google.gerrit.common.EventListener;
import com.google.gerrit.extensions.annotations.Exports;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.registration.DynamicSet;
@@ -74,11 +74,11 @@
bind(ExecutorService.class).toInstance(
new ScheduledThreadPoolExecutor(THREAD_POOL_EXECUTORS));
- DynamicSet.bind(binder(), ChangeListener.class).to(
+ DynamicSet.bind(binder(), EventListener.class).to(
RTCAddRelatedLinkToChangeId.class);
- DynamicSet.bind(binder(), ChangeListener.class).to(RTCAddComment.class);
- DynamicSet.bind(binder(), ChangeListener.class).to(RTCChangeState.class);
- DynamicSet.bind(binder(), ChangeListener.class).to(
+ DynamicSet.bind(binder(), EventListener.class).to(RTCAddComment.class);
+ DynamicSet.bind(binder(), EventListener.class).to(RTCChangeState.class);
+ DynamicSet.bind(binder(), EventListener.class).to(
RTCAddRelatedLinkToGitWeb.class);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/ChangeListenerAsyncDecorator.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/ChangeListenerAsyncDecorator.java
index 43a8ef5..8734ca7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/ChangeListenerAsyncDecorator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/ChangeListenerAsyncDecorator.java
@@ -13,36 +13,36 @@
// limitations under the License.
package com.googlesource.gerrit.plugins.hooks.rtc.filters;
+import com.google.gerrit.common.EventListener;
+import com.google.gerrit.server.events.Event;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.util.ArrayList;
import java.util.Queue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.gerrit.common.ChangeListener;
-import com.google.gerrit.server.events.ChangeEvent;
-
-public class ChangeListenerAsyncDecorator<T extends ChangeListener> implements
- ChangeListener {
+public class ChangeListenerAsyncDecorator<T extends EventListener> implements
+ EventListener {
private static final int MAX_PENDING_EVENTS = 1024;
private static final int MAX_BATCH_SIZE = 64;
private static final Logger log = LoggerFactory
.getLogger(ChangeListenerAsyncDecorator.class);
private T innerListener;
- private final LinkedBlockingQueue<ChangeEvent> queue =
- new LinkedBlockingQueue<ChangeEvent>(MAX_PENDING_EVENTS);
+ private final LinkedBlockingQueue<Event> queue =
+ new LinkedBlockingQueue<>(MAX_PENDING_EVENTS);
private ExecutorService executor;
public class ChangeRunner implements Runnable {
@Override
public void run() {
- ArrayList<ChangeEvent> failedEvents = new ArrayList<ChangeEvent>();
+ ArrayList<Event> failedEvents = new ArrayList<>();
for (int i = 0; !queue.isEmpty() && i < MAX_BATCH_SIZE; i++) {
- ChangeEvent event = queue.remove();
+ Event event = queue.remove();
try {
- innerListener.onChangeEvent(event);
+ innerListener.onEvent(event);
} catch (Throwable e) {
log.error("Execution of event " + event.getClass().getName() + "/"
+ event.toString()
@@ -50,7 +50,7 @@
failedEvents.add(event);
}
}
-
+
queue.addAll(failedEvents);
}
}
@@ -61,12 +61,12 @@
}
@Override
- public void onChangeEvent(ChangeEvent event) {
+ public void onEvent(Event event) {
queue.add(event);
executor.submit(new ChangeRunner());
}
- public Queue<ChangeEvent> getQueue() {
+ public Queue<Event> getQueue() {
return queue;
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/hooks/rtc/ChangeListenerAsyncDecoratorTest.java b/src/test/java/com/googlesource/gerrit/plugins/hooks/rtc/ChangeListenerAsyncDecoratorTest.java
index 764f5f5..1b47829 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/hooks/rtc/ChangeListenerAsyncDecoratorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/hooks/rtc/ChangeListenerAsyncDecoratorTest.java
@@ -17,10 +17,16 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
+import com.google.gerrit.common.EventListener;
+import com.google.gerrit.server.events.ChangeEvent;
+
+import com.googlesource.gerrit.plugins.hooks.rtc.filters.ChangeListenerAsyncDecorator;
import org.junit.Before;
import org.junit.Test;
@@ -30,15 +36,14 @@
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
-import com.google.gerrit.common.ChangeListener;
-import com.google.gerrit.server.events.ChangeEvent;
-import com.googlesource.gerrit.plugins.hooks.rtc.filters.ChangeListenerAsyncDecorator;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
@RunWith(MockitoJUnitRunner.class)
public class ChangeListenerAsyncDecoratorTest {
@Mock
- ChangeListener listener;
+ EventListener listener;
@Mock
ChangeEvent event;
@Mock
@@ -46,7 +51,7 @@
@Mock
ExecutorService immediateExecutor;
- ChangeListenerAsyncDecorator<ChangeListener> asyncListener;
+ ChangeListenerAsyncDecorator<EventListener> asyncListener;
@Before
public void setUp() {
@@ -62,7 +67,7 @@
}
});
asyncListener =
- new ChangeListenerAsyncDecorator<ChangeListener>(listener, executor);
+ new ChangeListenerAsyncDecorator<EventListener>(listener, executor);
}
@Test
@@ -72,19 +77,19 @@
@Test
public void testQueueShouldNotBeEmptyWhenOneEventSubmitted() {
- asyncListener.onChangeEvent(event);
+ asyncListener.onEvent(event);
assertFalse(asyncListener.getQueue().isEmpty());
}
@Test
public void testChangeEventShouldBeQueuedWhenSubmitted() {
- asyncListener.onChangeEvent(event);
+ asyncListener.onEvent(event);
assertEquals(event, asyncListener.getQueue().peek());
}
@Test
public void testChangeEventShouldBeSentToExecutor() {
- asyncListener.onChangeEvent(event);
+ asyncListener.onEvent(event);
verify(executor).submit(
any(ChangeListenerAsyncDecorator.ChangeRunner.class));
}
@@ -92,42 +97,39 @@
@Test
public void testChangeEventShouldBePropagatedToListenerWhenImmediatelyExecuted() {
asyncListener =
- new ChangeListenerAsyncDecorator<ChangeListener>(listener,
- immediateExecutor);
- asyncListener.onChangeEvent(event);
- verify(listener).onChangeEvent(event);
+ new ChangeListenerAsyncDecorator<>(listener, immediateExecutor);
+ asyncListener.onEvent(event);
+ verify(listener).onEvent(event);
assertTrue(asyncListener.getQueue().isEmpty());
}
@Test
public void testChangeEventShouldStayInQueueWhenExecutionFailed() {
asyncListener =
- new ChangeListenerAsyncDecorator<ChangeListener>(listener,
- immediateExecutor);
- doThrow(new IllegalArgumentException()).when(listener).onChangeEvent(
+ new ChangeListenerAsyncDecorator<>(listener, immediateExecutor);
+ doThrow(new IllegalArgumentException()).when(listener).onEvent(
any(ChangeEvent.class));
- asyncListener.onChangeEvent(event);
- verify(listener).onChangeEvent(event);
+ asyncListener.onEvent(event);
+ verify(listener).onEvent(event);
assertFalse(asyncListener.getQueue().isEmpty());
}
-
+
@Test
public void testChangeShouldProcessAllPreviouslyFailedEventsInQueue() {
asyncListener =
- new ChangeListenerAsyncDecorator<ChangeListener>(listener,
- immediateExecutor);
-
- doThrow(new IllegalArgumentException()).when(listener).onChangeEvent(
+ new ChangeListenerAsyncDecorator<>(listener, immediateExecutor);
+
+ doThrow(new IllegalArgumentException()).when(listener).onEvent(
any(ChangeEvent.class));
- asyncListener.onChangeEvent(event);
- verify(listener).onChangeEvent(event);
+ asyncListener.onEvent(event);
+ verify(listener).onEvent(event);
assertFalse(asyncListener.getQueue().isEmpty());
-
- doNothing().when(listener).onChangeEvent(any(ChangeEvent.class));
- asyncListener.onChangeEvent(event);
- verify(listener, times(3)).onChangeEvent(event);
-
+
+ doNothing().when(listener).onEvent(any(ChangeEvent.class));
+ asyncListener.onEvent(event);
+ verify(listener, times(3)).onEvent(event);
+
assertTrue(asyncListener.getQueue().isEmpty());
}