|
42 | 42 | import static org.junit.jupiter.api.Assertions.assertThrows; |
43 | 43 | import static org.mockito.ArgumentMatchers.any; |
44 | 44 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 45 | +import static org.mockito.ArgumentMatchers.argThat; |
45 | 46 | import static org.mockito.ArgumentMatchers.eq; |
46 | 47 | import static org.mockito.Mockito.doThrow; |
47 | 48 | import static org.mockito.Mockito.lenient; |
@@ -135,17 +136,21 @@ private void assertExecuteFailureWhenThrowException(final ShardingContexts shard |
135 | 136 | } finally { |
136 | 137 | verify(jobFacade).postJobStatusTraceEvent(shardingContexts.getTaskId(), State.TASK_STAGING, "Job 'test_job' execute begin."); |
137 | 138 | verify(jobFacade).postJobStatusTraceEvent(shardingContexts.getTaskId(), State.TASK_RUNNING, ""); |
138 | | - verify(jobFacade).postJobStatusTraceEvent(shardingContexts.getTaskId(), State.TASK_ERROR, getErrorMessage(shardingContexts)); |
| 139 | + verify(jobFacade).postJobStatusTraceEvent(eq(shardingContexts.getTaskId()), eq(State.TASK_ERROR), argThat(msg -> isValidErrorMessage(msg, shardingContexts))); |
139 | 140 | verify(jobFacade).registerJobBegin(shardingContexts); |
140 | 141 | verify(jobItemExecutor, times(shardingContexts.getShardingTotalCount())).process(eq(fooJob), eq(jobConfig), eq(jobRuntimeService), any()); |
141 | 142 | verify(jobFacade).registerJobCompleted(shardingContexts); |
142 | 143 | } |
143 | 144 | } |
144 | 145 |
|
145 | | - private String getErrorMessage(final ShardingContexts shardingContexts) { |
146 | | - return 1 == shardingContexts.getShardingItemParameters().size() |
147 | | - ? "{0=java.lang.RuntimeException" + System.lineSeparator() + "}" |
148 | | - : "{0=java.lang.RuntimeException" + System.lineSeparator() + ", 1=java.lang.RuntimeException" + System.lineSeparator() + "}"; |
| 146 | + private boolean isValidErrorMessage(final String errorMessage, final ShardingContexts shardingContexts) { |
| 147 | + if (1 == shardingContexts.getShardingItemParameters().size()) { |
| 148 | + return errorMessage.equals("{0=java.lang.RuntimeException" + System.lineSeparator() + "}"); |
| 149 | + } else { |
| 150 | + String pattern1 = "{0=java.lang.RuntimeException" + System.lineSeparator() + ", 1=java.lang.RuntimeException" + System.lineSeparator() + "}"; |
| 151 | + String pattern2 = "{1=java.lang.RuntimeException" + System.lineSeparator() + ", 0=java.lang.RuntimeException" + System.lineSeparator() + "}"; |
| 152 | + return errorMessage.equals(pattern1) || errorMessage.equals(pattern2); |
| 153 | + } |
149 | 154 | } |
150 | 155 |
|
151 | 156 | @Test |
|
0 commit comments