fixed live tests

This commit is contained in:
Adrian Cole 2010-09-16 07:05:07 -07:00
parent 20b46f6757
commit 5b16a80d2d
4 changed files with 102 additions and 41 deletions

View File

@ -70,6 +70,7 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
try {
AWSError error = null;
String message = null;
if (response.getPayload() != null) {
if (response.getPayload().getContentType() != null
&& (response.getPayload().getContentType().indexOf("xml") != -1 || response.getPayload()
.getContentType().indexOf("unknown") != -1)) {
@ -84,6 +85,7 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
} catch (IOException e) {
}
}
}
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
.getStatusLine());
switch (response.getStatusCode()) {

View File

@ -54,4 +54,29 @@ public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> imple
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;
}
}

View File

@ -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.get;
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.newLinkedHashSet;
import static com.google.common.collect.Sets.newTreeSet;
import static org.jclouds.compute.options.RunScriptOptions.Builder.overrideCredentialsWith;
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.FileNotFoundException;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;
@ -81,6 +83,7 @@ import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files;
@ -197,19 +200,37 @@ public abstract class BaseComputeServiceLiveTest {
// wait up to 5 seconds for an auth exception
@Test(enabled = true, expectedExceptions = AuthorizationException.class)
public void testCorrectAuthException() throws Exception {
synchronized (ComputeServiceContext.class) {
ComputeServiceContext context = null;
// system properties override crendentials passed
// if in the form provider.identity, provider.credential
// we want this to fail, so we save off old state and reset those
// properties to garbage.
String oldIdentity = System.getProperty(provider + ".identity");
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 {
client.listImages();
long time = System.currentTimeMillis();
@ -374,10 +395,18 @@ public abstract class BaseComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
public void testGet() throws Exception {
Set<? extends NodeMetadata> nodes = client.listNodesDetailsMatching(all());
Set<? extends NodeMetadata> metadataSet = newLinkedHashSet(filter(nodes, and(withTag(tag), not(TERMINATED))));
Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(filter(client
.listNodesDetailsMatching(all()), and(withTag(tag), not(TERMINATED))),
new Function<NodeMetadata, String>() {
@Override
public String apply(NodeMetadata from) {
return from.getId();
}
}));
for (NodeMetadata node : nodes) {
metadataSet.remove(node);
metadataMap.remove(node.getId());
NodeMetadata metadata = client.getNodeMetadata(node.getId());
assertEquals(metadata.getProviderId(), node.getProviderId());
assertEquals(metadata.getTag(), node.getTag());
@ -388,10 +417,10 @@ public abstract class BaseComputeServiceLiveTest {
assertEquals(metadata.getPrivateAddresses(), node.getPrivateAddresses());
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]",
metadataSet, nodes);
}

View File

@ -26,6 +26,7 @@ import static com.google.common.collect.Iterables.transform;
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
import java.util.List;
import java.util.NoSuchElementException;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -67,7 +68,7 @@ public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp,
public Hardware apply(VCloudExpressVApp from) {
checkNotNull(from, "VApp");
Location location = findLocationForResource.apply(checkNotNull(from, "from").getVDC());
try {
int ram = (int) find(from.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity();
List<Processor> processors = Lists.newArrayList(transform(filter(from.getResourceAllocations(),
@ -80,8 +81,12 @@ public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp,
}));
Iterable<? extends Volume> volumes = resourceAllocationsToVolumes.apply(from.getResourceAllocations());
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()));
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) {
logger.debug("incomplete data to form vApp %s", from.getHref());
return null;
}
}
}