jeongyooneo commented on a change in pull request #27: [NEMO-49] Replace failed executor with a new executor URL: https://github.com/apache/incubator-nemo/pull/27#discussion_r192939528
########## File path: runtime/master/src/test/java/edu/snu/nemo/runtime/master/ContainerManagerTest.java ########## @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2017 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.runtime.master; + +import edu.snu.nemo.common.ir.vertex.executionproperty.ExecutorPlacementProperty; +import edu.snu.nemo.conf.JobConf; +import edu.snu.nemo.runtime.common.message.MessageEnvironment; +import edu.snu.nemo.runtime.master.resource.ContainerManager; +import edu.snu.nemo.runtime.master.resource.ResourceSpecification; +import org.apache.reef.driver.catalog.NodeDescriptor; +import org.apache.reef.driver.context.ActiveContext; +import org.apache.reef.driver.evaluator.AllocatedEvaluator; +import org.apache.reef.driver.evaluator.EvaluatorDescriptor; +import org.apache.reef.driver.evaluator.EvaluatorRequestor; +import org.apache.reef.tang.Configuration; +import org.apache.reef.tang.Injector; +import org.apache.reef.tang.Tang; +import org.apache.reef.tang.exceptions.InjectionException; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.IntStream; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Tests {@link edu.snu.nemo.runtime.master.resource.ContainerManager}. + */ +public final class ContainerManagerTest { + private static final ResourceSpecification RESOURCE_SPEC_A = + new ResourceSpecification(ExecutorPlacementProperty.COMPUTE, 1, 1024); + private static final ResourceSpecification RESOURCE_SPEC_B = + new ResourceSpecification(ExecutorPlacementProperty.TRANSIENT, 2, 2048); + private static final ResourceSpecification RESOURCE_SPEC_C = + new ResourceSpecification(ExecutorPlacementProperty.RESERVED, 3, 3072); + + private ContainerManager containerManager; + private AtomicInteger testIdNumber = new AtomicInteger(0); + + private String getNodeName() { + return "NODE-" + testIdNumber.incrementAndGet(); + } + + private String getEvaluatorId() { + return "EVALUATOR-" + testIdNumber.incrementAndGet(); + } + + private String getExecutorId() { + return "EXECUTOR-" + testIdNumber.incrementAndGet(); + } + + @Before + public void setUp() throws InjectionException { + + final MessageEnvironment mockMsgEnv = mock(MessageEnvironment.class); + when(mockMsgEnv.asyncConnect(anyString(), anyString())).thenReturn(mock(Future.class)); + final Configuration configuration = Tang.Factory.getTang().newConfigurationBuilder() + .bindNamedParameter(JobConf.ScheduleSerThread.class, "1") + .build(); + final Injector injector = Tang.Factory.getTang().newInjector(configuration); + injector.bindVolatileInstance(EvaluatorRequestor.class, mock(EvaluatorRequestor.class)); + injector.bindVolatileInstance(MessageEnvironment.class, mockMsgEnv); + containerManager = injector.getInstance(ContainerManager.class); + } + + @Test + public void testRequestAllocateLaunch() { + // Create 2 of A, 2 of B and 1 of C. + final Map<Integer, ResourceSpecification> numToSpec = new HashMap(); + numToSpec.put(2, RESOURCE_SPEC_A); + numToSpec.put(2, RESOURCE_SPEC_B); + numToSpec.put(1, RESOURCE_SPEC_C); + + // Request -> Allocate -> Launch + for (final Map.Entry<Integer, ResourceSpecification> entry : numToSpec.entrySet()) { + final int num = entry.getKey(); + final ResourceSpecification spec = entry.getValue(); + containerManager.requestContainer(num, spec); + + IntStream.range(0, num).forEach(n -> { + final String evaluatorId = getEvaluatorId(); + final String executorId = getExecutorId(); + final EvaluatorDescriptor descriptor = createDescriptor(spec); + + containerManager.onContainerAllocated( + executorId, + createMockEvaluator(evaluatorId, descriptor), + mock(Configuration.class)); + containerManager.onContainerLaunched(createMockContext(executorId, descriptor)); + }); Review comment: There is no code to check whether this test passes or fails(ex. `assertEquals`). Is it enough to just call `onContainerRequested` - `onContainerAllocated` - `onContainerLaunched`? ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
