mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 1272817 - Return early if file is empty + regression test. r=sebastian
MozReview-Commit-ID: FPdDr2t1wEy --HG-- extra : rebase_source : 4fd7975262ac3af23d0a5f6b921cbe7a0863760e
This commit is contained in:
parent
cee6eaeeaa
commit
9b29ebd0df
@ -150,6 +150,12 @@ public class TelemetryJSONFilePingStore implements TelemetryPingStore {
|
||||
* @return the JSON object from the given file or null if there is an error.
|
||||
*/
|
||||
private JSONObject lockAndReadJSONFromFile(final File file) {
|
||||
// lockAndReadFileAndCloseStream doesn't handle file size of 0.
|
||||
if (file.length() == 0) {
|
||||
Log.w(LOGTAG, "Unexpected empty file: " + file.getName() + ". Ignoring");
|
||||
return null;
|
||||
}
|
||||
|
||||
final FileInputStream inputStream;
|
||||
try {
|
||||
inputStream = new FileInputStream(file);
|
||||
|
@ -120,6 +120,14 @@ public class TestTelemetryJSONFilePingStore {
|
||||
}
|
||||
}
|
||||
|
||||
@Test // regression test: bug 1272817
|
||||
public void testGetAllPingsHandlesEmptyFiles() throws Exception {
|
||||
final int expectedPingCount = 3;
|
||||
writeTestPingsToStore(expectedPingCount, "whatever");
|
||||
assertTrue("Empty file is created", testStore.getPingFile(getDocID()).createNewFile());
|
||||
assertEquals("Returned pings only contains valid files", expectedPingCount, testStore.getAllPings().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaybePrunePingsDoesNothingIfAtMax() throws Exception {
|
||||
final int pingCount = TelemetryJSONFilePingStore.MAX_PING_COUNT;
|
||||
|
Loading…
Reference in New Issue
Block a user