зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1272431 - Correct order errors in maybePrunePings tests. r=ahunt
MozReview-Commit-ID: CQKjiD5PomF --HG-- extra : rebase_source : cc06c7ecbf958f3a82cf982fbcc491772b56f63e
This commit is contained in:
Родитель
551df5bc27
Коммит
0ffccb4798
|
@ -37,6 +37,7 @@ public interface TelemetryPingStore extends Parcelable {
|
|||
|
||||
/**
|
||||
* Removes telemetry pings from the store if there are too many pings or they take up too much space.
|
||||
* Pings should be removed from oldest to newest.
|
||||
*/
|
||||
void maybePrunePings();
|
||||
|
||||
|
|
|
@ -140,16 +140,14 @@ public class TestTelemetryJSONFilePingStore {
|
|||
@Test
|
||||
public void testMaybePrunePingsPrunesIfAboveMax() throws Exception {
|
||||
final int pingCount = TelemetryJSONFilePingStore.MAX_PING_COUNT + 1;
|
||||
writeTestPingsToStore(pingCount, "whatever");
|
||||
final List<String> expectedDocIDs = writeTestPingsToStore(pingCount, "whatever");
|
||||
assertStoreFileCount(pingCount);
|
||||
testStore.maybePrunePings();
|
||||
assertStoreFileCount(TelemetryJSONFilePingStore.MAX_PING_COUNT);
|
||||
|
||||
final HashSet<String> existingIDs = new HashSet<>(TelemetryJSONFilePingStore.MAX_PING_COUNT);
|
||||
for (final String filename : testDir.list()) {
|
||||
existingIDs.add(filename);
|
||||
}
|
||||
assertFalse("Smallest ID was removed", existingIDs.contains(1));
|
||||
Collections.addAll(existingIDs, testDir.list());
|
||||
assertFalse("Oldest ping was removed", existingIDs.contains(expectedDocIDs.get(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -184,16 +182,22 @@ public class TestTelemetryJSONFilePingStore {
|
|||
*
|
||||
* Note: assumes {@link TelemetryJSONFilePingStore#getPingFile(String)} works.
|
||||
*
|
||||
* @return a list of doc IDs saved to disk
|
||||
* @return a list of doc IDs saved to disk in ascending order of last modified date
|
||||
*/
|
||||
private List<String> writeTestPingsToStore(final int count, final String urlPrefix) throws Exception {
|
||||
final List<String> savedDocIDs = new ArrayList<>(count);
|
||||
final long now = System.currentTimeMillis();
|
||||
for (int i = 1; i <= count; ++i) {
|
||||
final String docID = getDocID();
|
||||
final JSONObject obj = new JSONObject()
|
||||
.put(TelemetryJSONFilePingStore.KEY_URL_PATH, urlPrefix + docID)
|
||||
.put(TelemetryJSONFilePingStore.KEY_PAYLOAD, generateTelemetryPayload());
|
||||
FileUtils.writeJSONObjectToFile(testStore.getPingFile(docID), obj);
|
||||
final File pingFile = testStore.getPingFile(docID);
|
||||
FileUtils.writeJSONObjectToFile(pingFile, obj);
|
||||
|
||||
// If we don't set an explicit time, the modified times are all equal.
|
||||
// Also, last modified times are rounded by second.
|
||||
assertTrue("Able to set last modified time", pingFile.setLastModified(now - (count * 10_000) + i * 10_000));
|
||||
savedDocIDs.add(docID);
|
||||
}
|
||||
return savedDocIDs;
|
||||
|
|
Загрузка…
Ссылка в новой задаче