@Test public void testSynchronizedPoolableFactoryPoolableObjectFactory() throws Exception { try { PoolUtils.synchronizedPooledFactory((PooledObjectFactory<Object>)null); fail("PoolUtils.synchronizedPoolableFactory(PoolableObjectFactory) must not allow a null factory."); } catch(final IllegalArgumentException iae) { // expected } final List<String> calledMethods = new ArrayList<>(); @SuppressWarnings("unchecked") final PooledObjectFactory<Object> pof = createProxy(PooledObjectFactory.class, calledMethods); final PooledObjectFactory<Object> spof = PoolUtils.synchronizedPooledFactory(pof); final List<String> expectedMethods = invokeEveryMethod(spof); assertEquals(expectedMethods, calledMethods); // TODO: Anyone feel motivated to construct a test that verifies proper synchronization? }
@Test public void testGetFactoryType_PoolUtilsSynchronizedNullPooledFactory() { try (final GenericObjectPool<String> pool = new GenericObjectPool<>( PoolUtils.synchronizedPooledFactory(createNullPooledObjectFactory()))) { Assert.assertNotNull((pool.getFactoryType())); } }
@Test public void testGetFactoryType_PoolUtilsSynchronizedDefaultPooledFactory() { try (final GenericObjectPool<String> pool = new GenericObjectPool<>( PoolUtils.synchronizedPooledFactory(createDefaultPooledObjectFactory()))) { Assert.assertNotNull((pool.getFactoryType())); } }
/** * Constructor for OmimServices. Takes OMIM API keys from molgenis.properties and puts them in a pool. * * @param apiKeys * list of OMIM API keys from molgenis.properties */ @Autowired public OmimService(@Value("#{'${omim_key:@null}'.split(',')}") List<String> apiKeys) { // initialize a pool for OMIM keys to circulate them and protect them from over-use PooledOmimKeyFactory keyFactory = new PooledOmimKeyFactory(apiKeys); PooledObjectFactory<String> syncFactory = PoolUtils.synchronizedPooledFactory(keyFactory); GenericObjectPool<String> genericPool = new GenericObjectPool<String>(syncFactory); genericPool.setBlockWhenExhausted(true); genericPool.setLifo(false); genericPool.setMaxTotal(apiKeys.size()); pool = PoolUtils.synchronizedPool(genericPool); }