Source:
public void testCompositeStrategy() throws Exception { MaxConnectionsBasedStrategy global = new MaxConnectionsBasedStrategy(1); MaxConnectionsBasedStrategy local = new MaxConnectionsBasedStrategy(2); CompositePoolLimitDeterminationStrategy strategy = new CompositePoolLimitDeterminationStrategy(local, global); Assert.assertTrue("Invalid permit acquire failure.", strategy.acquireCreationPermit()); Assert.assertEquals("Unexpected available global permits.", 0, global.getAvailablePermits()); Assert.assertEquals("Unexpected available local permits.", 1, local.getAvailablePermits()); Assert.assertEquals("Unexpected available composite permits.", 0, strategy.getAvailablePermits()); Assert.assertFalse("Invalid permit acquire success.", strategy.acquireCreationPermit()); Assert.assertEquals("Unexpected available global permits.", 0, global.getAvailablePermits()); Assert.assertEquals("Unexpected available local permits.", 1, local.getAvailablePermits()); Assert.assertEquals("Unexpected available composite permits.", 0, strategy.getAvailablePermits()); strategy.onNext(PoolInsightProvider.StateChangeEvent.OnConnectionEviction); Assert.assertEquals("Unexpected available global permits.", 1, global.getAvailablePermits()); Assert.assertEquals("Unexpected available local permits.", 2, local.getAvailablePermits()); Assert.assertEquals("Unexpected available composite permits.", 1, strategy.getAvailablePermits()); Assert.assertTrue("Invalid permit acquire failure.", strategy.acquireCreationPermit()); Assert.assertEquals("Unexpected available global permits.", 0, global.getAvailablePermits()); Assert.assertEquals("Unexpected available local permits.", 1, local.getAvailablePermits()); Assert.assertEquals("Unexpected available composite permits.", 0, strategy.getAvailablePermits()); }

Target:
public void testCompositeStrategy() throws Exception { MaxConnectionsBasedStrategy global = new MaxConnectionsBasedStrategy(1); MaxConnectionsBasedStrategy local = new MaxConnectionsBasedStrategy(2); CompositePoolLimitDeterminationStrategy strategy = new CompositePoolLimitDeterminationStrategy(local, global); Assert.assertTrue("Invalid permit acquire failure.", strategy.acquireCreationPermit()); Assert.assertEquals("Unexpected available global permits.", 0, global.getAvailablePermits()); Assert.assertEquals("Unexpected available local permits.", 1, local.getAvailablePermits()); Assert.assertEquals("Unexpected available composite permits.", 0, strategy.getAvailablePermits()); Assert.assertFalse("Invalid permit acquire success.", strategy.acquireCreationPermit()); Assert.assertEquals("Unexpected available global permits.", 0, global.getAvailablePermits()); Assert.assertEquals("Unexpected available local permits.", 1, local.getAvailablePermits()); Assert.assertEquals("Unexpected available composite permits.", 0, strategy.getAvailablePermits()); strategy.onNext(PoolInsightProvider.PoolStateChangeEvent.OnConnectionEviction); Assert.assertEquals("Unexpected available global permits.", 1, global.getAvailablePermits()); Assert.assertEquals("Unexpected available local permits.", 2, local.getAvailablePermits()); Assert.assertEquals("Unexpected available composite permits.", 1, strategy.getAvailablePermits()); Assert.assertTrue("Invalid permit acquire failure.", strategy.acquireCreationPermit()); Assert.assertEquals("Unexpected available global permits.", 0, global.getAvailablePermits()); Assert.assertEquals("Unexpected available local permits.", 1, local.getAvailablePermits()); Assert.assertEquals("Unexpected available composite permits.", 0, strategy.getAvailablePermits()); }