Allow to parse stored replication tasks using the "ref" key Before change Ic0534d03dee6759ba4cb6b19ae87fd75269b437b a single ref was stored per task using the "ref" key. The above change changed it to the key name "refs", that had an array of refs as a value. This led to issues, when tasks with the old format were still present, when the change was applied. Now, the old "ref" key is supported again and will be parsed correctly. Bug: Issue 15922 Change-Id: I907109d0581ffa01781603741f4271471b19d71d
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java index ce7fe7b..f603466 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
@@ -289,6 +289,8 @@ refs.add(in.nextString()); } in.endArray(); + } else if ("ref".equals(fieldname)) { + refs.add(in.nextString()); } else if ("uri".equals(fieldname)) { try { uri = new URIish(in.nextString());
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTaskTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTaskTest.java index 3b7aec7..da27bc1 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTaskTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTaskTest.java
@@ -428,6 +428,25 @@ () -> gson.fromJson("{\"unknownKey\":\"someValue\"}", ReplicateRefUpdate.class)); } + @Test + public void ReadOldFormatReplicateRefUpdateTypeAdapter() throws Exception { + Gson gson = + new GsonBuilder() + .registerTypeAdapterFactory(new ReplicateRefUpdateTypeAdapterFactory()) + .create(); + ReplicateRefUpdate update = + ReplicateRefUpdate.create( + "someProject", + ImmutableSet.of("ref1"), + new URIish("git://host1/someRepo.git"), + "someRemote"); + assertEquals( + gson.fromJson( + "{\"project\":\"someProject\",\"ref\":\"ref1\",\"uri\":\"git://host1/someRepo.git\",\"remote\":\"someRemote\"}", + ReplicateRefUpdate.class), + update); + } + protected static void assertIsWaiting(Task task) { assertTrue(task.isWaiting()); }