Skip to content

Commit 0755579

Browse files
committed
update test
1 parent 5622be2 commit 0755579

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

library/src/androidTest/java/com/qiniu/android/TestFileRecorder.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.File;
2222
import java.io.IOException;
23+
import java.security.MessageDigest;
2324
import java.util.Date;
2425
import java.util.HashMap;
2526
import java.util.Map;
@@ -171,7 +172,7 @@ public void testLastModify() throws IOException {
171172
fr.set(key, data);
172173
byte[] data2 = fr.get(key);
173174

174-
File recoderFile = new File(folder, UrlSafeBase64.encodeToString(key));
175+
File recoderFile = new File(folder, hash(key));
175176

176177
long m1 = recoderFile.lastModified();
177178

@@ -183,10 +184,12 @@ public void testLastModify() throws IOException {
183184
assertEquals(3, data2.length);
184185
assertEquals('8', data2[1]);
185186

187+
// 让记录文件过期,两天
186188
recoderFile.setLastModified(new Date().getTime() - 1000 * 3600 * 48 - 2300);
187189

188190
long m2 = recoderFile.lastModified();
189191

192+
// 过期后,记录数据作废
190193
byte[] data3 = fr.get(key);
191194

192195
assertNull(data3);
@@ -201,4 +204,21 @@ public void testLastModify() throws IOException {
201204
long m4 = recoderFile.lastModified();
202205
assertTrue(m4 > m1);
203206
}
207+
208+
// copy from FileRecorder.
209+
private static String hash(String base) {
210+
try {
211+
MessageDigest digest = MessageDigest.getInstance("SHA-1");
212+
byte[] hash = digest.digest(base.getBytes());
213+
StringBuffer hexString = new StringBuffer();
214+
215+
for (int i = 0; i < hash.length; i++) {
216+
hexString.append(Integer.toString((hash[i] & 0xff) + 0x100, 16).substring(1));
217+
}
218+
return hexString.toString();
219+
} catch (Exception ex) {
220+
ex.printStackTrace();
221+
}
222+
return null;
223+
}
204224
}

0 commit comments

Comments
 (0)