Skip to content

Commit d276f4f

Browse files
formatting
1 parent 3af83d1 commit d276f4f

File tree

3 files changed

+132
-133
lines changed

3 files changed

+132
-133
lines changed

dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/TasksRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ private Duration getAverageTaskDurationFromLatestTasks() {
134134

135135
private Duration getTaskDuration() {
136136
return Collections.max(
137-
Arrays.asList(
138-
getAverageTaskDurationFromAllTasks(), getAverageTaskDurationFromLatestTasks()));
137+
Arrays.asList(
138+
getAverageTaskDurationFromAllTasks(), getAverageTaskDurationFromLatestTasks()));
139139
}
140140

141141
private void logProgress() {

dumper/app/src/test/java/com/google/edwmigration/dumper/application/dumper/DurationFormatterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class DurationFormatterTest {
3838
Pair.of(Duration.ofSeconds(1), "less than 15 minutes"),
3939
Pair.of(Duration.ofSeconds(59), "less than 15 minutes"),
4040
Pair.of(Duration.ofMinutes(1), "less than 15 minutes"),
41-
Pair.of(Duration.ofMinutes(1).plusSeconds(1),"less than 15 minutes"),
42-
Pair.of(Duration.ofMinutes(1).plusSeconds(59),"less than 15 minutes"),
41+
Pair.of(Duration.ofMinutes(1).plusSeconds(1), "less than 15 minutes"),
42+
Pair.of(Duration.ofMinutes(1).plusSeconds(59), "less than 15 minutes"),
4343
Pair.of(Duration.ofMinutes(2), "less than 15 minutes"),
4444
Pair.of(Duration.ofMinutes(2).plusSeconds(1), "less than 15 minutes"),
4545
Pair.of(Duration.ofMinutes(2).plusSeconds(59), "less than 15 minutes"),

dumper/app/src/test/java/com/google/edwmigration/dumper/application/dumper/TasksRunnerTest.java

Lines changed: 128 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.Collections;
3333
import java.util.Deque;
3434
import java.util.List;
35-
3635
import org.junit.Before;
3736
import org.junit.Rule;
3837
import org.junit.Test;
@@ -42,13 +41,13 @@
4241

4342
@RunWith(JUnit4.class)
4443
public class TasksRunnerTest {
45-
@Rule
46-
public final SystemOutRule systemOutRule = new SystemOutRule().enableLog();
44+
@Rule public final SystemOutRule systemOutRule = new SystemOutRule().enableLog();
4745

4846
@Before
4947
public void setUp() {
5048
System.setProperty("org.slf4j.simpleLogger.logFile", "System.out");
51-
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info"); }
49+
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
50+
}
5251

5352
@Test
5453
public void testCreateContext_returnsValidTaskRunContext() throws IOException {
@@ -89,131 +88,131 @@ public void testCreateContext_returnsValidTaskRunContext() throws IOException {
8988
}
9089
}
9190

92-
@Test
93-
public void testGetTaskDuration_ReturnsMaxOfAllAndLatest() throws Exception {
94-
OutputHandleFactory mockSinkFactory = mock(OutputHandleFactory.class);
95-
Handle mockHandle = mock(Handle.class);
96-
int threadPoolSize = 2;
97-
TaskSetState.Impl mockState = mock(TaskSetState.Impl.class);
98-
ConnectorArguments arguments = new ConnectorArguments("--connector", "test");
99-
List<Task<?>> tasks = Collections.nCopies(10, mock(Task.class));
100-
TasksRunner runner =
101-
new TasksRunner(mockSinkFactory, mockHandle, threadPoolSize, mockState, tasks, arguments);
102-
103-
java.lang.reflect.Field completedField =
104-
TasksRunner.class.getDeclaredField("numberOfCompletedTasks");
105-
completedField.setAccessible(true);
106-
completedField.set(runner, new java.util.concurrent.atomic.AtomicInteger(5));
107-
108-
java.lang.reflect.Field stopwatchField =
109-
TasksRunner.class.getDeclaredField("stopwatch");
110-
stopwatchField.setAccessible(true);
111-
com.google.common.base.Stopwatch mockStopwatch = mock(com.google.common.base.Stopwatch.class);
112-
when(mockStopwatch.elapsed()).thenReturn(Duration.ofSeconds(50));
113-
stopwatchField.set(runner, mockStopwatch);
114-
115-
java.lang.reflect.Field durationsField =
116-
TasksRunner.class.getDeclaredField("lastTaskDurations");
117-
durationsField.setAccessible(true);
118-
@SuppressWarnings("unchecked")
119-
Deque<Duration> durations = (Deque<Duration>) durationsField.get(runner);
120-
durations.clear();
121-
durations.add(Duration.ofSeconds(10));
122-
durations.add(Duration.ofSeconds(20));
123-
durations.add(Duration.ofSeconds(30));
124-
durations.add(Duration.ofSeconds(40));
125-
durations.add(Duration.ofSeconds(50));
126-
127-
// getAverageTaskDurationFromAllTasks = 50s / 5 = 10s
128-
// getAverageTaskDurationFromLatestTasks = (50s - 10s) / 5 = 8s
129-
// getTaskDuration should return max(10s, 8s) = 10s
130-
java.lang.reflect.Method getTaskDuration = TasksRunner.class.getDeclaredMethod("getTaskDuration");
131-
getTaskDuration.setAccessible(true);
132-
Duration result = (Duration) getTaskDuration.invoke(runner);
133-
134-
assertEquals(Duration.ofSeconds(10), result);
135-
}
91+
@Test
92+
public void testGetTaskDuration_ReturnsMaxOfAllAndLatest() throws Exception {
93+
OutputHandleFactory mockSinkFactory = mock(OutputHandleFactory.class);
94+
Handle mockHandle = mock(Handle.class);
95+
int threadPoolSize = 2;
96+
TaskSetState.Impl mockState = mock(TaskSetState.Impl.class);
97+
ConnectorArguments arguments = new ConnectorArguments("--connector", "test");
98+
List<Task<?>> tasks = Collections.nCopies(10, mock(Task.class));
99+
TasksRunner runner =
100+
new TasksRunner(mockSinkFactory, mockHandle, threadPoolSize, mockState, tasks, arguments);
101+
102+
java.lang.reflect.Field completedField =
103+
TasksRunner.class.getDeclaredField("numberOfCompletedTasks");
104+
completedField.setAccessible(true);
105+
completedField.set(runner, new java.util.concurrent.atomic.AtomicInteger(5));
106+
107+
java.lang.reflect.Field stopwatchField = TasksRunner.class.getDeclaredField("stopwatch");
108+
stopwatchField.setAccessible(true);
109+
com.google.common.base.Stopwatch mockStopwatch = mock(com.google.common.base.Stopwatch.class);
110+
when(mockStopwatch.elapsed()).thenReturn(Duration.ofSeconds(50));
111+
stopwatchField.set(runner, mockStopwatch);
112+
113+
java.lang.reflect.Field durationsField =
114+
TasksRunner.class.getDeclaredField("lastTaskDurations");
115+
durationsField.setAccessible(true);
116+
@SuppressWarnings("unchecked")
117+
Deque<Duration> durations = (Deque<Duration>) durationsField.get(runner);
118+
durations.clear();
119+
durations.add(Duration.ofSeconds(10));
120+
durations.add(Duration.ofSeconds(20));
121+
durations.add(Duration.ofSeconds(30));
122+
durations.add(Duration.ofSeconds(40));
123+
durations.add(Duration.ofSeconds(50));
124+
125+
// getAverageTaskDurationFromAllTasks = 50s / 5 = 10s
126+
// getAverageTaskDurationFromLatestTasks = (50s - 10s) / 5 = 8s
127+
// getTaskDuration should return max(10s, 8s) = 10s
128+
java.lang.reflect.Method getTaskDuration =
129+
TasksRunner.class.getDeclaredMethod("getTaskDuration");
130+
getTaskDuration.setAccessible(true);
131+
Duration result = (Duration) getTaskDuration.invoke(runner);
132+
133+
assertEquals(Duration.ofSeconds(10), result);
134+
}
136135

137-
@Test
138-
public void testGetTaskDuration_EmptyLastTaskDurations() throws Exception {
139-
OutputHandleFactory mockSinkFactory = mock(OutputHandleFactory.class);
140-
Handle mockHandle = mock(Handle.class);
141-
int threadPoolSize = 2;
142-
TaskSetState.Impl mockState = mock(TaskSetState.Impl.class);
143-
ConnectorArguments arguments = new ConnectorArguments("--connector", "test");
144-
List<Task<?>> tasks = Collections.nCopies(3, mock(Task.class));
145-
TasksRunner runner =
146-
new TasksRunner(mockSinkFactory, mockHandle, threadPoolSize, mockState, tasks, arguments);
147-
148-
java.lang.reflect.Field completedField =
149-
TasksRunner.class.getDeclaredField("numberOfCompletedTasks");
150-
completedField.setAccessible(true);
151-
completedField.set(runner, new java.util.concurrent.atomic.AtomicInteger(3));
152-
153-
java.lang.reflect.Field stopwatchField =
154-
TasksRunner.class.getDeclaredField("stopwatch");
155-
stopwatchField.setAccessible(true);
156-
com.google.common.base.Stopwatch mockStopwatch = mock(com.google.common.base.Stopwatch.class);
157-
when(mockStopwatch.elapsed()).thenReturn(Duration.ofSeconds(9));
158-
stopwatchField.set(runner, mockStopwatch);
159-
160-
java.lang.reflect.Field durationsField =
161-
TasksRunner.class.getDeclaredField("lastTaskDurations");
162-
durationsField.setAccessible(true);
163-
@SuppressWarnings("unchecked")
164-
Deque<Duration> durations = (Deque<Duration>) durationsField.get(runner);
165-
durations.clear();
166-
167-
// getAverageTaskDurationFromAllTasks = 9s / 3 = 3s
168-
// getAverageTaskDurationFromLatestTasks = 0s
169-
// getTaskDuration should return max(3s, 0s) = 3s
170-
java.lang.reflect.Method getTaskDuration = TasksRunner.class.getDeclaredMethod("getTaskDuration");
171-
getTaskDuration.setAccessible(true);
172-
Duration result = (Duration) getTaskDuration.invoke(runner);
173-
174-
assertEquals(Duration.ofSeconds(3), result);
175-
}
136+
@Test
137+
public void testGetTaskDuration_EmptyLastTaskDurations() throws Exception {
138+
OutputHandleFactory mockSinkFactory = mock(OutputHandleFactory.class);
139+
Handle mockHandle = mock(Handle.class);
140+
int threadPoolSize = 2;
141+
TaskSetState.Impl mockState = mock(TaskSetState.Impl.class);
142+
ConnectorArguments arguments = new ConnectorArguments("--connector", "test");
143+
List<Task<?>> tasks = Collections.nCopies(3, mock(Task.class));
144+
TasksRunner runner =
145+
new TasksRunner(mockSinkFactory, mockHandle, threadPoolSize, mockState, tasks, arguments);
146+
147+
java.lang.reflect.Field completedField =
148+
TasksRunner.class.getDeclaredField("numberOfCompletedTasks");
149+
completedField.setAccessible(true);
150+
completedField.set(runner, new java.util.concurrent.atomic.AtomicInteger(3));
151+
152+
java.lang.reflect.Field stopwatchField = TasksRunner.class.getDeclaredField("stopwatch");
153+
stopwatchField.setAccessible(true);
154+
com.google.common.base.Stopwatch mockStopwatch = mock(com.google.common.base.Stopwatch.class);
155+
when(mockStopwatch.elapsed()).thenReturn(Duration.ofSeconds(9));
156+
stopwatchField.set(runner, mockStopwatch);
157+
158+
java.lang.reflect.Field durationsField =
159+
TasksRunner.class.getDeclaredField("lastTaskDurations");
160+
durationsField.setAccessible(true);
161+
@SuppressWarnings("unchecked")
162+
Deque<Duration> durations = (Deque<Duration>) durationsField.get(runner);
163+
durations.clear();
164+
165+
// getAverageTaskDurationFromAllTasks = 9s / 3 = 3s
166+
// getAverageTaskDurationFromLatestTasks = 0s
167+
// getTaskDuration should return max(3s, 0s) = 3s
168+
java.lang.reflect.Method getTaskDuration =
169+
TasksRunner.class.getDeclaredMethod("getTaskDuration");
170+
getTaskDuration.setAccessible(true);
171+
Duration result = (Duration) getTaskDuration.invoke(runner);
172+
173+
assertEquals(Duration.ofSeconds(3), result);
174+
}
176175

177-
@Test
178-
public void testGetTaskDuration_LastTaskDurationsGreaterThanAllTasks() throws Exception {
179-
OutputHandleFactory mockSinkFactory = mock(OutputHandleFactory.class);
180-
Handle mockHandle = mock(Handle.class);
181-
int threadPoolSize = 2;
182-
TaskSetState.Impl mockState = mock(TaskSetState.Impl.class);
183-
ConnectorArguments arguments = new ConnectorArguments("--connector", "test");
184-
List<Task<?>> tasks = Collections.nCopies(4, mock(Task.class));
185-
TasksRunner runner =
186-
new TasksRunner(mockSinkFactory, mockHandle, threadPoolSize, mockState, tasks, arguments);
187-
188-
// Set numberOfCompletedTasks to 2
189-
java.lang.reflect.Field completedField =
190-
TasksRunner.class.getDeclaredField("numberOfCompletedTasks");
191-
completedField.setAccessible(true);
192-
completedField.set(runner, new java.util.concurrent.atomic.AtomicInteger(2));
193-
194-
java.lang.reflect.Field stopwatchField =
195-
TasksRunner.class.getDeclaredField("stopwatch");
196-
stopwatchField.setAccessible(true);
197-
com.google.common.base.Stopwatch mockStopwatch = mock(com.google.common.base.Stopwatch.class);
198-
when(mockStopwatch.elapsed()).thenReturn(Duration.ofSeconds(6));
199-
stopwatchField.set(runner, mockStopwatch);
200-
201-
java.lang.reflect.Field durationsField =
202-
TasksRunner.class.getDeclaredField("lastTaskDurations");
203-
durationsField.setAccessible(true);
204-
@SuppressWarnings("unchecked")
205-
Deque<Duration> durations = (Deque<Duration>) durationsField.get(runner);
206-
durations.clear();
207-
durations.add(Duration.ofSeconds(2));
208-
durations.add(Duration.ofSeconds(10));
209-
210-
// getAverageTaskDurationFromAllTasks = 6s / 2 = 3s
211-
// getAverageTaskDurationFromLatestTasks = (10s - 2s) / 2 = 4s
212-
// getTaskDuration should return max(3s, 4s) = 4s
213-
java.lang.reflect.Method getTaskDuration = TasksRunner.class.getDeclaredMethod("getTaskDuration");
214-
getTaskDuration.setAccessible(true);
215-
Duration result = (Duration) getTaskDuration.invoke(runner);
216-
217-
assertEquals(Duration.ofSeconds(4), result);
218-
}
176+
@Test
177+
public void testGetTaskDuration_LastTaskDurationsGreaterThanAllTasks() throws Exception {
178+
OutputHandleFactory mockSinkFactory = mock(OutputHandleFactory.class);
179+
Handle mockHandle = mock(Handle.class);
180+
int threadPoolSize = 2;
181+
TaskSetState.Impl mockState = mock(TaskSetState.Impl.class);
182+
ConnectorArguments arguments = new ConnectorArguments("--connector", "test");
183+
List<Task<?>> tasks = Collections.nCopies(4, mock(Task.class));
184+
TasksRunner runner =
185+
new TasksRunner(mockSinkFactory, mockHandle, threadPoolSize, mockState, tasks, arguments);
186+
187+
// Set numberOfCompletedTasks to 2
188+
java.lang.reflect.Field completedField =
189+
TasksRunner.class.getDeclaredField("numberOfCompletedTasks");
190+
completedField.setAccessible(true);
191+
completedField.set(runner, new java.util.concurrent.atomic.AtomicInteger(2));
192+
193+
java.lang.reflect.Field stopwatchField = TasksRunner.class.getDeclaredField("stopwatch");
194+
stopwatchField.setAccessible(true);
195+
com.google.common.base.Stopwatch mockStopwatch = mock(com.google.common.base.Stopwatch.class);
196+
when(mockStopwatch.elapsed()).thenReturn(Duration.ofSeconds(6));
197+
stopwatchField.set(runner, mockStopwatch);
198+
199+
java.lang.reflect.Field durationsField =
200+
TasksRunner.class.getDeclaredField("lastTaskDurations");
201+
durationsField.setAccessible(true);
202+
@SuppressWarnings("unchecked")
203+
Deque<Duration> durations = (Deque<Duration>) durationsField.get(runner);
204+
durations.clear();
205+
durations.add(Duration.ofSeconds(2));
206+
durations.add(Duration.ofSeconds(10));
207+
208+
// getAverageTaskDurationFromAllTasks = 6s / 2 = 3s
209+
// getAverageTaskDurationFromLatestTasks = (10s - 2s) / 2 = 4s
210+
// getTaskDuration should return max(3s, 4s) = 4s
211+
java.lang.reflect.Method getTaskDuration =
212+
TasksRunner.class.getDeclaredMethod("getTaskDuration");
213+
getTaskDuration.setAccessible(true);
214+
Duration result = (Duration) getTaskDuration.invoke(runner);
215+
216+
assertEquals(Duration.ofSeconds(4), result);
217+
}
219218
}

0 commit comments

Comments
 (0)