use of androidx.media3.test.utils.FakeDataSet in project media by androidx.
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 androidx.media3.test.utils.FakeDataSet in project media by androidx.
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);
}
use of androidx.media3.test.utils.FakeDataSet in project media by androidx.
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();
});
}
use of androidx.media3.test.utils.FakeDataSet in project media by androidx.
the class DownloadServiceDashTest method setUp.
@Before
public void setUp() throws IOException {
testThread = new DummyMainThread();
context = ApplicationProvider.getApplicationContext();
tempFolder = Util.createTempDirectory(context, "ExoPlayerTest");
cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
Runnable pauseAction = () -> {
if (pauseDownloadCondition != null) {
try {
pauseDownloadCondition.block();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
};
fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).newData("audio_init_data").appendReadAction(pauseAction).appendReadData(TestUtil.buildTestData(10)).endData().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);
final DataSource.Factory fakeDataSourceFactory = new FakeDataSource.Factory().setFakeDataSet(fakeDataSet);
fakeStreamKey1 = new StreamKey(0, 0, 0);
fakeStreamKey2 = new StreamKey(0, 1, 0);
testThread.runTestOnMainThread(() -> {
DefaultDownloadIndex downloadIndex = new DefaultDownloadIndex(TestUtil.getInMemoryDatabaseProvider());
DefaultDownloaderFactory downloaderFactory = new DefaultDownloaderFactory(new CacheDataSource.Factory().setCache(cache).setUpstreamDataSourceFactory(fakeDataSourceFactory), /* executor= */
Runnable::run);
final DownloadManager dashDownloadManager = new DownloadManager(ApplicationProvider.getApplicationContext(), downloadIndex, downloaderFactory);
downloadManagerListener = new TestDownloadManagerListener(dashDownloadManager);
dashDownloadManager.resumeDownloads();
dashDownloadService = new DownloadService(DownloadService.FOREGROUND_NOTIFICATION_ID_NONE) {
@Override
protected DownloadManager getDownloadManager() {
return dashDownloadManager;
}
@Override
@Nullable
protected Scheduler getScheduler() {
return null;
}
@Override
protected Notification getForegroundNotification(List<Download> downloads, @Requirements.RequirementFlags int notMetRequirements) {
throw new UnsupportedOperationException();
}
};
dashDownloadService.onCreate();
});
}
use of androidx.media3.test.utils.FakeDataSet in project media by androidx.
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);
}
Aggregations