sanha commented on a change in pull request #1: [NEMO-26] Implement 
SourceLocationAwareSchedulingPolicy
URL: https://github.com/apache/incubator-nemo/pull/1#discussion_r173044113
 
 

 ##########
 File path: 
tests/src/test/java/edu/snu/nemo/tests/runtime/master/scheduler/SourceLocationAwareSchedulingPolicyTest.java
 ##########
 @@ -0,0 +1,418 @@
+/*
+ * Copyright (C) 2018 Seoul National University
+ *
+ * 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 edu.snu.nemo.tests.runtime.master.scheduler;
+
+import 
edu.snu.nemo.common.ir.vertex.executionproperty.ExecutorPlacementProperty;
+import edu.snu.nemo.runtime.common.plan.physical.ScheduledTaskGroup;
+import edu.snu.nemo.runtime.common.state.TaskGroupState;
+import edu.snu.nemo.common.ir.Readable;
+import edu.snu.nemo.runtime.master.JobStateManager;
+import edu.snu.nemo.runtime.master.scheduler.ExecutorRegistry;
+import edu.snu.nemo.runtime.master.resource.ExecutorRepresenter;
+import edu.snu.nemo.runtime.master.scheduler.RoundRobinSchedulingPolicy;
+import edu.snu.nemo.runtime.master.scheduler.SchedulingPolicy;
+import 
edu.snu.nemo.runtime.master.scheduler.SourceLocationAwareSchedulingPolicy;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.*;
+
+/**
+ * Test cases for
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({JobStateManager.class, ExecutorRepresenter.class, 
RoundRobinSchedulingPolicy.class,
+    ScheduledTaskGroup.class, Readable.class})
+public final class SourceLocationAwareSchedulingPolicyTest {
+  private static final String SITE_0 = "SEOUL";
+  private static final String SITE_1 = "JINJU";
+  private static final String SITE_2 = "BUSAN";
+  private static final int SCHEDULER_TIMEOUT_MS = 500;
+
+  private SourceLocationAwareSchedulingPolicy sourceLocationAware;
+  private SpiedSchedulingPolicyWrapper<RoundRobinSchedulingPolicy> roundRobin;
+  private MockJobStateManagerWrapper jobStateManager;
+
+  @Before
+  public void setup() throws InjectionException {
+    final Injector injector = Tang.Factory.getTang().newInjector();
+    jobStateManager = new MockJobStateManagerWrapper();
+
+    final ExecutorRegistry executorRegistry = new ExecutorRegistry();
+    final RoundRobinSchedulingPolicy roundRobinSchedulingPolicy =
+        new RoundRobinSchedulingPolicy(executorRegistry, SCHEDULER_TIMEOUT_MS);
+    roundRobin = new SpiedSchedulingPolicyWrapper(roundRobinSchedulingPolicy, 
jobStateManager.get());
+
+    injector.bindVolatileInstance(RoundRobinSchedulingPolicy.class, 
roundRobin.get());
+    injector.bindVolatileInstance(JobStateManager.class, 
jobStateManager.get());
+    injector.bindVolatileInstance(ExecutorRegistry.class, executorRegistry);
+    sourceLocationAware = 
injector.getInstance(SourceLocationAwareSchedulingPolicy.class);
+  }
+
+  @After
+  public void teardown() {
+    // All expectations should be resolved at this time.
+    roundRobin.ensureNoUnresolvedExpectation();
+  }
+
+  /**
+   * {@link SourceLocationAwareSchedulingPolicy} should delegate scheduling 
decision when the
+   * {@link ScheduledTaskGroup} does not have any source tasks.
+   */
+  @Test
+  public void testRoundRobinSchedulerFallback() {
+    // Prepare test scenario
+    final ScheduledTaskGroup tg0 = 
CreateScheduledTaskGroup.withoutReadables(ExecutorPlacementProperty.NONE);
+    final ScheduledTaskGroup tg1 = 
CreateScheduledTaskGroup.withReadablesWithoutSourceLocations(2,
+        ExecutorPlacementProperty.NONE);
+    final ScheduledTaskGroup tg2 = 
CreateScheduledTaskGroup.withReadablesWhichThrowException(5,
+        ExecutorPlacementProperty.NONE);
+    addExecutor(new MockExecutorRepresenterWrapper(SITE_0, 
ExecutorPlacementProperty.NONE, 1));
+    addExecutor(new MockExecutorRepresenterWrapper(SITE_1, 
ExecutorPlacementProperty.NONE, 1));
+
+    // Trying to schedule tg0: expected to fall back to 
RoundRobinSchedulingPolicy
+    roundRobin.expectSchedulingRequest(tg0);
+    // ...and scheduling attempt must success
+    assertTrue(sourceLocationAware.scheduleTaskGroup(tg0, 
jobStateManager.get()));
+    // ...thus the TaskGroup should be running
+    jobStateManager.assertTaskGroupState(tg0.getTaskGroupId(), 
TaskGroupState.State.EXECUTING);
+
+    // Trying to schedule tg1: expected to fall back to 
RoundRobinSchedulingPolicy
+    roundRobin.expectSchedulingRequest(tg1);
+    // ...and scheduling attempt must success
+    assertTrue(sourceLocationAware.scheduleTaskGroup(tg1, 
jobStateManager.get()));
+    // ...thus the TaskGroup should be running
+    jobStateManager.assertTaskGroupState(tg1.getTaskGroupId(), 
TaskGroupState.State.EXECUTING);
+
+    // Trying to schedule tg2: expected to fall back to 
RoundRobinSchedulingPolicy
+    roundRobin.expectSchedulingRequest(tg2);
+    // ...and scheduling attempt must success
+    assertTrue(sourceLocationAware.scheduleTaskGroup(tg2, 
jobStateManager.get()));
+    // ...thus the TaskGroup should be running
+    jobStateManager.assertTaskGroupState(tg2.getTaskGroupId(), 
TaskGroupState.State.EXECUTING);
+  }
+
+  /**
+   * {@link SourceLocationAwareSchedulingPolicy} should fail to schedule a 
{@link ScheduledTaskGroup} when
 
 Review comment:
   Please update this comment. What scenario did you mind?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to