|
22 | 22 | import static org.junit.Assert.fail; |
23 | 23 | import static org.mockito.Mockito.*; |
24 | 24 |
|
25 | | -import ch.qos.logback.classic.Logger; |
26 | | -import ch.qos.logback.classic.spi.ILoggingEvent; |
27 | | -import ch.qos.logback.core.read.ListAppender; |
28 | 25 | import com.google.edwmigration.dumper.application.dumper.handle.Handle; |
29 | 26 | import com.google.edwmigration.dumper.application.dumper.io.OutputHandleFactory; |
30 | 27 | import com.google.edwmigration.dumper.application.dumper.task.Task; |
|
42 | 39 | import org.junit.contrib.java.lang.system.SystemOutRule; |
43 | 40 | import org.junit.runner.RunWith; |
44 | 41 | import org.junit.runners.JUnit4; |
45 | | -import org.slf4j.LoggerFactory; |
46 | 42 |
|
47 | 43 | @RunWith(JUnit4.class) |
48 | 44 | public class TasksRunnerTest { |
@@ -70,7 +66,6 @@ public void testCreateContext_returnsValidTaskRunContext() throws IOException { |
70 | 66 | Collections.emptyList(), |
71 | 67 | arguments); |
72 | 68 |
|
73 | | - // Use reflection to access the private createContext method for direct testing |
74 | 69 | try { |
75 | 70 | java.lang.reflect.Method method = |
76 | 71 | TasksRunner.class.getDeclaredMethod( |
@@ -105,21 +100,18 @@ public void testGetTaskDuration_ReturnsMaxOfAllAndLatest() throws Exception { |
105 | 100 | TasksRunner runner = |
106 | 101 | new TasksRunner(mockSinkFactory, mockHandle, threadPoolSize, mockState, tasks, arguments); |
107 | 102 |
|
108 | | - // Set numberOfCompletedTasks to 5 |
109 | 103 | java.lang.reflect.Field completedField = |
110 | 104 | TasksRunner.class.getDeclaredField("numberOfCompletedTasks"); |
111 | 105 | completedField.setAccessible(true); |
112 | 106 | completedField.set(runner, new java.util.concurrent.atomic.AtomicInteger(5)); |
113 | 107 |
|
114 | | - // Mock stopwatch to control elapsed time |
115 | 108 | java.lang.reflect.Field stopwatchField = |
116 | 109 | TasksRunner.class.getDeclaredField("stopwatch"); |
117 | 110 | stopwatchField.setAccessible(true); |
118 | 111 | com.google.common.base.Stopwatch mockStopwatch = mock(com.google.common.base.Stopwatch.class); |
119 | 112 | when(mockStopwatch.elapsed()).thenReturn(Duration.ofSeconds(50)); |
120 | 113 | stopwatchField.set(runner, mockStopwatch); |
121 | 114 |
|
122 | | - // Fill lastTaskDurations with 5 durations: 10, 20, 30, 40, 50 seconds |
123 | 115 | java.lang.reflect.Field durationsField = |
124 | 116 | TasksRunner.class.getDeclaredField("lastTaskDurations"); |
125 | 117 | durationsField.setAccessible(true); |
@@ -153,21 +145,18 @@ public void testGetTaskDuration_EmptyLastTaskDurations() throws Exception { |
153 | 145 | TasksRunner runner = |
154 | 146 | new TasksRunner(mockSinkFactory, mockHandle, threadPoolSize, mockState, tasks, arguments); |
155 | 147 |
|
156 | | - // Set numberOfCompletedTasks to 3 |
157 | 148 | java.lang.reflect.Field completedField = |
158 | 149 | TasksRunner.class.getDeclaredField("numberOfCompletedTasks"); |
159 | 150 | completedField.setAccessible(true); |
160 | 151 | completedField.set(runner, new java.util.concurrent.atomic.AtomicInteger(3)); |
161 | 152 |
|
162 | | - // Mock stopwatch to control elapsed time |
163 | 153 | java.lang.reflect.Field stopwatchField = |
164 | 154 | TasksRunner.class.getDeclaredField("stopwatch"); |
165 | 155 | stopwatchField.setAccessible(true); |
166 | 156 | com.google.common.base.Stopwatch mockStopwatch = mock(com.google.common.base.Stopwatch.class); |
167 | 157 | when(mockStopwatch.elapsed()).thenReturn(Duration.ofSeconds(9)); |
168 | 158 | stopwatchField.set(runner, mockStopwatch); |
169 | 159 |
|
170 | | - // Ensure lastTaskDurations is empty |
171 | 160 | java.lang.reflect.Field durationsField = |
172 | 161 | TasksRunner.class.getDeclaredField("lastTaskDurations"); |
173 | 162 | durationsField.setAccessible(true); |
@@ -202,15 +191,13 @@ public void testGetTaskDuration_LastTaskDurationsGreaterThanAllTasks() throws Ex |
202 | 191 | completedField.setAccessible(true); |
203 | 192 | completedField.set(runner, new java.util.concurrent.atomic.AtomicInteger(2)); |
204 | 193 |
|
205 | | - // Mock stopwatch to control elapsed time |
206 | 194 | java.lang.reflect.Field stopwatchField = |
207 | 195 | TasksRunner.class.getDeclaredField("stopwatch"); |
208 | 196 | stopwatchField.setAccessible(true); |
209 | 197 | com.google.common.base.Stopwatch mockStopwatch = mock(com.google.common.base.Stopwatch.class); |
210 | 198 | when(mockStopwatch.elapsed()).thenReturn(Duration.ofSeconds(6)); |
211 | 199 | stopwatchField.set(runner, mockStopwatch); |
212 | 200 |
|
213 | | - // Fill lastTaskDurations with 2 durations: 2s, 10s |
214 | 201 | java.lang.reflect.Field durationsField = |
215 | 202 | TasksRunner.class.getDeclaredField("lastTaskDurations"); |
216 | 203 | durationsField.setAccessible(true); |
|
0 commit comments