use of android.app.DownloadManager.Query in project android_frameworks_base by crdroidandroid.
the class DownloadManagerStressTest method testMultipleDownloads.
/**
* Attempts to download several files simultaneously
*/
@LargeTest
public void testMultipleDownloads() throws Exception {
// need to be sure all current downloads have stopped first
removeAllCurrentDownloads();
int NUM_FILES = 10;
// 10 kb
int MAX_FILE_SIZE = 10 * 1024;
Random r = new LoggingRng();
for (int i = 0; i < NUM_FILES; ++i) {
int size = r.nextInt(MAX_FILE_SIZE);
byte[] blobData = generateData(size, DataType.TEXT);
Uri uri = getServerUri(DEFAULT_FILENAME + i);
Request request = new Request(uri);
request.setTitle(String.format("%s--%d", DEFAULT_FILENAME + i, i));
// Prepare the mock server with a standard response
enqueueResponse(buildResponse(HTTP_OK, blobData));
long requestID = mDownloadManager.enqueue(request);
}
waitForDownloadsOrTimeout(WAIT_FOR_DOWNLOAD_POLL_TIME, MAX_WAIT_FOR_DOWNLOAD_TIME);
Cursor cursor = mDownloadManager.query(new Query());
try {
assertEquals(NUM_FILES, cursor.getCount());
if (cursor.moveToFirst()) {
do {
int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
String filename = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_URI));
String errorString = String.format("File %s failed to download successfully. Status code: %d", filename, status);
assertEquals(errorString, DownloadManager.STATUS_SUCCESSFUL, status);
} while (cursor.moveToNext());
}
assertEquals(NUM_FILES, mReceiver.numDownloadsCompleted());
} finally {
cursor.close();
}
}
Aggregations