Skip to content

Commit

Permalink
Merge pull request #159 from MarkEWaite/improve-NodeLabelCache-coverage
Browse files Browse the repository at this point in the history
Cover NodeLabelCache case when computer is null
  • Loading branch information
MarkEWaite authored Feb 8, 2020
2 parents 35025b8 + 95f22fb commit 66ca8cc
Showing 1 changed file with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import hudson.slaves.RetentionStrategy;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -85,6 +86,13 @@ public void testCacheLabelsNullingComputer() throws Exception {
nodeLabelCache.cacheLabels(nullingComputer);
}

@Test
public void testGetLabelsForNode_IsNull() throws Exception {
Node nullingNode = new NullingNode();
Collection<LabelAtom> labels = nodeLabelCache.getLabelsForNode(nullingNode);
assertThat(labels, is(empty()));
}

/** Class that intentionally returns nulls for test purposes. */
private class NullingComputer extends Computer {

Expand Down Expand Up @@ -140,4 +148,61 @@ public RetentionStrategy getRetentionStrategy() {
throw new UnsupportedOperationException("Unsupported");
}
}

private class NullingNode extends Node {
public hudson.remoting.Callable<hudson.util.ClockDifference, IOException>
getClockDifferenceCallable() {
throw new UnsupportedOperationException("Unsupported");
}

public hudson.slaves.NodeDescriptor getDescriptor() {
throw new UnsupportedOperationException("Unsupported");
}

public hudson.util.DescribableList<
hudson.slaves.NodeProperty<?>, hudson.slaves.NodePropertyDescriptor>
getNodeProperties() {
throw new UnsupportedOperationException("Unsupported");
}

public hudson.FilePath getRootPath() {
throw new UnsupportedOperationException("Unsupported");
}

public hudson.FilePath getWorkspaceFor(hudson.model.TopLevelItem item) {
throw new UnsupportedOperationException("Unsupported");
}

public String getLabelString() {
throw new UnsupportedOperationException("Unsupported");
}

public Computer createComputer() {
throw new UnsupportedOperationException("Unsupported");
}

public Node.Mode getMode() {
throw new UnsupportedOperationException("Unsupported");
}

public int getNumExecutors() {
throw new UnsupportedOperationException("Unsupported");
}

public hudson.Launcher createLauncher(TaskListener listener) {
throw new UnsupportedOperationException("Unsupported");
}

public String getNodeDescription() {
throw new UnsupportedOperationException("Unsupported");
}

public void setNodeName(String name) {
throw new UnsupportedOperationException("Unsupported");
}

public String getNodeName() {
throw new UnsupportedOperationException("Unsupported");
}
}
}

0 comments on commit 66ca8cc

Please sign in to comment.