Skip to content

Commit 2f5e98b

Browse files
committed
---
yaml --- r: 6829 b: refs/heads/tswast-patch-1 c: c0c5451 h: refs/heads/master i: 6827: 2035a94
1 parent 1eec099 commit 2f5e98b

7 files changed

Lines changed: 80 additions & 48 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: d1c45124dffd0a5a3bfdc2a4abe5c6483f32c295
60+
refs/heads/tswast-patch-1: c0c5451d286675248e32fdf3a37c7c9293cd3f4a
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsImpl.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ public Page<DnsRecord> nextPage() {
120120
}
121121
}
122122

123+
@Override
124+
public Page<Zone> listZones(ZoneListOption... options) {
125+
return listZones(options(), optionMap(options));
126+
}
127+
123128
private static Page<Zone> listZones(final DnsOptions serviceOptions,
124129
final Map<DnsRpc.Option, ?> optionsMap) {
125130
// define transformation function
@@ -151,9 +156,16 @@ public DnsRpc.ListResult<ManagedZone> call() {
151156
}
152157
}
153158

159+
@Override
160+
public Page<ChangeRequest> listChangeRequests(String zoneName,
161+
ChangeRequestListOption... options) {
162+
return listChangeRequests(zoneName, options(), optionMap(options),
163+
ChangeRequestPageFetcher.PB_TO_CHANGE_REQUEST);
164+
}
165+
154166
private static Page<ChangeRequest> listChangeRequests(final String zoneName,
155167
final DnsOptions serviceOptions, final Map<DnsRpc.Option, ?> optionsMap,
156-
Function<Change, ChangeRequest> TRANSFORM_FUNCTION) {
168+
Function<Change, ChangeRequest> transformFunction) {
157169
try {
158170
// get a list of changes
159171
DnsRpc.ListResult<Change> result = runWithRetries(new Callable<DnsRpc.ListResult<Change>>() {
@@ -166,17 +178,23 @@ public DnsRpc.ListResult<Change> call() {
166178
// transform that list into change request objects
167179
Iterable<ChangeRequest> changes = result.results() == null
168180
? ImmutableList.<ChangeRequest>of()
169-
: Iterables.transform(result.results(), TRANSFORM_FUNCTION);
181+
: Iterables.transform(result.results(), transformFunction);
170182
return new PageImpl<>(new ChangeRequestPageFetcher(zoneName, serviceOptions, cursor,
171183
optionsMap), cursor, changes);
172184
} catch (RetryHelperException e) {
173185
throw DnsException.translateAndThrow(e);
174186
}
175187
}
176188

189+
@Override
190+
public Page<DnsRecord> listDnsRecords(String zoneName, DnsRecordListOption... options) {
191+
return listDnsRecords(zoneName, options(), optionMap(options),
192+
DnsRecordPageFetcher.PB_TO_DNS_RECORD);
193+
}
194+
177195
private static Page<DnsRecord> listDnsRecords(final String zoneName,
178196
final DnsOptions serviceOptions, final Map<DnsRpc.Option, ?> optionsMap,
179-
Function<ResourceRecordSet, DnsRecord> TRANSFORM_FUNCTION) {
197+
Function<ResourceRecordSet, DnsRecord> transformFunction) {
180198
try {
181199
// get a list of resource record sets
182200
DnsRpc.ListResult<ResourceRecordSet> result = runWithRetries(
@@ -190,7 +208,7 @@ public DnsRpc.ListResult<ResourceRecordSet> call() {
190208
// transform that list into dns records
191209
Iterable<DnsRecord> records = result.results() == null
192210
? ImmutableList.<DnsRecord>of()
193-
: Iterables.transform(result.results(), TRANSFORM_FUNCTION);
211+
: Iterables.transform(result.results(), transformFunction);
194212
return new PageImpl<>(new DnsRecordPageFetcher(zoneName, serviceOptions, cursor, optionsMap),
195213
cursor, records);
196214
} catch (RetryHelperException e) {
@@ -203,24 +221,6 @@ public DnsRpc.ListResult<ResourceRecordSet> call() {
203221
dnsRpc = options.rpc();
204222
}
205223

206-
@Override
207-
public Page<Zone> listZones(ZoneListOption... options) {
208-
return listZones(options(), optionMap(options));
209-
}
210-
211-
@Override
212-
public Page<ChangeRequest> listChangeRequests(String zoneName,
213-
ChangeRequestListOption... options) {
214-
return listChangeRequests(zoneName, options(), optionMap(options),
215-
ChangeRequestPageFetcher.PB_TO_CHANGE_REQUEST);
216-
}
217-
218-
@Override
219-
public Page<DnsRecord> listDnsRecords(String zoneName, DnsRecordListOption... options) {
220-
return listDnsRecords(zoneName, options(), optionMap(options),
221-
DnsRecordPageFetcher.PB_TO_DNS_RECORD);
222-
}
223-
224224
@Override
225225
public Zone create(final ZoneInfo zoneInfo, Dns.ZoneOption... options) {
226226
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);

branches/tswast-patch-1/gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsOptions.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525
import java.util.Set;
2626

27-
public class DnsOptions
28-
extends ServiceOptions<Dns, DnsRpc, DnsOptions> {
27+
public class DnsOptions extends ServiceOptions<Dns, DnsRpc, DnsOptions> {
2928

3029
private static final long serialVersionUID = -519128051411747771L;
3130
private static final String GC_DNS_RW = "https://www.googleapis.com/auth/ndev.clouddns.readwrite";
@@ -36,7 +35,6 @@ public static class DefaultDnsFactory implements DnsFactory {
3635

3736
@Override
3837
public Dns create(DnsOptions options) {
39-
// TODO(mderka) Implement when DnsImpl is available. Created issue #595.
4038
return new DnsImpl(options);
4139
}
4240
}

branches/tswast-patch-1/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import com.google.gcloud.Page;
2222

23+
import java.io.IOException;
24+
import java.io.ObjectInputStream;
2325
import java.util.List;
2426
import java.util.Objects;
2527

@@ -36,7 +38,8 @@
3638
*/
3739
public class Zone extends ZoneInfo {
3840

39-
private static final long serialVersionUID = 564454483894599281L;
41+
private static final long serialVersionUID = -5817771337847861598L;
42+
private final DnsOptions options;
4043
private transient Dns dns;
4144

4245
/**
@@ -102,6 +105,7 @@ public Zone build() {
102105
Zone(Dns dns, ZoneInfo.BuilderImpl infoBuilder) {
103106
super(infoBuilder);
104107
this.dns = dns;
108+
this.options = dns.options();
105109
}
106110

107111
@Override
@@ -115,6 +119,7 @@ public Builder toBuilder() {
115119
public Zone(Dns dns, ZoneInfo zoneInfo) {
116120
super(new BuilderImpl(zoneInfo));
117121
this.dns = dns;
122+
this.options = dns.options();
118123
}
119124

120125
/**
@@ -215,12 +220,18 @@ public Dns dns() {
215220

216221
@Override
217222
public boolean equals(Object obj) {
218-
return obj instanceof Zone && Objects.equals(toPb(), ((Zone) obj).toPb());
223+
return obj instanceof Zone && Objects.equals(toPb(), ((Zone) obj).toPb())
224+
&& Objects.equals(options, ((Zone) obj).options);
219225
}
220226

221227
@Override
222228
public int hashCode() {
223-
return super.hashCode();
229+
return Objects.hash(super.hashCode(), options);
230+
}
231+
232+
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
233+
in.defaultReadObject();
234+
this.dns = options.service();
224235
}
225236

226237
static Zone fromPb(Dns dns, com.google.api.services.dns.model.ManagedZone zone) {

branches/tswast-patch-1/gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import java.io.Serializable;
2929
import java.math.BigInteger;
30-
import java.util.LinkedList;
3130
import java.util.List;
3231
import java.util.Objects;
3332

@@ -97,14 +96,14 @@ public abstract static class Builder {
9796
public abstract ZoneInfo build();
9897
}
9998

100-
public static class BuilderImpl extends Builder {
99+
static class BuilderImpl extends Builder {
101100
private String name;
102101
private String id;
103102
private Long creationTimeMillis;
104103
private String dnsName;
105104
private String description;
106105
private String nameServerSet;
107-
private List<String> nameServers = new LinkedList<>();
106+
private List<String> nameServers;
108107

109108
private BuilderImpl(String name) {
110109
this.name = checkNotNull(name);
@@ -120,7 +119,9 @@ private BuilderImpl(String name) {
120119
this.dnsName = info.dnsName;
121120
this.description = info.description;
122121
this.nameServerSet = info.nameServerSet;
123-
this.nameServers.addAll(info.nameServers);
122+
if (info.nameServers != null) {
123+
this.nameServers = ImmutableList.copyOf(info.nameServers);
124+
}
124125
}
125126

126127
@Override
@@ -179,7 +180,8 @@ public ZoneInfo build() {
179180
this.dnsName = builder.dnsName;
180181
this.description = builder.description;
181182
this.nameServerSet = builder.nameServerSet;
182-
this.nameServers = ImmutableList.copyOf(builder.nameServers);
183+
this.nameServers = builder.nameServers == null
184+
? null : ImmutableList.copyOf(builder.nameServers);
183185
}
184186

185187
/**
@@ -236,7 +238,7 @@ public String nameServerSet() {
236238
* The nameservers that the zone should be delegated to. This is defined by the Google DNS cloud.
237239
*/
238240
public List<String> nameServers() {
239-
return nameServers;
241+
return nameServers == null ? ImmutableList.<String>of() : nameServers;
240242
}
241243

242244
/**
@@ -255,7 +257,7 @@ com.google.api.services.dns.model.ManagedZone toPb() {
255257
pb.setId(new BigInteger(this.id()));
256258
}
257259
pb.setName(this.name());
258-
pb.setNameServers(this.nameServers());
260+
pb.setNameServers(this.nameServers); // do use real attribute value which may be null
259261
pb.setNameServerSet(this.nameServerSet());
260262
if (this.creationTimeMillis() != null) {
261263
pb.setCreationTime(ISODateTimeFormat.dateTime()
@@ -290,7 +292,8 @@ static ZoneInfo fromPb(com.google.api.services.dns.model.ManagedZone pb) {
290292

291293
@Override
292294
public boolean equals(Object obj) {
293-
return obj instanceof ZoneInfo && Objects.equals(toPb(), ((ZoneInfo) obj).toPb());
295+
return obj != null && obj.getClass().equals(ZoneInfo.class)
296+
&& Objects.equals(toPb(), ((ZoneInfo) obj).toPb());
294297
}
295298

296299
@Override

branches/tswast-patch-1/gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsImplTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ public void testCreateZone() {
136136
.andReturn(ZONE_INFO.toPb());
137137
EasyMock.replay(dnsRpcMock);
138138
dns = options.service(); // creates DnsImpl
139-
ZoneInfo zoneInfo = dns.create(ZONE_INFO);
140-
assertEquals(ZONE_INFO, zoneInfo);
139+
Zone zone = dns.create(ZONE_INFO);
140+
assertEquals(new Zone(dns, ZONE_INFO), zone);
141141
}
142142

143143
@Test
@@ -149,7 +149,7 @@ public void testCreateZoneWithOptions() {
149149
dns = options.service(); // creates DnsImpl
150150
Zone zone = dns.create(ZONE_INFO, ZONE_FIELDS);
151151
String selector = (String) capturedOptions.getValue().get(ZONE_FIELDS.rpcOption());
152-
assertEquals(ZONE_INFO, zone);
152+
assertEquals(new Zone(dns, ZONE_INFO), zone);
153153
assertTrue(selector.contains(Dns.ZoneField.CREATION_TIME.selector()));
154154
assertTrue(selector.contains(Dns.ZoneField.NAME.selector()));
155155
}
@@ -160,8 +160,8 @@ public void testGetZone() {
160160
.andReturn(ZONE_INFO.toPb());
161161
EasyMock.replay(dnsRpcMock);
162162
dns = options.service(); // creates DnsImpl
163-
ZoneInfo zoneInfo = dns.getZone(ZONE_INFO.name());
164-
assertEquals(ZONE_INFO, zoneInfo);
163+
Zone zone = dns.getZone(ZONE_INFO.name());
164+
assertEquals(new Zone(dns, ZONE_INFO), zone);
165165
}
166166

167167
@Test
@@ -171,9 +171,9 @@ public void testGetZoneWithOptions() {
171171
EasyMock.capture(capturedOptions))).andReturn(ZONE_INFO.toPb());
172172
EasyMock.replay(dnsRpcMock);
173173
dns = options.service(); // creates DnsImpl
174-
ZoneInfo zoneInfo = dns.getZone(ZONE_INFO.name(), ZONE_FIELDS);
174+
Zone zone = dns.getZone(ZONE_INFO.name(), ZONE_FIELDS);
175175
String selector = (String) capturedOptions.getValue().get(ZONE_FIELDS.rpcOption());
176-
assertEquals(ZONE_INFO, zoneInfo);
176+
assertEquals(new Zone(dns, ZONE_INFO), zone);
177177
assertTrue(selector.contains(Dns.ZoneField.CREATION_TIME.selector()));
178178
assertTrue(selector.contains(Dns.ZoneField.NAME.selector()));
179179
}
@@ -308,7 +308,7 @@ public void testListZones() {
308308
dns = options.service(); // creates DnsImpl
309309
Page<Zone> zonePage = dns.listZones();
310310
assertEquals(1, Lists.newArrayList(zonePage.values()).size());
311-
assertEquals(ZONE_INFO, Lists.newArrayList(zonePage.values()).get(0));
311+
assertEquals(new Zone(dns, ZONE_INFO), Lists.newArrayList(zonePage.values()).get(0));
312312
}
313313

314314
@Test
@@ -320,7 +320,7 @@ public void testListZonesWithOptions() {
320320
dns = options.service(); // creates DnsImpl
321321
Page<Zone> zonePage = dns.listZones(ZONE_LIST_OPTIONS);
322322
assertEquals(1, Lists.newArrayList(zonePage.values()).size());
323-
assertEquals(ZONE_INFO, Lists.newArrayList(zonePage.values()).get(0));
323+
assertEquals(new Zone(dns, ZONE_INFO), Lists.newArrayList(zonePage.values()).get(0));
324324
Integer size = (Integer) capturedOptions.getValue().get(ZONE_LIST_OPTIONS[0].rpcOption());
325325
assertEquals(MAX_SIZE, size);
326326
String selector = (String) capturedOptions.getValue().get(ZONE_LIST_OPTIONS[1].rpcOption());

branches/tswast-patch-1/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.easymock.EasyMock.createStrictMock;
2020
import static org.easymock.EasyMock.expect;
2121
import static org.easymock.EasyMock.replay;
22+
import static org.easymock.EasyMock.reset;
2223
import static org.easymock.EasyMock.verify;
2324
import static org.junit.Assert.assertEquals;
2425
import static org.junit.Assert.assertFalse;
@@ -64,16 +65,22 @@ public class ZoneTest {
6465
.startTimeMillis(123465L).build();
6566
private static final ChangeRequest CHANGE_REQUEST_NO_ID = ChangeRequest.builder().build();
6667
private static final DnsException EXCEPTION = createStrictMock(DnsException.class);
68+
private static final DnsOptions OPTIONS = createStrictMock(DnsOptions.class);
6769

6870
private Dns dns;
6971
private Zone zone;
7072
private Zone zoneNoId;
7173

74+
7275
@Before
7376
public void setUp() throws Exception {
7477
dns = createStrictMock(Dns.class);
78+
expect(dns.options()).andReturn(OPTIONS);
79+
expect(dns.options()).andReturn(OPTIONS);
80+
replay(dns);
7581
zone = new Zone(dns, ZONE_INFO);
7682
zoneNoId = new Zone(dns, NO_ID_INFO);
83+
reset(dns);
7784
}
7885

7986
@After
@@ -347,13 +354,13 @@ public void getChangeAndZoneNotFoundByName() {
347354
.andThrow(EXCEPTION);
348355
replay(dns);
349356
try {
350-
ChangeRequest result = zoneNoId.getChangeRequest(CHANGE_REQUEST.id());
357+
zoneNoId.getChangeRequest(CHANGE_REQUEST.id());
351358
fail("Parent container not found, should throw an exception.");
352359
} catch (DnsException e) {
353360
// expected
354361
}
355362
try {
356-
ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST.id());
363+
zone.getChangeRequest(CHANGE_REQUEST.id());
357364
fail("Parent container not found, should throw an exception.");
358365
} catch (DnsException e) {
359366
// expected
@@ -505,18 +512,31 @@ public void listChangeRequestsAndZoneNotFound() {
505512

506513
@Test
507514
public void testFromPb() {
515+
expect(dns.options()).andReturn(OPTIONS);
508516
replay(dns);
509517
assertEquals(Zone.fromPb(dns, zone.toPb()), zone);
510518
}
511519

512520
@Test
513521
public void testEqualsAndToBuilder() {
522+
expect(dns.options()).andReturn(OPTIONS);
523+
expect(dns.options()).andReturn(OPTIONS);
514524
replay(dns);
515525
assertEquals(zone, zone.toBuilder().build());
526+
assertEquals(zone.hashCode(), zone.toBuilder().build().hashCode());
516527
}
517528

518529
@Test
519530
public void testBuilder() {
531+
// one for each build() call because it invokes a constructor
532+
expect(dns.options()).andReturn(OPTIONS);
533+
expect(dns.options()).andReturn(OPTIONS);
534+
expect(dns.options()).andReturn(OPTIONS);
535+
expect(dns.options()).andReturn(OPTIONS);
536+
expect(dns.options()).andReturn(OPTIONS);
537+
expect(dns.options()).andReturn(OPTIONS);
538+
expect(dns.options()).andReturn(OPTIONS);
539+
expect(dns.options()).andReturn(OPTIONS);
520540
replay(dns);
521541
assertNotEquals(zone, zone.toBuilder()
522542
.id((new BigInteger(zone.id())).add(BigInteger.ONE).toString())

0 commit comments

Comments
 (0)