test_class.declarator: mockPartition
test_class.modifier: private
test_class.original_string: private ConnectionPartition mockPartition;
test_class.type: ConnectionPartition
test_class.var_name: mockPartition
test_class.declarator: mockPool
test_class.modifier: private
test_class.original_string: private BoneCP mockPool;
test_class.type: BoneCP
test_class.var_name: mockPool
test_class.declarator: testClass
test_class.modifier: static
test_class.original_string: static PoolWatchThread testClass;
test_class.type: PoolWatchThread
test_class.var_name: testClass
test_class.declarator: mockLogger
test_class.modifier: private
test_class.original_string: private Logger mockLogger;
test_class.type: Logger
test_class.var_name: mockLogger
test_class.declarator: first = true
test_class.modifier: static
test_class.original_string: static boolean first = true;
test_class.type: boolean
test_class.var_name: first
test_class.declarator: mockConfig
test_class.modifier: private
test_class.original_string: private BoneCPConfig mockConfig;
test_class.type: BoneCPConfig
test_class.var_name: mockConfig
test_class.declarator: driver
test_class.modifier: private
test_class.original_string: private MockJDBCDriver driver;
test_class.type: MockJDBCDriver
test_class.var_name: driver
test_class.file: bonecp/src/test/java/com/jolbox/bonecp/TestPoolWatchThread.java
test_class.identifier: TestPoolWatchThread
test_case.body: @Test
  	public void testRunCreateConnections() throws InterruptedException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, SQLException{
  		expect(mockLogger.isDebugEnabled()).andReturn(true).anyTimes();
  
  		LinkedBlockingQueue<ConnectionHandle> fakeConnections = new LinkedBlockingQueue<ConnectionHandle>(100);
  //		mockPartition.almostFullWait();
  //		expectLastCall().anyTimes();
  		expect(mockPartition.getMaxConnections()).andAnswer(new IAnswer<Integer>() {
  
  			// @Override
  			public Integer answer() throws Throwable {
  				if (first) {
  					first=false;
  					return 4;
  				} 
  				Field field = testClass.getClass().getDeclaredField("signalled");
  				field.setAccessible(true);
  				field.setBoolean(testClass, true);
  				return 4;
  
  			}
  		}).anyTimes();
  		
  		expect(mockPartition.getFreeConnections()).andReturn(fakeConnections).anyTimes();
  
  
  		expect(mockPartition.getAcquireIncrement()).andReturn(1);
  		
  		
  		expect(mockPartition.getUrl()).andReturn(CommonTestUtils.url).anyTimes();
  		expect(mockPartition.getPassword()).andReturn(CommonTestUtils.password).anyTimes();
  		expect(mockPartition.getUsername()).andReturn(CommonTestUtils.username).anyTimes();
  		expect(mockPartition.getAvailableConnections()).andReturn(fakeConnections.size()).anyTimes();
  
  		mockPartition.addFreeConnection((ConnectionHandle)anyObject());
  		expectLastCall().once();
  		expect(mockPool.obtainInternalConnection((ConnectionHandle)anyObject())).andReturn(EasyMock.createNiceMock(Connection.class)).anyTimes();
  		expect(mockPool.getDbIsDown()).andReturn(new AtomicBoolean()).anyTimes();
      	expect(mockPool.getConfig()).andReturn(mockConfig).anyTimes();
  		replay(mockPool, mockPartition, mockLogger);
  		testClass.run();
  		EasyMock.verify(mockPartition);
  		
  		// check exceptional cases
  		reset(mockPartition, mockPool, mockLogger);
  		resetSignalled();
  
  
  		first = true;
  //		mockPartition.unlockAlmostFullLock();
  //		expectLastCall().once();
  		
  //		mockPartition.lockAlmostFullLock();
  //		expectLastCall().andThrow(new RuntimeException());
  		replay(mockPartition, mockLogger);
  		try{
  			testClass.run();
  			Assert.fail("Exception should have been thrown");
  		} catch (RuntimeException e){
  			// do nothing
  		}
  		EasyMock.verify(mockPartition);
  
  		
  		// check case where creating new ConnectionHandle fails
  		reset(mockPool, mockLogger, mockConfig);
  		reset(mockPartition);
  		resetSignalled();
  
  		first = true;
  		expect(mockPartition.getFreeConnections()).andReturn(fakeConnections).anyTimes();
  		
  		expect(mockPartition.getMaxConnections()).andAnswer(new IAnswer<Integer>() {
  
  			// @Override
  			public Integer answer() throws Throwable {
  				if (first) {
  					first=false;
  					return 4;
  				} 
  				Field field = testClass.getClass().getDeclaredField("signalled");
  				field.setAccessible(true);
  				field.setBoolean(testClass, true);
  				return 4;
  
  			}
  		}).anyTimes();
  		
  //		mockPartition.unlockAlmostFullLock();
  //		expectLastCall().once();
  		
  //		mockPartition.lockAlmostFullLock();
  //		expectLastCall().once();
  
  		expect(mockConfig.getStatementsCacheSize()).andAnswer(new IAnswer<Integer>() {
  			
  			// @Override
  			public Integer answer() throws Throwable {
  				throw new SQLException();
  				
  			} 
  		}).once();
  		expect(mockPartition.getAcquireIncrement()).andReturn(1).anyTimes();
  		expect(mockPartition.getAvailableConnections()).andReturn(fakeConnections.size()).anyTimes();
      	expect(mockPool.getConfig()).andReturn(mockConfig).anyTimes();
  
  		expect(mockConfig.getAcquireRetryAttempts()).andReturn(0).anyTimes();
  
  		mockLogger.error((String)anyObject(), anyObject());
  		expectLastCall(); 
  		expect(mockPool.getDbIsDown()).andReturn(new AtomicBoolean()).anyTimes();
  		replay(mockPartition, mockPool, mockLogger, mockConfig);
  		testClass.run();
  		EasyMock.verify(mockPartition);
  
  	}
test_case.class_method_signature: TestPoolWatchThread.testRunCreateConnections()
test_case.full_signature: @Test public void testRunCreateConnections()
test_case.identifier: testRunCreateConnections
test_case.invocations: anyTimes andReturn expect isDebugEnabled anyTimes andAnswer expect getMaxConnections getDeclaredField getClass setAccessible setBoolean anyTimes andReturn expect getFreeConnections andReturn expect getAcquireIncrement anyTimes andReturn expect getUrl anyTimes andReturn expect getPassword anyTimes andReturn expect getUsername anyTimes andReturn expect getAvailableConnections size addFreeConnection anyObject once expectLastCall anyTimes andReturn expect obtainInternalConnection anyObject createNiceMock anyTimes andReturn expect getDbIsDown anyTimes andReturn expect getConfig replay run verify reset resetSignalled replay run fail verify reset reset resetSignalled anyTimes andReturn expect getFreeConnections anyTimes andAnswer expect getMaxConnections getDeclaredField getClass setAccessible setBoolean once andAnswer expect getStatementsCacheSize anyTimes andReturn expect getAcquireIncrement anyTimes andReturn expect getAvailableConnections size anyTimes andReturn expect getConfig anyTimes andReturn expect getAcquireRetryAttempts error anyObject anyObject expectLastCall anyTimes andReturn expect getDbIsDown replay run verify
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testRunCreateConnections()
focal_class.declarator: partition
focal_class.modifier: private
focal_class.original_string: private ConnectionPartition partition;
focal_class.type: ConnectionPartition
focal_class.var_name: partition
focal_class.declarator: pool
focal_class.modifier: private
focal_class.original_string: private BoneCP pool;
focal_class.type: BoneCP
focal_class.var_name: pool
focal_class.declarator: signalled
focal_class.modifier: private
focal_class.original_string: private boolean signalled;
focal_class.type: boolean
focal_class.var_name: signalled
focal_class.declarator: acquireRetryDelayInMs = 1000L
focal_class.modifier: private
focal_class.original_string: private long acquireRetryDelayInMs = 1000L;
focal_class.type: long
focal_class.var_name: acquireRetryDelayInMs
focal_class.declarator: lazyInit
focal_class.modifier: protected
focal_class.original_string: protected boolean lazyInit;
focal_class.type: boolean
focal_class.var_name: lazyInit
focal_class.declarator: poolAvailabilityThreshold
focal_class.modifier: private
focal_class.original_string: private int poolAvailabilityThreshold;
focal_class.type: int
focal_class.var_name: poolAvailabilityThreshold
focal_class.declarator: logger = LoggerFactory.getLogger(PoolWatchThread.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = LoggerFactory.getLogger(PoolWatchThread.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.file: bonecp/src/main/java/com/jolbox/bonecp/PoolWatchThread.java
focal_class.identifier: PoolWatchThread
focal_class.interfaces: implements Runnable
focal_class.class_method_signature: PoolWatchThread.PoolWatchThread(ConnectionPartition connectionPartition, BoneCP pool)
focal_class.full_signature: public  PoolWatchThread(ConnectionPartition connectionPartition, BoneCP pool)
focal_class.identifier: PoolWatchThread
focal_class.modifiers: public
focal_class.parameters: (ConnectionPartition connectionPartition, BoneCP pool)
focal_class.signature:  PoolWatchThread(ConnectionPartition connectionPartition, BoneCP pool)
focal_class.class_method_signature: PoolWatchThread.run()
focal_class.full_signature: public void run()
focal_class.identifier: run
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void run()
focal_class.class_method_signature: PoolWatchThread.fillConnections(int connectionsToCreate)
focal_class.full_signature: private void fillConnections(int connectionsToCreate)
focal_class.identifier: fillConnections
focal_class.modifiers: private
focal_class.parameters: (int connectionsToCreate)
focal_class.return: void
focal_class.signature: void fillConnections(int connectionsToCreate)
focal_method.body: public void run() {
  		int maxNewConnections;
  		while (!this.signalled){
  			maxNewConnections=0;
  
  			try{
  				if (this.lazyInit){ // block the first time if this is on.
  					this.partition.getPoolWatchThreadSignalQueue().take();
  				}
   
  
  				maxNewConnections = this.partition.getMaxConnections()-this.partition.getCreatedConnections();
  				// loop for spurious interrupt
  				while (maxNewConnections == 0 || (this.partition.getAvailableConnections() *100/this.partition.getMaxConnections() > this.poolAvailabilityThreshold)){
  					if (maxNewConnections == 0){
  						this.partition.setUnableToCreateMoreTransactions(true);
  					}
  					
  					this.partition.getPoolWatchThreadSignalQueue().take();
  					maxNewConnections = this.partition.getMaxConnections()-this.partition.getCreatedConnections();
  					
  				}
  
  				if (maxNewConnections > 0 
  						&& !this.pool.poolShuttingDown){
  					fillConnections(Math.min(maxNewConnections, this.partition.getAcquireIncrement()));
  					// for the case where we have killed off all our connections due to network/db error
  					if (this.partition.getCreatedConnections() < this.partition.getMinConnections()){
  						fillConnections(this.partition.getMinConnections() - this.partition.getCreatedConnections() );
  							
  					}
  				}
  				
  				if (this.pool.poolShuttingDown){
  					return;
  				}
  
  
  			} catch (InterruptedException e) {
  				logger.debug("Terminating pool watch thread");
  				return; // we've been asked to terminate.
  			}
  		}
  	}
focal_method.class_method_signature: PoolWatchThread.run()
focal_method.full_signature: public void run()
focal_method.identifier: run
focal_method.invocations: take getPoolWatchThreadSignalQueue getMaxConnections getCreatedConnections getAvailableConnections getMaxConnections setUnableToCreateMoreTransactions take getPoolWatchThreadSignalQueue getMaxConnections getCreatedConnections fillConnections min getAcquireIncrement getCreatedConnections getMinConnections fillConnections getMinConnections getCreatedConnections debug
focal_method.modifiers: public
focal_method.parameters: ()
focal_method.return: void
focal_method.signature: void run()