Skip to content

Commit

Permalink
Return PersistJobDataAfterExecution flag in SelectJobDetail (#2014)
Browse files Browse the repository at this point in the history
Co-authored-by: Marko Lahma <marko.lahma@gmail.com>
  • Loading branch information
wuuer and lahma authored Jun 25, 2023
1 parent 6233af7 commit 97e045c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/Quartz.Tests.Integration/Core/RecoverJobsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ await scheduler.ScheduleJob(
// check that trigger is blocked after fail over situation
Assert.AreEqual("BLOCKED", triggerState);

command.CommandText = "SELECT count(*) from QRTZ_FIRED_TRIGGERS";
command.CommandText = $"SELECT count(*) from QRTZ_FIRED_TRIGGERS WHERE SCHED_NAME = '{scheduler.SchedulerName}' AND TRIGGER_NAME='test'";
int count = Convert.ToInt32(command.ExecuteScalar());

// check that fired trigger remains after fail over situation
Expand Down
2 changes: 1 addition & 1 deletion src/Quartz.Tests.Unit/CronExpressionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void CronExpression_Throw_Error_Contructed_With_Null()
{
Action act = () => new CronExpression(null);
act.Should().Throw<ArgumentException>()
.WithMessage("cronExpression cannot be null (Parameter 'cronExpression')");
.WithMessage($"cronExpression cannot be null*");
}

[TestCase('h')]
Expand Down
5 changes: 4 additions & 1 deletion src/Quartz.Tests.Unit/Impl/AdoJobStore/StdAdoDelegateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ public async Task TestSelectJobDetail()
.Returns(true);
A.CallTo(() => dataReader[AdoConstants.ColumnIsNonConcurrent])
.Returns(true);
A.CallTo(() => dataReader[AdoConstants.ColumnIsUpdateData])
.Returns(true);

var command = A.Fake<StubCommand>();

Expand Down Expand Up @@ -312,7 +314,8 @@ public async Task TestSelectJobDetail()
+ "IS_DURABLE,"
+ "REQUESTS_RECOVERY,"
+ "JOB_DATA,"
+ "IS_NONCONCURRENT "
+ "IS_NONCONCURRENT,"
+ "IS_UPDATE_DATA "
+ "FROM QRTZ_JOB_DETAILS "
+ "WHERE SCHED_NAME = @schedulerName "
+ "AND JOB_NAME = @jobName "
Expand Down
13 changes: 7 additions & 6 deletions src/Quartz.Tests.Unit/SchedulerListenerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ public Task Execute(IJobExecutionContext context)

public class Qtz205TriggerListener : ITriggerListener
{
public int FireCount { get; private set; }
public int FireCount;

public string Name => "Qtz205TriggerListener";

public Task TriggerFired(ITrigger trigger, IJobExecutionContext context, CancellationToken cancellationToken)
{
FireCount++;
Interlocked.Increment(ref FireCount);
logger.Info("Trigger fired. count " + FireCount);
return Task.FromResult(true);
}

public Task<bool> VetoJobExecution(ITrigger trigger, IJobExecutionContext context, CancellationToken cancellationToken)
{
if (FireCount >= 3)
if (FireCount > 3)
{
return Task.FromResult(true);
}
Expand Down Expand Up @@ -196,14 +196,15 @@ public async Task TestTriggerFinalized()
.WithIdentity("test")
.WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForTotalCount(3))
.Build();

await scheduler.ScheduleJob(job, trigger);
await scheduler.Start();
await Task.Delay(5000);

await scheduler.Shutdown(true);

Assert.AreEqual(2, jobExecutionCount);

//RepeatSecondlyForTotalCount(3) means that the total Execution times is 3
Assert.AreEqual(3, jobExecutionCount);
Assert.AreEqual(3, triggerListener.FireCount);
Assert.AreEqual(1, schedulerListener.TriggerFinalizedCount);
}
Expand Down
33 changes: 17 additions & 16 deletions src/Quartz.Tests.Unit/Simpl/RAMJobStoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public void SetUp()
public async Task TestAcquireNextTrigger()
{
DateTimeOffset d = DateBuilder.EvenMinuteDateAfterNow();
IOperableTrigger trigger1 = new SimpleTriggerImpl("trigger1", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d.AddSeconds(200), d.AddSeconds(200), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger2 = new SimpleTriggerImpl("trigger2", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d.AddSeconds(50), d.AddSeconds(200), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger3 = new SimpleTriggerImpl("trigger1", "triggerGroup2", fJobDetail.Name, fJobDetail.Group, d.AddSeconds(100), d.AddSeconds(200), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger1 = new SimpleTriggerImpl("trigger1", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d.AddSeconds(200), d.AddSeconds(400), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger2 = new SimpleTriggerImpl("trigger2", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d.AddSeconds(50), d.AddSeconds(250), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger3 = new SimpleTriggerImpl("trigger1", "triggerGroup2", fJobDetail.Name, fJobDetail.Group, d.AddSeconds(100), d.AddSeconds(300), 2, TimeSpan.FromSeconds(2));

trigger1.ComputeFirstFireTimeUtc(null);
trigger2.ComputeFirstFireTimeUtc(null);
Expand All @@ -94,12 +94,12 @@ public async Task TestAcquireNextTriggerBatch()
{
DateTimeOffset d = DateTimeOffset.UtcNow.Subtract(TimeSpan.FromSeconds(1));

IOperableTrigger early = new SimpleTriggerImpl("early", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d, d.AddMilliseconds(5), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger1 = new SimpleTriggerImpl("trigger1", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d.AddMilliseconds(200000), d.AddMilliseconds(200005), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger2 = new SimpleTriggerImpl("trigger2", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d.AddMilliseconds(210000), d.AddMilliseconds(210005), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger3 = new SimpleTriggerImpl("trigger3", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d.AddMilliseconds(220000), d.AddMilliseconds(220005), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger4 = new SimpleTriggerImpl("trigger4", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d.AddMilliseconds(230000), d.AddMilliseconds(230005), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger10 = new SimpleTriggerImpl("trigger10", "triggerGroup2", fJobDetail.Name, fJobDetail.Group, d.AddMilliseconds(500000), d.AddMilliseconds(700000), 2, TimeSpan.FromSeconds(2));
IOperableTrigger early = new SimpleTriggerImpl("early", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d, d.AddMilliseconds(220000), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger1 = new SimpleTriggerImpl("trigger1", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d.AddMilliseconds(190000), d.AddMilliseconds(570000), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger2 = new SimpleTriggerImpl("trigger2", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d.AddMilliseconds(229000), d.AddMilliseconds(610050), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger3 = new SimpleTriggerImpl("trigger3", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d.AddMilliseconds(240000), d.AddMilliseconds(620050), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger4 = new SimpleTriggerImpl("trigger4", "triggerGroup1", fJobDetail.Name, fJobDetail.Group, d.AddMilliseconds(240000), d.AddMilliseconds(630050), 2, TimeSpan.FromSeconds(2));
IOperableTrigger trigger10 = new SimpleTriggerImpl("trigger10", "triggerGroup2", fJobDetail.Name, fJobDetail.Group, d.AddMilliseconds(5000000), d.AddMilliseconds(7000000), 2, TimeSpan.FromSeconds(2));

early.ComputeFirstFireTimeUtc(null);
early.MisfireInstruction = MisfireInstruction.IgnoreMisfirePolicy;
Expand All @@ -117,13 +117,14 @@ public async Task TestAcquireNextTriggerBatch()
await fJobStore.StoreTrigger(trigger10, false);

DateTimeOffset firstFireTime = trigger1.GetNextFireTimeUtc().Value;

DateTimeOffset firstFireTime2 = early.GetNextFireTimeUtc().Value;
List<IOperableTrigger> acquiredTriggers = (await fJobStore.AcquireNextTriggers(firstFireTime.AddSeconds(10), 4, TimeSpan.FromSeconds(1))).ToList();
Assert.AreEqual(1, acquiredTriggers.Count);
Assert.AreEqual(early.Key, acquiredTriggers[0].Key);
await fJobStore.ReleaseAcquiredTrigger(early);


acquiredTriggers = (await fJobStore.AcquireNextTriggers(firstFireTime.AddSeconds(10), 4, TimeSpan.FromMilliseconds(205000))).ToList();
acquiredTriggers = (await fJobStore.AcquireNextTriggers(firstFireTime.AddSeconds(10), 4, TimeSpan.FromMilliseconds(200000))).ToList();
Assert.AreEqual(2, acquiredTriggers.Count);
Assert.AreEqual(early.Key, acquiredTriggers[0].Key);
Assert.AreEqual(trigger1.Key, acquiredTriggers[1].Key);
Expand All @@ -132,7 +133,7 @@ public async Task TestAcquireNextTriggerBatch()

await fJobStore.RemoveTrigger(early.Key);

acquiredTriggers = (await fJobStore.AcquireNextTriggers(firstFireTime.AddSeconds(10), 5, TimeSpan.FromMilliseconds(100000))).ToList();
acquiredTriggers = (await fJobStore.AcquireNextTriggers(firstFireTime.AddSeconds(10), 5, TimeSpan.FromMilliseconds(300000))).ToList();
Assert.AreEqual(4, acquiredTriggers.Count);
Assert.AreEqual(trigger1.Key, acquiredTriggers[0].Key);
Assert.AreEqual(trigger2.Key, acquiredTriggers[1].Key);
Expand All @@ -143,7 +144,7 @@ public async Task TestAcquireNextTriggerBatch()
await fJobStore.ReleaseAcquiredTrigger(trigger3);
await fJobStore.ReleaseAcquiredTrigger(trigger4);

acquiredTriggers = (await fJobStore.AcquireNextTriggers(firstFireTime.AddSeconds(10), 6, TimeSpan.FromMilliseconds(100000))).ToList();
acquiredTriggers = (await fJobStore.AcquireNextTriggers(firstFireTime.AddSeconds(10), 6, TimeSpan.FromMilliseconds(300000))).ToList();

Assert.AreEqual(4, acquiredTriggers.Count);
Assert.AreEqual(trigger1.Key, acquiredTriggers[0].Key);
Expand All @@ -162,7 +163,7 @@ public async Task TestAcquireNextTriggerBatch()

await fJobStore.ReleaseAcquiredTrigger(trigger1);

acquiredTriggers = (await fJobStore.AcquireNextTriggers(firstFireTime.AddMilliseconds(250), 5, TimeSpan.FromMilliseconds(19999L))).ToList();
acquiredTriggers = (await fJobStore.AcquireNextTriggers(firstFireTime.AddMilliseconds(250), 5, TimeSpan.FromMilliseconds(40000))).ToList();
Assert.AreEqual(2, acquiredTriggers.Count);
Assert.AreEqual(trigger1.Key, acquiredTriggers[0].Key);
Assert.AreEqual(trigger2.Key, acquiredTriggers[1].Key);
Expand Down Expand Up @@ -366,7 +367,7 @@ public async Task TestAcquireTriggers()
// Test acquire one trigger at a time
for (int i = 0; i < 10; i++)
{
DateTimeOffset noLaterThan = startTime0.AddMinutes(i);
DateTimeOffset noLaterThan = startTime0.AddMinutes(i + 2);
int maxCount = 1;
TimeSpan timeWindow = TimeSpan.Zero;
var triggers = await store.AcquireNextTriggers(noLaterThan, maxCount, timeWindow);
Expand Down Expand Up @@ -429,7 +430,7 @@ public async Task TestResetErrorTrigger()
"triggerGroup1",
fJobDetail.Name,
fJobDetail.Group,
baseFireTimeDate.AddMilliseconds(200000),
baseFireTimeDate,
baseFireTimeDate.AddMilliseconds(200000),
2,
TimeSpan.FromMilliseconds(2000));
Expand Down
2 changes: 1 addition & 1 deletion src/Quartz/Impl/AdoJobStore/StdAdoConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public class StdAdoConstants : AdoConstants
$"SELECT * FROM {TablePrefixSubst}{TableFiredTriggers} WHERE {ColumnSchedulerName} = @schedulerName AND {ColumnInstanceName} = @instanceName AND {ColumnRequestsRecovery} = @requestsRecovery";

public static readonly string SqlSelectJobDetail =
$"SELECT {ColumnJobName},{ColumnJobGroup},{ColumnDescription},{ColumnJobClass},{ColumnIsDurable},{ColumnRequestsRecovery},{ColumnJobDataMap},{ColumnIsNonConcurrent} FROM {TablePrefixSubst}{TableJobDetails} WHERE {ColumnSchedulerName} = @schedulerName AND {ColumnJobName} = @jobName AND {ColumnJobGroup} = @jobGroup";
$"SELECT {ColumnJobName},{ColumnJobGroup},{ColumnDescription},{ColumnJobClass},{ColumnIsDurable},{ColumnRequestsRecovery},{ColumnJobDataMap},{ColumnIsNonConcurrent},{ColumnIsUpdateData} FROM {TablePrefixSubst}{TableJobDetails} WHERE {ColumnSchedulerName} = @schedulerName AND {ColumnJobName} = @jobName AND {ColumnJobGroup} = @jobGroup";

public static readonly string SqlSelectJobExecutionCount =
$"SELECT COUNT({ColumnTriggerName}) FROM {TablePrefixSubst}{TableFiredTriggers} WHERE {ColumnSchedulerName} = @schedulerName AND {ColumnJobName} = @jobName AND {ColumnJobGroup} = @jobGroup";
Expand Down
2 changes: 1 addition & 1 deletion src/Quartz/Impl/AdoJobStore/StdAdoDelegate.Jobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public virtual async Task<int> UpdateJobData(
requestsRecovery: GetBooleanFromDbValue(rs[ColumnRequestsRecovery]),
jobDataMap: jobDataMap,
disallowConcurrentExecution: GetBooleanFromDbValue(rs[ColumnIsNonConcurrent]),
persistJobDataAfterExecution: null);
persistJobDataAfterExecution: GetBooleanFromDbValue(rs[ColumnIsUpdateData]));
}

return job;
Expand Down

0 comments on commit 97e045c

Please sign in to comment.