use of com.google.android.exoplayer2.offline.Download in project ExoPlayer by google.
the class DefaultDownloadIndexTest method addAndGetDownload_existingId_returnsUpdatedDownload.
@Test
public void addAndGetDownload_existingId_returnsUpdatedDownload() throws DatabaseIOException {
String id = "id";
DownloadBuilder downloadBuilder = new DownloadBuilder(id);
downloadIndex.putDownload(downloadBuilder.build());
Download download = downloadBuilder.setUri("different uri").setMimeType(MimeTypes.APPLICATION_MP4).setCacheKey("different cacheKey").setState(Download.STATE_FAILED).setPercentDownloaded(50).setBytesDownloaded(200).setContentLength(400).setFailureReason(FAILURE_REASON_UNKNOWN).setStopReason(0x12345678).setStartTimeMs(10).setUpdateTimeMs(20).setStreamKeys(new StreamKey(/* periodIndex= */
0, /* groupIndex= */
1, /* trackIndex= */
2), new StreamKey(/* periodIndex= */
3, /* groupIndex= */
4, /* trackIndex= */
5)).setCustomMetadata(new byte[] { 0, 1, 2, 3, 7, 8, 9, 10 }).setKeySetId(new byte[] { 0, 1, 2, 3 }).build();
downloadIndex.putDownload(download);
Download readDownload = downloadIndex.getDownload(id);
assertThat(readDownload).isNotNull();
assertEqual(readDownload, download);
}
use of com.google.android.exoplayer2.offline.Download in project ExoPlayer by google.
the class DownloadManagerTest method mergeRequest_stopped_staysStopped.
@Test
public void mergeRequest_stopped_staysStopped() {
DownloadRequest downloadRequest = createDownloadRequest(ID1);
DownloadBuilder downloadBuilder = new DownloadBuilder(downloadRequest).setState(Download.STATE_STOPPED).setStopReason(/* stopReason= */
1);
Download download = downloadBuilder.build();
Download mergedDownload = DownloadManager.mergeRequest(download, downloadRequest, download.stopReason, NOW_MS);
assertEqualIgnoringUpdateTime(mergedDownload, download);
}
use of com.google.android.exoplayer2.offline.Download in project ExoPlayer by google.
the class DownloadManagerTest method mergeRequest_removing_becomesRestarting.
@Test
public void mergeRequest_removing_becomesRestarting() {
DownloadRequest downloadRequest = createDownloadRequest(ID1);
DownloadBuilder downloadBuilder = new DownloadBuilder(downloadRequest).setState(Download.STATE_REMOVING);
Download download = downloadBuilder.build();
Download mergedDownload = DownloadManager.mergeRequest(download, downloadRequest, download.stopReason, NOW_MS);
Download expectedDownload = downloadBuilder.setStartTimeMs(NOW_MS).setState(Download.STATE_RESTARTING).build();
assertEqualIgnoringUpdateTime(mergedDownload, expectedDownload);
}
use of com.google.android.exoplayer2.offline.Download in project ExoPlayer by google.
the class DefaultDownloadIndexTest method setSingleDownloadStopReason_setReason.
@Test
public void setSingleDownloadStopReason_setReason() throws Exception {
String id = "id";
DownloadBuilder downloadBuilder = new DownloadBuilder(id).setState(Download.STATE_FAILED).setFailureReason(FAILURE_REASON_UNKNOWN);
Download download = downloadBuilder.build();
downloadIndex.putDownload(download);
int stopReason = 0x12345678;
downloadIndex.setStopReason(id, stopReason);
Download readDownload = downloadIndex.getDownload(id);
Download expectedDownload = downloadBuilder.setStopReason(stopReason).build();
assertEqual(readDownload, expectedDownload);
}
use of com.google.android.exoplayer2.offline.Download in project ExoPlayer by google.
the class DefaultDownloadIndexTest method downloadIndex_versionDowngradeWipesData.
@Test
public void downloadIndex_versionDowngradeWipesData() throws DatabaseIOException {
Download download1 = new DownloadBuilder("id1").build();
downloadIndex.putDownload(download1);
DownloadCursor cursor = downloadIndex.getDownloads();
assertThat(cursor.getCount()).isEqualTo(1);
cursor.close();
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
VersionTable.setVersion(writableDatabase, VersionTable.FEATURE_OFFLINE, EMPTY_NAME, Integer.MAX_VALUE);
downloadIndex = new DefaultDownloadIndex(databaseProvider);
cursor = downloadIndex.getDownloads();
assertThat(cursor.getCount()).isEqualTo(0);
cursor.close();
assertThat(VersionTable.getVersion(writableDatabase, VersionTable.FEATURE_OFFLINE, EMPTY_NAME)).isEqualTo(DefaultDownloadIndex.TABLE_VERSION);
}
Aggregations