Skip to content

Commit

Permalink
Merge pull request #1253 from amergey/main
Browse files Browse the repository at this point in the history
unit test refactoring (ease support of test container)
  • Loading branch information
jhouserizer authored Nov 6, 2024
2 parents 08fb8ff + d519029 commit 94c890f
Show file tree
Hide file tree
Showing 27 changed files with 258 additions and 233 deletions.
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ commonjVersion = 1.0

junitVersion = 4.13.2
junitPlatformVersion = 5.11.3
#derbyVersion = 10.15.2.0
derbyVersion = 10.8.2.2
derbyVersion = 10.15.2.0

# For nexus-publish plugin
sonatypeUsername = OVERRIDE_ME
Expand Down
1 change: 0 additions & 1 deletion quartz/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dependencies {
testImplementation(platform("org.junit:junit-bom:5.11.3"))
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'org.mockito:mockito-core:5.14.2'
testImplementation 'org.testcontainers:mssqlserver:1.20.3'
testImplementation 'com.microsoft.sqlserver:mssql-jdbc:12.8.1.jre11'
Expand Down
7 changes: 4 additions & 3 deletions quartz/src/test/java/org/quartz/FlakyJdbcSchedulerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.quartz.impl.SchedulerRepository;
import org.quartz.impl.jdbcjobstore.JdbcQuartzTestUtilities;
import org.quartz.impl.jdbcjobstore.JobStoreTX;
import org.quartz.impl.jdbcjobstore.JdbcQuartzTestUtilities.DatabaseType;
import org.quartz.simpl.SimpleThreadPool;
import org.quartz.utils.ConnectionProvider;
import org.quartz.utils.DBConnectionManager;
Expand Down Expand Up @@ -156,7 +157,7 @@ private class FlakyConnectionProvider implements ConnectionProvider {
private FlakyConnectionProvider(String name) throws SQLException {
this.delegateName = "delegate_" + name;
this.safeThread = Thread.currentThread();
JdbcQuartzTestUtilities.createDatabase(delegateName);
JdbcQuartzTestUtilities.createDatabase(delegateName, DatabaseType.DERBY);
}

@Override
Expand All @@ -176,8 +177,8 @@ public Connection getConnection() throws SQLException {
@Override
public void shutdown() throws SQLException {
DBConnectionManager.getInstance().shutdown(delegateName);
JdbcQuartzTestUtilities.destroyDatabase(delegateName);
JdbcQuartzTestUtilities.shutdownDatabase();
JdbcQuartzTestUtilities.destroyDatabase(delegateName, DatabaseType.DERBY);
JdbcQuartzTestUtilities.shutdownDatabase(delegateName, DatabaseType.DERBY);
}

@Override
Expand Down
9 changes: 7 additions & 2 deletions quartz/src/test/java/org/quartz/JdbcSchedulerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@
import org.quartz.impl.SchedulerRepository;
import org.quartz.impl.jdbcjobstore.JdbcQuartzTestUtilities;
import org.quartz.impl.jdbcjobstore.JobStoreTX;
import org.quartz.impl.jdbcjobstore.JdbcQuartzTestUtilities.DatabaseType;
import org.quartz.simpl.SimpleThreadPool;

public class JdbcSchedulerTest extends AbstractSchedulerTest {

protected DatabaseType getDatabaseType() {
return DatabaseType.DERBY;
}

@Override
protected Scheduler createScheduler(String name, int threadPoolSize) throws SchedulerException {
try {
JdbcQuartzTestUtilities.createDatabase(name + "Database");
JdbcQuartzTestUtilities.createDatabase(name + getDatabaseType().name(), getDatabaseType());
} catch (SQLException e) {
throw new AssertionError(e);
}
JobStoreTX jobStore = new JobStoreTX();
jobStore.setDataSource(name + "Database");
jobStore.setDataSource(name + getDatabaseType().name());
jobStore.setTablePrefix("QRTZ_");
jobStore.setInstanceId("AUTO");
DirectSchedulerFactory.getInstance().createScheduler(name + "Scheduler", "AUTO", new SimpleThreadPool(threadPoolSize, Thread.NORM_PRIORITY), jobStore);
Expand Down
5 changes: 3 additions & 2 deletions quartz/src/test/java/org/quartz/core/QTZ385Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.quartz.impl.DirectSchedulerFactory;
import org.quartz.impl.jdbcjobstore.JdbcQuartzTestUtilities;
import org.quartz.impl.jdbcjobstore.JobStoreTX;
import org.quartz.impl.jdbcjobstore.JdbcQuartzTestUtilities.DatabaseType;
import org.quartz.integrations.tests.HelloJob;
import org.quartz.listeners.JobListenerSupport;
import org.quartz.simpl.SimpleThreadPool;
Expand All @@ -61,7 +62,7 @@ class QTZ385Test {

@Test
void testShutdownOrdering() throws SchedulerException, SQLException, InterruptedException, BrokenBarrierException {
JdbcQuartzTestUtilities.createDatabase("testShutdownOrdering");
JdbcQuartzTestUtilities.createDatabase("testShutdownOrdering", DatabaseType.DERBY);
try {
final CyclicBarrier barrier = new CyclicBarrier(2);
final JobStoreTX realJobStore = new JobStoreTX();
Expand Down Expand Up @@ -131,7 +132,7 @@ public void jobToBeExecuted(JobExecutionContext context) {
recovery.shutdown(true);
}
} finally {
JdbcQuartzTestUtilities.destroyDatabase("testShutdownOrdering");
JdbcQuartzTestUtilities.destroyDatabase("testShutdownOrdering", DatabaseType.DERBY);
}
}

Expand Down
6 changes: 3 additions & 3 deletions quartz/src/test/java/org/quartz/core/RecoverJobsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.quartz.impl.DirectSchedulerFactory;
import org.quartz.impl.jdbcjobstore.JdbcQuartzTestUtilities;
import org.quartz.impl.jdbcjobstore.JobStoreTX;

import org.quartz.impl.jdbcjobstore.JdbcQuartzTestUtilities.DatabaseType;
import org.quartz.*;
import org.quartz.listeners.JobListenerSupport;
import org.quartz.simpl.SimpleThreadPool;
Expand All @@ -46,7 +46,7 @@ public class RecoverJobsTest {
@Test
void testRecoveringRepeatJobWhichIsFiredAndMisfiredAtTheSameTime() throws SchedulerException, SQLException, InterruptedException {
String dsName = "recoverJobsTest";
JdbcQuartzTestUtilities.createDatabase(dsName);
JdbcQuartzTestUtilities.createDatabase(dsName, DatabaseType.DERBY);
try {
final JobStoreTX jobStore = new JobStoreTX();
jobStore.setDataSource(dsName);
Expand Down Expand Up @@ -130,7 +130,7 @@ public void jobToBeExecuted(JobExecutionContext context) {

assertTrue(isJobRecovered.get());
} finally {
JdbcQuartzTestUtilities.destroyDatabase(dsName);
JdbcQuartzTestUtilities.destroyDatabase(dsName, DatabaseType.DERBY);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
*/
package org.quartz.impl.jdbcjobstore;


import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.quartz.*;
import org.quartz.impl.DirectSchedulerFactory;
import org.quartz.impl.SchedulerRepository;
import org.quartz.impl.jdbcjobstore.JdbcQuartzTestUtilities.DatabaseType;
import org.quartz.simpl.SimpleThreadPool;
import org.quartz.utils.DBConnectionManager;
import org.slf4j.Logger;
Expand All @@ -45,7 +45,7 @@ public class DeleteNonExistsJobTest {

@BeforeAll
public static void beforeClass() throws Exception {
JdbcQuartzTestUtilities.createDatabase(DB_NAME);
JdbcQuartzTestUtilities.createDatabase(DB_NAME, DatabaseType.DERBY);
}

@BeforeEach
Expand All @@ -55,9 +55,10 @@ public void beforeTest() throws Exception {
jobStore.setDataSource(DB_NAME);
jobStore.setTablePrefix("QRTZ_");
jobStore.setInstanceId("AUTO");
DirectSchedulerFactory.getInstance().createScheduler(SCHEDULER_NAME, "AUTO", new SimpleThreadPool(4, Thread.NORM_PRIORITY), jobStore);
DirectSchedulerFactory.getInstance().createScheduler(SCHEDULER_NAME, "AUTO",
new SimpleThreadPool(4, Thread.NORM_PRIORITY), jobStore);
scheduler = SchedulerRepository.getInstance().lookup(SCHEDULER_NAME);
//scheduler.start(); // Do not start scheduler to produce the defect case.
// scheduler.start(); // Do not start scheduler to produce the defect case.
}

private void resetDatabaseData() throws Exception {
Expand Down Expand Up @@ -97,8 +98,7 @@ void deleteJobDetailOnly() throws Exception {
void deleteJobDetailWithTrigger() throws Exception {
JobDetail jobDetail = JobBuilder.newJob(TestJob.class).withIdentity("testjob2").storeDurably().build();
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("testjob2")
.withSchedule(CronScheduleBuilder.cronSchedule("* * * * * ?"))
.build();
.withSchedule(CronScheduleBuilder.cronSchedule("* * * * * ?")).build();
scheduler.scheduleJob(jobDetail, trigger);
modifyStoredJobClassName();

Expand All @@ -109,8 +109,7 @@ void deleteJobDetailWithTrigger() throws Exception {
void deleteTrigger() throws Exception {
JobDetail jobDetail = JobBuilder.newJob(TestJob.class).withIdentity("testjob3").storeDurably().build();
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("testjob3")
.withSchedule(CronScheduleBuilder.cronSchedule("* * * * * ?"))
.build();
.withSchedule(CronScheduleBuilder.cronSchedule("* * * * * ?")).build();
scheduler.scheduleJob(jobDetail, trigger);
modifyStoredJobClassName();

Expand All @@ -121,8 +120,7 @@ void deleteTrigger() throws Exception {
void replaceJobDetail() throws Exception {
JobDetail jobDetail = JobBuilder.newJob(TestJob.class).withIdentity("testjob3").storeDurably().build();
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("testjob3")
.withSchedule(CronScheduleBuilder.cronSchedule("* * * * * ?"))
.build();
.withSchedule(CronScheduleBuilder.cronSchedule("* * * * * ?")).build();
scheduler.scheduleJob(jobDetail, trigger);
modifyStoredJobClassName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,50 @@
import java.util.HashMap;

import org.quartz.AbstractJobStoreTest;
import org.quartz.impl.jdbcjobstore.JdbcQuartzTestUtilities.DatabaseType;
import org.quartz.spi.JobStore;

public class JdbcJobStoreTest extends AbstractJobStoreTest {

private HashMap<String, JobStoreSupport> stores = new HashMap<String, JobStoreSupport>();

void testNothing() {
// nothing
private HashMap<String, JobStoreSupport> stores = new HashMap<String, JobStoreSupport>();

protected DatabaseType getDatabaseType() {
return DatabaseType.DERBY;
}

private String name(String prefix) {
return prefix + "_" + getDatabaseType().name();
}

@Override
protected JobStore createJobStore(String name) {
protected JobStore createJobStore(String prefix) {
String name = name(prefix);
try {
JdbcQuartzTestUtilities.createDatabase(name);
JdbcQuartzTestUtilities.createDatabase(name, getDatabaseType());
JobStoreTX jdbcJobStore = new JobStoreTX();
jdbcJobStore.setDataSource(name);
jdbcJobStore.setTablePrefix("QRTZ_");
jdbcJobStore.setInstanceId("SINGLE_NODE_TEST");
jdbcJobStore.setInstanceId("SINGLE_NODE_TEST_" + getDatabaseType().name());
jdbcJobStore.setInstanceName(name);
jdbcJobStore.setUseDBLocks(true);
jdbcJobStore.setDriverDelegateClass(getDatabaseType().getDelegateClassName());

stores.put(name, jdbcJobStore);

return jdbcJobStore;
} catch (SQLException e) {
} catch (Exception e) {
throw new AssertionError(e);
}
}

@Override
protected void destroyJobStore(String name) {
protected void destroyJobStore(String prefix) {
String name = name(prefix);
try {
JobStoreSupport jdbcJobStore = stores.remove(name);
jdbcJobStore.shutdown();
JdbcQuartzTestUtilities.destroyDatabase(name);
JobStoreSupport jdbcJobStore = stores.remove(name);
jdbcJobStore.shutdown();

JdbcQuartzTestUtilities.destroyDatabase(name, getDatabaseType());
} catch (SQLException e) {
throw new AssertionError(e);
}
Expand Down

This file was deleted.

Loading

0 comments on commit 94c890f

Please sign in to comment.