Github user tweise commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-core/pull/98#discussion_r41456132
  
    --- Diff: 
engine/src/test/java/com/datatorrent/stram/StreamingAppMasterServiceTest.java 
---
    @@ -0,0 +1,319 @@
    +package com.datatorrent.stram;
    +
    +import static org.mockito.Matchers.any;
    +import static org.mockito.Mockito.doAnswer;
    +import static org.mockito.Mockito.doReturn;
    +import static org.mockito.Mockito.mock;
    +import static org.mockito.Mockito.spy;
    +import static org.mockito.Mockito.when;
    +
    +import java.io.File;
    +import java.io.IOException;
    +import java.nio.ByteBuffer;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.Iterator;
    +import java.util.List;
    +
    +import org.apache.commons.io.FileUtils;
    +import org.apache.hadoop.conf.Configuration;
    +import org.apache.hadoop.fs.Path;
    +import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse;
    +import 
org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse;
    +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
    +import org.apache.hadoop.yarn.api.records.Container;
    +import org.apache.hadoop.yarn.api.records.ContainerId;
    +import org.apache.hadoop.yarn.api.records.ContainerState;
    +import org.apache.hadoop.yarn.api.records.ContainerStatus;
    +import org.apache.hadoop.yarn.api.records.NodeId;
    +import org.apache.hadoop.yarn.api.records.Priority;
    +import org.apache.hadoop.yarn.api.records.Resource;
    +import org.apache.hadoop.yarn.api.records.Token;
    +import org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest;
    +import org.apache.hadoop.yarn.client.api.impl.AMRMClientImpl;
    +import org.apache.hadoop.yarn.conf.YarnConfiguration;
    +import org.junit.After;
    +import org.junit.Assert;
    +import org.junit.Before;
    +import org.junit.Test;
    +import org.mockito.invocation.InvocationOnMock;
    +import org.mockito.stubbing.Answer;
    +
    +import com.datatorrent.api.DAG;
    +import com.datatorrent.common.util.AsyncFSStorageAgent;
    +import com.datatorrent.netlet.util.DTThrowable;
    +import com.datatorrent.stram.engine.OperatorContext;
    +import com.datatorrent.stram.engine.TestGeneratorInputOperator;
    +import com.datatorrent.stram.plan.logical.LogicalPlan;
    +import com.datatorrent.stram.support.StramTestSupport;
    +
    +public class StreamingAppMasterServiceTest
    +{
    +  private static File CLUSTER_WORK_DIR = new File("target", 
StreamingAppMasterServiceTest.class.getName());
    +  StreamingAppMasterService appMaster;
    +  StreamingAppMasterService mockedAppMaster;
    +  Configuration conf;
    +  int containerCount = 1;
    +  ApplicationAttemptId appAttemptID;
    +  int priority = 0;
    +  List<ContainerId> containerIds = new ArrayList<>();
    +  List<String> containerHostnames = Arrays.asList("node1", "node1", 
"node1", "node2");
    +  List<Integer> containerExitCodes = Arrays.asList(-100, -100, -100, -100);
    +  Iterator<String> hostnameIterator;
    +  Iterator<Integer> exitCodeIterator;
    +
    +  @Before
    +  public void setupEachTime() throws Exception
    +  {
    +    hostnameIterator = containerHostnames.iterator();
    +    exitCodeIterator = containerExitCodes.iterator();
    +
    +    StramAppContext appContext = new StramTestSupport.TestAppContext(1, 
10, 10, 10);
    +    appAttemptID = appContext.getApplicationAttemptId();
    +    appMaster = new StreamingAppMasterService(appAttemptID);
    +    conf = new YarnConfiguration();
    +
    +    RegisterApplicationMasterResponse response = 
mock(RegisterApplicationMasterResponse.class);
    +    Resource resource = mock(Resource.class);
    +    when(resource.getMemory()).thenReturn(1024);
    +    when(resource.getVirtualCores()).thenReturn(10);
    +
    +    when(response.getMaximumResourceCapability()).thenReturn(resource);
    +
    +    ResourceRequestHandler resourceRequestor = new 
ResourceRequestHandler();
    +    AMRMClientImpl<ContainerRequest> client = mock(AMRMClientImpl.class);
    +    AllocateResponse allocateResponse = mock(AllocateResponse.class);
    +    when(client.allocate(0)).thenReturn(allocateResponse);
    +
    +    
doReturn(response).when(client).registerApplicationMaster(any(String.class), 
any(int.class), any(String.class));
    +
    +    doAnswer(new Answer<List<ContainerStatus>>()
    +    {
    +      public List<ContainerStatus> answer(InvocationOnMock invocation)
    +      {
    +        return getListOfContainerStatuses();
    +      }
    +    }).when(allocateResponse).getCompletedContainersStatuses();
    +
    +    doAnswer(new Answer<List<Container>>()
    +    {
    +      public List<Container> answer(InvocationOnMock invocation)
    +      {
    +        return getListOfContainers();
    +      }
    +    }).when(allocateResponse).getAllocatedContainers();
    +
    +    appMaster.setAmRmClient(client);
    +
    +    mockedAppMaster = spy(appMaster);
    +    LaunchContainerRunnable obj = mock(LaunchContainerRunnable.class);
    +
    +    
doReturn(obj).when(mockedAppMaster).createLaunchContainerRunnable(any(Container.class),
 any(StreamingContainerAgent.class), any(ByteBuffer.class));
    +
    +    
doReturn(resourceRequestor).when(mockedAppMaster).createResourceRequestor();
    +    
doReturn(true).when(mockedAppMaster).setupRMService(any(Configuration.class), 
any(int.class), any(ResourceRequestHandler.class));
    +    when(mockedAppMaster.getConfig()).thenReturn(conf);
    +  }
    +
    +  @After
    +  public void teardown()
    +  {
    +  }
    +
    +  @Test
    +  public void testBlacklistingOfFailedNodes() throws Exception
    +  {
    +    LogicalPlan dag = setupDag();
    +    dag.setAttribute(LogicalPlan.MAX_CONSECUTIVE_CONTAINER_FAILURES, 3);
    +
    +    Thread thread = new Thread("LocalAMService")
    +    {
    +      @Override
    +      public void run()
    +      {
    +        long startTms = System.currentTimeMillis();
    +        long timeout = 50000L;
    +        try {
    +          while (mockedAppMaster.getBlacklistedNodes().isEmpty() && 
System.currentTimeMillis() - startTms < timeout) {
    +            Thread.sleep(500);
    +          }
    +        } catch (InterruptedException ex) {
    +          DTThrowable.rethrow(ex);
    +        } finally {
    +          mockedAppMaster.setAppDone(true);
    +        }
    +      }
    +    };
    +    thread.start();
    +
    +    mockedAppMaster.run();
    +    thread.join();
    +    Assert.assertEquals("Node1 should be blacklisted after 3 consecutive 
failures", "node1", mockedAppMaster.getBlacklistedNodes().get(0));
    +    Assert.assertEquals("Node1 should have 3 failures marked", 3, 
mockedAppMaster.getFailedContainersMap().get("node1").get());
    +  }
    +
    +  @Test
    +  public void testBlacklistedNodesAreRemovedAfterTimeout() throws Exception
    +  {
    +    LogicalPlan dag = setupDag();
    +    dag.setAttribute(LogicalPlan.BLACKLIST_REMOVAL_TIME, new Long(0));
    +
    +    final Thread thread = new Thread("LocalAMService")
    +    {
    +      @Override
    +      public void run()
    +      {
    +        long startTms = System.currentTimeMillis();
    +        long timeout = 50000L;
    --- End diff --
    
    What are the timeouts and sleep intervals derived from?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to