summaryrefslogtreecommitdiff
path: root/javatests/com/google/android/libraries/mobiledatadownload/MddGarbageCollectionWithAndroidSharingIntegrationTest.java
blob: bc00cc3a547007924fdf22efc1e8712acb0be711 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/*
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.android.libraries.mobiledatadownload;

import static com.google.android.libraries.mobiledatadownload.testing.MddTestDependencies.ExecutorType;
import static com.google.common.truth.Truth.assertThat;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.app.blob.BlobStoreManager;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.libraries.mobiledatadownload.downloader.FileDownloader;
import com.google.android.libraries.mobiledatadownload.file.SynchronousFileStorage;
import com.google.android.libraries.mobiledatadownload.file.backends.AndroidFileBackend;
import com.google.android.libraries.mobiledatadownload.file.backends.BlobStoreBackend;
import com.google.android.libraries.mobiledatadownload.file.backends.BlobUri;
import com.google.android.libraries.mobiledatadownload.file.backends.JavaFileBackend;
import com.google.android.libraries.mobiledatadownload.file.transforms.CompressTransform;
import com.google.android.libraries.mobiledatadownload.internal.MddTestUtil;
import com.google.android.libraries.mobiledatadownload.monitor.DownloadProgressMonitor;
import com.google.android.libraries.mobiledatadownload.monitor.NetworkUsageMonitor;
import com.google.android.libraries.mobiledatadownload.testing.TestFileDownloader;
import com.google.android.libraries.mobiledatadownload.testing.TestFlags;
import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.mobiledatadownload.ClientConfigProto.ClientFile;
import com.google.mobiledatadownload.ClientConfigProto.ClientFileGroup;
import com.google.mobiledatadownload.DownloadConfigProto.DataFileGroup;
import com.google.mobiledatadownload.DownloadConfigProto.DownloadConditions.DeviceNetworkPolicy;
import com.google.mobiledatadownload.LogProto.DataDownloadFileGroupStats;
import com.google.mobiledatadownload.LogProto.MddLogData;
import com.google.testing.junit.testparameterinjector.TestParameter;
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

@RunWith(TestParameterInjector.class)
public final class MddGarbageCollectionWithAndroidSharingIntegrationTest {
  private static final String TAG = "MddGarbageCollectionWithAndroidSharingIntegrationTest";
  private static final int MAX_DOWNLOAD_FILE_GROUP_WAIT_TIME_SECS = 300;

  private static final String TEST_DATA_RELATIVE_PATH =
      "third_party/java_src/android_libs/mobiledatadownload/javatests/com/google/android/libraries/mobiledatadownload/testdata/";

  private static final ScheduledExecutorService DOWNLOAD_EXECUTOR =
      Executors.newScheduledThreadPool(2);

  private static final String FILE_GROUP_TO_SHARE_1 = "test-group-1";
  private static final String FILE_ID_1 = "test-file-to-share-1";
  private static final String FILE_CHECKSUM_1 = "fcc96b272633cdf6c4bbd2d77512cca51bfb1dbd"; // SHA_1
  static final String FILE_ANDROID_SHARING_CHECKSUM_1 =
      "225017b5d5ec35732940af813b1ab7be5191e4c52659953e75a1a36a1398c48d"; // SHA_256
  static final int FILE_SIZE_1 = 57;
  static final String FILE_URL_1 = "https://www.gstatic.com/icing/idd/sample_group/step1.txt";

  private static final Context context = ApplicationProvider.getApplicationContext();

  @Mock private TaskScheduler mockTaskScheduler;
  @Mock private NetworkUsageMonitor mockNetworkUsageMonitor;
  @Mock private DownloadProgressMonitor mockDownloadProgressMonitor;
  @Mock private Logger mockLogger;

  private SynchronousFileStorage fileStorage;

  private BlobStoreManager blobStoreManager;
  private MobileDataDownload mobileDataDownload;
  private Supplier<FileDownloader> fileDownloaderSupplier;
  private ListeningExecutorService controlExecutor;

  private final TestFlags flags = new TestFlags();

  @Rule(order = 1)
  public final MockitoRule mocks = MockitoJUnit.rule();

  @TestParameter ExecutorType controlExecutorType;

  @Before
  public void setUp() throws Exception {

    // cl/439051122 created a temporary FALSE override targeted to ASGA devices. This test suite
    // relies on garbage collection being enabled to test the metadata state transistions, but
    // all_on testing doesn't respect diversion criteria in the launch.
    //
    // So we temporarily force it on to bypass the launch so the tests can rely on expected
    // behavior.
    // TODO(b/226551373): remove these overrides once AsgaDisableMddLibGcLaunch is turned down
    flags.mddEnableGarbageCollection = Optional.of(true);

    flags.mddAndroidSharingSampleInterval = Optional.of(1);

    flags.mddDefaultSampleInterval = Optional.of(1);

    BlobStoreBackend blobStoreBackend = new BlobStoreBackend(context);
    blobStoreManager = (BlobStoreManager) context.getSystemService(Context.BLOB_STORE_SERVICE);

    controlExecutor = controlExecutorType.executor();

    fileStorage =
        new SynchronousFileStorage(
            /* backends= */ ImmutableList.of(
                AndroidFileBackend.builder(context).build(),
                blobStoreBackend,
                new JavaFileBackend()),
            /* transforms= */ ImmutableList.of(new CompressTransform()),
            /* monitors= */ ImmutableList.of(mockNetworkUsageMonitor, mockDownloadProgressMonitor));

    fileDownloaderSupplier =
        () ->
            new TestFileDownloader(
                TEST_DATA_RELATIVE_PATH,
                fileStorage,
                MoreExecutors.listeningDecorator(DOWNLOAD_EXECUTOR));
  }

  @After
  public void tearDown() throws Exception {
    mobileDataDownload.clear().get();
    // Commands to clean up the blob storage.
    MddTestUtil.runShellCmd("cmd blob_store clear-all-sessions");
    MddTestUtil.runShellCmd("cmd blob_store clear-all-blobs");
  }

  private void downloadFileGroup(DataFileGroup fileGroup) throws Exception {
    assertThat(
            mobileDataDownload
                .addFileGroup(AddFileGroupRequest.newBuilder().setDataFileGroup(fileGroup).build())
                .get())
        .isTrue();
    mobileDataDownload
        .downloadFileGroup(
            DownloadFileGroupRequest.newBuilder()
                .setGroupName(fileGroup.getGroupName())
                .setListenerOptional(
                    Optional.of(
                        new DownloadListener() {
                          @Override
                          public void onProgress(long currentSize) {
                            Log.i(TAG, "onProgress " + currentSize);
                          }

                          @Override
                          public void onComplete(ClientFileGroup clientFileGroup) {
                            Log.i(TAG, "onComplete " + clientFileGroup.getGroupName());
                          }
                        }))
                .build())
        .get(MAX_DOWNLOAD_FILE_GROUP_WAIT_TIME_SECS, SECONDS);
  }

  private ClientFileGroup verifyDownloadedGroupIsDownloaded(DataFileGroup fileGroup, int fileCount)
      throws Exception {
    ClientFileGroup clientFileGroup =
        mobileDataDownload
            .getFileGroup(
                GetFileGroupRequest.newBuilder().setGroupName(fileGroup.getGroupName()).build())
            .get();

    assertThat(clientFileGroup).isNotNull();
    assertThat(clientFileGroup.getGroupName()).isEqualTo(fileGroup.getGroupName());
    assertThat(clientFileGroup.getFileCount()).isEqualTo(fileCount);
    return clientFileGroup;
  }

  @Test
  public void deletesStaleGroups_staleLifetimeZero() throws Exception {
    mobileDataDownload = builderForTest().build();
    Uri androidUri =
        BlobUri.builder(context).setBlobParameters(FILE_ANDROID_SHARING_CHECKSUM_1).build();
    assertThat(fileStorage.exists(androidUri)).isFalse();

    // Download file group with stale lifetime 0.
    DataFileGroup fileGroup =
        TestFileGroupPopulator.createDataFileGroup(
            FILE_GROUP_TO_SHARE_1,
            context.getPackageName(),
            new String[] {FILE_ID_1},
            new int[] {FILE_SIZE_1},
            new String[] {FILE_CHECKSUM_1},
            new String[] {FILE_ANDROID_SHARING_CHECKSUM_1},
            new String[] {FILE_URL_1},
            DeviceNetworkPolicy.DOWNLOAD_ON_ANY_NETWORK);

    downloadFileGroup(fileGroup);

    ClientFileGroup clientFileGroup = verifyDownloadedGroupIsDownloaded(fileGroup, 1);

    ClientFile clientFile = clientFileGroup.getFileList().get(0);
    assertThat(clientFile.getFileId()).isEqualTo(FILE_ID_1);
    Uri uri = Uri.parse(clientFile.getFileUri());

    // The file is now available in the android shared storage.
    assertThat(uri).isEqualTo(androidUri);
    assertThat(fileStorage.exists(uri)).isTrue();
    assertThat(blobStoreManager.getLeasedBlobs()).hasSize(1);

    // Send an empty group so that the old group is now stale.
    DataFileGroup emptyFileGroup =
        TestFileGroupPopulator.createDataFileGroup(
            FILE_GROUP_TO_SHARE_1,
            context.getPackageName(),
            new String[] {},
            new int[] {},
            new String[] {},
            new String[] {},
            new String[] {},
            DeviceNetworkPolicy.DOWNLOAD_ON_ANY_NETWORK);

    downloadFileGroup(emptyFileGroup);

    // Run maintenance taks.
    mobileDataDownload.maintenance().get(MAX_DOWNLOAD_FILE_GROUP_WAIT_TIME_SECS, SECONDS);

    verifyDownloadedGroupIsDownloaded(emptyFileGroup, 0);

    // Old stale file has been released
    assertThat(blobStoreManager.getLeasedBlobs()).isEmpty();

    // Verify logging events.

    ArgumentCaptor<MddLogData> logDataCaptor = ArgumentCaptor.forClass(MddLogData.class);
    // 1050 is the tag number for MddClientEvent.Code.EVENT_CODE_UNSPECIFIED.
    verify(mockLogger).log(logDataCaptor.capture(), /* eventCode= */ eq(1050));
    List<MddLogData> logData = logDataCaptor.getAllValues();
    assertThat(logData).hasSize(1);

    DataDownloadFileGroupStats dataDownloadFileGroupStats =
        logData.get(0).getDataDownloadFileGroupStats();
    DataDownloadFileGroupStats staleGroupExpired =
        DataDownloadFileGroupStats.newBuilder()
            .setFileGroupName(fileGroup.getGroupName())
            .setFileGroupVersionNumber(fileGroup.getFileGroupVersionNumber())
            .setBuildId(0)
            .setVariantId("")
            .build();
    assertThat(dataDownloadFileGroupStats).isEqualTo(staleGroupExpired);

    logDataCaptor = ArgumentCaptor.forClass(MddLogData.class);
    // 1084 is the tag number for MddClientEvent.Code.EVENT_CODE_UNSPECIFIED;
    // Called once for every released lease.
    verify(mockLogger).log(logDataCaptor.capture(), /* eventCode= */ eq(1084));

    logDataCaptor = ArgumentCaptor.forClass(MddLogData.class);
    // 1051 is the tag number for MddClientEvent.Code.EVENT_CODE_UNSPECIFIED.
    // It's logged once by mobileDataDownload.maintenance() and three times in the
    // ExpirationHandler, once when the file metadata is deleted, once when the lease is released
    // and once when the temporary local copy of the shared file is deleted.
    verify(mockLogger, times(4)).log(logDataCaptor.capture(), /* eventCode= */ eq(1051));
    logData = logDataCaptor.getAllValues();
    assertThat(logData).hasSize(4);

    Void metadafileDeleted = null;
    Void fileReleased = null;
    Void fileDeleted = null;
  }

  @Test
  public void deletesStaleGroups_staleLifetimeTwoDays() throws Exception {
    mobileDataDownload = builderForTest().build();
    Uri androidUri =
        BlobUri.builder(context).setBlobParameters(FILE_ANDROID_SHARING_CHECKSUM_1).build();
    assertThat(fileStorage.exists(androidUri)).isFalse();

    // Download file group with stale lifetime +2 days.
    DataFileGroup fileGroup =
        TestFileGroupPopulator.createDataFileGroup(
            FILE_GROUP_TO_SHARE_1,
            context.getPackageName(),
            new String[] {FILE_ID_1},
            new int[] {FILE_SIZE_1},
            new String[] {FILE_CHECKSUM_1},
            new String[] {FILE_ANDROID_SHARING_CHECKSUM_1},
            new String[] {FILE_URL_1},
            DeviceNetworkPolicy.DOWNLOAD_ON_ANY_NETWORK);
    fileGroup = fileGroup.toBuilder().setStaleLifetimeSecs(DAYS.toSeconds(2)).build();

    downloadFileGroup(fileGroup);

    ClientFileGroup clientFileGroup = verifyDownloadedGroupIsDownloaded(fileGroup, 1);

    ClientFile clientFile = clientFileGroup.getFileList().get(0);
    assertThat(clientFile.getFileId()).isEqualTo(FILE_ID_1);
    Uri uri = Uri.parse(clientFile.getFileUri());

    // The file is now available in the android shared storage.
    assertThat(uri).isEqualTo(androidUri);
    assertThat(fileStorage.exists(uri)).isTrue();
    assertThat(blobStoreManager.getLeasedBlobs()).hasSize(1);

    // Send an empty group so that the old group is now stale.
    DataFileGroup emptyFileGroup =
        TestFileGroupPopulator.createDataFileGroup(
            FILE_GROUP_TO_SHARE_1,
            context.getPackageName(),
            new String[] {},
            new int[] {},
            new String[] {},
            new String[] {},
            new String[] {},
            DeviceNetworkPolicy.DOWNLOAD_ON_ANY_NETWORK);
    downloadFileGroup(emptyFileGroup);

    // Run maintenance taks.
    mobileDataDownload.maintenance().get(MAX_DOWNLOAD_FILE_GROUP_WAIT_TIME_SECS, SECONDS);

    verifyDownloadedGroupIsDownloaded(emptyFileGroup, 0);

    // Old stale file hasn't been released yet
    assertThat(blobStoreManager.getLeasedBlobs()).hasSize(1);

    // Advance time by 2 days, and verify that the lease on the shared file has been
    // released.
    MddTestUtil.timeTravel(context, DAYS.toMillis(2));
    mobileDataDownload.maintenance().get(MAX_DOWNLOAD_FILE_GROUP_WAIT_TIME_SECS, SECONDS);

    verifyDownloadedGroupIsDownloaded(emptyFileGroup, 0);

    assertThat(blobStoreManager.getLeasedBlobs()).isEmpty();

    // Verify logging events.

    ArgumentCaptor<MddLogData> logDataCaptor = ArgumentCaptor.forClass(MddLogData.class);
    // 1050 is the tag number for MddClientEvent.Code.EVENT_CODE_UNSPECIFIED.
    verify(mockLogger).log(logDataCaptor.capture(), /* eventCode= */ eq(1050));
    List<MddLogData> logData = logDataCaptor.getAllValues();
    assertThat(logData).hasSize(1);

    DataDownloadFileGroupStats dataDownloadFileGroupStats =
        logData.get(0).getDataDownloadFileGroupStats();
    DataDownloadFileGroupStats staleGroupExpired =
        DataDownloadFileGroupStats.newBuilder()
            .setFileGroupName(fileGroup.getGroupName())
            .setFileGroupVersionNumber(fileGroup.getFileGroupVersionNumber())
            .setBuildId(0)
            .setVariantId("")
            .build();
    assertThat(dataDownloadFileGroupStats).isEqualTo(staleGroupExpired);

    logDataCaptor = ArgumentCaptor.forClass(MddLogData.class);
    // 1084 is the tag number for MddClientEvent.Code.EVENT_CODE_UNSPECIFIED;
    // Called once for every released lease.
    verify(mockLogger).log(logDataCaptor.capture(), /* eventCode= */ eq(1084));

    logDataCaptor = ArgumentCaptor.forClass(MddLogData.class);
    // 1051 is the tag number for MddClientEvent.Code.EVENT_CODE_UNSPECIFIED.
    // It's logged once every time mobileDataDownload.maintenance() is called and three times in the
    // ExpirationHandler, once when the file metadata is deleted, once when the lease is released
    // and once when the temporary local copy of the shared file is deleted.
    verify(mockLogger, times(5)).log(logDataCaptor.capture(), /* eventCode= */ eq(1051));
    logData = logDataCaptor.getAllValues();
    assertThat(logData).hasSize(5);

    Void metadafileDeleted = null;
    Void fileReleased = null;
    Void fileDeleted = null;
  }

  @Test
  public void deletesExpiredGroups() throws Exception {
    mobileDataDownload = builderForTest().build();
    Uri androidUri =
        BlobUri.builder(context).setBlobParameters(FILE_ANDROID_SHARING_CHECKSUM_1).build();
    assertThat(fileStorage.exists(androidUri)).isFalse();

    // Download file group with stale lifetime +2 days.
    DataFileGroup fileGroup =
        TestFileGroupPopulator.createDataFileGroup(
            FILE_GROUP_TO_SHARE_1,
            context.getPackageName(),
            new String[] {FILE_ID_1},
            new int[] {FILE_SIZE_1},
            new String[] {FILE_CHECKSUM_1},
            new String[] {FILE_ANDROID_SHARING_CHECKSUM_1},
            new String[] {FILE_URL_1},
            DeviceNetworkPolicy.DOWNLOAD_ON_ANY_NETWORK);

    // It expires in two days.
    fileGroup = fileGroup.toBuilder().setExpirationDate(MddTestUtil.daysFromNow(2)).build();

    downloadFileGroup(fileGroup);

    ClientFileGroup clientFileGroup = verifyDownloadedGroupIsDownloaded(fileGroup, 1);

    ClientFile clientFile = clientFileGroup.getFileList().get(0);
    assertThat(clientFile.getFileId()).isEqualTo(FILE_ID_1);
    Uri uri = Uri.parse(clientFile.getFileUri());

    // The file is now available in the android shared storage.
    assertThat(uri).isEqualTo(androidUri);
    assertThat(fileStorage.exists(uri)).isTrue();
    assertThat(blobStoreManager.getLeasedBlobs()).hasSize(1);

    // Run maintenance tasks and verify that we still own the lease om the shared file.
    mobileDataDownload.maintenance().get(MAX_DOWNLOAD_FILE_GROUP_WAIT_TIME_SECS, SECONDS);

    verifyDownloadedGroupIsDownloaded(fileGroup, 1);

    assertThat(blobStoreManager.getLeasedBlobs()).hasSize(1);

    // Advance time by 3 days, and verify that the group and files can no longer be read
    // because they expired.
    MddTestUtil.timeTravel(context, DAYS.toMillis(3));
    mobileDataDownload.maintenance().get(MAX_DOWNLOAD_FILE_GROUP_WAIT_TIME_SECS, SECONDS);
    clientFileGroup =
        mobileDataDownload
            .getFileGroup(
                GetFileGroupRequest.newBuilder().setGroupName(FILE_GROUP_TO_SHARE_1).build())
            .get();
    assertThat(clientFileGroup).isNull();

    assertThat(blobStoreManager.getLeasedBlobs()).isEmpty();

    // Verify logging events.

    ArgumentCaptor<MddLogData> logDataCaptor = ArgumentCaptor.forClass(MddLogData.class);
    // 1049 is the tag number for MddClientEvent.Code.EVENT_CODE_UNSPECIFIED.
    verify(mockLogger).log(logDataCaptor.capture(), /* eventCode= */ eq(1049));

    List<MddLogData> logData = logDataCaptor.getAllValues();
    assertThat(logData).hasSize(1);

    DataDownloadFileGroupStats dataDownloadFileGroupStats =
        logData.get(0).getDataDownloadFileGroupStats();
    DataDownloadFileGroupStats groupExpired =
        DataDownloadFileGroupStats.newBuilder()
            .setFileGroupName(fileGroup.getGroupName())
            .setFileGroupVersionNumber(fileGroup.getFileGroupVersionNumber())
            .setBuildId(0)
            .setVariantId("")
            .build();
    assertThat(dataDownloadFileGroupStats).isEqualTo(groupExpired);

    logDataCaptor = ArgumentCaptor.forClass(MddLogData.class);
    // 1084 is the tag number for MddClientEvent.Code.EVENT_CODE_UNSPECIFIED;
    // Called once for every released lease.
    verify(mockLogger).log(logDataCaptor.capture(), /* eventCode= */ eq(1084));

    logDataCaptor = ArgumentCaptor.forClass(MddLogData.class);
    // 1051 is the tag number for MddClientEvent.Code.EVENT_CODE_UNSPECIFIED.
    // It's logged once every time mobileDataDownload.maintenance() is called and three times in the
    // ExpirationHandler, once when the file metadata is deleted, once when the lease is
    // released and once when the temporary local copy of the shared file is deleted.
    verify(mockLogger, times(5)).log(logDataCaptor.capture(), /* eventCode= */ eq(1051));
    logData = logDataCaptor.getAllValues();
    assertThat(logData).hasSize(5);

    Void metadafileDeleted = null;
    Void fileReleased = null;
    Void fileDeleted = null;
  }

  /**
   * Returns MDD Builder with common dependencies set -- additional dependencies are added in each
   * test as needed.
   */
  private MobileDataDownloadBuilder builderForTest() {
    return MobileDataDownloadBuilder.newBuilder()
        .setContext(context)
        .setControlExecutor(controlExecutor)
        .setFileDownloaderSupplier(fileDownloaderSupplier)
        .setTaskScheduler(Optional.of(mockTaskScheduler))
        .setDeltaDecoderOptional(Optional.absent())
        .setFileStorage(fileStorage)
        .setNetworkUsageMonitor(mockNetworkUsageMonitor)
        .setDownloadMonitorOptional(Optional.of(mockDownloadProgressMonitor))
        .setLoggerOptional(Optional.of(mockLogger))
        .setFlagsOptional(Optional.of(flags));
  }
}