Skip to content

Commit 818798e

Browse files
committed
Fix test race-condition
1 parent 1b03709 commit 818798e

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/helper/ExecutionCompletedCondition.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.github.kagkarlsson.scheduler.helper;
22

33
import com.github.kagkarlsson.scheduler.stats.StatsRegistry;
4+
import com.github.kagkarlsson.scheduler.task.ExecutionComplete;
5+
import com.github.kagkarlsson.scheduler.task.ExecutionComplete.Result;
46
import java.util.concurrent.CountDownLatch;
57
import org.slf4j.LoggerFactory;
68

@@ -32,10 +34,13 @@ public void apply(StatsRegistry.SchedulerStatsEvent e) {}
3234
public void apply(StatsRegistry.CandidateStatsEvent e) {}
3335

3436
@Override
35-
public void apply(StatsRegistry.ExecutionStatsEvent e) {
36-
if (e == StatsRegistry.ExecutionStatsEvent.COMPLETED) {
37+
public void apply(StatsRegistry.ExecutionStatsEvent e) {}
38+
39+
@Override
40+
public void applyExecutionComplete(ExecutionComplete complete) {
41+
if (complete.getResult() == Result.OK) {
3742
LoggerFactory.getLogger(ExecutionCompletedCondition.class)
38-
.debug("Received event execution-completed, counting down");
43+
.debug("Received event execution-completed, counting down");
3944
completed.countDown();
4045
}
4146
}

db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/helper/RanExecuteDueCondition.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.kagkarlsson.scheduler.helper;
22

33
import com.github.kagkarlsson.scheduler.stats.StatsRegistry;
4+
import com.github.kagkarlsson.scheduler.task.ExecutionComplete;
45
import java.util.concurrent.CountDownLatch;
56
import org.slf4j.LoggerFactory;
67

@@ -39,4 +40,7 @@ public void apply(StatsRegistry.CandidateStatsEvent e) {}
3940

4041
@Override
4142
public void apply(StatsRegistry.ExecutionStatsEvent e) {}
43+
44+
@Override
45+
public void applyExecutionComplete(ExecutionComplete complete) {}
4246
}

db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/helper/RanUpdateHeartbeatsCondition.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.kagkarlsson.scheduler.stats.StatsRegistry;
44
import com.github.kagkarlsson.scheduler.stats.StatsRegistry.SchedulerStatsEvent;
5+
import com.github.kagkarlsson.scheduler.task.ExecutionComplete;
56
import java.util.concurrent.CountDownLatch;
67
import org.slf4j.Logger;
78
import org.slf4j.LoggerFactory;
@@ -41,4 +42,7 @@ public void apply(StatsRegistry.CandidateStatsEvent e) {}
4142

4243
@Override
4344
public void apply(StatsRegistry.ExecutionStatsEvent e) {}
45+
46+
@Override
47+
public void applyExecutionComplete(ExecutionComplete complete) {}
4448
}

db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/helper/TestableRegistry.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public void register(ExecutionStatsEvent e) {
6161

6262
@Override
6363
public void registerSingleCompletedExecution(ExecutionComplete completeEvent) {
64+
applyToConditions(completeEvent);
6465
completed.add(completeEvent);
6566
log(completeEvent);
6667
}
@@ -95,6 +96,11 @@ private void applyToConditions(ExecutionStatsEvent e) {
9596
waitConditions.forEach(c -> c.apply(e));
9697
}
9798

99+
private void applyToConditions(ExecutionComplete complete) {
100+
waitConditions.forEach(c -> c.applyExecutionComplete(complete));
101+
}
102+
103+
98104
private void countEvent(Enum e) {
99105
String key = counterKey(e.getClass(), e.name());
100106
AtomicLong counter = counters.get(key);
@@ -146,6 +152,8 @@ public interface Condition {
146152
void apply(CandidateStatsEvent e);
147153

148154
void apply(ExecutionStatsEvent e);
155+
156+
void applyExecutionComplete(ExecutionComplete complete);
149157
}
150158

151159
public static class Builder {

0 commit comments

Comments
 (0)