Skip to content

Commit

Permalink
[hotfix][yarn][test] Avoid using Mockito for ContainerStatus in YarnR…
Browse files Browse the repository at this point in the history
…esourceManagerTest.
  • Loading branch information
xintongsong authored and tillrohrmann committed Apr 25, 2020
1 parent bdd3978 commit 8b2376a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* https://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.flink.yarn;

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.impl.pb.ContainerStatusPBImpl;

/**
* A {@link ContainerStatus} implementation for testing.
*/
class TestingContainerStatus extends ContainerStatusPBImpl {

private final ContainerId containerId;
private final ContainerState containerState;
private final String diagnostics;
private final int exitStatus;

TestingContainerStatus(
final ContainerId containerId,
final ContainerState containerState,
final String diagnostics,
final int exitStatus) {

this.containerId = containerId;
this.containerState = containerState;
this.diagnostics = diagnostics;
this.exitStatus = exitStatus;
}

@Override
public ContainerId getContainerId() {
return containerId;
}

@Override
public ContainerState getState() {
return containerState;
}

@Override
public int getExitStatus() {
return exitStatus;
}

@Override
public String getDiagnostics() {
return diagnostics;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
* General tests for the YARN resource manager component.
Expand Down Expand Up @@ -342,17 +341,10 @@ Container createTestingContainer() {
final NodeId nodeId = NodeId.newInstance("container", 1234);
return new TestingContainer(containerId, nodeId, resourceManager.getContainerResource(), Priority.UNDEFINED);
}
}

private static ContainerStatus mockContainerStatus(ContainerId containerId) {
ContainerStatus mockContainerStatus = mock(ContainerStatus.class);

when(mockContainerStatus.getContainerId()).thenReturn(containerId);
when(mockContainerStatus.getState()).thenReturn(ContainerState.COMPLETE);
when(mockContainerStatus.getDiagnostics()).thenReturn("Test exit");
when(mockContainerStatus.getExitStatus()).thenReturn(-1);

return mockContainerStatus;
ContainerStatus createTestingContainerStatus(final ContainerId containerId) {
return new TestingContainerStatus(containerId, ContainerState.COMPLETE, "Test exit", -1);
}
}

@Test
Expand Down Expand Up @@ -487,7 +479,7 @@ public void testOnContainerCompleted() throws Exception {

// Callback from YARN when container is Completed, pending request can not be fulfilled by pending
// containers, need to request new container.
ContainerStatus testingContainerStatus = mockContainerStatus(testingContainer.getId());
ContainerStatus testingContainerStatus = createTestingContainerStatus(testingContainer.getId());

resourceManager.onContainersCompleted(ImmutableList.of(testingContainerStatus));
verify(mockResourceManagerClient, VERIFICATION_TIMEOUT.times(2)).addContainerRequest(any(AMRMClient.ContainerRequest.class));
Expand Down

0 comments on commit 8b2376a

Please sign in to comment.