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();
}
}
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);
}
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);
}
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();
}
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();
});
}
Aggregations