Search in sources :

Example 31 with Cache

use of com.google.android.exoplayer2.upstream.cache.Cache in project ExoPlayer by google.

the class DownloadManagerDashTest method createDownloadManager.

private void createDownloadManager() {
    runOnMainThread(() -> {
        Factory fakeDataSourceFactory = new FakeDataSource.Factory().setFakeDataSet(fakeDataSet);
        DefaultDownloaderFactory downloaderFactory = new DefaultDownloaderFactory(new CacheDataSource.Factory().setCache(cache).setUpstreamDataSourceFactory(fakeDataSourceFactory), /* executor= */
        Runnable::run);
        downloadManager = new DownloadManager(ApplicationProvider.getApplicationContext(), downloadIndex, downloaderFactory);
        downloadManager.setRequirements(new Requirements(0));
        downloadManagerListener = new TestDownloadManagerListener(downloadManager);
        downloadManager.resumeDownloads();
    });
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) TestRunnable(com.google.android.exoplayer2.testutil.DummyMainThread.TestRunnable) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) Factory(com.google.android.exoplayer2.upstream.DataSource.Factory) DownloadManager(com.google.android.exoplayer2.offline.DownloadManager) Requirements(com.google.android.exoplayer2.scheduler.Requirements) TestDownloadManagerListener(com.google.android.exoplayer2.robolectric.TestDownloadManagerListener)

Example 32 with Cache

use of com.google.android.exoplayer2.upstream.cache.Cache in project ExoPlayer by google.

the class DownloadManagerDashTest method saveAndLoadActionFile.

@Ignore("Disabled due to flakiness")
@Test
public void saveAndLoadActionFile() throws Throwable {
    // Configure fakeDataSet to block until interrupted when TEST_MPD is read.
    fakeDataSet.newData(TEST_MPD_URI).appendReadAction(() -> {
        try {
            // Wait until interrupted.
            while (true) {
                Thread.sleep(100000);
            }
        } catch (InterruptedException ignored) {
            Thread.currentThread().interrupt();
        }
    }).appendReadData(TEST_MPD).endData();
    // Run DM accessing code on UI/main thread as it should be. Also not to block handling of loaded
    // actions.
    runOnMainThread(() -> {
        // Setup an Action and immediately release the DM.
        DownloadRequest request = getDownloadRequest(fakeStreamKey1, fakeStreamKey2);
        downloadManager.addDownload(request);
        downloadManager.release();
    });
    assertCacheEmpty(cache);
    // Revert fakeDataSet to normal.
    fakeDataSet.setData(TEST_MPD_URI, TEST_MPD);
    testThread.runOnMainThread(this::createDownloadManager);
    // Block on the test thread.
    downloadManagerListener.blockUntilIdleAndThrowAnyFailure();
    assertCachedData(cache, fakeDataSet);
}
Also used : DownloadRequest(com.google.android.exoplayer2.offline.DownloadRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 33 with Cache

use of com.google.android.exoplayer2.upstream.cache.Cache in project ExoPlayer by google.

the class DownloadServiceDashTest method removeBeforeDownloadComplete.

@Ignore("Internal ref: b/78877092")
@Test
public void removeBeforeDownloadComplete() throws Throwable {
    pauseDownloadCondition = new ConditionVariable();
    downloadKeys(fakeStreamKey1, fakeStreamKey2);
    removeAll();
    downloadManagerListener.blockUntilIdleAndThrowAnyFailure();
    assertCacheEmpty(cache);
}
Also used : ConditionVariable(com.google.android.exoplayer2.util.ConditionVariable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 34 with Cache

use of com.google.android.exoplayer2.upstream.cache.Cache in project ExoPlayer by google.

the class DashDownloaderTest method downloadRepresentationFailure.

@Test
public void downloadRepresentationFailure() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).newData("audio_segment_2").appendReadData(TestUtil.buildTestData(2)).appendReadError(new IOException()).appendReadData(TestUtil.buildTestData(3)).endData().setRandomData("audio_segment_3", 6);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0));
    try {
        dashDownloader.download(progressListener);
        fail();
    } catch (IOException e) {
    // Expected.
    }
    dashDownloader.download(progressListener);
    assertCachedData(cache, new RequestSet(fakeDataSet).useBoundedDataSpecFor("audio_init_data"));
}
Also used : RequestSet(com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) IOException(java.io.IOException) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 35 with Cache

use of com.google.android.exoplayer2.upstream.cache.Cache in project ExoPlayer by google.

the class DashDownloaderTest method remove.

@Test
public void remove() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("text_segment_1", 1).setRandomData("text_segment_2", 2).setRandomData("text_segment_3", 3);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0), new StreamKey(0, 1, 0));
    dashDownloader.download(progressListener);
    dashDownloader.remove();
    assertCacheEmpty(cache);
}
Also used : FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)25 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)19 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)18 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)16 SimpleCache (com.google.android.exoplayer2.upstream.cache.SimpleCache)10 StreamKey (com.google.android.exoplayer2.offline.StreamKey)9 File (java.io.File)9 DataSource (com.google.android.exoplayer2.upstream.DataSource)8 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)8 Uri (android.net.Uri)7 FileDataSource (com.google.android.exoplayer2.upstream.FileDataSource)6 NoOpCacheEvictor (com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor)6 IOException (java.io.IOException)6 Before (org.junit.Before)6 RequestSet (com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet)5 Nullable (androidx.annotation.Nullable)3 LeastRecentlyUsedCacheEvictor (com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor)3 Notification (android.app.Notification)2 NotificationManager (android.app.NotificationManager)2 Context (android.content.Context)2