You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by ma...@apache.org on 2015/02/09 23:34:01 UTC
incubator-aurora git commit: Fixing test coverage in startJobUpdate
RPC
Repository: incubator-aurora
Updated Branches:
refs/heads/master dcae1e8d2 -> 68aa28540
Fixing test coverage in startJobUpdate RPC
Reviewed at https://reviews.apache.org/r/30804/
Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/68aa2854
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/68aa2854
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/68aa2854
Branch: refs/heads/master
Commit: 68aa2854013c80ba94c18f50267cbd7676c23bbb
Parents: dcae1e8
Author: Maxim Khutornenko <ma...@apache.org>
Authored: Mon Feb 9 14:34:00 2015 -0800
Committer: Maxim Khutornenko <ma...@apache.org>
Committed: Mon Feb 9 14:34:00 2015 -0800
----------------------------------------------------------------------
.../thrift/SchedulerThriftInterface.java | 33 +++++++--
.../thrift/SchedulerThriftInterfaceTest.java | 73 +++++++++++++-------
2 files changed, 75 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/68aa2854/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java b/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
index 2b5383f..fd4d690 100644
--- a/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
+++ b/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
@@ -1362,28 +1362,28 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
.setName(mutableRequest.getTaskConfig().getJobName())));
if (!mutableRequest.getTaskConfig().isIsService()) {
- return invalidResponse("Updates are not supported for non-service tasks.");
+ return invalidResponse(NON_SERVICE_TASK);
}
JobUpdateSettings settings = requireNonNull(mutableRequest.getSettings());
if (settings.getUpdateGroupSize() <= 0) {
- return invalidResponse("updateGroupSize must be positive.");
+ return invalidResponse(INVALID_GROUP_SIZE);
}
if (settings.getMaxPerInstanceFailures() < 0) {
- return invalidResponse("maxPerInstanceFailures must be non-negative.");
+ return invalidResponse(INVALID_MAX_INSTANCE_FAILURES);
}
if (settings.getMaxFailedInstances() < 0) {
- return invalidResponse("maxFailedInstances must be non-negative.");
+ return invalidResponse(INVALID_MAX_FAILED_INSTANCES);
}
if (settings.getMaxWaitToInstanceRunningMs() < 0) {
- return invalidResponse("maxWaitToInstanceRunningMs must be non-negative.");
+ return invalidResponse(INVALID_MAX_WAIT_TO_RUNNING);
}
if (settings.getMinWaitInInstanceRunningMs() < 0) {
- return invalidResponse("minWaitInInstanceRunningMs must be non-negative.");
+ return invalidResponse(INVALID_MIN_WAIT_TO_RUNNING);
}
final SessionContext context;
@@ -1609,6 +1609,27 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
@VisibleForTesting
static final String NO_CRON = "Cron jobs may only be created/updated by calling scheduleCronJob.";
+ @VisibleForTesting
+ static final String NON_SERVICE_TASK = "Updates are not supported for non-service tasks.";
+
+ @VisibleForTesting
+ static final String INVALID_GROUP_SIZE = "updateGroupSize must be positive.";
+
+ @VisibleForTesting
+ static final String INVALID_MAX_FAILED_INSTANCES = "maxFailedInstances must be non-negative.";
+
+ @VisibleForTesting
+ static final String INVALID_MAX_INSTANCE_FAILURES =
+ "maxPerInstanceFailures must be non-negative.";
+
+ @VisibleForTesting
+ static final String INVALID_MAX_WAIT_TO_RUNNING =
+ "maxWaitToInstanceRunningMs must be non-negative.";
+
+ @VisibleForTesting
+ static final String INVALID_MIN_WAIT_TO_RUNNING =
+ "minWaitInInstanceRunningMs must be non-negative.";
+
private static Response okEmptyResponse() {
return emptyResponse().setResponseCode(OK);
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/68aa2854/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
index c6fe218..a9966a8 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
@@ -2683,46 +2683,61 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
@Test
public void testStartUpdateFailsInvalidGroupSize() throws Exception {
control.replay();
- assertResponse(INVALID_REQUEST, thrift.startJobUpdate(new JobUpdateRequest(
- defaultTask(true),
- 5,
- buildJobUpdateSettings().setUpdateGroupSize(0)), SESSION));
+
+ JobUpdateRequest updateRequest = buildServiceJobUpdateRequest();
+ updateRequest.getSettings().setUpdateGroupSize(0);
+
+ assertEquals(
+ invalidResponse(SchedulerThriftInterface.INVALID_GROUP_SIZE),
+ thrift.startJobUpdate(updateRequest, SESSION));
}
@Test
public void testStartUpdateFailsInvalidMaxInstanceFailures() throws Exception {
control.replay();
- assertResponse(INVALID_REQUEST, thrift.startJobUpdate(new JobUpdateRequest(
- defaultTask(true),
- 5,
- buildJobUpdateSettings().setMaxPerInstanceFailures(-1)), SESSION));
+
+ JobUpdateRequest updateRequest = buildServiceJobUpdateRequest();
+ updateRequest.getSettings().setMaxPerInstanceFailures(-1);
+
+ assertEquals(
+ invalidResponse(SchedulerThriftInterface.INVALID_MAX_INSTANCE_FAILURES),
+ thrift.startJobUpdate(updateRequest, SESSION));
}
@Test
public void testStartUpdateFailsInvalidMaxFailedInstances() throws Exception {
control.replay();
- assertResponse(INVALID_REQUEST, thrift.startJobUpdate(new JobUpdateRequest(
- defaultTask(true),
- 5,
- buildJobUpdateSettings().setMaxFailedInstances(-1)), SESSION));
+
+ JobUpdateRequest updateRequest = buildServiceJobUpdateRequest();
+ updateRequest.getSettings().setMaxFailedInstances(-1);
+
+ assertEquals(
+ invalidResponse(SchedulerThriftInterface.INVALID_MAX_FAILED_INSTANCES),
+ thrift.startJobUpdate(updateRequest, SESSION));
}
@Test
public void testStartUpdateFailsInvalidMaxWaitToRunning() throws Exception {
control.replay();
- assertResponse(INVALID_REQUEST, thrift.startJobUpdate(new JobUpdateRequest(
- defaultTask(true),
- 5,
- buildJobUpdateSettings().setMaxWaitToInstanceRunningMs(-1)), SESSION));
+
+ JobUpdateRequest updateRequest = buildServiceJobUpdateRequest();
+ updateRequest.getSettings().setMaxWaitToInstanceRunningMs(-1);
+
+ assertEquals(
+ invalidResponse(SchedulerThriftInterface.INVALID_MAX_WAIT_TO_RUNNING),
+ thrift.startJobUpdate(updateRequest, SESSION));
}
@Test
public void testStartUpdateFailsInvalidMinWaitInRunning() throws Exception {
control.replay();
- assertResponse(INVALID_REQUEST, thrift.startJobUpdate(new JobUpdateRequest(
- defaultTask(true),
- 5,
- buildJobUpdateSettings().setMinWaitInInstanceRunningMs(-1)), SESSION));
+
+ JobUpdateRequest updateRequest = buildServiceJobUpdateRequest();
+ updateRequest.getSettings().setMinWaitInInstanceRunningMs(-1);
+
+ assertEquals(
+ invalidResponse(SchedulerThriftInterface.INVALID_MIN_WAIT_TO_RUNNING),
+ thrift.startJobUpdate(updateRequest, SESSION));
}
@Test
@@ -2734,7 +2749,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
@Test
public void testStartUpdateFailsAuth() throws Exception {
- JobUpdateRequest request = buildJobUpdateRequest(populatedTask().setIsService(true));
+ JobUpdateRequest request = buildServiceJobUpdateRequest(populatedTask());
expectAuth(ROLE, false);
control.replay();
@@ -2743,7 +2758,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
@Test
public void testStartUpdateFailsForCronJob() throws Exception {
- JobUpdateRequest request = buildJobUpdateRequest(populatedTask().setIsService(true));
+ JobUpdateRequest request = buildServiceJobUpdateRequest(populatedTask());
expectAuth(ROLE, true);
expect(cronJobManager.hasJob(JOB_KEY)).andReturn(true);
@@ -2810,7 +2825,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
@Test
public void testStartUpdateFailsInstanceCountCheck() throws Exception {
- JobUpdateRequest request = buildJobUpdateRequest(populatedTask().setIsService(true));
+ JobUpdateRequest request = buildServiceJobUpdateRequest(populatedTask());
request.setInstanceCount(4001);
expectAuth(ROLE, true);
expect(cronJobManager.hasJob(JOB_KEY)).andReturn(false);
@@ -2825,7 +2840,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
@Test
public void testStartUpdateFailsTaskIdLength() throws Exception {
- JobUpdateRequest request = buildJobUpdateRequest(populatedTask().setIsService(true));
+ JobUpdateRequest request = buildServiceJobUpdateRequest(populatedTask());
expectAuth(ROLE, true);
expect(cronJobManager.hasJob(JOB_KEY)).andReturn(false);
expect(uuidGenerator.createNew()).andReturn(UU_ID);
@@ -2841,7 +2856,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
@Test
public void testStartUpdateFailsQuotaCheck() throws Exception {
- JobUpdateRequest request = buildJobUpdateRequest(populatedTask().setIsService(true));
+ JobUpdateRequest request = buildServiceJobUpdateRequest(populatedTask());
expectAuth(ROLE, true);
expect(cronJobManager.hasJob(JOB_KEY)).andReturn(false);
expect(uuidGenerator.createNew()).andReturn(UU_ID);
@@ -3131,6 +3146,14 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
TaskConstraint.value(new ValueConstraint(false, values)));
}
+ private static JobUpdateRequest buildServiceJobUpdateRequest() {
+ return buildServiceJobUpdateRequest(defaultTask(true));
+ }
+
+ private static JobUpdateRequest buildServiceJobUpdateRequest(TaskConfig config) {
+ return buildJobUpdateRequest(config.setIsService(true));
+ }
+
private static JobUpdateRequest buildJobUpdateRequest(TaskConfig config) {
return new JobUpdateRequest()
.setInstanceCount(6)