FileDocCategorySizeDatePackage
FileClientSessionCacheTest.javaAPI DocAndroid 1.5 API2097Wed May 06 22:41:06 BST 2009org.apache.harmony.xnet.provider.jsse

FileClientSessionCacheTest

public class FileClientSessionCacheTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtestMaxSize()

        String tmpDir = System.getProperty("java.io.tmpdir");
        if (tmpDir == null) {
            fail("Please set 'java.io.tmpdir' system property.");
        }
        File cacheDir = new File(tmpDir
                + "/" + FileClientSessionCacheTest.class.getName() + "/cache");
        final SSLClientSessionCache cache
                = FileClientSessionCache.usingDirectory(cacheDir);
        Thread[] threads = new Thread[10];
        final int iterations = FileClientSessionCache.MAX_SIZE * 10;
        for (int i = 0; i < threads.length; i++) {
            final int id = i;
            threads[i] = new Thread() {
                @Override
                public void run() {
                    for (int i = 0; i < iterations; i++) {
                        cache.putSessionData(new FakeSession(id + "." + i),
                                new byte[10]);
                    }
                }
            };
        }
        for (int i = 0; i < threads.length; i++) {
            threads[i].start();
        }
        for (int i = 0; i < threads.length; i++) {
            threads[i].join();
        }
        assertEquals(FileClientSessionCache.MAX_SIZE, cacheDir.list().length);