Search in sources :

Example 11 with FakeDataSet

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

the class FakeDataSourceTest method testOpenSourceFailures.

@Test
public void testOpenSourceFailures() {
    // Empty data.
    FakeDataSource dataSource = new FakeDataSource(new FakeDataSet().newData(uri.toString()).endData());
    try {
        dataSource.open(new DataSpec(uri));
        fail("IOException expected.");
    } catch (IOException e) {
    // Expected.
    } finally {
        dataSource.close();
    }
    // Non-existent data
    dataSource = new FakeDataSource(new FakeDataSet());
    try {
        dataSource.open(new DataSpec(uri));
        fail("IOException expected.");
    } catch (IOException e) {
    // Expected.
    } finally {
        dataSource.close();
    }
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with FakeDataSet

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

the class ProgressiveDownloaderTest method download_afterWriteFailureOnClose_succeeds.

@Test
public void download_afterWriteFailureOnClose_succeeds() throws Exception {
    Uri uri = Uri.parse("test:///test.mp4");
    FakeDataSet data = new FakeDataSet();
    data.newData(uri).appendReadData(1024);
    DataSource.Factory upstreamDataSource = new FakeDataSource.Factory().setFakeDataSet(data);
    AtomicBoolean failOnClose = new AtomicBoolean(/* initialValue= */
    true);
    FailOnCloseDataSink.Factory dataSinkFactory = new FailOnCloseDataSink.Factory(downloadCache, failOnClose);
    MediaItem mediaItem = MediaItem.fromUri(uri);
    CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(downloadCache).setCacheWriteDataSinkFactory(dataSinkFactory).setUpstreamDataSourceFactory(upstreamDataSource);
    ProgressiveDownloader downloader = new ProgressiveDownloader(mediaItem, cacheDataSourceFactory);
    TestProgressListener progressListener = new TestProgressListener();
    // Failure expected after 1024 bytes.
    assertThrows(IOException.class, () -> downloader.download(progressListener));
    assertThat(progressListener.bytesDownloaded).isEqualTo(1024);
    failOnClose.set(false);
    // Retry should succeed.
    downloader.download(progressListener);
    assertThat(progressListener.bytesDownloaded).isEqualTo(1024);
}
Also used : FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) Uri(android.net.Uri) FailOnCloseDataSink(com.google.android.exoplayer2.testutil.FailOnCloseDataSink) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) MediaItem(com.google.android.exoplayer2.MediaItem) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) Test(org.junit.Test)

Example 13 with FakeDataSet

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

the class ProgressiveDownloaderTest method download_afterReadFailure_succeeds.

@Test
public void download_afterReadFailure_succeeds() throws Exception {
    Uri uri = Uri.parse("test:///test.mp4");
    // Fake data has a built in failure after 10 bytes.
    FakeDataSet data = new FakeDataSet();
    data.newData(uri).appendReadData(10).appendReadError(new IOException()).appendReadData(20);
    DataSource.Factory upstreamDataSource = new FakeDataSource.Factory().setFakeDataSet(data);
    MediaItem mediaItem = MediaItem.fromUri(uri);
    CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(downloadCache).setUpstreamDataSourceFactory(upstreamDataSource);
    ProgressiveDownloader downloader = new ProgressiveDownloader(mediaItem, cacheDataSourceFactory);
    TestProgressListener progressListener = new TestProgressListener();
    // Failure expected after 10 bytes.
    assertThrows(IOException.class, () -> downloader.download(progressListener));
    assertThat(progressListener.bytesDownloaded).isEqualTo(10);
    // Retry should succeed.
    downloader.download(progressListener);
    assertThat(progressListener.bytesDownloaded).isEqualTo(30);
}
Also used : FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) IOException(java.io.IOException) Uri(android.net.Uri) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) MediaItem(com.google.android.exoplayer2.MediaItem) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) Test(org.junit.Test)

Example 14 with FakeDataSet

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

the class DownloadManagerDashTest method setUp.

@Before
public void setUp() throws Exception {
    ShadowLog.stream = System.out;
    testThread = new DummyMainThread();
    Context context = ApplicationProvider.getApplicationContext();
    tempFolder = Util.createTempDirectory(context, "ExoPlayerTest");
    File cacheFolder = new File(tempFolder, "cache");
    cacheFolder.mkdir();
    cache = new SimpleCache(cacheFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    MockitoAnnotations.initMocks(this);
    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);
    fakeStreamKey1 = new StreamKey(0, 0, 0);
    fakeStreamKey2 = new StreamKey(0, 1, 0);
    downloadIndex = new DefaultDownloadIndex(TestUtil.getInMemoryDatabaseProvider());
    createDownloadManager();
}
Also used : Context(android.content.Context) DefaultDownloadIndex(com.google.android.exoplayer2.offline.DefaultDownloadIndex) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) DummyMainThread(com.google.android.exoplayer2.testutil.DummyMainThread) NoOpCacheEvictor(com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) File(java.io.File) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Before(org.junit.Before)

Example 15 with FakeDataSet

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

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