Methods Summary |
---|
private void | closeDatabase()
if (DatabaseSessionCache.sDefaultDatabaseHelper != null) {
DatabaseSessionCache.sDefaultDatabaseHelper.close();
}
DatabaseSessionCache.sDefaultDatabaseHelper = null;
DatabaseSessionCache.sHookInitializationDone = false;
DatabaseSessionCache.mNeedsCacheLoad = true;
|
private void | closeDirectoryCache()
try {
Method reset = FileClientSessionCache.class
.getDeclaredMethod("reset");
reset.setAccessible(true);
reset.invoke(null);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
|
private void | deleteDatabase()
closeDatabase();
if (!new File(dbDir, "ssl_sessions.db").delete()) {
System.err.println("Failed to delete database.");
}
|
private void | deleteDirectory()
closeDirectoryCache();
File dir = getCacheDirectory();
if (!dir.exists()) {
return;
}
for (File file : dir.listFiles()) {
file.delete();
}
if (!dir.delete()) {
System.err.println("Failed to delete directory.");
}
|
private java.io.File | getCacheDirectory()
return new File(getContext().getFilesDir(), CACHE_DIR);
|
private void | getVerisignDotCom(org.apache.harmony.xnet.provider.jsse.SSLContextImpl sslContext)
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("https",
new SSLSocketFactory(sslContext.engineGetSocketFactory()),
443));
ClientConnectionManager manager =
new SingleClientConnManager(null, schemeRegistry);
new DefaultHttpClient(manager, null).execute(
new HttpGet("https://www.verisign.com"),
new ResponseHandler<Object>() {
public Object handleResponse(HttpResponse response)
throws ClientProtocolException, IOException {
return null;
}
});
|
private void | putSessionsIn(org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache cache)
for (int i = 0; i < 10; i++) {
cache.putSessionData(new FakeSession("host" + i), SESSION_DATA);
}
|
public void | testCreateNewEmptyDatabase()
deleteDatabase();
Stopwatch stopwatch = new Stopwatch();
DatabaseSessionCache cache = new DatabaseSessionCache(getContext());
cache.getSessionData("crazybob.org", 443);
stopwatch.stop();
|
public void | testCreateNewEmptyDirectory()
deleteDirectory();
Stopwatch stopwatch = new Stopwatch();
SSLClientSessionCache cache = FileClientSessionCache.usingDirectory(
getCacheDirectory());
cache.getSessionData("crazybob.org", 443);
stopwatch.stop();
|
public void | testEngineInit()
Stopwatch stopwatch = new Stopwatch();
new SSLContextImpl().engineInit(null, null, null);
stopwatch.stop();
|
public void | testGetSessionFromDatabase()
deleteDatabase();
DatabaseSessionCache cache = new DatabaseSessionCache(getContext());
cache.putSessionData(new FakeSession("foo"), SESSION_DATA);
closeDatabase();
cache = new DatabaseSessionCache(getContext());
cache.getSessionData("crazybob.org", 443);
Stopwatch stopwatch = new Stopwatch();
byte[] sessionData = cache.getSessionData("foo", 443);
stopwatch.stop();
assertTrue(Arrays.equals(SESSION_DATA, sessionData));
|
public void | testGetSessionFromDirectory()
deleteDirectory();
SSLClientSessionCache cache = FileClientSessionCache.usingDirectory(
getCacheDirectory());
cache.putSessionData(new FakeSession("foo"), SESSION_DATA);
closeDirectoryCache();
cache = FileClientSessionCache.usingDirectory(
getCacheDirectory());
cache.getSessionData("crazybob.org", 443);
Stopwatch stopwatch = new Stopwatch();
byte[] sessionData = cache.getSessionData("foo", 443);
stopwatch.stop();
assertTrue(Arrays.equals(SESSION_DATA, sessionData));
|
public void | testOpenDatabaseWith10Sessions()
deleteDatabase();
DatabaseSessionCache cache = new DatabaseSessionCache(getContext());
putSessionsIn(cache);
closeDatabase();
System.err.println("Size of ssl_sessions.db w/ 10 sessions: "
+ new File(dbDir, "ssl_sessions.db").length());
Stopwatch stopwatch = new Stopwatch();
cache = new DatabaseSessionCache(getContext());
cache.getSessionData("crazybob.org", 443);
stopwatch.stop();
|
public void | testOpenDirectoryWith10Sessions()
deleteDirectory();
SSLClientSessionCache cache = FileClientSessionCache.usingDirectory(
getCacheDirectory());
putSessionsIn(cache);
closeDirectoryCache();
Stopwatch stopwatch = new Stopwatch();
cache = FileClientSessionCache.usingDirectory(
getCacheDirectory());
cache.getSessionData("crazybob.org", 443);
stopwatch.stop();
|
public void | testPutSessionIntoDatabase()
deleteDatabase();
DatabaseSessionCache cache = new DatabaseSessionCache(getContext());
cache.getSessionData("crazybob.org", 443);
Stopwatch stopwatch = new Stopwatch();
cache.putSessionData(new FakeSession("foo"), SESSION_DATA);
stopwatch.stop();
|
public void | testPutSessionIntoDirectory()
deleteDirectory();
SSLClientSessionCache cache = FileClientSessionCache.usingDirectory(
getCacheDirectory());
cache.getSessionData("crazybob.org", 443);
Stopwatch stopwatch = new Stopwatch();
cache.putSessionData(new FakeSession("foo"), SESSION_DATA);
stopwatch.stop();
|
public void | testWebRequestWithFileCache()
deleteDirectory();
SSLContextImpl sslContext = new SSLContextImpl();
sslContext.engineInit(null, null, null,
FileClientSessionCache.usingDirectory(getCacheDirectory()),
null);
// Make sure www.google.com is in the cache.
getVerisignDotCom(sslContext);
// Re-initialize so we hit the file cache.
sslContext.engineInit(null, null, null,
FileClientSessionCache.usingDirectory(getCacheDirectory()),
null);
Stopwatch stopwatch = new Stopwatch();
getVerisignDotCom(sslContext);
stopwatch.stop();
|
public void | testWebRequestWithInMemoryCache()
deleteDirectory();
SSLContextImpl sslContext = new SSLContextImpl();
sslContext.engineInit(null, null, null);
// Make sure www.google.com is in the cache.
getVerisignDotCom(sslContext);
Stopwatch stopwatch = new Stopwatch();
getVerisignDotCom(sslContext);
stopwatch.stop();
|
public void | testWebRequestWithoutCache()
SSLContextImpl sslContext = new SSLContextImpl();
sslContext.engineInit(null, null, null);
Stopwatch stopwatch = new Stopwatch();
getVerisignDotCom(sslContext);
stopwatch.stop();
|