private boolean canCreateSession() { synchronized (lock) { return totalSessions() + numSessionsBeingCreated < options.getMaxSessions(); } }
closeSession = true; } else { Preconditions.checkState(totalSessions() <= options.getMaxSessions() - 1); allSessions.add(pooledSession); releaseSession(pooledSession);
@Test public void atMostMaxSessionsCreated() { setupMockSessionCreation(); AtomicBoolean failed = new AtomicBoolean(false); pool = createPool(); int numSessions = 10; final CountDownLatch latch = new CountDownLatch(numSessions); for (int i = 0; i < numSessions; i++) { getSessionAsync(latch, failed); } Uninterruptibles.awaitUninterruptibly(latch); verify(client, atMost(options.getMaxSessions())).createSession(db); assertThat(failed.get()).isFalse(); }
@Test public void setMinMaxSessions() { if (minSessions > maxSessions) { expectedException.expect(IllegalArgumentException.class); } SessionPoolOptions options = SessionPoolOptions.newBuilder() .setMinSessions(minSessions) .setMaxSessions(maxSessions) .build(); assertEquals(minSessions, options.getMinSessions()); assertEquals(maxSessions, options.getMaxSessions()); } }
private boolean canCreateSession() { synchronized (lock) { return totalSessions() + numSessionsBeingCreated < options.getMaxSessions(); } }
closeSession = true; } else { Preconditions.checkState(totalSessions() <= options.getMaxSessions() - 1); allSessions.add(pooledSession); releaseSession(pooledSession);