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:
@@ -137,6 +137,7 @@ java_test(
|
|||||||
'//lib/guice:guice',
|
'//lib/guice:guice',
|
||||||
'//lib/jgit:jgit',
|
'//lib/jgit:jgit',
|
||||||
'//lib/jgit:junit',
|
'//lib/jgit:junit',
|
||||||
|
'//lib/joda:joda-time',
|
||||||
'//lib/prolog:prolog-cafe',
|
'//lib/prolog:prolog-cafe',
|
||||||
],
|
],
|
||||||
source_under_test = [':server'],
|
source_under_test = [':server'],
|
||||||
|
@@ -14,9 +14,9 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.query.change;
|
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.MILLISECONDS;
|
||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
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.internal.storage.dfs.InMemoryRepository;
|
||||||
import org.eclipse.jgit.junit.TestRepository;
|
import org.eclipse.jgit.junit.TestRepository;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
|
import org.joda.time.DateTimeUtils;
|
||||||
|
import org.joda.time.DateTimeUtils.MillisProvider;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public abstract class AbstractQueryChangesTest {
|
public abstract class AbstractQueryChangesTest {
|
||||||
@@ -88,10 +90,7 @@ public abstract class AbstractQueryChangesTest {
|
|||||||
protected ReviewDb db;
|
protected ReviewDb db;
|
||||||
protected Account.Id userId;
|
protected Account.Id userId;
|
||||||
protected CurrentUser user;
|
protected CurrentUser user;
|
||||||
protected int clockStepMs = 1;
|
protected volatile long clockStepMs;
|
||||||
private long clockMs =
|
|
||||||
MILLISECONDS.convert(ChangeUtil.SORT_KEY_EPOCH_MINS, MINUTES)
|
|
||||||
+ MILLISECONDS.convert(60, DAYS);
|
|
||||||
|
|
||||||
protected abstract Injector createInjector();
|
protected abstract Injector createInjector();
|
||||||
|
|
||||||
@@ -134,6 +133,26 @@ public abstract class AbstractQueryChangesTest {
|
|||||||
InMemoryDatabase.drop(schemaFactory);
|
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
|
@Test
|
||||||
public void byId() throws Exception {
|
public void byId() throws Exception {
|
||||||
TestRepository<InMemoryRepository> repo = createProject("repo");
|
TestRepository<InMemoryRepository> repo = createProject("repo");
|
||||||
@@ -422,8 +441,6 @@ public abstract class AbstractQueryChangesTest {
|
|||||||
|
|
||||||
Change change = new Change(new Change.Key(key), id, ownerId,
|
Change change = new Change(new Change.Key(key), id, ownerId,
|
||||||
new Branch.NameKey(project, branch), TimeUtil.nowTs());
|
new Branch.NameKey(project, branch), TimeUtil.nowTs());
|
||||||
change.setLastUpdatedOn(new Timestamp(clockMs));
|
|
||||||
clockMs += clockStepMs;
|
|
||||||
return changeFactory.create(
|
return changeFactory.create(
|
||||||
projectControlFactory.controlFor(project,
|
projectControlFactory.controlFor(project,
|
||||||
userFactory.create(ownerId)).controlFor(change).getRefControl(),
|
userFactory.create(ownerId)).controlFor(change).getRefControl(),
|
||||||
|
Reference in New Issue
Block a user