Use a fake MillisProvider in AbstractQueryChangesTest

Setting only the change timestamp based on a counter is not
sufficient; other callers elsewhere also call
DateTimeUtils.currentTimeMillis().

Change-Id: I897a6413a0d3f94cbab276bfc24468ee21458fdd
diff --git a/gerrit-server/BUCK b/gerrit-server/BUCK
index 66929cb..1db7555 100644
--- a/gerrit-server/BUCK
+++ b/gerrit-server/BUCK
@@ -137,6 +137,7 @@
     '//lib/guice:guice',
     '//lib/jgit:jgit',
     '//lib/jgit:junit',
+    '//lib/joda:joda-time',
     '//lib/prolog:prolog-cafe',
   ],
   source_under_test = [':server'],
diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
index c75c8fb..87fdb18 100644
--- a/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
+++ b/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
@@ -14,9 +14,9 @@
 
 package com.google.gerrit.server.query.change;
 
+import static java.util.concurrent.TimeUnit.DAYS;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.MINUTES;
-import static java.util.concurrent.TimeUnit.DAYS;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -59,13 +59,15 @@
 import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
 import org.eclipse.jgit.junit.TestRepository;
 import org.eclipse.jgit.revwalk.RevCommit;
+import org.joda.time.DateTimeUtils;
+import org.joda.time.DateTimeUtils.MillisProvider;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import java.sql.Timestamp;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
 
 @Ignore
 public abstract class AbstractQueryChangesTest {
@@ -88,10 +90,7 @@
   protected ReviewDb db;
   protected Account.Id userId;
   protected CurrentUser user;
-  protected int clockStepMs = 1;
-  private long clockMs =
-      MILLISECONDS.convert(ChangeUtil.SORT_KEY_EPOCH_MINS, MINUTES)
-      + MILLISECONDS.convert(60, DAYS);
+  protected volatile long clockStepMs;
 
   protected abstract Injector createInjector();
 
@@ -134,6 +133,26 @@
     InMemoryDatabase.drop(schemaFactory);
   }
 
+  @Before
+  public void setMillisProvider() {
+    clockStepMs = 1;
+    final AtomicLong clockMs = new AtomicLong(
+        MILLISECONDS.convert(ChangeUtil.SORT_KEY_EPOCH_MINS, MINUTES)
+        + MILLISECONDS.convert(60, DAYS));
+
+    DateTimeUtils.setCurrentMillisProvider(new MillisProvider() {
+      @Override
+      public long getMillis() {
+        return clockMs.getAndAdd(clockStepMs);
+      }
+    });
+  }
+
+  @After
+  public void resetMillisProvider() {
+    DateTimeUtils.setCurrentMillisSystem();
+  }
+
   @Test
   public void byId() throws Exception {
     TestRepository<InMemoryRepository> repo = createProject("repo");
@@ -422,8 +441,6 @@
 
     Change change = new Change(new Change.Key(key), id, ownerId,
         new Branch.NameKey(project, branch), TimeUtil.nowTs());
-    change.setLastUpdatedOn(new Timestamp(clockMs));
-    clockMs += clockStepMs;
     return changeFactory.create(
         projectControlFactory.controlFor(project,
           userFactory.create(ownerId)).controlFor(change).getRefControl(),