Skip to content

Commit

Permalink
xds: fix Node.toBuilder() bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dapengzhang0 committed Mar 12, 2021
1 parent 6cc2023 commit bd86002
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
16 changes: 9 additions & 7 deletions xds/src/main/java/io/grpc/xds/EnvoyProtoData.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,16 @@ static Builder newBuilder() {
}

Builder toBuilder() {
Builder builder = new Builder().setId(id).setCluster(cluster);
if (metadata != null) {
builder.setMetadata(metadata);
}
if (locality != null) {
builder.setLocality(locality);
}
Builder builder = new Builder();
builder.id = id;
builder.cluster = cluster;
builder.metadata = metadata;
builder.locality = locality;
builder.buildVersion = buildVersion;
builder.listeningAddresses.addAll(listeningAddresses);
builder.userAgentName = userAgentName;
builder.userAgentVersion = userAgentVersion;
builder.clientFeatures.addAll(clientFeatures);
return builder;
}

Expand Down
18 changes: 18 additions & 0 deletions xds/src/test/java/io/grpc/xds/EnvoyProtoDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -626,4 +626,22 @@ public void clusterStats_convertToEnvoyProto() {
.setDroppedCount(100))
.build());
}

@Test
public void nodeToBuilderPropagatesAllAttributes() {
Node node = Node.newBuilder()
.setId("id")
.setCluster("cluster")
.setMetadata(ImmutableMap.of("key1", "value1", "key2", "value2"))
.setLocality(new Locality("region", "zone", "subzone"))
.setBuildVersion("v1")
.setUserAgentName("grpc-java")
.setUserAgentVersion("v1.0.9")
.addListeningAddresses(new Address("localhost", 8080))
.addListeningAddresses(new Address("localhost", 8081))
.addClientFeatures("feature1")
.addClientFeatures("feature2")
.build();
assertThat(node.toBuilder().build()).isEqualTo(node);
}
}

0 comments on commit bd86002

Please sign in to comment.