| 21478 |
rajender |
1 |
// Copyright 2011 Google Inc. All Rights Reserved.
|
|
|
2 |
|
|
|
3 |
package com.android.volley.utils;
|
|
|
4 |
|
|
|
5 |
import com.android.volley.Cache;
|
|
|
6 |
|
|
|
7 |
import java.util.Random;
|
|
|
8 |
|
|
|
9 |
public class CacheTestUtils {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Makes a random cache entry.
|
|
|
13 |
* @param data Data to use, or null to use random data
|
|
|
14 |
* @param isExpired Whether the TTLs should be set such that this entry is expired
|
|
|
15 |
* @param needsRefresh Whether the TTLs should be set such that this entry needs refresh
|
|
|
16 |
*/
|
|
|
17 |
public static Cache.Entry makeRandomCacheEntry(
|
|
|
18 |
byte[] data, boolean isExpired, boolean needsRefresh) {
|
|
|
19 |
Random random = new Random();
|
|
|
20 |
Cache.Entry entry = new Cache.Entry();
|
|
|
21 |
if (data != null) {
|
|
|
22 |
entry.data = data;
|
|
|
23 |
} else {
|
|
|
24 |
entry.data = new byte[random.nextInt(1024)];
|
|
|
25 |
}
|
|
|
26 |
entry.etag = String.valueOf(random.nextLong());
|
|
|
27 |
entry.lastModified = random.nextLong();
|
|
|
28 |
entry.ttl = isExpired ? 0 : Long.MAX_VALUE;
|
|
|
29 |
entry.softTtl = needsRefresh ? 0 : Long.MAX_VALUE;
|
|
|
30 |
return entry;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Like {@link #makeRandomCacheEntry(byte[], boolean, boolean)} but
|
|
|
35 |
* defaults to an unexpired entry.
|
|
|
36 |
*/
|
|
|
37 |
public static Cache.Entry makeRandomCacheEntry(byte[] data) {
|
|
|
38 |
return makeRandomCacheEntry(data, false, false);
|
|
|
39 |
}
|
|
|
40 |
}
|