Skip to content

Commit

Permalink
Add unit test for DataSourcePoolReflection against Alibaba Druid
Browse files Browse the repository at this point in the history
  • Loading branch information
linghengqian committed Mar 19, 2024
1 parent 3bb9a42 commit f738e92
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
11 changes: 11 additions & 0 deletions infra/data-source-pool/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,16 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@

package org.apache.shardingsphere.infra.datasource.pool.creator;

import com.alibaba.druid.pool.DruidDataSource;
import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
import org.junit.jupiter.api.Test;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNull;

class DataSourcePoolCreatorTest {

Expand Down Expand Up @@ -59,4 +61,19 @@ private void assertDataSource(final MockedDataSource actual) {
assertThat(actual.getMaxPoolSize(), is(100));
assertNull(actual.getMinPoolSize());
}

@Test
void assertCreateAlibabaDruidDataSource() throws SQLException {
Map<String, Object> props = new LinkedHashMap<>(4, 1F);
props.put("url", "jdbc:h2:mem:foo_ds");
props.put("driverClassName", "org.h2.Driver");
props.put("username", "root");
props.put("password", "root");
DruidDataSource dataSource = (DruidDataSource) DataSourcePoolCreator.create(new DataSourcePoolProperties(DruidDataSource.class.getName(), props));
dataSource.init();
assertThat(dataSource.getUrl(), is("jdbc:h2:mem:foo_ds"));
assertThat(dataSource.getUsername(), is("root"));
assertThat(dataSource.getPassword(), is("root"));
dataSource.close();
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<mariadb-java-client.version>2.4.2</mariadb-java-client.version>

<hikari-cp.version>4.0.3</hikari-cp.version>
<druid.version>1.2.22</druid.version>

<prometheus-simpleclient.version>0.11.0</prometheus-simpleclient.version>
<prometheus-jmx.version>0.16.1</prometheus-jmx.version>
Expand Down

0 comments on commit f738e92

Please sign in to comment.