Skip to content

Commit

Permalink
Fix test failure in MagicSchedulerTest post improvements (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-sita committed Jun 8, 2024
1 parent 12aadd1 commit 6d177e4
Showing 1 changed file with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

public class MagicSchedulerTest extends TestContainersTest {

@Autowired
private MagicScheduler magicScheduler;

@Autowired
private StringTestTask stringTestTask;

Expand All @@ -53,10 +49,9 @@ public void shouldRunTask() {
when(stringTaskTestValueProcessor.process(any(), any())).thenReturn(TaskResult.success("Success: test"));

// when
runTasksAsTest(stringTestTask, "test", 0, callback);
runTasksAsTest(stringTestTask, "test");

// then
verify(callback, never()).onExecutionFinished();
var tasksBefore = executionsService.getScheduledTasks(Integer.MAX_VALUE, 0, null);
assertThat(tasksBefore).hasSize(1);
assertThat(tasksBefore.get(0).taskCode()).isEqualTo(stringTestTask.code());
Expand All @@ -71,7 +66,6 @@ public void shouldRunTask() {
argumentCaptor.getValue().run();

// then
verify(callback).onExecutionFinished();
var tasksAfter = executionsService.getScheduledTasks(Integer.MAX_VALUE, 0, null);
assertThat(tasksAfter).hasSize(1);
assertThat(tasksAfter.get(0).taskCode()).isEqualTo(stringTestTask.code());
Expand All @@ -88,17 +82,12 @@ public void shouldRunTask() {
// todo test return value
}

private <ParameterT> void runTasksAsTest(TaskType<ParameterT, ?, ?> taskType,
ParameterT parameter,
int executionCount,
MagicScheduler.ExecutionFinishedCallback callback) {
UUID id;
private <ParameterT> void runTasksAsTest(TaskType<ParameterT, ?, ?> taskType, ParameterT parameter) {
try {
id = internalTaskSubmitter.submitTaskForLater(taskType.code(), new ObjectMapper().writeValueAsString(parameter), InternalTaskSubmitter.UUID_FOR_USER_SUBMITTED_TASKS);
internalTaskSubmitter.submitTaskForLater(taskType.code(), new ObjectMapper().writeValueAsString(parameter), InternalTaskSubmitter.UUID_FOR_USER_SUBMITTED_TASKS);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
magicScheduler.schedule(id, taskType, parameter, executionCount, callback);
}

}

0 comments on commit 6d177e4

Please sign in to comment.