Search in sources :

Example 16 with FakeDataSet

use of com.google.android.exoplayer2.testutil.FakeDataSet 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 17 with FakeDataSet

use of com.google.android.exoplayer2.testutil.FakeDataSet 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 18 with FakeDataSet

use of com.google.android.exoplayer2.testutil.FakeDataSet 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)

Example 19 with FakeDataSet

use of com.google.android.exoplayer2.testutil.FakeDataSet in project ExoPlayer by google.

the class DashDownloaderTest method downloadRepresentation.

@Test
public void downloadRepresentation() 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);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0));
    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) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 20 with FakeDataSet

use of com.google.android.exoplayer2.testutil.FakeDataSet in project ExoPlayer by google.

the class DashDownloaderTest method downloadRepresentationInSmallParts.

@Test
public void downloadRepresentationInSmallParts() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).newData("audio_segment_1").appendReadData(TestUtil.buildTestData(10)).appendReadData(TestUtil.buildTestData(10)).appendReadData(TestUtil.buildTestData(10)).endData().setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0));
    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) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)29 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)23 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)16 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)14 StreamKey (com.google.android.exoplayer2.offline.StreamKey)11 Uri (android.net.Uri)6 IOException (java.io.IOException)6 RequestSet (com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet)5 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)4 DataSource (com.google.android.exoplayer2.upstream.DataSource)3 NoOpCacheEvictor (com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor)3 SimpleCache (com.google.android.exoplayer2.upstream.cache.SimpleCache)3 Before (org.junit.Before)3 MediaItem (com.google.android.exoplayer2.MediaItem)2 DefaultDownloadIndex (com.google.android.exoplayer2.offline.DefaultDownloadIndex)2 DefaultDownloaderFactory (com.google.android.exoplayer2.offline.DefaultDownloaderFactory)2 DownloadManager (com.google.android.exoplayer2.offline.DownloadManager)2 TestDownloadManagerListener (com.google.android.exoplayer2.robolectric.TestDownloadManagerListener)2 DummyMainThread (com.google.android.exoplayer2.testutil.DummyMainThread)2 FailOnCloseDataSink (com.google.android.exoplayer2.testutil.FailOnCloseDataSink)2