NodePredicates gained static predicate SUSPENDED

Replaced hard-coded Strings in toString methods of static predicates with their enum.toString counterparts

Added test 'testNodeRunningFailsOnSuspended'

Revert "Added test 'testNodeRunningFailsOnSuspended'"

This reverts commit 2a543bfe20540bb4f10ef4f86e845a63bdbe90e3.

Removed test 'testNodeRunningFailsOnSuspended'. Added test 'testNodeSuspendedReturnsTrueWhenSuspended'.

Renamed '

Revert "Renamed '"

This reverts commit 061e9292a812066562ab47ba5eea15337fc13c3d.

Renamed 'AtomicNodeSuspended.nodeRunning' to 'AtomicNodeSuspended.nodeSuspended'.\nWhere applicable combined all calls to 'replay(Object...)' instead of the old 'replay(node);replay(computeService);'
This commit is contained in:
Christopher Dancy 2014-06-12 11:33:49 -04:00 committed by Everett Toews
parent e799a7409c
commit ea68554244
2 changed files with 32 additions and 8 deletions

View File

@ -252,7 +252,7 @@ public class NodePredicates {
@Override @Override
public String toString() { public String toString() {
return "RUNNING"; return Status.RUNNING.toString();
} }
}; };
@ -267,7 +267,22 @@ public class NodePredicates {
@Override @Override
public String toString() { public String toString() {
return "TERMINATED"; return Status.TERMINATED.toString();
}
};
/**
* Match nodes with State == SUSPENDED
*/
public static final Predicate<NodeMetadata> SUSPENDED = new Predicate<NodeMetadata>() {
@Override
public boolean apply(NodeMetadata nodeMetadata) {
return nodeMetadata.getStatus() == Status.SUSPENDED;
}
@Override
public String toString() {
return Status.SUSPENDED.toString();
} }
}; };

View File

@ -133,21 +133,31 @@ public class AtomicNodePredicatesTest {
public void testNodeRunningReturnsTrueWhenRunning() { public void testNodeRunningReturnsTrueWhenRunning() {
expect(node.getStatus()).andReturn(Status.RUNNING).atLeastOnce(); expect(node.getStatus()).andReturn(Status.RUNNING).atLeastOnce();
expect(node.getBackendStatus()).andReturn(null).atLeastOnce(); expect(node.getBackendStatus()).andReturn(null).atLeastOnce();
replay(node); replay(node, computeService);
replay(computeService);
AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService);
AtomicReference<NodeMetadata> reference = Atomics.newReference(node); AtomicReference<NodeMetadata> reference = Atomics.newReference(node);
Assert.assertTrue(nodeRunning.apply(reference)); Assert.assertTrue(nodeRunning.apply(reference));
Assert.assertEquals(reference.get(), node); 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<NodeMetadata> reference = Atomics.newReference(node);
Assert.assertTrue(nodeSuspended.apply(reference));
Assert.assertEquals(reference.get(), node);
}
@Test(expectedExceptions = IllegalStateException.class) @Test(expectedExceptions = IllegalStateException.class)
public void testNodeRunningFailsOnTerminated() { public void testNodeRunningFailsOnTerminated() {
expect(node.getStatus()).andReturn(Status.TERMINATED).atLeastOnce(); expect(node.getStatus()).andReturn(Status.TERMINATED).atLeastOnce();
expect(node.getBackendStatus()).andReturn(null).atLeastOnce(); expect(node.getBackendStatus()).andReturn(null).atLeastOnce();
replay(node); replay(node, computeService);
replay(computeService);
AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService);
AtomicReference<NodeMetadata> reference = Atomics.newReference(node); AtomicReference<NodeMetadata> reference = Atomics.newReference(node);
@ -159,8 +169,7 @@ public class AtomicNodePredicatesTest {
public void testNodeRunningFailsOnError() { public void testNodeRunningFailsOnError() {
expect(node.getStatus()).andReturn(Status.ERROR).atLeastOnce(); expect(node.getStatus()).andReturn(Status.ERROR).atLeastOnce();
expect(node.getBackendStatus()).andReturn(null).atLeastOnce(); expect(node.getBackendStatus()).andReturn(null).atLeastOnce();
replay(node); replay(node, computeService);
replay(computeService);
AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService);
AtomicReference<NodeMetadata> reference = Atomics.newReference(node); AtomicReference<NodeMetadata> reference = Atomics.newReference(node);