Skip to content

Commit d2008bd

Browse files
committed
Fixed warnings in src/test/.../jobmaster
1 parent e2dcdc6 commit d2008bd

File tree

3 files changed

+41
-51
lines changed

3 files changed

+41
-51
lines changed

mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/AutoScaleMetricsConfigTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void testGenerateSourceJobMetricGroups() {
3636
}
3737

3838
@Test
39-
public void testGetAggregationAlgoForSourceJobMetrics() throws Exception {
39+
public void testGetAggregationAlgoForSourceJobMetrics() {
4040
AutoScaleMetricsConfig config = new AutoScaleMetricsConfig();
4141

4242
AutoScaleMetricsConfig.AggregationAlgo aglo = config.getAggregationAlgo(

mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/JobAutoScalerTest.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@
4444
import java.util.concurrent.TimeUnit;
4545
import java.util.concurrent.atomic.AtomicInteger;
4646
import org.junit.Test;
47-
import org.mockito.invocation.InvocationOnMock;
4847
import org.mockito.stubbing.Answer;
4948
import org.slf4j.Logger;
5049
import org.slf4j.LoggerFactory;
5150
import rx.Observable;
5251
import rx.Observer;
53-
import rx.functions.Func1;
5452

5553

5654
public class JobAutoScalerTest {
@@ -107,12 +105,13 @@ public void testScaleUp() throws InterruptedException {
107105
// retry sending auto scale event till scaleJobStage request sent to master, as there is possible a race between the sleep for coolDownSecs in the Test and the event being processed before coolDownSecs
108106
final CountDownLatch retryLatch = new CountDownLatch(1);
109107

110-
when(mockMasterClientApi.scaleJobStage(eq(jobId), eq(scalingStageNum), eq(numStage1Workers + 2 * increment), anyString())).thenAnswer(new Answer<Observable<Void>>() {
111-
@Override
112-
public Observable<Void> answer(InvocationOnMock invocation) throws Throwable {
113-
retryLatch.countDown();
114-
return Observable.just(null);
115-
}
108+
when(mockMasterClientApi.scaleJobStage(
109+
eq(jobId), eq(scalingStageNum),
110+
eq(numStage1Workers + 2 * increment),
111+
anyString()))
112+
.thenAnswer((Answer<Observable<Void>>) invocation -> {
113+
retryLatch.countDown();
114+
return Observable.just(null);
116115
});
117116
do {
118117
logger.info("sending Job auto scale Event");
@@ -152,15 +151,12 @@ public void testScalingResiliency() throws InterruptedException {
152151

153152
final CountDownLatch scaleJobStageSuccessLatch = new CountDownLatch(1);
154153
final AtomicInteger count = new AtomicInteger(0);
155-
final Observable<Boolean> simulateScaleJobStageFailureResp = Observable.just(1).map(new Func1<Integer, Boolean>() {
156-
@Override
157-
public Boolean call(Integer integer) {
158-
if (count.incrementAndGet() < 3) {
159-
throw new IllegalStateException("fake connection exception");
160-
} else {
161-
scaleJobStageSuccessLatch.countDown();
162-
return true;
163-
}
154+
final Observable<Boolean> simulateScaleJobStageFailureResp = Observable.just(1).map(integer -> {
155+
if (count.incrementAndGet() < 3) {
156+
throw new IllegalStateException("fake connection exception");
157+
} else {
158+
scaleJobStageSuccessLatch.countDown();
159+
return true;
164160
}
165161
});
166162
when(mockMasterClientApi.scaleJobStage(eq(jobId), eq(scalingStageNum), eq(numStage1Workers + increment), anyString())).thenReturn(simulateScaleJobStageFailureResp);
@@ -235,7 +231,7 @@ public void testScaleDown() throws InterruptedException {
235231
}
236232

237233
@Test
238-
public void testScaleDownNotLessThanMin() throws InterruptedException {
234+
public void testScaleDownNotLessThanMin() {
239235
final String jobId = "test-job-1";
240236
final int coolDownSec = 2;
241237
final int scalingStageNum = 1;
@@ -329,13 +325,15 @@ public void testScaleUpOnDifferentScalingReasons() throws InterruptedException {
329325

330326
// retry sending auto scale event till scaleJobStage request sent to master, as there is possible a race between the sleep for coolDownSecs in the Test and the event being processed before coolDownSecs
331327
final CountDownLatch retryLatch = new CountDownLatch(1);
332-
when(mockMasterClientApi.scaleJobStage(eq(jobId), eq(scalingStageNum), eq(numStage1Workers + 2 * increment), anyString())).thenAnswer(new Answer<Observable<Void>>() {
333-
@Override
334-
public Observable<Void> answer(InvocationOnMock invocation) throws Throwable {
328+
when(mockMasterClientApi.scaleJobStage(
329+
eq(jobId),
330+
eq(scalingStageNum),
331+
eq(numStage1Workers + 2 * increment),
332+
anyString()))
333+
.thenAnswer((Answer<Observable<Void>>) invocation -> {
335334
retryLatch.countDown();
336335
return Observable.just(null);
337-
}
338-
});
336+
});
339337

340338
do {
341339
logger.info("sending Job auto scale Event");
@@ -348,7 +346,7 @@ public Observable<Void> answer(InvocationOnMock invocation) throws Throwable {
348346
}
349347

350348
@Test
351-
public void testGetClutchConfigurationFromJson() throws Exception {
349+
public void testGetClutchConfigurationFromJson() {
352350
String json = "{" +
353351
" \"cooldownSeconds\": 100," +
354352
" \"integralDecay\": 0.7," +

mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/WorkerMetricHandlerTest.java

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@
4444
import java.util.concurrent.CountDownLatch;
4545
import java.util.concurrent.TimeUnit;
4646
import org.junit.Test;
47-
import org.mockito.invocation.InvocationOnMock;
4847
import org.mockito.stubbing.Answer;
4948
import org.slf4j.Logger;
5049
import org.slf4j.LoggerFactory;
5150
import rx.Observable;
5251
import rx.Observer;
53-
import rx.functions.Func1;
5452

5553

5654
public class WorkerMetricHandlerTest {
@@ -220,30 +218,24 @@ public void testOutlierResubmitWorks() throws InterruptedException {
220218
final CountDownLatch autoScaleLatch = new CountDownLatch(1);
221219

222220
when(mockMasterClientApi.schedulingChanges(jobId)).thenReturn(Observable.just(new JobSchedulingInfo(jobId, assignmentsMap)));
223-
when(mockMasterClientApi.resubmitJobWorker(anyString(), anyString(), anyInt(), anyString())).thenAnswer(new Answer<Observable<Boolean>>() {
224-
@Override
225-
public Observable<Boolean> answer(InvocationOnMock invocation) throws Throwable {
226-
227-
final Object[] arguments = invocation.getArguments();
228-
final String jobIdRecv = (String) arguments[0];
229-
final String user = (String) arguments[1];
230-
final int resubmittedWorkerNum = (Integer) arguments[2];
231-
// final String reason = (String)arguments[3];
232-
233-
final Observable<Boolean> result = Observable.just(1).map(new Func1<Integer, Boolean>() {
234-
@Override
235-
public Boolean call(Integer integer) {
236-
logger.info("resubmitting worker {} of jobId {}", resubmittedWorkerNum, jobId);
237-
assertEquals(workerNum, resubmittedWorkerNum);
238-
assertEquals(user, "JobMaster");
239-
assertEquals(jobId, jobIdRecv);
240-
241-
resubmitLatch.countDown();
242-
return true;
243-
}
244-
});
245-
return result;
246-
}
221+
when(mockMasterClientApi.resubmitJobWorker(anyString(), anyString(), anyInt(), anyString())).thenAnswer((Answer<Observable<Boolean>>) invocation -> {
222+
223+
final Object[] arguments = invocation.getArguments();
224+
final String jobIdRecv = (String) arguments[0];
225+
final String user = (String) arguments[1];
226+
final int resubmittedWorkerNum = (Integer) arguments[2];
227+
// final String reason = (String)arguments[3];
228+
229+
final Observable<Boolean> result = Observable.just(1).map(integer -> {
230+
logger.info("resubmitting worker {} of jobId {}", resubmittedWorkerNum, jobId);
231+
assertEquals(workerNum, resubmittedWorkerNum);
232+
assertEquals(user, "JobMaster");
233+
assertEquals(jobId, jobIdRecv);
234+
235+
resubmitLatch.countDown();
236+
return true;
237+
});
238+
return result;
247239
});
248240

249241

0 commit comments

Comments
 (0)