Skip to content

Commit

Permalink
[FLINK-7773] [tests] Fix unfinished stubbing in UtilsTest
Browse files Browse the repository at this point in the history
The problem seemed to be that the TestingContainer dynamically stubbed the
ContainerId and the NodeId. I assume that this could happen concurrently
to mocking the nodeManagerClient which would cause the unfinished stubbing
exception.
  • Loading branch information
tillrohrmann committed Nov 1, 2017
1 parent 358aacd commit a7e0a27
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions flink-yarn/src/test/java/org/apache/flink/yarn/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import akka.actor.PoisonPill;
import akka.actor.Props;
import akka.testkit.JavaTestKit;
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.api.records.Container;
import org.apache.hadoop.yarn.api.records.ContainerId;
import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
Expand Down Expand Up @@ -71,7 +73,6 @@
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* Tests for {@link Utils}.
Expand Down Expand Up @@ -117,7 +118,7 @@ public void testYarnFlinkResourceManagerJobManagerLostLeadership() throws Except
final List<Container> containerList = new ArrayList<>();

for (int i = 0; i < numInitialTaskManagers; i++) {
containerList.add(new TestingContainer("container_" + i, "localhost"));
containerList.add(new TestingContainer("container", 1234, i));
}

doAnswer(new Answer() {
Expand Down Expand Up @@ -223,19 +224,22 @@ public Object answer(InvocationOnMock invocation) throws Throwable {

static class TestingContainer extends Container {

private final String id;
private final String host;

TestingContainer(String id, String host) {
this.id = id;
this.host = host;
private final NodeId nodeId;
private final ContainerId containerId;

TestingContainer(String host, int port, int containerId) {
this.nodeId = NodeId.newInstance(host, port);
this.containerId = ContainerId.newInstance(
ApplicationAttemptId.newInstance(
ApplicationId.newInstance(
System.currentTimeMillis(),
1),
1),
containerId);
}

@Override
public ContainerId getId() {
ContainerId containerId = mock(ContainerId.class);
when(containerId.toString()).thenReturn(id);

return containerId;
}

Expand All @@ -246,9 +250,6 @@ public void setId(ContainerId containerId) {

@Override
public NodeId getNodeId() {
NodeId nodeId = mock(NodeId.class);
when(nodeId.getHost()).thenReturn(host);

return nodeId;
}

Expand Down

0 comments on commit a7e0a27

Please sign in to comment.