DataSourceFactory { public DataSource getPooledDataSource(Map configMap, List<ConfigProperty> props) throws DataSourceCreateException { ConfiguredDataSourceProperties configs = createDataSourceProperties(configMap); String connpoolClassName = configs.getConnectionPoolDSClass(); if (connpoolClassName == null) { connpoolClassName = DEFAULT_CONNECTION_POOL_DS_CLASS; } try { Properties poolProperties = createPoolProperties(configMap, props); Properties dataSourceProperties = createDataSourceProperties(props); Class<?> cl = ClassPathLoader.getLatest().forName(connpoolClassName); PooledDataSourceFactory factory = (PooledDataSourceFactory) cl.newInstance(); return factory.createDataSource(poolProperties, dataSourceProperties); } catch (Exception ex) { String exception = String.format( "DataSourceFactory::getPooledDataSource:Exception creating ConnectionPoolDataSource.Exception string=%s", new Object[] {ex}); logger.error(String.format( "DataSourceFactory::getPooledDataSource:Exception creating ConnectionPoolDataSource.Exception string=%s", ex), ex); throw new DataSourceCreateException(exception, ex); } } DataSourceFactory(); DataSource getSimpleDataSource(Map configMap); ClientConnectionFactoryWrapper getManagedDataSource(Map configMap,
      List<ConfigProperty> props); DataSource getPooledDataSource(Map configMap, List<ConfigProperty> props); DataSource getTranxDataSource(Map configMap, List<ConfigProperty> props); static void setTestConnectionUrl(String url); static void setTestConnectionHost(String host); static void setTestConnectionPort(String port);  }
@Test public void getPooledDataSourceUsesConnPooledDataSourceClass() throws DataSourceCreateException { inputs.put("conn-pooled-datasource-class", "org.apache.geode.internal.datasource.DataSourceFactoryTest$TestPooledDataSourceFactory"); DataSource dataSource = new DataSourceFactory().getPooledDataSource(inputs, configProperties); assertThat(dataSource).isInstanceOf(TestDataSource.class); }
@Test public void getPooledDataSourcePassesCorrectPropertiesToConnPooledDataSourceClass() throws DataSourceCreateException { inputs.put("conn-pooled-datasource-class", "org.apache.geode.internal.datasource.DataSourceFactoryTest$TestPooledDataSourceFactory"); inputs.put("name1", ""); inputs.put("name2", null); inputs.put("type", "value"); inputs.put("jndi-name", "value"); inputs.put("transaction-type", "value"); inputs.put("managed-conn-factory-class", "value"); inputs.put("xa-datasource-class", "value"); inputs.put("validname1", "value1"); inputs.put("validname2", "value2"); configProperties.add(new ConfigProperty("pool.n1", "v1", null)); configProperties.add(new ConfigProperty("dataSourceProp", "dataSourceValue", null)); configProperties.add(new ConfigProperty("pool.n2", "v2", null)); TestDataSource dataSource = (TestDataSource) new DataSourceFactory().getPooledDataSource(inputs, configProperties); Properties poolProperties = dataSource.getPoolProperties(); Properties dataSourceProperties = dataSource.getDataSourceProperties(); assertThat(poolProperties.size()).isEqualTo(4); assertThat(poolProperties.getProperty("validname1")).isEqualTo("value1"); assertThat(poolProperties.getProperty("validname2")).isEqualTo("value2"); assertThat(poolProperties.getProperty("n1")).isEqualTo("v1"); assertThat(poolProperties.getProperty("n2")).isEqualTo("v2"); assertThat(dataSourceProperties.size()).isEqualTo(1); assertThat(dataSourceProperties.getProperty("dataSourceProp")).isEqualTo("dataSourceValue"); }
@Test public void getPooledDataSourceFailsIfClassDoesNotExist() throws DataSourceCreateException { inputs.put("conn-pooled-datasource-class", "doesNotExist"); Throwable throwable = catchThrowable(() -> new DataSourceFactory().getPooledDataSource(inputs, configProperties)); assertThat(throwable).isInstanceOf(DataSourceCreateException.class).hasMessage( "DataSourceFactory::getPooledDataSource:Exception creating ConnectionPoolDataSource.Exception string=java.lang.ClassNotFoundException: doesNotExist"); }