How to use getViburDataSource method of org.testcontainers.jdbc.mysql.JDBCDriverWithPoolTest class

Best Testcontainers-java code snippet using org.testcontainers.jdbc.mysql.JDBCDriverWithPoolTest.getViburDataSource

Source:JDBCDriverWithPoolTest.java Github

copy

Full Screen

...34 JDBCDriverWithPoolTest::getTomcatDataSourceWithDriverClassName,35 JDBCDriverWithPoolTest::getTomcatDataSource,36 JDBCDriverWithPoolTest::getHikariDataSourceWithDriverClassName,37 JDBCDriverWithPoolTest::getHikariDataSource,38 JDBCDriverWithPoolTest::getViburDataSourceWithDriverClassName,39 JDBCDriverWithPoolTest::getViburDataSource40 );41 }42 public JDBCDriverWithPoolTest(Supplier<DataSource> dataSourceSupplier) {43 this.dataSource = dataSourceSupplier.get();44 }45 private ExecutorService executorService = Executors.newFixedThreadPool(5);46 @Test47 public void testMySQLWithConnectionPoolUsingSameContainer() throws SQLException, InterruptedException {48 // Populate the database with some data in multiple threads, so that multiple connections from the pool will be used49 for (int i = 0; i < 100; i++) {50 executorService.submit(() -> {51 try {52 new QueryRunner(dataSource).insert("INSERT INTO my_counter (n) VALUES (5)",53 (ResultSetHandler<Object>) rs -> true);54 } catch (SQLException e) {55 e.printStackTrace();56 }57 });58 }59 // Complete population of the database60 executorService.shutdown();61 executorService.awaitTermination(5, TimeUnit.MINUTES);62 // compare to expected results63 int count = new QueryRunner(dataSource).query("SELECT COUNT(1) FROM my_counter", rs -> {64 rs.next();65 return rs.getInt(1);66 });67 assertEquals("Reuse of a datasource points to the same DB container", 100, count);68 int sum = new QueryRunner(dataSource).query("SELECT SUM(n) FROM my_counter", rs -> {69 rs.next();70 return rs.getInt(1);71 });72 // 100 records * 5 = 500 expected73 assertEquals("Reuse of a datasource points to the same DB container", 500, sum);74 }75 private static DataSource getTomcatDataSourceWithDriverClassName() {76 PoolProperties poolProperties = new PoolProperties();77 poolProperties.setUrl(URL + ";TEST=TOMCAT_WITH_CLASSNAME"); // append a dummy URL element to ensure different DB per test78 poolProperties.setValidationQuery("SELECT 1");79 poolProperties.setMinIdle(3);80 poolProperties.setMaxActive(10);81 poolProperties.setDriverClassName(ContainerDatabaseDriver.class.getName());82 return new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);83 }84 private static DataSource getTomcatDataSource() {85 PoolProperties poolProperties = new PoolProperties();86 poolProperties.setUrl(URL + ";TEST=TOMCAT"); // append a dummy URL element to ensure different DB per test87 poolProperties.setValidationQuery("SELECT 1");88 poolProperties.setInitialSize(3);89 poolProperties.setMaxActive(10);90 return new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);91 }92 private static HikariDataSource getHikariDataSourceWithDriverClassName() {93 HikariConfig hikariConfig = new HikariConfig();94 hikariConfig.setJdbcUrl(URL + ";TEST=HIKARI_WITH_CLASSNAME"); // append a dummy URL element to ensure different DB per test95 hikariConfig.setConnectionTestQuery("SELECT 1");96 hikariConfig.setMinimumIdle(3);97 hikariConfig.setMaximumPoolSize(10);98 hikariConfig.setDriverClassName(ContainerDatabaseDriver.class.getName());99 return new HikariDataSource(hikariConfig);100 }101 private static HikariDataSource getHikariDataSource() {102 HikariConfig hikariConfig = new HikariConfig();103 hikariConfig.setJdbcUrl(URL + ";TEST=HIKARI"); // append a dummy URL element to ensure different DB per test104 hikariConfig.setConnectionTestQuery("SELECT 1");105 hikariConfig.setMinimumIdle(3);106 hikariConfig.setMaximumPoolSize(10);107 return new HikariDataSource(hikariConfig);108 }109 private static DataSource getViburDataSourceWithDriverClassName() {110 ViburDBCPDataSource ds = new ViburDBCPDataSource();111 ds.setJdbcUrl(URL + ";TEST=VIBUR_WITH_CLASSNAME");112 ds.setUsername("any"); // Recent versions of Vibur require a username, even though it will not be used113 ds.setPassword("");114 ds.setPoolInitialSize(3);115 ds.setPoolMaxSize(10);116 ds.setTestConnectionQuery("SELECT 1");117 ds.setDriverClassName(ContainerDatabaseDriver.class.getName());118 ds.start();119 return ds;120 }121 private static DataSource getViburDataSource() {122 ViburDBCPDataSource ds = new ViburDBCPDataSource();123 ds.setJdbcUrl(URL + ";TEST=VIBUR");124 ds.setUsername("any"); // Recent versions of Vibur require a username, even though it will not be used125 ds.setPassword("");126 ds.setPoolInitialSize(3);127 ds.setPoolMaxSize(10);128 ds.setTestConnectionQuery("SELECT 1");129 ds.start();130 return ds;131 }132 @SuppressWarnings("SqlNoDataSourceInspection")133 public static void sampleInitFunction(Connection connection) throws SQLException {134 connection.createStatement().execute("CREATE TABLE bar (\n" +135 " foo VARCHAR(255)\n" +...

Full Screen

Full Screen

getViburDataSource

Using AI Code Generation

copy

Full Screen

1JDBCDriverWithPoolTest.getViburDataSource();2JDBCDriverWithPoolTest.getHikariDataSource();3JDBCDriverWithPoolTest.getTomcatDataSource();4JDBCDriverWithPoolTest.getBoneCPDataSource();5JDBCDriverWithPoolTest.getDbcp2DataSource();6JDBCDriverWithPoolTest.getDbcpDataSource();7JDBCDriverWithPoolTest.getProxoolDataSource();8JDBCDriverWithPoolTest.getDruidDataSource();9JDBCDriverWithPoolTest.getDbcpPoolingDataSource();10package org.testcontainers.jdbc.mysql;11import com.zaxxer.hikari.HikariConfig;12import com.zaxxer.hikari.HikariDataSource;13import com.zaxxer.hikari.pool.HikariPool;14import com.zaxxer.hikari.pool.HikariProxyConnection;15import com.zaxxer.hikari.util.PropertyElf;16import org.apache.commons.dbcp2.BasicDataSource;17import org.apache.commons.dbcp2.BasicDataSourceFactory;18import org.apache.commons.dbcp2.PoolableConnection;19import org.apache.commons.dbcp2.PoolingDataSource;20import org.apache.commons.dbcp2.managed.BasicManagedDataSource;21import org.apache.commons.dbcp2.managed.BasicManagedDataSourceMXBean;22import org.apache.commons.dbcp2.managed.BasicManagedPooledConnection;23import org.apache.commons.dbcp2.managed.BasicManagedPooledConnectionManager;24import org.apache.commons

Full Screen

Full Screen

getViburDataSource

Using AI Code Generation

copy

Full Screen

1public void testGetViburDataSource()2public void testGetViburDataSourceWithPoolSize()3public void testGetViburDataSourceWithPoolSizeAndConnectionTimeout()4public void testGetViburDataSourceWithPoolSizeAndConnectionTimeoutAndValidationTimeout()5public void testGetViburDataSourceWithPoolSizeAndConnectionTimeoutAndValidationTimeoutAndCachePrepStmts()6public void testGetViburDataSourceWithPoolSizeAndConnectionTimeoutAndValidationTimeoutAndCachePrepStmtsAndPrepStmtCacheSize()7public void testGetViburDataSourceWithPoolSizeAndConnectionTimeoutAndValidationTimeoutAndCachePrepStmtsAndPrepStmtCacheSizeAndPrepStmtCacheSqlLimit()8public void testGetViburDataSourceWithPoolSizeAndConnectionTimeoutAndValidationTimeoutAndCachePrepStmtsAndPrepStmtCacheSizeAndPrepStmtCacheSqlLimitAndUseServerPrepStmts()9public void testGetViburDataSourceWithPoolSizeAndConnectionTimeoutAndValidationTimeoutAndCachePrepStmtsAndPrepStmtCacheSizeAndPrepStmtCacheSqlLimitAndUseServerPrepStmtsAndUseLocalSessionState()

Full Screen

Full Screen

getViburDataSource

Using AI Code Generation

copy

Full Screen

1import org.vibur.dbcp.ViburDBCPDataSource;2import java.sql.Connection;3import java.sql.ResultSet;4import java.sql.SQLException;5import java.sql.Statement;6public class Test {7 public static void main(String[] args) throws SQLException {8 ViburDBCPDataSource ds = JDBCDriverWithPoolTest.getViburDataSource();9 Connection con = ds.getConnection();10 Statement stmt = con.createStatement();11 ResultSet rs = stmt.executeQuery("select * from test");12 while (rs.next()) {13 System.out.println(rs.getString(1));14 }15 }16}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful