Skip to content

Commit

Permalink
refactor: Moved tests and benchmarks to jdbc project
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Ruaux committed Feb 15, 2023
1 parent 47756db commit 40ebfd7
Show file tree
Hide file tree
Showing 29 changed files with 90 additions and 81 deletions.
29 changes: 27 additions & 2 deletions core/redis-smart-cache-jdbc/redis-smart-cache-jdbc.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dependencies {
dependencies {
implementation group: 'com.redis', name: 'lettucemod', version: lettucemodVersion
implementation 'org.apache.commons:commons-pool2'
implementation 'com.fasterxml.jackson.core:jackson-databind'
Expand All @@ -7,8 +7,20 @@
implementation group: 'com.redis', name: 'micrometer-registry-redistimeseries', version: micrometerRtsVersion
implementation group: 'io.trino', name: 'trino-parser', version: trinoVersion
implementation group: 'io.airlift', name: 'units', version: airliftVersion
testImplementation project(':redis-smart-cache-test')
testImplementation 'org.slf4j:slf4j-simple'
testImplementation 'org.postgresql:postgresql'
testImplementation 'com.oracle.database.jdbc:ojdbc8'
testImplementation 'com.mysql:mysql-connector-j'
testImplementation group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: mssqlVersion
testImplementation group: 'com.ibm.db2', name: 'jcc', version: db2Version
testImplementation group: 'com.redis.testcontainers', name: 'testcontainers-redis-junit', version: testcontainersRedisVersion
testImplementation group: 'org.testcontainers', name: 'postgresql', version: testcontainersVersion
testImplementation group: 'org.testcontainers', name: 'oracle-xe', version: testcontainersVersion
testImplementation group: 'org.testcontainers', name: 'mssqlserver', version: testcontainersVersion
testImplementation group: 'org.testcontainers', name: 'db2', version: testcontainersVersion
testImplementation group: 'org.testcontainers', name: 'mysql', version: testcontainersVersion
testImplementation group: 'org.awaitility', name: 'awaitility', version: awaitilityVersion
}

bootJar {
Expand All @@ -32,4 +44,17 @@ task relocateShadowJar(type: ConfigureShadowRelocation) {
prefix = "com.redis.smartcache.shaded"
}

tasks.shadowJar.dependsOn tasks.relocateShadowJar
tasks.shadowJar.dependsOn tasks.relocateShadowJar

jmh {
fork = 1
iterations = 1
timeUnit = 'ms'
warmup = '1s'
warmupForks = 0
warmupIterations = 0
}

jmhJar {
exclude('org/slf4j/impl/**')
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static synchronized java.sql.Driver getBackendDriver(String className) th
try {
driver = (java.sql.Driver) Class.forName(className).getConstructor().newInstance();
} catch (Exception e) {
throw new SQLException("Could not load driver class '" + className + "'", e);
throw new SQLException("Could not load backend driver class '" + className + "'", e);
}
drivers.put(className, driver);
return driver;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.redis.smartcache;

import java.io.IOException;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
Expand All @@ -9,10 +10,10 @@
import java.util.Properties;

import org.awaitility.Awaitility;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;

import com.redis.smartcache.core.Config;
import com.redis.smartcache.core.Config.RulesetConfig;
import com.redis.smartcache.core.ConfigManager;
import com.redis.testcontainers.RedisServer;
Expand All @@ -33,19 +34,28 @@ protected Collection<RedisServer> redisServers() {

@ParameterizedTest
@RedisTestContextsSource
void testDriver(RedisTestContext redis) throws SQLException, ClassNotFoundException {
void testDriver(RedisTestContext redis) throws SQLException, ClassNotFoundException, IOException {
Class.forName(Driver.class.getName());
java.sql.Driver driver = DriverManager.getDriver("jdbc:" + redis.getRedisURI());
Assert.assertNotNull(driver);
Assert.assertTrue(driver.getMajorVersion() >= 0);
Assert.assertTrue(driver.getMinorVersion() >= 0);
Assert.assertNotNull(driver.getParentLogger());
Assert.assertFalse(driver.jdbcCompliant());
Assertions.assertNotNull(driver);
Assertions.assertTrue(driver.getMajorVersion() >= 0);
Assertions.assertTrue(driver.getMinorVersion() >= 0);
Assertions.assertNotNull(driver.getParentLogger());
Assertions.assertFalse(driver.jdbcCompliant());
DriverPropertyInfo[] infos = driver.getPropertyInfo(null, new Properties());
Assert.assertNotNull(infos);
Assert.assertEquals(2, infos.length);
Assert.assertEquals(Driver.PROPERTY_PREFIX_DRIVER + ".url", infos[0].name);
Assert.assertEquals(Driver.PROPERTY_PREFIX_DRIVER + ".class-name", infos[1].name);
Assertions.assertNotNull(infos);
Assertions.assertEquals(2, infos.length);
Assertions.assertEquals(Driver.PROPERTY_PREFIX_DRIVER + ".url", infos[0].name);
Assertions.assertEquals(Driver.PROPERTY_PREFIX_DRIVER + ".class-name", infos[1].name);
String jdbcUrl = "jdbc:" + redis.getRedisURI();
Assertions.assertTrue(driver.acceptsURL(jdbcUrl));
Assertions.assertThrows(SQLException.class, () -> driver.connect(null, null));
Assertions.assertNull(driver.connect("jdbc:asdf:", null));
Assertions.assertNull(driver.connect("jdbc:redis:", null));
Config config = new Config();
config.getDriver().setUrl("jdbc:asdf://sdfsdf");
config.getDriver().setClassName("com.asdfasdf.sdfsdfkds.Issks");
Assertions.assertThrows(SQLException.class, () -> driver.connect(jdbcUrl, Driver.properties(config)));
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redis.smartcache;
package com.redis.smartcache.jdbc;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -19,12 +19,13 @@
import java.util.logging.Logger;

import org.awaitility.Awaitility;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.testcontainers.containers.JdbcDatabaseContainer;

import com.redis.smartcache.Driver;
import com.redis.smartcache.TestUtils;
import com.redis.smartcache.core.Config;
import com.redis.smartcache.jdbc.SmartConnection;
import com.redis.testcontainers.RedisServer;
import com.redis.testcontainers.RedisStackContainer;
import com.redis.testcontainers.junit.AbstractTestcontainersRedisTestBase;
Expand Down Expand Up @@ -164,20 +165,20 @@ protected void testResultSetMetaData(JdbcDatabaseContainer<?> databaseContainer,
Statement statement = connection.createStatement();
statement.execute(sql);
ResultSet resultSet = statement.getResultSet();
Assert.assertNotNull(resultSet);
Assertions.assertNotNull(resultSet);
final ResultSetMetaData metaData = resultSet.getMetaData();
Assert.assertNotNull(metaData);
Assertions.assertNotNull(metaData);
int colCount = metaData.getColumnCount();
Assert.assertTrue(colCount > 0);
Assertions.assertTrue(colCount > 0);
for (int i = 1; i <= colCount; i++) {
Assert.assertNotNull(metaData.getColumnName(i));
Assert.assertNotNull(metaData.getColumnLabel(i));
Assert.assertNotNull(metaData.getColumnTypeName(i));
Assert.assertNotNull(metaData.getCatalogName(i));
Assert.assertNotNull(metaData.getColumnClassName(i));
Assert.assertTrue(metaData.getColumnDisplaySize(i) > 0);
Assert.assertNotNull(metaData.getSchemaName(i));
Assert.assertNotNull(metaData.getTableName(i));
Assertions.assertNotNull(metaData.getColumnName(i));
Assertions.assertNotNull(metaData.getColumnLabel(i));
Assertions.assertNotNull(metaData.getColumnTypeName(i));
Assertions.assertNotNull(metaData.getCatalogName(i));
Assertions.assertNotNull(metaData.getColumnClassName(i));
Assertions.assertTrue(metaData.getColumnDisplaySize(i) > 0);
Assertions.assertNotNull(metaData.getSchemaName(i));
Assertions.assertNotNull(metaData.getTableName(i));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redis.smartcache;
package com.redis.smartcache.jdbc;

import java.io.IOException;
import java.sql.Connection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redis.smartcache;
package com.redis.smartcache.jdbc;

import java.io.IOException;
import java.sql.Connection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redis.smartcache;
package com.redis.smartcache.jdbc;

import java.io.IOException;
import java.sql.Connection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redis.smartcache;
package com.redis.smartcache.jdbc;

import java.io.IOException;
import java.math.BigDecimal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.redis.smartcache;
package com.redis.smartcache.jdbc;

import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.List;
import java.util.Properties;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -16,6 +18,7 @@
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.utility.DockerImageName;

import com.redis.smartcache.Driver;
import com.redis.smartcache.core.Config;
import com.redis.testcontainers.junit.RedisTestContext;
import com.redis.testcontainers.junit.RedisTestContextsSource;
Expand Down Expand Up @@ -118,4 +121,18 @@ void testResultSetMetadata(RedisTestContext redis) throws Exception {
testResultSetMetaData(POSTGRESQL, redis, "SELECT * FROM orders");
}

@ParameterizedTest
@RedisTestContextsSource
void testConnect(RedisTestContext redis) throws SQLException, IOException {
Config config = new Config();
config.getDriver().setClassName(POSTGRESQL.getDriverClassName());
config.getDriver().setUrl(POSTGRESQL.getJdbcUrl());
Properties info = Driver.properties(config);
info.setProperty("user", POSTGRESQL.getUsername());
info.setProperty("password", POSTGRESQL.getPassword());
java.sql.Driver driver = DriverManager.getDriver("jdbc:" + redis.getRedisURI());
Connection connection = driver.connect("jdbc:" + redis.getRedisURI(), info);
Assertions.assertInstanceOf(SmartConnection.class, connection);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redis.smartcache;
package com.redis.smartcache.jdbc;

import java.io.IOException;
import java.io.LineNumberReader;
Expand Down
43 changes: 1 addition & 42 deletions core/redis-smart-cache-test/redis-smart-cache-test.gradle
Original file line number Diff line number Diff line change
@@ -1,48 +1,7 @@
dependencies {
implementation project(':redis-smart-cache-jdbc')
testImplementation 'commons-codec:commons-codec'
testImplementation 'org.slf4j:slf4j-simple'
testImplementation 'org.postgresql:postgresql'
testImplementation 'com.oracle.database.jdbc:ojdbc8'
testImplementation 'com.mysql:mysql-connector-j'
testImplementation 'com.fasterxml.jackson.core:jackson-databind'
testImplementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-properties'
testImplementation 'com.zaxxer:HikariCP'
testImplementation group: 'io.trino', name: 'trino-parser', version: trinoVersion
testImplementation group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: mssqlVersion
testImplementation group: 'com.ibm.db2', name: 'jcc', version: db2Version
testImplementation group: 'com.redis.testcontainers', name: 'testcontainers-redis-junit', version: testcontainersRedisVersion
testImplementation group: 'org.testcontainers', name: 'postgresql', version: testcontainersVersion
testImplementation group: 'org.testcontainers', name: 'oracle-xe', version: testcontainersVersion
testImplementation group: 'org.testcontainers', name: 'mssqlserver', version: testcontainersVersion
testImplementation group: 'org.testcontainers', name: 'db2', version: testcontainersVersion
testImplementation group: 'org.testcontainers', name: 'mysql', version: testcontainersVersion
testImplementation group: 'org.awaitility', name: 'awaitility', version: awaitilityVersion
}

bootJar {
enabled = false
}

jar {
enabled = true
archiveClassifier = ''
}

jmh {
fork = 1
iterations = 1
timeUnit = 'ms'
warmup = '1s'
warmupForks = 0
warmupIterations = 0
}

jmhJar {
exclude('org/slf4j/impl/**')
}

tasks.bootJar.dependsOn ':redis-smart-cache-jdbc:shadowJar'
tasks.bootJarMainClassName.dependsOn ':redis-smart-cache-jdbc:shadowJar'
tasks.test.dependsOn ':redis-smart-cache-jdbc:shadowJar'
tasks.jmhRunBytecodeGenerator.dependsOn ':redis-smart-cache-jdbc:shadowJar'
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.RowSetFactory;
import javax.sql.rowset.RowSetMetaDataImpl;

import com.redis.smartcache.core.rowset.CachedRowSetFactory;
import javax.sql.rowset.RowSetProvider;

public class RowSetBuilder {

Expand All @@ -40,7 +39,7 @@ public class RowSetBuilder {
private final RowSetFactory rowSetFactory;

public RowSetBuilder() throws SQLException {
this(new CachedRowSetFactory());
this(RowSetProvider.newFactory());
}

public RowSetBuilder(RowSetFactory rowSetFactory) {
Expand Down
2 changes: 0 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ projects {
}
path(':redis-smart-cache-jdbc') {
id 'com.github.johnrengelman.shadow'
}
path(':redis-smart-cache-test') {
id 'me.champeau.jmh'
}
}
Expand Down

0 comments on commit 40ebfd7

Please sign in to comment.