Update test to fix test of ChangeMessage migration to notedb

Added two helper methods to ChangeMessagesIT to change the
granularity of time to fix a problem with the ties in
timestamps for change messages. Additionally added necessary
dependency in BUCK file.

Change-Id: I5a22529bbb62450c98b2c7172a59abbe3ab7e32c
This commit is contained in:
Yacob Yonas 2014-06-13 12:35:34 -07:00 committed by Dave Borowitz
parent 60f32f6193
commit 901a5893c2
2 changed files with 47 additions and 0 deletions

View File

@ -10,6 +10,10 @@ OTHER_TESTS = glob(['*IT.java'], excludes = SUBMIT_TESTS + SUBMIT_UTIL_SRCS)
acceptance_tests(
srcs = OTHER_TESTS,
deps = [
':submit_util',
'//lib/joda:joda-time',
],
labels = ['rest'],
)

View File

@ -14,6 +14,8 @@
package com.google.gerrit.acceptance.rest.change;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@ -23,14 +25,55 @@ import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.ChangeMessageInfo;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.testutil.ConfigSuite;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Config;
import org.joda.time.DateTime;
import org.joda.time.DateTimeUtils;
import org.joda.time.DateTimeUtils.MillisProvider;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicLong;
@RunWith(ConfigSuite.class)
public class ChangeMessagesIT extends AbstractDaemonTest {
private String systemTimeZone;
private volatile long clockStepMs;
@ConfigSuite.Config
public static Config noteDbEnabled() {
Config cfg = new Config();
cfg.setBoolean("notedb", null, "write", true);
cfg.setBoolean("notedb", "changeMessages", "read", true);
return cfg;
}
@Before
public void setTimeForTesting() {
systemTimeZone = System.setProperty("user.timezone", "US/Eastern");
clockStepMs = MILLISECONDS.convert(1, SECONDS);
final AtomicLong clockMs = new AtomicLong(
new DateTime(2009, 9, 30, 17, 0, 0).getMillis());
DateTimeUtils.setCurrentMillisProvider(new MillisProvider() {
@Override
public long getMillis() {
return clockMs.getAndAdd(clockStepMs);
}
});
}
@After
public void resetTime() {
DateTimeUtils.setCurrentMillisSystem();
System.setProperty("user.timezone", systemTimeZone);
}
@Test
public void messagesNotReturnedByDefault() throws Exception {