diff --git a/compute/src/main/java/org/jclouds/compute/predicates/NodePredicates.java b/compute/src/main/java/org/jclouds/compute/predicates/NodePredicates.java index 0bc54aaaad..65a4d72de1 100644 --- a/compute/src/main/java/org/jclouds/compute/predicates/NodePredicates.java +++ b/compute/src/main/java/org/jclouds/compute/predicates/NodePredicates.java @@ -252,7 +252,7 @@ public class NodePredicates { @Override public String toString() { - return "RUNNING"; + return Status.RUNNING.toString(); } }; @@ -267,7 +267,22 @@ public class NodePredicates { @Override public String toString() { - return "TERMINATED"; + return Status.TERMINATED.toString(); + } + }; + + /** + * Match nodes with State == SUSPENDED + */ + public static final Predicate SUSPENDED = new Predicate() { + @Override + public boolean apply(NodeMetadata nodeMetadata) { + return nodeMetadata.getStatus() == Status.SUSPENDED; + } + + @Override + public String toString() { + return Status.SUSPENDED.toString(); } }; diff --git a/compute/src/test/java/org/jclouds/compute/predicates/AtomicNodePredicatesTest.java b/compute/src/test/java/org/jclouds/compute/predicates/AtomicNodePredicatesTest.java index cd21be4a35..b5c10c9c2f 100644 --- a/compute/src/test/java/org/jclouds/compute/predicates/AtomicNodePredicatesTest.java +++ b/compute/src/test/java/org/jclouds/compute/predicates/AtomicNodePredicatesTest.java @@ -133,21 +133,31 @@ public class AtomicNodePredicatesTest { public void testNodeRunningReturnsTrueWhenRunning() { expect(node.getStatus()).andReturn(Status.RUNNING).atLeastOnce(); expect(node.getBackendStatus()).andReturn(null).atLeastOnce(); - replay(node); - replay(computeService); + replay(node, computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); AtomicReference reference = Atomics.newReference(node); Assert.assertTrue(nodeRunning.apply(reference)); Assert.assertEquals(reference.get(), node); } + + @Test + public void testNodeSuspendedReturnsTrueWhenSuspended() { + expect(node.getStatus()).andReturn(Status.SUSPENDED).atLeastOnce(); + expect(node.getBackendStatus()).andReturn(null).atLeastOnce(); + replay(node, computeService); + + AtomicNodeSuspended nodeSuspended = new AtomicNodeSuspended(computeService); + AtomicReference reference = Atomics.newReference(node); + Assert.assertTrue(nodeSuspended.apply(reference)); + Assert.assertEquals(reference.get(), node); + } @Test(expectedExceptions = IllegalStateException.class) public void testNodeRunningFailsOnTerminated() { expect(node.getStatus()).andReturn(Status.TERMINATED).atLeastOnce(); expect(node.getBackendStatus()).andReturn(null).atLeastOnce(); - replay(node); - replay(computeService); + replay(node, computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); AtomicReference reference = Atomics.newReference(node); @@ -159,8 +169,7 @@ public class AtomicNodePredicatesTest { public void testNodeRunningFailsOnError() { expect(node.getStatus()).andReturn(Status.ERROR).atLeastOnce(); expect(node.getBackendStatus()).andReturn(null).atLeastOnce(); - replay(node); - replay(computeService); + replay(node, computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); AtomicReference reference = Atomics.newReference(node);