mirror of https://github.com/apache/jclouds.git
eliminated errors when multiple groups have the same name
This commit is contained in:
parent
b582d4a4a8
commit
9237f1a406
|
@ -204,7 +204,7 @@ public class SecurityGroup extends ForwardingSet<IpPermission> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(region, id, name, ownerId, description, ipPermissions);
|
return Objects.hashCode(region, id, name, ownerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -217,9 +217,7 @@ public class SecurityGroup extends ForwardingSet<IpPermission> {
|
||||||
return Objects.equal(this.region, that.region)
|
return Objects.equal(this.region, that.region)
|
||||||
&& Objects.equal(this.id, that.id)
|
&& Objects.equal(this.id, that.id)
|
||||||
&& Objects.equal(this.name, that.name)
|
&& Objects.equal(this.name, that.name)
|
||||||
&& Objects.equal(this.ownerId, that.ownerId)
|
&& Objects.equal(this.ownerId, that.ownerId);
|
||||||
&& Objects.equal(this.description, that.description)
|
|
||||||
&& Objects.equal(this.ipPermissions, that.ipPermissions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ToStringHelper string() {
|
protected ToStringHelper string() {
|
||||||
|
|
|
@ -18,10 +18,15 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.ec2.services;
|
package org.jclouds.ec2.services;
|
||||||
|
|
||||||
|
import static com.google.common.base.Predicates.compose;
|
||||||
|
import static com.google.common.base.Predicates.in;
|
||||||
|
import static com.google.common.collect.Iterables.all;
|
||||||
|
import static com.google.common.collect.Iterables.getLast;
|
||||||
|
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
|
import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
|
||||||
|
@ -34,10 +39,11 @@ import org.jclouds.ec2.domain.UserIdGroupPair;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code SecurityGroupClient}
|
* Tests behavior of {@code SecurityGroupClient}
|
||||||
|
@ -67,11 +73,19 @@ public class SecurityGroupClientLiveTest extends BaseComputeServiceContextLiveTe
|
||||||
Set<SecurityGroup> allResults = client.describeSecurityGroupsInRegion(region);
|
Set<SecurityGroup> allResults = client.describeSecurityGroupsInRegion(region);
|
||||||
assertNotNull(allResults);
|
assertNotNull(allResults);
|
||||||
if (allResults.size() >= 1) {
|
if (allResults.size() >= 1) {
|
||||||
SecurityGroup group = Iterables.getLast(allResults);
|
final SecurityGroup group = getLast(allResults);
|
||||||
Set<SecurityGroup> result = client.describeSecurityGroupsInRegion(region, group.getName());
|
// in case there are multiple groups with the same name, which is the case with VPC
|
||||||
assertNotNull(result);
|
ImmutableSet<SecurityGroup> expected = FluentIterable.from(allResults)
|
||||||
SecurityGroup compare = Iterables.getLast(result);
|
.filter(new Predicate<SecurityGroup>() {
|
||||||
assertEquals(compare, group);
|
@Override
|
||||||
|
public boolean apply(SecurityGroup in) {
|
||||||
|
return group.getName().equals(in.getName());
|
||||||
|
}
|
||||||
|
}).toSet();
|
||||||
|
ImmutableSet<SecurityGroup> result = ImmutableSet.copyOf(client.describeSecurityGroupsInRegion(region,
|
||||||
|
group.getName()));
|
||||||
|
// the above command has a chance of returning less groups than the original
|
||||||
|
assertTrue(expected.containsAll(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,7 +211,7 @@ public class SecurityGroupClientLiveTest extends BaseComputeServiceContextLiveTe
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Set<SecurityGroup> oneResult = client.describeSecurityGroupsInRegion(null, group);
|
Set<SecurityGroup> oneResult = client.describeSecurityGroupsInRegion(null, group);
|
||||||
assert Iterables.all(Iterables.getOnlyElement(oneResult).getIpPermissions(), permission) : permission
|
assert all(getOnlyElement(oneResult), permission) : permission
|
||||||
+ ": " + oneResult;
|
+ ": " + oneResult;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
|
@ -220,7 +234,7 @@ public class SecurityGroupClientLiveTest extends BaseComputeServiceContextLiveTe
|
||||||
assertNotNull(oneResult);
|
assertNotNull(oneResult);
|
||||||
assertEquals(oneResult.size(), 1);
|
assertEquals(oneResult.size(), 1);
|
||||||
SecurityGroup listPair = oneResult.iterator().next();
|
SecurityGroup listPair = oneResult.iterator().next();
|
||||||
assertEquals(listPair.getIpPermissions().size(), 0);
|
assertEquals(listPair.size(), 0);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
|
@ -230,15 +244,15 @@ public class SecurityGroupClientLiveTest extends BaseComputeServiceContextLiveTe
|
||||||
protected void ensureGroupsExist(String group1Name, String group2Name) {
|
protected void ensureGroupsExist(String group1Name, String group2Name) {
|
||||||
Set<SecurityGroup> twoResults = client.describeSecurityGroupsInRegion(null, group1Name, group2Name);
|
Set<SecurityGroup> twoResults = client.describeSecurityGroupsInRegion(null, group1Name, group2Name);
|
||||||
assertNotNull(twoResults);
|
assertNotNull(twoResults);
|
||||||
assertEquals(twoResults.size(), 2);
|
assertTrue(twoResults.size() >= 2);// in VPC could be multiple groups with the same name
|
||||||
Iterator<SecurityGroup> iterator = twoResults.iterator();
|
|
||||||
SecurityGroup listPair1 = iterator.next();
|
|
||||||
assertEquals(listPair1.getName(), group1Name);
|
|
||||||
assertEquals(listPair1.getDescription(), group1Name);
|
|
||||||
|
|
||||||
SecurityGroup listPair2 = iterator.next();
|
assertTrue(all(twoResults, compose(in(ImmutableSet.of(group1Name, group2Name)),
|
||||||
assertEquals(listPair2.getName(), group2Name);
|
new Function<SecurityGroup, String>() {
|
||||||
assertEquals(listPair2.getDescription(), group2Name);
|
@Override
|
||||||
|
public String apply(SecurityGroup in) {
|
||||||
|
return in.getName();
|
||||||
|
}
|
||||||
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int INCONSISTENCY_WINDOW = 5000;
|
private static final int INCONSISTENCY_WINDOW = 5000;
|
||||||
|
|
Loading…
Reference in New Issue