Search in sources :

Example 1 with ReferenceType

use of org.apache.hadoop.hbase.util.IdReadWriteLock.ReferenceType in project hbase by apache.

the class TestIdReadWriteLock method testMultipleClients.

@Test(timeout = 60000)
public void testMultipleClients() throws Exception {
    ExecutorService exec = Executors.newFixedThreadPool(NUM_THREADS);
    try {
        ExecutorCompletionService<Boolean> ecs = new ExecutorCompletionService<>(exec);
        for (int i = 0; i < NUM_THREADS; ++i) ecs.submit(new IdLockTestThread("client_" + i));
        for (int i = 0; i < NUM_THREADS; ++i) {
            Future<Boolean> result = ecs.take();
            assertTrue(result.get());
        }
        int entryPoolSize = idLock.purgeAndGetEntryPoolSize();
        LOG.debug("Size of entry pool after gc and purge: " + entryPoolSize);
        ReferenceType refType = idLock.getReferenceType();
        switch(refType) {
            case WEAK:
                // make sure the entry pool will be cleared after GC and purge call
                assertEquals(0, entryPoolSize);
                break;
            case SOFT:
                // make sure the entry pool won't be cleared when JVM memory is enough
                // even after GC and purge call
                assertEquals(NUM_IDS, entryPoolSize);
                break;
            default:
                break;
        }
    } finally {
        exec.shutdown();
        exec.awaitTermination(5000, TimeUnit.MILLISECONDS);
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) ReferenceType(org.apache.hadoop.hbase.util.IdReadWriteLock.ReferenceType) Test(org.junit.Test)

Aggregations

ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 ExecutorService (java.util.concurrent.ExecutorService)1 ReferenceType (org.apache.hadoop.hbase.util.IdReadWriteLock.ReferenceType)1 Test (org.junit.Test)1