DefaultConnectionLimitManager implements ConnectionLimitManager { @Override public boolean isLimitExceeded() { final boolean exceeded = currentConnections.get() >= limit; if (exceeded) { LOG.debug("Connection limit ({}) exceeded", limit); } return exceeded; } DefaultConnectionLimitManager(final ConnectionLimitStrategy strategy, final Supplier<Integer> currentConnections,
            final ProtocolAdapterProperties config); @Override boolean isLimitExceeded();  }
@Test public void testLimitIsEqual() { final ProtocolAdapterProperties config = new ProtocolAdapterProperties(); config.setMaxConnections(1); final Supplier<Integer> currentConnections = () -> 1; assertTrue(new DefaultConnectionLimitManager(strategy, currentConnections, config).isLimitExceeded()); }
@Test public void testLimitIsLower() { final ProtocolAdapterProperties config = new ProtocolAdapterProperties(); config.setMaxConnections(1); final Supplier<Integer> currentConnections = () -> 2; assertTrue(new DefaultConnectionLimitManager(strategy, currentConnections, config).isLimitExceeded()); }
@Test public void testLimitIsHigher() { final ProtocolAdapterProperties config = new ProtocolAdapterProperties(); config.setMaxConnections(2); final Supplier<Integer> currentConnections = () -> 1; assertFalse(new DefaultConnectionLimitManager(strategy, currentConnections, config).isLimitExceeded()); }
@SuppressWarnings("unchecked") @Test public void testAutoconfigIfNotConfigured() { final Supplier<Integer> currentConnections = mock(Supplier.class); final ProtocolAdapterProperties config = new ProtocolAdapterProperties(); when(strategy.getRecommendedLimit()).thenReturn(2); final ConnectionLimitManager connectionLimitManager = new DefaultConnectionLimitManager(strategy, currentConnections, config); when(currentConnections.get()).thenReturn(1); assertFalse(connectionLimitManager.isLimitExceeded()); when(currentConnections.get()).thenReturn(2); assertTrue(connectionLimitManager.isLimitExceeded()); }
@SuppressWarnings("unchecked") @Test public void testAutoconfigIfConfigIsNull() { final Supplier<Integer> currentConnections = mock(Supplier.class); final ProtocolAdapterProperties config = null; when(strategy.getRecommendedLimit()).thenReturn(2); final ConnectionLimitManager connectionLimitManager = new DefaultConnectionLimitManager(strategy, currentConnections, config); when(currentConnections.get()).thenReturn(1); assertFalse(connectionLimitManager.isLimitExceeded()); when(currentConnections.get()).thenReturn(2); assertTrue(connectionLimitManager.isLimitExceeded()); }