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
This commit is contained in:
parent
288ed98c01
commit
ef21debe37
@ -137,6 +137,7 @@ java_test(
|
||||
'//lib/guice:guice',
|
||||
'//lib/jgit:jgit',
|
||||
'//lib/jgit:junit',
|
||||
'//lib/joda:joda-time',
|
||||
'//lib/prolog:prolog-cafe',
|
||||
],
|
||||
source_under_test = [':server'],
|
||||
|
@ -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 com.google.inject.util.Providers;
|
||||
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 @@ public abstract class AbstractQueryChangesTest {
|
||||
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 @@ public abstract class AbstractQueryChangesTest {
|
||||
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 @@ public abstract class AbstractQueryChangesTest {
|
||||
|
||||
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(),
|
||||
|
Loading…
Reference in New Issue
Block a user