aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject git commit: Improve test coverage for TaskAssignerImpl.
Date Wed, 22 Jan 2014 18:27:33 GMT
Updated Branches:
  refs/heads/master 28372648a -> b0f268b36


Improve test coverage for TaskAssignerImpl.

Bugs closed: AURORA-63

Reviewed at https://reviews.apache.org/r/17133/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/b0f268b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/b0f268b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/b0f268b3

Branch: refs/heads/master
Commit: b0f268b360adfcf97edae9affa91137eb137bbf8
Parents: 2837264
Author: Bill Farner <wfarner@apache.org>
Authored: Wed Jan 22 10:26:20 2014 -0800
Committer: Bill Farner <wfarner@apache.org>
Committed: Wed Jan 22 10:26:20 2014 -0800

----------------------------------------------------------------------
 .../apache/aurora/scheduler/ResourceSlot.java   |  15 +++
 .../scheduler/state/TaskAssignerImplTest.java   | 124 +++++++++++++++++++
 2 files changed, 139 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/b0f268b3/src/main/java/org/apache/aurora/scheduler/ResourceSlot.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/ResourceSlot.java b/src/main/java/org/apache/aurora/scheduler/ResourceSlot.java
index 339773d..d3a9959 100644
--- a/src/main/java/org/apache/aurora/scheduler/ResourceSlot.java
+++ b/src/main/java/org/apache/aurora/scheduler/ResourceSlot.java
@@ -92,6 +92,21 @@ public final class ResourceSlot {
     return new ResourceSlot(new Resources(totalCPU, totalRAM, disk, ports));
   }
 
+  @Override
+  public boolean equals(Object o) {
+    if (!(o instanceof ResourceSlot)) {
+      return false;
+    }
+
+    ResourceSlot other = (ResourceSlot) o;
+    return resources.equals(other.resources);
+  }
+
+  @Override
+  public int hashCode() {
+    return resources.hashCode();
+  }
+
   public static ResourceSlot sum(ResourceSlot... rs) {
     return sum(Arrays.asList(rs));
   }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/b0f268b3/src/test/java/org/apache/aurora/scheduler/state/TaskAssignerImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/state/TaskAssignerImplTest.java b/src/test/java/org/apache/aurora/scheduler/state/TaskAssignerImplTest.java
new file mode 100644
index 0000000..154ccc4
--- /dev/null
+++ b/src/test/java/org/apache/aurora/scheduler/state/TaskAssignerImplTest.java
@@ -0,0 +1,124 @@
+/**
+ * Copyright 2014 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aurora.scheduler.state;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableSet;
+import com.twitter.common.testing.easymock.EasyMockTest;
+
+import org.apache.aurora.gen.AssignedTask;
+import org.apache.aurora.gen.ExecutorConfig;
+import org.apache.aurora.gen.ScheduledTask;
+import org.apache.aurora.gen.TaskConfig;
+import org.apache.aurora.scheduler.MesosTaskFactory;
+import org.apache.aurora.scheduler.ResourceSlot;
+import org.apache.aurora.scheduler.base.Tasks;
+import org.apache.aurora.scheduler.filter.SchedulingFilter;
+import org.apache.aurora.scheduler.filter.SchedulingFilter.Veto;
+import org.apache.aurora.scheduler.state.TaskAssigner.TaskAssignerImpl;
+import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
+import org.apache.mesos.Protos.FrameworkID;
+import org.apache.mesos.Protos.Offer;
+import org.apache.mesos.Protos.OfferID;
+import org.apache.mesos.Protos.Resource;
+import org.apache.mesos.Protos.SlaveID;
+import org.apache.mesos.Protos.TaskID;
+import org.apache.mesos.Protos.TaskInfo;
+import org.apache.mesos.Protos.Value.Range;
+import org.apache.mesos.Protos.Value.Ranges;
+import org.apache.mesos.Protos.Value.Type;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+
+public class TaskAssignerImplTest extends EasyMockTest {
+
+  private static final int PORT = 5000;
+  private static final Offer OFFER = Offer.newBuilder()
+      .setId(OfferID.newBuilder().setValue("offerId"))
+      .setFrameworkId(FrameworkID.newBuilder().setValue("frameworkId"))
+      .setSlaveId(SlaveID.newBuilder().setValue("slaveId"))
+      .setHostname("hostName")
+      .addResources(Resource.newBuilder()
+          .setName("ports")
+          .setType(Type.RANGES)
+          .setRanges(
+              Ranges.newBuilder().addRange(Range.newBuilder().setBegin(PORT).setEnd(PORT))))
+      .build();
+  private static final IScheduledTask TASK = IScheduledTask.build(
+      new ScheduledTask()
+          .setAssignedTask(new AssignedTask()
+              .setTaskId("taskId")
+              .setTask(new TaskConfig()
+                  .setExecutorConfig(new ExecutorConfig().setData("opaque data"))
+                  .setRequestedPorts(ImmutableSet.of("http")))));
+  private static final TaskInfo TASK_INFO = TaskInfo.newBuilder()
+      .setName("taskName")
+      .setTaskId(TaskID.newBuilder().setValue(Tasks.id(TASK)))
+      .setSlaveId(OFFER.getSlaveId())
+      .build();
+
+  private StateManager stateManager;
+  private SchedulingFilter filter;
+  private MesosTaskFactory taskFactory;
+  private TaskAssigner assigner;
+
+  @Before
+  public void setUp() throws Exception {
+    stateManager = createMock(StateManager.class);
+    filter = createMock(SchedulingFilter.class);
+    taskFactory = createMock(MesosTaskFactory.class);
+    assigner = new TaskAssignerImpl(stateManager, filter, taskFactory);
+  }
+
+  @Test
+  public void testAssignNoVetoes() {
+    expect(filter.filter(
+        ResourceSlot.from(OFFER),
+        OFFER.getHostname(),
+        TASK.getAssignedTask().getTask(),
+        Tasks.id(TASK)))
+        .andReturn(ImmutableSet.<Veto>of());
+    expect(stateManager.assignTask(
+        Tasks.id(TASK),
+        OFFER.getHostname(),
+        OFFER.getSlaveId(),
+        ImmutableSet.of(PORT)))
+        .andReturn(TASK.getAssignedTask());
+    expect(taskFactory.createFrom(TASK.getAssignedTask(), OFFER.getSlaveId())).andReturn(TASK_INFO);
+
+    control.replay();
+
+    assertEquals(Optional.of(TASK_INFO), assigner.maybeAssign(OFFER, TASK));
+  }
+
+
+  @Test
+  public void testAssignVetoes() {
+    expect(filter.filter(
+        ResourceSlot.from(OFFER),
+        OFFER.getHostname(),
+        TASK.getAssignedTask().getTask(),
+        Tasks.id(TASK)))
+        .andReturn(ImmutableSet.of(Veto.constraintMismatch("denied")));
+
+    control.replay();
+
+    assertEquals(Optional.<TaskInfo>absent(), assigner.maybeAssign(OFFER, TASK));
+  }
+}


Mime
View raw message