aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com
diff options
context:
space:
mode:
authorRalph Bergmann <ralph@the4thfloor.eu>2014-09-21 22:09:33 +0200
committerFicus Kirkpatrick <ficus@android.com>2015-02-15 09:09:05 -0800
commit9324df1b8046548587ffec89ec755264f6fbb097 (patch)
tree0f0cb0b835925767038340745b0faf82bce15996 /src/test/java/com
parent3ac982d9455cb18d1c9ca10e695770d72fe21c90 (diff)
downloadvolley-9324df1b8046548587ffec89ec755264f6fbb097.tar.gz
Uses the "Last-Modified" header for "If-Modified-Since"
Uses the "Last-Modified" header for "If-Modified-Since" see http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3.4 Change-Id: I0f5e9b45f4f79d7c1b286e465f9750dcd71b6bfd Signed-off-by: Ralph Bergmann <ralph@the4thfloor.eu>
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java41
-rw-r--r--src/test/java/com/android/volley/toolbox/HttpHeaderParserTest.java4
-rw-r--r--src/test/java/com/android/volley/utils/CacheTestUtils.java2
3 files changed, 46 insertions, 1 deletions
diff --git a/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java b/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java
index 4b2955d..d9d49e9 100644
--- a/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java
+++ b/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java
@@ -34,6 +34,7 @@ public class DiskBasedCacheTest {
Cache.Entry e = new Cache.Entry();
e.data = new byte[8];
e.serverDate = 1234567L;
+ e.lastModified = 13572468L;
e.ttl = 9876543L;
e.softTtl = 8765432L;
e.etag = "etag";
@@ -48,6 +49,7 @@ public class DiskBasedCacheTest {
assertEquals(first.key, second.key);
assertEquals(first.serverDate, second.serverDate);
+ assertEquals(first.lastModified, second.lastModified);
assertEquals(first.ttl, second.ttl);
assertEquals(first.softTtl, second.softTtl);
assertEquals(first.etag, second.etag);
@@ -121,4 +123,43 @@ public class DiskBasedCacheTest {
assertEquals(DiskBasedCache.readStringStringMap(bais), emptyKey);
assertEquals(DiskBasedCache.readStringStringMap(bais), emptyValue);
}
+
+ // Test deserializing the old format into the new one.
+ public void testCacheHeaderSerializationOldToNewFormat() throws Exception {
+
+ final int CACHE_MAGIC = 0x20140623;
+ final String key = "key";
+ final String etag = "etag";
+ final long serverDate = 1234567890l;
+ final long ttl = 1357924680l;
+ final long softTtl = 2468013579l;
+
+ Map<String, String> responseHeaders = new HashMap<String, String>();
+ responseHeaders.put("first", "thing");
+ responseHeaders.put("second", "item");
+
+ // write old sytle header (without lastModified)
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DiskBasedCache.writeInt(baos, CACHE_MAGIC);
+ DiskBasedCache.writeString(baos, key);
+ DiskBasedCache.writeString(baos, etag == null ? "" : etag);
+ DiskBasedCache.writeLong(baos, serverDate);
+ DiskBasedCache.writeLong(baos, ttl);
+ DiskBasedCache.writeLong(baos, softTtl);
+ DiskBasedCache.writeStringStringMap(responseHeaders, baos);
+
+ // read / test new style header (with lastModified)
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ CacheHeader cacheHeader = CacheHeader.readHeader(bais);
+
+ assertEquals(cacheHeader.key, key);
+ assertEquals(cacheHeader.etag, etag);
+ assertEquals(cacheHeader.serverDate, serverDate);
+ assertEquals(cacheHeader.ttl, ttl);
+ assertEquals(cacheHeader.softTtl, softTtl);
+ assertEquals(cacheHeader.responseHeaders, responseHeaders);
+
+ // the old format doesn't know lastModified
+ assertEquals(cacheHeader.lastModified, 0);
+ }
}
diff --git a/src/test/java/com/android/volley/toolbox/HttpHeaderParserTest.java b/src/test/java/com/android/volley/toolbox/HttpHeaderParserTest.java
index b8c4847..01ff2c2 100644
--- a/src/test/java/com/android/volley/toolbox/HttpHeaderParserTest.java
+++ b/src/test/java/com/android/volley/toolbox/HttpHeaderParserTest.java
@@ -40,6 +40,7 @@ public class HttpHeaderParserTest {
private static long ONE_MINUTE_MILLIS = 1000L * 60;
private static long ONE_HOUR_MILLIS = 1000L * 60 * 60;
+ private static long ONE_DAY_MILLIS = ONE_HOUR_MILLIS * 24;
private NetworkResponse response;
private Map<String, String> headers;
@@ -55,6 +56,7 @@ public class HttpHeaderParserTest {
assertNotNull(entry);
assertNull(entry.etag);
assertEquals(0, entry.serverDate);
+ assertEquals(0, entry.lastModified);
assertEquals(0, entry.ttl);
assertEquals(0, entry.softTtl);
}
@@ -82,6 +84,7 @@ public class HttpHeaderParserTest {
@Test public void parseCacheHeaders_normalExpire() {
long now = System.currentTimeMillis();
headers.put("Date", rfc1123Date(now));
+ headers.put("Last-Modified", rfc1123Date(now - ONE_DAY_MILLIS));
headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));
Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
@@ -89,6 +92,7 @@ public class HttpHeaderParserTest {
assertNotNull(entry);
assertNull(entry.etag);
assertEqualsWithin(entry.serverDate, now, ONE_MINUTE_MILLIS);
+ assertEqualsWithin(entry.lastModified, (now - ONE_DAY_MILLIS), ONE_MINUTE_MILLIS);
assertTrue(entry.softTtl >= (now + ONE_HOUR_MILLIS));
assertTrue(entry.ttl == entry.softTtl);
}
diff --git a/src/test/java/com/android/volley/utils/CacheTestUtils.java b/src/test/java/com/android/volley/utils/CacheTestUtils.java
index cd2b8e7..898d055 100644
--- a/src/test/java/com/android/volley/utils/CacheTestUtils.java
+++ b/src/test/java/com/android/volley/utils/CacheTestUtils.java
@@ -24,7 +24,7 @@ public class CacheTestUtils {
entry.data = new byte[random.nextInt(1024)];
}
entry.etag = String.valueOf(random.nextLong());
- entry.serverDate = random.nextLong();
+ entry.lastModified = random.nextLong();
entry.ttl = isExpired ? 0 : Long.MAX_VALUE;
entry.softTtl = needsRefresh ? 0 : Long.MAX_VALUE;
return entry;