@SuppressWarnings("unchecked") @Test public void testDestroyNodeTerminatesInstanceAndReturnsRefreshedNode() throws Exception { EC2Api client = createMock(EC2Api.class); InstanceApi instanceClient = createMock(InstanceApi.class); GetNodeMetadataStrategy getNode = createMock(GetNodeMetadataStrategy.class); LoadingCache<RegionAndName, String> elasticIpCache = createMock(LoadingCache.class); NodeMetadata node = createMock(NodeMetadata.class); expect(client.getInstanceApi()).andReturn((Optional) Optional.of(instanceClient)).atLeastOnce(); expect(instanceClient.terminateInstancesInRegion("region", "i-blah")).andReturn(null); expect(getNode.getNode("region/i-blah")).andReturn(node); replay(client); replay(getNode); replay(instanceClient); replay(elasticIpCache); EC2DestroyNodeStrategy destroyer = new EC2DestroyNodeStrategy(client, getNode, elasticIpCache); assertEquals(destroyer.destroyNode("region/i-blah"), node); verify(client); verify(getNode); verify(instanceClient); verify(elasticIpCache); }
@Override public NodeMetadata destroyNode(String id) { String[] parts = AWSUtils.parseHandle(id); String region = parts[0]; String instanceId = parts[1]; releaseAnyPublicIpForInstanceInRegion(instanceId, region); destroyInstanceInRegion(instanceId, region); return getNode.getNode(id); }
EC2DestroyNodeStrategy implements DestroyNodeStrategy { @Override public NodeMetadata destroyNode(String id) { String[] parts = AWSUtils.parseHandle(id); String region = parts[0]; String instanceId = parts[1]; releaseAnyPublicIpForInstanceInRegion(instanceId, region); destroyInstanceInRegion(instanceId, region); return getNode.getNode(id); } }
EC2DestroyNodeStrategy implements DestroyNodeStrategy { @Override public NodeMetadata destroyNode(String id) { String[] parts = AWSUtils.parseHandle(id); String region = parts[0]; String instanceId = parts[1]; releaseAnyPublicIpForInstanceInRegion(instanceId, region); destroyInstanceInRegion(instanceId, region); return getNode.getNode(id); } @Inject protected  EC2DestroyNodeStrategy(EC2Api client, GetNodeMetadataStrategy getNode,
            @Named("ELASTICIP") LoadingCache<RegionAndName, String> elasticIpCache); }
EC2DestroyNodeStrategy implements DestroyNodeStrategy { @Override public NodeMetadata destroyNode(String id) { String[] parts = AWSUtils.parseHandle(id); String region = parts[0]; String instanceId = parts[1]; releaseAnyPublicIpForInstanceInRegion(instanceId, region); destroyInstanceInRegion(instanceId, region); return getNode.getNode(id); } @Inject protected  EC2DestroyNodeStrategy(EC2Api client, GetNodeMetadataStrategy getNode,
            @Named("ELASTICIP") LoadingCache<RegionAndName, String> elasticIpCache); @Override NodeMetadata destroyNode(String id); }
EC2DestroyNodeStrategy implements DestroyNodeStrategy { @Override public NodeMetadata destroyNode(String id) { String[] parts = AWSUtils.parseHandle(id); String region = parts[0]; String instanceId = parts[1]; releaseAnyPublicIpForInstanceInRegion(instanceId, region); destroyInstanceInRegion(instanceId, region); return getNode.getNode(id); } @Inject protected  EC2DestroyNodeStrategy(EC2Api client, GetNodeMetadataStrategy getNode,
            @Named("ELASTICIP") LoadingCache<RegionAndName, String> elasticIpCache); @Override NodeMetadata destroyNode(String id);  }