mirror of https://github.com/apache/jclouds.git
fixed live tests
This commit is contained in:
parent
20b46f6757
commit
5b16a80d2d
|
@ -70,18 +70,20 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
||||||
try {
|
try {
|
||||||
AWSError error = null;
|
AWSError error = null;
|
||||||
String message = null;
|
String message = null;
|
||||||
if (response.getPayload().getContentType() != null
|
if (response.getPayload() != null) {
|
||||||
&& (response.getPayload().getContentType().indexOf("xml") != -1 || response.getPayload()
|
if (response.getPayload().getContentType() != null
|
||||||
.getContentType().indexOf("unknown") != -1)) {
|
&& (response.getPayload().getContentType().indexOf("xml") != -1 || response.getPayload()
|
||||||
error = utils.parseAWSErrorFromContent(request, response);
|
.getContentType().indexOf("unknown") != -1)) {
|
||||||
if (error != null) {
|
error = utils.parseAWSErrorFromContent(request, response);
|
||||||
message = error.getMessage();
|
if (error != null) {
|
||||||
exception = new AWSResponseException(command, response, error);
|
message = error.getMessage();
|
||||||
}
|
exception = new AWSResponseException(command, response, error);
|
||||||
} else {
|
}
|
||||||
try {
|
} else {
|
||||||
message = Utils.toStringAndClose(response.getPayload().getInput());
|
try {
|
||||||
} catch (IOException e) {
|
message = Utils.toStringAndClose(response.getPayload().getInput());
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
|
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
|
||||||
|
|
|
@ -54,4 +54,29 @@ public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> imple
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (!super.equals(obj))
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
ComputeMetadataImpl other = (ComputeMetadataImpl) obj;
|
||||||
|
if (id == null) {
|
||||||
|
if (other.id != null)
|
||||||
|
return false;
|
||||||
|
} else if (!id.equals(other.id))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,9 @@ import static com.google.common.base.Throwables.getRootCause;
|
||||||
import static com.google.common.collect.Iterables.concat;
|
import static com.google.common.collect.Iterables.concat;
|
||||||
import static com.google.common.collect.Iterables.get;
|
import static com.google.common.collect.Iterables.get;
|
||||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||||
|
import static com.google.common.collect.Maps.newLinkedHashMap;
|
||||||
|
import static com.google.common.collect.Maps.uniqueIndex;
|
||||||
import static com.google.common.collect.Sets.filter;
|
import static com.google.common.collect.Sets.filter;
|
||||||
import static com.google.common.collect.Sets.newLinkedHashSet;
|
|
||||||
import static com.google.common.collect.Sets.newTreeSet;
|
import static com.google.common.collect.Sets.newTreeSet;
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.overrideCredentialsWith;
|
import static org.jclouds.compute.options.RunScriptOptions.Builder.overrideCredentialsWith;
|
||||||
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
|
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
|
||||||
|
@ -42,6 +43,7 @@ import static org.testng.Assert.assertNotNull;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -81,6 +83,7 @@ import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
@ -197,19 +200,37 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
// wait up to 5 seconds for an auth exception
|
// wait up to 5 seconds for an auth exception
|
||||||
@Test(enabled = true, expectedExceptions = AuthorizationException.class)
|
@Test(enabled = true, expectedExceptions = AuthorizationException.class)
|
||||||
public void testCorrectAuthException() throws Exception {
|
public void testCorrectAuthException() throws Exception {
|
||||||
ComputeServiceContext context = null;
|
synchronized (ComputeServiceContext.class) {
|
||||||
try {
|
ComputeServiceContext context = null;
|
||||||
context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", ImmutableSet
|
// system properties override crendentials passed
|
||||||
.<Module> of(new Log4JLoggingModule()));
|
// if in the form provider.identity, provider.credential
|
||||||
context.getComputeService().listNodes();
|
// we want this to fail, so we save off old state and reset those
|
||||||
} finally {
|
// properties to garbage.
|
||||||
if (context != null)
|
String oldIdentity = System.getProperty(provider + ".identity");
|
||||||
context.close();
|
String oldCredential = System.getProperty(provider + ".credential");
|
||||||
|
try {
|
||||||
|
System.setProperty(provider + ".identity", "MOMMA");
|
||||||
|
System.setProperty(provider + ".credential", "MIA");
|
||||||
|
context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", ImmutableSet
|
||||||
|
.<Module> of(new Log4JLoggingModule()));
|
||||||
|
context.getComputeService().listNodes();
|
||||||
|
} catch (AuthorizationException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (oldIdentity != null)
|
||||||
|
System.setProperty(provider + ".identity", oldIdentity);
|
||||||
|
if (oldCredential != null)
|
||||||
|
System.setProperty(provider + ".credential", oldCredential);
|
||||||
|
if (context != null)
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = true, dependsOnMethods = "testCorrectAuthException")
|
@Test(enabled = true)
|
||||||
public void testImagesCache() throws Exception {
|
public void testImagesCache() throws Exception {
|
||||||
client.listImages();
|
client.listImages();
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
|
@ -374,10 +395,18 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
|
|
||||||
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
|
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
|
||||||
public void testGet() throws Exception {
|
public void testGet() throws Exception {
|
||||||
Set<? extends NodeMetadata> nodes = client.listNodesDetailsMatching(all());
|
Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(filter(client
|
||||||
Set<? extends NodeMetadata> metadataSet = newLinkedHashSet(filter(nodes, and(withTag(tag), not(TERMINATED))));
|
.listNodesDetailsMatching(all()), and(withTag(tag), not(TERMINATED))),
|
||||||
|
new Function<NodeMetadata, String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apply(NodeMetadata from) {
|
||||||
|
return from.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
}));
|
||||||
for (NodeMetadata node : nodes) {
|
for (NodeMetadata node : nodes) {
|
||||||
metadataSet.remove(node);
|
metadataMap.remove(node.getId());
|
||||||
NodeMetadata metadata = client.getNodeMetadata(node.getId());
|
NodeMetadata metadata = client.getNodeMetadata(node.getId());
|
||||||
assertEquals(metadata.getProviderId(), node.getProviderId());
|
assertEquals(metadata.getProviderId(), node.getProviderId());
|
||||||
assertEquals(metadata.getTag(), node.getTag());
|
assertEquals(metadata.getTag(), node.getTag());
|
||||||
|
@ -388,10 +417,10 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
assertEquals(metadata.getPrivateAddresses(), node.getPrivateAddresses());
|
assertEquals(metadata.getPrivateAddresses(), node.getPrivateAddresses());
|
||||||
assertEquals(metadata.getPublicAddresses(), node.getPublicAddresses());
|
assertEquals(metadata.getPublicAddresses(), node.getPublicAddresses());
|
||||||
}
|
}
|
||||||
assertNodeZero(metadataSet);
|
assertNodeZero(metadataMap.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertNodeZero(Set<? extends NodeMetadata> metadataSet) {
|
protected void assertNodeZero(Collection<? extends NodeMetadata> metadataSet) {
|
||||||
assert metadataSet.size() == 0 : String.format("nodes left in set: [%s] which didn't match set: [%s]",
|
assert metadataSet.size() == 0 : String.format("nodes left in set: [%s] which didn't match set: [%s]",
|
||||||
metadataSet, nodes);
|
metadataSet, nodes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import static com.google.common.collect.Iterables.transform;
|
||||||
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
|
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -67,21 +68,25 @@ public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp,
|
||||||
public Hardware apply(VCloudExpressVApp from) {
|
public Hardware apply(VCloudExpressVApp from) {
|
||||||
checkNotNull(from, "VApp");
|
checkNotNull(from, "VApp");
|
||||||
Location location = findLocationForResource.apply(checkNotNull(from, "from").getVDC());
|
Location location = findLocationForResource.apply(checkNotNull(from, "from").getVDC());
|
||||||
|
try {
|
||||||
|
int ram = (int) find(from.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity();
|
||||||
|
|
||||||
int ram = (int) find(from.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity();
|
List<Processor> processors = Lists.newArrayList(transform(filter(from.getResourceAllocations(),
|
||||||
|
resourceType(ResourceType.PROCESSOR)), new Function<ResourceAllocation, Processor>() {
|
||||||
|
|
||||||
List<Processor> processors = Lists.newArrayList(transform(filter(from.getResourceAllocations(),
|
@Override
|
||||||
resourceType(ResourceType.PROCESSOR)), new Function<ResourceAllocation, Processor>() {
|
public Processor apply(ResourceAllocation arg0) {
|
||||||
|
return new Processor(arg0.getVirtualQuantity(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
}));
|
||||||
public Processor apply(ResourceAllocation arg0) {
|
Iterable<? extends Volume> volumes = resourceAllocationsToVolumes.apply(from.getResourceAllocations());
|
||||||
return new Processor(arg0.getVirtualQuantity(), 1);
|
return new HardwareImpl(from.getHref().toASCIIString(), from.getName(), from.getHref().toASCIIString(),
|
||||||
}
|
location, null, ImmutableMap.<String, String> of(), processors, ram, volumes, ImagePredicates
|
||||||
|
.idEquals(from.getHref().toASCIIString()));
|
||||||
}));
|
} catch (NoSuchElementException e) {
|
||||||
Iterable<? extends Volume> volumes = resourceAllocationsToVolumes.apply(from.getResourceAllocations());
|
logger.debug("incomplete data to form vApp %s", from.getHref());
|
||||||
return new HardwareImpl(from.getHref().toASCIIString(), from.getName(), from.getHref().toASCIIString(), location,
|
return null;
|
||||||
null, ImmutableMap.<String, String> of(), processors, ram, volumes, ImagePredicates.idEquals(from
|
}
|
||||||
.getHref().toASCIIString()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue