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 65d2a3f0ef..70d1590d8e 100644 --- a/compute/src/main/java/org/jclouds/compute/predicates/NodePredicates.java +++ b/compute/src/main/java/org/jclouds/compute/predicates/NodePredicates.java @@ -254,7 +254,7 @@ public class NodePredicates { @Override public String toString() { - return "RUNNING"; + return Status.RUNNING.toString(); } }; @@ -269,7 +269,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 f4e969d56b..2e056dcac7 100644 --- a/compute/src/test/java/org/jclouds/compute/predicates/AtomicNodePredicatesTest.java +++ b/compute/src/test/java/org/jclouds/compute/predicates/AtomicNodePredicatesTest.java @@ -135,21 +135,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); @@ -161,8 +171,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);