Bug 1243585 - Rename JSONFilePingStore -> TelemetryJSONFilePingStore. r=sebastian draft
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 28 Apr 2016 17:10:19 -0700
changeset 357493 3d37bc386910366a1468c8cc91a7e0a65d22340e
parent 357492 63b671fab5f79659a9a0f10ed5df0fee0b880fb2
child 357995 4396470ee7aa7e06ff3a7dec7117e654b8164b41
push id16806
push usermichael.l.comella@gmail.com
push dateFri, 29 Apr 2016 00:52:31 +0000
reviewerssebastian
bugs1243585
milestone49.0a1
Bug 1243585 - Rename JSONFilePingStore -> TelemetryJSONFilePingStore. r=sebastian I would have done this sooner but it's a version control nightmare. I made the change because it's harder to grep for logs when the logtag doesn't include "Telemetry". MozReview-Commit-ID: GD8Cb8D5CRy
mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryDispatcher.java
mobile/android/base/java/org/mozilla/gecko/telemetry/stores/JSONFilePingStore.java
mobile/android/base/java/org/mozilla/gecko/telemetry/stores/TelemetryJSONFilePingStore.java
mobile/android/base/moz.build
mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/stores/TestJSONFilePingStore.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/stores/TestTelemetryJSONFilePingStore.java
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryDispatcher.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryDispatcher.java
@@ -6,17 +6,17 @@
 
 package org.mozilla.gecko.telemetry;
 
 import android.content.Context;
 import android.util.Log;
 import org.mozilla.gecko.telemetry.core.TelemetryCorePingBuilder;
 import org.mozilla.gecko.telemetry.schedulers.TelemetryUploadScheduler;
 import org.mozilla.gecko.telemetry.schedulers.TelemetryUploadAllPingsImmediatelyScheduler;
-import org.mozilla.gecko.telemetry.stores.JSONFilePingStore;
+import org.mozilla.gecko.telemetry.stores.TelemetryJSONFilePingStore;
 import org.mozilla.gecko.telemetry.stores.TelemetryPingStore;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import java.io.File;
 import java.io.IOException;
 import java.lang.ref.WeakReference;
 
 /**
@@ -48,27 +48,27 @@ import java.lang.ref.WeakReference;
  * pass it to the new queuePingForUpload method.
  */
 public class TelemetryDispatcher {
     private static final String LOGTAG = "Gecko" + TelemetryDispatcher.class.getSimpleName();
 
     private static final String STORE_CONTAINER_DIR_NAME = "telemetry_java";
     private static final String CORE_STORE_DIR_NAME = "core";
 
-    private final JSONFilePingStore coreStore;
+    private final TelemetryJSONFilePingStore coreStore;
 
     private final TelemetryUploadAllPingsImmediatelyScheduler uploadAllPingsImmediatelyScheduler;
 
     public TelemetryDispatcher(final String profilePath) {
         final String storePath = profilePath + File.separator + STORE_CONTAINER_DIR_NAME;
 
         // There are measurements in the core ping (e.g. seq #) that would ideally be atomically updated
         // when the ping is stored. However, for simplicity, we use the json store and accept the possible
         // loss of data (see bug 1243585 comment 16+ for more).
-        coreStore = new JSONFilePingStore(new File(storePath, CORE_STORE_DIR_NAME));
+        coreStore = new TelemetryJSONFilePingStore(new File(storePath, CORE_STORE_DIR_NAME));
 
         uploadAllPingsImmediatelyScheduler = new TelemetryUploadAllPingsImmediatelyScheduler();
     }
 
     private void queuePingForUpload(final Context context, final int uniqueID, final TelemetryPing ping,
             final TelemetryPingStore store, final TelemetryUploadScheduler scheduler) {
         final QueuePingRunnable runnable = new QueuePingRunnable(context, uniqueID, ping, store, scheduler);
         ThreadUtils.postToBackgroundThread(runnable); // TODO: Investigate how busy this thread is. See if we want another.
rename from mobile/android/base/java/org/mozilla/gecko/telemetry/stores/JSONFilePingStore.java
rename to mobile/android/base/java/org/mozilla/gecko/telemetry/stores/TelemetryJSONFilePingStore.java
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/stores/JSONFilePingStore.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/stores/TelemetryJSONFilePingStore.java
@@ -47,31 +47,31 @@ import java.util.regex.Pattern;
  *   * requires locking: {@link #storePing(long, TelemetryPing)} writes a new file
  *   * requires locking: {@link #getAllPings()} reads all files, including those potentially being written,
  * hence locking
  *   * no locking: {@link #maybePrunePings()} deletes the least recently written pings, none of which should
  * be currently written
  *   * no locking: {@link #onUploadAttemptComplete(Set)} deletes the given pings, none of which should be
  * currently written
  */
-public class JSONFilePingStore implements TelemetryPingStore {
-    private static final String LOGTAG = "Gecko" + JSONFilePingStore.class.getSimpleName();
+public class TelemetryJSONFilePingStore implements TelemetryPingStore {
+    private static final String LOGTAG = "Gecko" + TelemetryJSONFilePingStore.class.getSimpleName();
 
     @VisibleForTesting static final int MAX_PING_COUNT = 40; // TODO: value.
 
     private static final String FILENAME = "ping-%s.json";
     private static final Pattern FILENAME_PATTERN = Pattern.compile("ping-([0-9]+)\\.json");
 
     // We keep the key names short to reduce storage size impact.
     @VisibleForTesting static final String KEY_PAYLOAD = "p";
     @VisibleForTesting static final String KEY_URL_PATH = "u";
 
     private final File storeDir;
 
-    public JSONFilePingStore(final File storeDir) {
+    public TelemetryJSONFilePingStore(final File storeDir) {
         this.storeDir = storeDir;
         this.storeDir.mkdirs();
     }
 
     @VisibleForTesting File getPingFile(final long id) {
         final String filename = String.format(Locale.US, FILENAME, id);
         return new File(storeDir, filename);
     }
@@ -249,26 +249,26 @@ public class JSONFilePingStore implement
             if (idsToFilter == null) {
                 return FILENAME_PATTERN.matcher(filename).matches();
             }
 
             return idsToFilter.contains(getIDFromFilename(filename));
         }
     }
 
-    public static final Parcelable.Creator<JSONFilePingStore> CREATOR = new Parcelable.Creator<JSONFilePingStore>() {
+    public static final Parcelable.Creator<TelemetryJSONFilePingStore> CREATOR = new Parcelable.Creator<TelemetryJSONFilePingStore>() {
         @Override
-        public JSONFilePingStore createFromParcel(final Parcel source) {
+        public TelemetryJSONFilePingStore createFromParcel(final Parcel source) {
             final String storeDirPath = source.readString();
-            return new JSONFilePingStore(new File(storeDirPath));
+            return new TelemetryJSONFilePingStore(new File(storeDirPath));
         }
 
         @Override
-        public JSONFilePingStore[] newArray(final int size) {
-            return new JSONFilePingStore[size];
+        public TelemetryJSONFilePingStore[] newArray(final int size) {
+            return new TelemetryJSONFilePingStore[size];
         }
     };
 
     @Override
     public int describeContents() {
         return 0;
     }
 
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -569,17 +569,17 @@ gbjar.sources += ['java/org/mozilla/geck
     'tabs/TabsLayoutItemView.java',
     'tabs/TabsListLayout.java',
     'tabs/TabsPanel.java',
     'tabs/TabsPanelThumbnailView.java',
     'Telemetry.java',
     'telemetry/core/TelemetryCorePingBuilder.java',
     'telemetry/schedulers/TelemetryUploadAllPingsImmediatelyScheduler.java',
     'telemetry/schedulers/TelemetryUploadScheduler.java',
-    'telemetry/stores/JSONFilePingStore.java',
+    'telemetry/stores/TelemetryJSONFilePingStore.java',
     'telemetry/stores/TelemetryPingStore.java',
     'telemetry/TelemetryConstants.java',
     'telemetry/TelemetryDispatcher.java',
     'telemetry/TelemetryPing.java',
     'telemetry/TelemetryPingBuilder.java',
     'telemetry/TelemetryPingFromStore.java',
     'telemetry/TelemetryUploadService.java',
     'TelemetryContract.java',
rename from mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/stores/TestJSONFilePingStore.java
rename to mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/stores/TestTelemetryJSONFilePingStore.java
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/stores/TestJSONFilePingStore.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/stores/TestTelemetryJSONFilePingStore.java
@@ -24,32 +24,32 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import static org.junit.Assert.*;
 
 /**
- * Unit test methods of the {@link JSONFilePingStore} class.
+ * Unit test methods of the {@link TelemetryJSONFilePingStore} class.
  */
 @RunWith(TestRunner.class)
-public class TestJSONFilePingStore {
+public class TestTelemetryJSONFilePingStore {
 
     private final Pattern ID_PATTERN = Pattern.compile("[^0-9]*([0-9]+)[^0-9]*");
 
     @Rule
     public TemporaryFolder tempDir = new TemporaryFolder();
     private File testDir;
-    private JSONFilePingStore testStore;
+    private TelemetryJSONFilePingStore testStore;
 
     @Before
     public void setUp() throws Exception {
         testDir = tempDir.newFolder();
-        testStore = new JSONFilePingStore(testDir);
+        testStore = new TelemetryJSONFilePingStore(testDir);
     }
 
     private ExtendedJSONObject generateTelemetryPayload() {
         final ExtendedJSONObject out = new ExtendedJSONObject();
         out.put("str", "a String");
         out.put("int", 42);
         out.put("null", (ExtendedJSONObject) null);
         return out;
@@ -79,18 +79,18 @@ public class TestJSONFilePingStore {
         final int expectedID = 48679;
         final TelemetryPing expectedPing = new TelemetryPing("a/server/url", generateTelemetryPayload());
         testStore.storePing(expectedID, expectedPing);
 
         assertStoreFileCount(1);
         final String filename = testDir.list()[0];
         assertTrue("Filename contains expected ID", filename.contains(Integer.toString(expectedID)));
         final JSONObject actual = FileUtils.readJSONObjectFromFile(new File(testDir, filename));
-        assertEquals("Ping url paths are equal", expectedPing.getURLPath(), actual.getString(JSONFilePingStore.KEY_URL_PATH));
-        assertIsGeneratedPayload(new ExtendedJSONObject(actual.getString(JSONFilePingStore.KEY_PAYLOAD)));
+        assertEquals("Ping url paths are equal", expectedPing.getURLPath(), actual.getString(TelemetryJSONFilePingStore.KEY_URL_PATH));
+        assertIsGeneratedPayload(new ExtendedJSONObject(actual.getString(TelemetryJSONFilePingStore.KEY_PAYLOAD)));
     }
 
     @Test
     public void testStorePingMultiplePingsStoreSeparateFiles() throws Exception {
         assertStoreFileCount(0);
         for (int i = 1; i < 10; ++i) {
             testStore.storePing(i, new TelemetryPing("server " + i, generateTelemetryPayload()));
             assertStoreFileCount(i);
@@ -121,32 +121,32 @@ public class TestJSONFilePingStore {
             final int id = ping.getUniqueID(); // we use ID as a key for specific pings and check against the url values.
             assertEquals("Expected url path value received", urlPrefix + id, ping.getURLPath());
             assertIsGeneratedPayload(ping.getPayload());
         }
     }
 
     @Test
     public void testMaybePrunePingsDoesNothingIfAtMax() throws Exception {
-        final int pingCount = JSONFilePingStore.MAX_PING_COUNT;
+        final int pingCount = TelemetryJSONFilePingStore.MAX_PING_COUNT;
         writeTestPingsToStore(pingCount, "whatever");
         assertStoreFileCount(pingCount);
         testStore.maybePrunePings();
         assertStoreFileCount(pingCount);
     }
 
     @Test
     public void testMaybePrunePingsPrunesIfAboveMax() throws Exception {
-        final int pingCount = JSONFilePingStore.MAX_PING_COUNT + 1;
+        final int pingCount = TelemetryJSONFilePingStore.MAX_PING_COUNT + 1;
         writeTestPingsToStore(pingCount, "whatever");
         assertStoreFileCount(pingCount);
         testStore.maybePrunePings();
-        assertStoreFileCount(JSONFilePingStore.MAX_PING_COUNT);
+        assertStoreFileCount(TelemetryJSONFilePingStore.MAX_PING_COUNT);
 
-        final HashSet<Integer> existingIDs = new HashSet<>(JSONFilePingStore.MAX_PING_COUNT);
+        final HashSet<Integer> existingIDs = new HashSet<>(TelemetryJSONFilePingStore.MAX_PING_COUNT);
         for (final String filename : testDir.list()) {
             existingIDs.add(getIDFromFilename(filename));
         }
         assertFalse("Smallest ID was removed", existingIDs.contains(1));
     }
 
     @Test
     public void testOnUploadAttemptCompleted() throws Exception {
@@ -166,38 +166,38 @@ public class TestJSONFilePingStore {
 
     @Test
     public void testGetPingFileContainsID() throws Exception {
         final int expected = 1234567890;
         final File file = testStore.getPingFile(expected);
         assertTrue("Ping filename contains ID", file.getName().contains(Integer.toString(expected)));
     }
 
-    @Test // assumes {@link JSONFilePingStore.getPingFile(String)} is working.
+    @Test // assumes {@link TelemetryJSONFilePingStore.getPingFile(String)} is working.
     public void testGetIDFromFilename() throws Exception {
         final int expectedID = 465739201;
         final File file = testStore.getPingFile(expectedID);
-        assertEquals("Retrieved ID from filename", expectedID, JSONFilePingStore.getIDFromFilename(file.getName()));
+        assertEquals("Retrieved ID from filename", expectedID, TelemetryJSONFilePingStore.getIDFromFilename(file.getName()));
     }
 
     private int getIDFromFilename(final String filename) {
         final Matcher matcher = ID_PATTERN.matcher(filename);
         assertTrue("Filename contains ID", matcher.matches());
         return Integer.parseInt(matcher.group(1));
     }
 
     /**
      * Writes pings to store without using store API with:
      *   id = 1 to count (inclusive)
      *   server = urlPrefix + id
      *   payload = generated payload
      *
-     * Note: assumes {@link JSONFilePingStore#getPingFile(long)} works.
+     * Note: assumes {@link TelemetryJSONFilePingStore#getPingFile(long)} works.
      */
     private void writeTestPingsToStore(final int count, final String urlPrefix) throws Exception {
         for (int i = 1; i <= count; ++i) {
             final JSONObject obj = new JSONObject()
-                    .put(JSONFilePingStore.KEY_URL_PATH, urlPrefix + i)
-                    .put(JSONFilePingStore.KEY_PAYLOAD, generateTelemetryPayload());
+                    .put(TelemetryJSONFilePingStore.KEY_URL_PATH, urlPrefix + i)
+                    .put(TelemetryJSONFilePingStore.KEY_PAYLOAD, generateTelemetryPayload());
             FileUtils.writeJSONObjectToFile(testStore.getPingFile(i), obj);
         }
     }
 }