Skip to content

Commit

Permalink
Fixed zone name to be unique and added missing waits for change compl…
Browse files Browse the repository at this point in the history
…etion
  • Loading branch information
mderka committed Mar 3, 2016
1 parent 22153aa commit 799c950
Showing 1 changed file with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.junit.Test;
import org.junit.rules.Timeout;

import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -50,13 +51,12 @@ public class ITDnsTest {

// todo(mderka) Implement test for creating invalid change when DnsException is finished. #673

public static final HashSet<String> ZONE_NAMES = new HashSet<>();
public static final String PREFIX = "gcldjvit-";
public static final Dns DNS = DnsOptions.builder().build().service();
public static final String PROJECT_ID = DNS.options().projectId();
public static final String ZONE_NAME1 = (PREFIX + UUID.randomUUID()).substring(0, 32);
public static final String ZONE_NAME_EMPTY_DESCRIPTION =
("gcldjvit-" + UUID.randomUUID()).substring(0, 32);
public static final String ZONE_NAME_TOO_LONG = (PREFIX + UUID.randomUUID());
public static final String ZONE_NAME1 = uniqueName();
public static final String ZONE_NAME_EMPTY_DESCRIPTION = uniqueName();
public static final String ZONE_NAME_TOO_LONG = uniqueName() + uniqueName();
public static final String ZONE_DESCRIPTION1 = "first zone";
public static final String ZONE_DNS_NAME1 = ZONE_NAME1 + ".com.";
public static final String ZONE_DNS_EMPTY_DESCRIPTION = ZONE_NAME_EMPTY_DESCRIPTION + ".com.";
Expand Down Expand Up @@ -103,6 +103,20 @@ public class ITDnsTest {
.delete(AAAA_RECORD_ZONE1)
.build();

/**
* Since we are taking only substring of UUID, it does not need to be unique any more. This should
* take care of this.
*/
private static String uniqueName() {
long id = Thread.currentThread().getId();
String candidate;
do {
candidate = (PREFIX + id + UUID.randomUUID()).substring(0, 32);
} while (ZONE_NAMES.contains(candidate));
ZONE_NAMES.add(candidate);
return candidate;
}

public static void clear() {
Page<Zone> zones = DNS.listZones();
Iterator<Zone> zoneIterator = zones.iterateAll();
Expand Down Expand Up @@ -727,37 +741,43 @@ public void testGetChange() {
ChangeRequest created = zone.applyChangeRequest(CHANGE_ADD_ZONE1);
ChangeRequest retrieved = DNS.getChangeRequest(zone.name(), created.id());
assertEqChangesIgnoreStatus(created, retrieved);
waitUntilComplete(zone.name(), created.id());
zone.applyChangeRequest(CHANGE_DELETE_ZONE1);
// with options
created = zone.applyChangeRequest(CHANGE_ADD_ZONE1,
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.ID));
retrieved = DNS.getChangeRequest(zone.name(), created.id(),
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.ID));
assertEqChangesIgnoreStatus(created, retrieved);
waitUntilComplete(zone.name(), created.id());
zone.applyChangeRequest(CHANGE_DELETE_ZONE1);
created = zone.applyChangeRequest(CHANGE_ADD_ZONE1,
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.STATUS));
retrieved = DNS.getChangeRequest(zone.name(), created.id(),
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.STATUS));
assertEqChangesIgnoreStatus(created, retrieved);
waitUntilComplete(zone.name(), created.id());
zone.applyChangeRequest(CHANGE_DELETE_ZONE1);
created = zone.applyChangeRequest(CHANGE_ADD_ZONE1,
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.START_TIME));
retrieved = DNS.getChangeRequest(zone.name(), created.id(),
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.START_TIME));
assertEqChangesIgnoreStatus(created, retrieved);
waitUntilComplete(zone.name(), created.id());
zone.applyChangeRequest(CHANGE_DELETE_ZONE1);
created = zone.applyChangeRequest(CHANGE_ADD_ZONE1,
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.ADDITIONS));
retrieved = DNS.getChangeRequest(zone.name(), created.id(),
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.ADDITIONS));
assertEqChangesIgnoreStatus(created, retrieved);
waitUntilComplete(zone.name(), created.id());
// finishes with delete otherwise we cannot delete the zone
created = zone.applyChangeRequest(CHANGE_DELETE_ZONE1,
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.DELETIONS));
retrieved = DNS.getChangeRequest(zone.name(), created.id(),
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.DELETIONS));
assertEqChangesIgnoreStatus(created, retrieved);
waitUntilComplete(zone.name(), created.id());
} finally {
clear();
}
Expand Down

0 comments on commit 799c950

Please sign in to comment.