4040import org .junit .Test ;
4141import org .junit .rules .Timeout ;
4242
43+ import java .util .HashSet ;
4344import java .util .Iterator ;
4445import java .util .LinkedList ;
4546import java .util .List ;
@@ -50,13 +51,12 @@ public class ITDnsTest {
5051
5152 // todo(mderka) Implement test for creating invalid change when DnsException is finished. #673
5253
54+ public static final HashSet <String > ZONE_NAMES = new HashSet <>();
5355 public static final String PREFIX = "gcldjvit-" ;
5456 public static final Dns DNS = DnsOptions .builder ().build ().service ();
55- public static final String PROJECT_ID = DNS .options ().projectId ();
56- public static final String ZONE_NAME1 = (PREFIX + UUID .randomUUID ()).substring (0 , 32 );
57- public static final String ZONE_NAME_EMPTY_DESCRIPTION =
58- ("gcldjvit-" + UUID .randomUUID ()).substring (0 , 32 );
59- public static final String ZONE_NAME_TOO_LONG = (PREFIX + UUID .randomUUID ());
57+ public static final String ZONE_NAME1 = uniqueName ();
58+ public static final String ZONE_NAME_EMPTY_DESCRIPTION = uniqueName ();
59+ public static final String ZONE_NAME_TOO_LONG = uniqueName () + uniqueName ();
6060 public static final String ZONE_DESCRIPTION1 = "first zone" ;
6161 public static final String ZONE_DNS_NAME1 = ZONE_NAME1 + ".com." ;
6262 public static final String ZONE_DNS_EMPTY_DESCRIPTION = ZONE_NAME_EMPTY_DESCRIPTION + ".com." ;
@@ -103,6 +103,20 @@ public class ITDnsTest {
103103 .delete (AAAA_RECORD_ZONE1 )
104104 .build ();
105105
106+ /**
107+ * Since we are taking only substring of UUID, it does not need to be unique any more. This should
108+ * take care of this.
109+ */
110+ private static String uniqueName () {
111+ long id = Thread .currentThread ().getId ();
112+ String candidate ;
113+ do {
114+ candidate = (PREFIX + id + UUID .randomUUID ()).substring (0 , 32 );
115+ } while (ZONE_NAMES .contains (candidate ));
116+ ZONE_NAMES .add (candidate );
117+ return candidate ;
118+ }
119+
106120 public static void clear () {
107121 Page <Zone > zones = DNS .listZones ();
108122 Iterator <Zone > zoneIterator = zones .iterateAll ();
@@ -727,37 +741,43 @@ public void testGetChange() {
727741 ChangeRequest created = zone .applyChangeRequest (CHANGE_ADD_ZONE1 );
728742 ChangeRequest retrieved = DNS .getChangeRequest (zone .name (), created .id ());
729743 assertEqChangesIgnoreStatus (created , retrieved );
744+ waitUntilComplete (zone .name (), created .id ());
730745 zone .applyChangeRequest (CHANGE_DELETE_ZONE1 );
731746 // with options
732747 created = zone .applyChangeRequest (CHANGE_ADD_ZONE1 ,
733748 Dns .ChangeRequestOption .fields (Dns .ChangeRequestField .ID ));
734749 retrieved = DNS .getChangeRequest (zone .name (), created .id (),
735750 Dns .ChangeRequestOption .fields (Dns .ChangeRequestField .ID ));
736751 assertEqChangesIgnoreStatus (created , retrieved );
752+ waitUntilComplete (zone .name (), created .id ());
737753 zone .applyChangeRequest (CHANGE_DELETE_ZONE1 );
738754 created = zone .applyChangeRequest (CHANGE_ADD_ZONE1 ,
739755 Dns .ChangeRequestOption .fields (Dns .ChangeRequestField .STATUS ));
740756 retrieved = DNS .getChangeRequest (zone .name (), created .id (),
741757 Dns .ChangeRequestOption .fields (Dns .ChangeRequestField .STATUS ));
742758 assertEqChangesIgnoreStatus (created , retrieved );
759+ waitUntilComplete (zone .name (), created .id ());
743760 zone .applyChangeRequest (CHANGE_DELETE_ZONE1 );
744761 created = zone .applyChangeRequest (CHANGE_ADD_ZONE1 ,
745762 Dns .ChangeRequestOption .fields (Dns .ChangeRequestField .START_TIME ));
746763 retrieved = DNS .getChangeRequest (zone .name (), created .id (),
747764 Dns .ChangeRequestOption .fields (Dns .ChangeRequestField .START_TIME ));
748765 assertEqChangesIgnoreStatus (created , retrieved );
766+ waitUntilComplete (zone .name (), created .id ());
749767 zone .applyChangeRequest (CHANGE_DELETE_ZONE1 );
750768 created = zone .applyChangeRequest (CHANGE_ADD_ZONE1 ,
751769 Dns .ChangeRequestOption .fields (Dns .ChangeRequestField .ADDITIONS ));
752770 retrieved = DNS .getChangeRequest (zone .name (), created .id (),
753771 Dns .ChangeRequestOption .fields (Dns .ChangeRequestField .ADDITIONS ));
754772 assertEqChangesIgnoreStatus (created , retrieved );
773+ waitUntilComplete (zone .name (), created .id ());
755774 // finishes with delete otherwise we cannot delete the zone
756775 created = zone .applyChangeRequest (CHANGE_DELETE_ZONE1 ,
757776 Dns .ChangeRequestOption .fields (Dns .ChangeRequestField .DELETIONS ));
758777 retrieved = DNS .getChangeRequest (zone .name (), created .id (),
759778 Dns .ChangeRequestOption .fields (Dns .ChangeRequestField .DELETIONS ));
760779 assertEqChangesIgnoreStatus (created , retrieved );
780+ waitUntilComplete (zone .name (), created .id ());
761781 } finally {
762782 clear ();
763783 }
0 commit comments