test_class.file: bonecp-spring/src/test/java/com/jolbox/bonecp/spring/TestDynamicDataSourceProxy.java
test_class.identifier: TestDynamicDataSourceProxy
test_case.body: @Test
  	public void testSwitchDataSource() throws SQLException, ClassNotFoundException {
  
  		BoneCPDataSource mockDataSource = createNiceMock(BoneCPDataSource.class);
  		DynamicDataSourceProxy ddsp = new DynamicDataSourceProxy();
  		// Test #1: Check for correct instance.
  		ddsp.setTargetDataSource(new DelegatingDataSource());
  		try{
  			ddsp.switchDataSource(null);
  			fail("Should throw an exception");
  		} catch(SQLException e){
  			// do nothing
  		}
  		
  		// Test #2: Given a good config, should initialize pool and switch datasource to it
  		BoneCPConfig config = new BoneCPConfig();
  		config.setJdbcUrl("jdbc:mock");
  		config.setUsername("sa");
  		config.setPassword("");
  		config.setMinConnectionsPerPartition(2);
  		config.setMaxConnectionsPerPartition(2);
  		config.setPartitionCount(1);
  		
  
  		ddsp = new DynamicDataSourceProxy(mockDataSource);
  
  		// Old datasource should be closed.
  		mockDataSource.close();
  		expectLastCall().once();
  		replay(mockDataSource);
  		ddsp.switchDataSource(config);
  		// and a new datasource should be in place
  		assertNotSame(mockDataSource, ddsp.getTargetDataSource());
  		verify(mockDataSource);
  	}
test_case.class_method_signature: TestDynamicDataSourceProxy.testSwitchDataSource()
test_case.full_signature: @Test public void testSwitchDataSource()
test_case.identifier: testSwitchDataSource
test_case.invocations: createNiceMock setTargetDataSource switchDataSource fail setJdbcUrl setUsername setPassword setMinConnectionsPerPartition setMaxConnectionsPerPartition setPartitionCount close once expectLastCall replay switchDataSource assertNotSame getTargetDataSource verify
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testSwitchDataSource()
focal_class.declarator: logger = LogFactory.getLog(LazyConnectionDataSourceProxy.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Log logger = LogFactory.getLog(LazyConnectionDataSourceProxy.class);
focal_class.type: Log
focal_class.var_name: logger
focal_class.file: bonecp-spring/src/main/java/com/jolbox/bonecp/spring/DynamicDataSourceProxy.java
focal_class.identifier: DynamicDataSourceProxy
focal_class.class_method_signature: DynamicDataSourceProxy.DynamicDataSourceProxy(DataSource targetDataSource)
focal_class.full_signature: public  DynamicDataSourceProxy(DataSource targetDataSource)
focal_class.identifier: DynamicDataSourceProxy
focal_class.modifiers: public
focal_class.parameters: (DataSource targetDataSource)
focal_class.signature:  DynamicDataSourceProxy(DataSource targetDataSource)
focal_class.class_method_signature: DynamicDataSourceProxy.DynamicDataSourceProxy()
focal_class.full_signature: public  DynamicDataSourceProxy()
focal_class.identifier: DynamicDataSourceProxy
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  DynamicDataSourceProxy()
focal_class.class_method_signature: DynamicDataSourceProxy.switchDataSource(BoneCPConfig newConfig)
focal_class.full_signature: public void switchDataSource(BoneCPConfig newConfig)
focal_class.identifier: switchDataSource
focal_class.modifiers: public
focal_class.parameters: (BoneCPConfig newConfig)
focal_class.return: void
focal_class.signature: void switchDataSource(BoneCPConfig newConfig)
focal_class.superclass: extends DelegatingDataSource
focal_method.body: public void switchDataSource(BoneCPConfig newConfig) throws SQLException {
  		logger.info("Switch to new datasource requested. New Config: "+newConfig);
  		DataSource oldDS = getTargetDataSource();
   
  		if (!(oldDS instanceof BoneCPDataSource)){
  			throw new SQLException("Unknown datasource type! Was expecting BoneCPDataSource but received "+oldDS.getClass()+". Not switching datasource!");
  		}
  		
  		BoneCPDataSource newDS = new BoneCPDataSource(newConfig);
  		newDS.getConnection().close(); // initialize a connection (+ throw it away) to force the datasource to initialize the pool
  		
  		// force application to start using the new one 
  		setTargetDataSource(newDS);
  		
  		logger.info("Shutting down old datasource slowly. Old Config: "+oldDS);
  		// tell the old datasource to terminate. This terminates the pool lazily so existing checked out connections can still be used.
  		((BoneCPDataSource)oldDS).close();
  	}
focal_method.class_method_signature: DynamicDataSourceProxy.switchDataSource(BoneCPConfig newConfig)
focal_method.full_signature: public void switchDataSource(BoneCPConfig newConfig)
focal_method.identifier: switchDataSource
focal_method.invocations: info getTargetDataSource getClass close getConnection setTargetDataSource info close
focal_method.modifiers: public
focal_method.parameters: (BoneCPConfig newConfig)
focal_method.return: void
focal_method.signature: void switchDataSource(BoneCPConfig newConfig)