mirror of https://github.com/apache/jclouds.git
corrected serialization bug in weighted route53 rrsets and backfilled missing tests
This commit is contained in:
parent
1713e9f102
commit
6b931eeb25
|
@ -103,7 +103,7 @@ public class ResourceRecordSet {
|
|||
private Weighted(String id, String name, String type, int weight, Optional<Integer> ttl, List<String> values,
|
||||
Optional<AliasTarget> aliasTarget) {
|
||||
super(id, name, type, ttl, values, aliasTarget);
|
||||
this.weight = checkNotNull(weight, "weight");
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.route53.functions;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.rest.annotations.ParamParser;
|
||||
import org.jclouds.route53.domain.ResourceRecordSet;
|
||||
import org.jclouds.route53.domain.ResourceRecordSet.RecordSubset;
|
||||
import org.jclouds.route53.domain.ResourceRecordSet.RecordSubset.Latency;
|
||||
|
@ -30,7 +29,6 @@ import com.google.common.base.Function;
|
|||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
* @see ParamParser
|
||||
*/
|
||||
public class SerializeRRS implements Function<Object, String> {
|
||||
@Override
|
||||
|
@ -41,7 +39,7 @@ public class SerializeRRS implements Function<Object, String> {
|
|||
builder.append("<Type>").append(rrs.getType()).append("</Type>");
|
||||
if (rrs instanceof RecordSubset) {
|
||||
String id = RecordSubset.class.cast(rrs).getId();
|
||||
builder.append("<ResourceRecordSubset>").append(id).append("</ResourceRecordSubset>");
|
||||
builder.append("<SetIdentifier>").append(id).append("</SetIdentifier>");
|
||||
}
|
||||
if (rrs instanceof Weighted)
|
||||
builder.append("<Weight>").append(Weighted.class.cast(rrs).getWeight()).append("</Weight>");
|
||||
|
|
|
@ -135,33 +135,59 @@ public class ResourceRecordSetApiLiveTest extends BaseRoute53ApiLiveTest {
|
|||
@Test
|
||||
public void testCreateAndDeleteBulkRecords() {
|
||||
String name = System.getProperty("user.name").replace('.', '-') + ".bulk.route53test.jclouds.org.";
|
||||
try {
|
||||
String zoneId = recreateZone(name);
|
||||
|
||||
ImmutableList<ResourceRecordSet> records = ImmutableList.<ResourceRecordSet> builder()
|
||||
.add(ResourceRecordSet.builder().name("dom1." + name).type("TXT").add("\"somehow\" \" somewhere\"")
|
||||
.build())
|
||||
.add(ResourceRecordSet.builder().name("dom2." + name).type("TXT").add("\"goodies\"").build()).build();
|
||||
|
||||
createAndDeleteRecordsInZone(records, zoneId);
|
||||
} finally {
|
||||
clearAndDeleteHostedZonesNamed(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAndDeleteWeightedRecords() {
|
||||
String name = System.getProperty("user.name").replace('.', '-') + ".weight.route53test.jclouds.org.";
|
||||
try {
|
||||
String zoneId = recreateZone(name);
|
||||
|
||||
ImmutableList<ResourceRecordSet> records = ImmutableList.<ResourceRecordSet> builder()
|
||||
.add(Weighted.builder().id("dom1").weight(1).name("dom." + name).type("CNAME").add("dom1." + name)
|
||||
.build())
|
||||
.add(Weighted.builder().id("dom2").weight(1).name("dom." + name).type("CNAME").add("dom2." + name)
|
||||
.build()).build();
|
||||
|
||||
createAndDeleteRecordsInZone(records, zoneId);
|
||||
} finally {
|
||||
clearAndDeleteHostedZonesNamed(name);
|
||||
}
|
||||
}
|
||||
|
||||
private String recreateZone(String name) {
|
||||
clearAndDeleteHostedZonesNamed(name);
|
||||
|
||||
ImmutableList<ResourceRecordSet> records = ImmutableList.<ResourceRecordSet> builder()
|
||||
.add(ResourceRecordSet.builder().name("dom1." + name).type("TXT").add("\"somehow\" \" somewhere\"").build())
|
||||
.add(ResourceRecordSet.builder().name("dom2." + name).type("TXT").add("\"goodies\"").build()).build();
|
||||
|
||||
String nonce = name + " @ " + new Date();
|
||||
String comment = name + " for " + JcloudsVersion.get();
|
||||
NewHostedZone newHostedZone = context.getApi().getHostedZoneApi()
|
||||
.createWithReferenceAndComment(name, nonce, comment);
|
||||
String zoneId = newHostedZone.getZone().getId();
|
||||
getAnonymousLogger().info("created zone: " + newHostedZone);
|
||||
try {
|
||||
assertTrue(inSync.apply(newHostedZone.getChange()), "zone didn't sync " + newHostedZone);
|
||||
sync(api(zoneId).apply(createAll(records)));
|
||||
assertTrue(inSync.apply(newHostedZone.getChange()), "zone didn't sync " + newHostedZone);
|
||||
return newHostedZone.getZone().getId();
|
||||
}
|
||||
|
||||
checkAllRRs(zoneId);
|
||||
private void createAndDeleteRecordsInZone(ImmutableList<ResourceRecordSet> records, String zoneId) {
|
||||
sync(api(zoneId).apply(createAll(records)));
|
||||
|
||||
sync(api(zoneId).apply(deleteAll(records)));
|
||||
checkAllRRs(zoneId);
|
||||
|
||||
PagedIterable<ResourceRecordSet> refreshed = refresh(zoneId);
|
||||
assertTrue(refreshed.concat().filter(not(requiredRRTypes)).isEmpty(), "zone still has optional records: "
|
||||
+ refreshed);
|
||||
sync(api(zoneId).apply(deleteAll(records)));
|
||||
|
||||
} finally {
|
||||
clearAndDeleteHostedZonesNamed(name);
|
||||
}
|
||||
PagedIterable<ResourceRecordSet> refreshed = refresh(zoneId);
|
||||
assertTrue(refreshed.concat().filter(not(requiredRRTypes)).isEmpty(), "zone still has optional records: "
|
||||
+ refreshed);
|
||||
}
|
||||
|
||||
private void clearAndDeleteHostedZonesNamed(String name) {
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.route53.filters;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code RestAuthentication}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "RestAuthenticationTest")
|
||||
public class RestAuthenticationTest {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.route53.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.route53.domain.ResourceRecordSet;
|
||||
import org.jclouds.route53.domain.ResourceRecordSet.RecordSubset.Weighted;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class SerializeRRSTest {
|
||||
|
||||
@Test
|
||||
void roundRobinRRSetToXML() {
|
||||
assertEquals(
|
||||
new SerializeRRS().apply(ResourceRecordSet.builder()
|
||||
.name("dom1.foo.com.")
|
||||
.type("A")
|
||||
.add("1.2.3.4")
|
||||
.add("5.6.7.8").build()),
|
||||
"<ResourceRecordSet><Name>dom1.foo.com.</Name><Type>A</Type><TTL>300</TTL><ResourceRecords><ResourceRecord><Value>1.2.3.4</Value></ResourceRecord><ResourceRecord><Value>5.6.7.8</Value></ResourceRecord></ResourceRecords></ResourceRecordSet>");
|
||||
}
|
||||
|
||||
@Test
|
||||
void roundWeightedRRSetToXML() {
|
||||
assertEquals(new SerializeRRS().apply(Weighted.builder()
|
||||
.id("dom1")
|
||||
.weight(1)
|
||||
.name("dom.foo.com.")
|
||||
.type("CNAME")
|
||||
.add("dom1.foo.com.").build()),
|
||||
"<ResourceRecordSet><Name>dom.foo.com.</Name><Type>CNAME</Type><SetIdentifier>dom1</SetIdentifier><Weight>1</Weight><TTL>300</TTL><ResourceRecords><ResourceRecord><Value>dom1.foo.com.</Value></ResourceRecord></ResourceRecords></ResourceRecordSet>");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue