xds: fix lint

This commit is contained in:
ZHANG Dapeng 2020-05-12 16:51:24 -07:00 committed by GitHub
parent b1ca6e8d27
commit f9353e09c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 32 deletions

View File

@ -24,6 +24,7 @@ import com.google.protobuf.UInt32Value;
import io.envoyproxy.envoy.api.v2.auth.CommonTlsContext; import io.envoyproxy.envoy.api.v2.auth.CommonTlsContext;
import io.envoyproxy.envoy.api.v2.auth.DownstreamTlsContext; import io.envoyproxy.envoy.api.v2.auth.DownstreamTlsContext;
import io.envoyproxy.envoy.api.v2.auth.SdsSecretConfig; import io.envoyproxy.envoy.api.v2.auth.SdsSecretConfig;
import io.envoyproxy.envoy.api.v2.core.Address;
import io.envoyproxy.envoy.api.v2.core.CidrRange; import io.envoyproxy.envoy.api.v2.core.CidrRange;
import io.envoyproxy.envoy.api.v2.core.SocketAddress; import io.envoyproxy.envoy.api.v2.core.SocketAddress;
import io.envoyproxy.envoy.api.v2.core.TransportSocket; import io.envoyproxy.envoy.api.v2.core.TransportSocket;
@ -45,12 +46,10 @@ public class EnvoyServerProtoDataTest {
@Test @Test
public void listener_convertFromListenerProto() throws InvalidProtocolBufferException { public void listener_convertFromListenerProto() throws InvalidProtocolBufferException {
io.envoyproxy.envoy.api.v2.core.Address address = Address address =
io.envoyproxy.envoy.api.v2.core.Address.newBuilder() Address.newBuilder()
.setSocketAddress(SocketAddress.newBuilder() .setSocketAddress(
.setPortValue(8000) SocketAddress.newBuilder().setPortValue(8000).setAddress("10.2.1.34").build())
.setAddress("10.2.1.34")
.build())
.build(); .build();
io.envoyproxy.envoy.api.v2.Listener listener = io.envoyproxy.envoy.api.v2.Listener listener =
io.envoyproxy.envoy.api.v2.Listener.newBuilder() io.envoyproxy.envoy.api.v2.Listener.newBuilder()
@ -85,12 +84,10 @@ public class EnvoyServerProtoDataTest {
assertThat(inFilterChainMatch.getPrefixRanges()).containsExactly( assertThat(inFilterChainMatch.getPrefixRanges()).containsExactly(
new EnvoyServerProtoData.CidrRange("10.20.0.15", 32)); new EnvoyServerProtoData.CidrRange("10.20.0.15", 32));
DownstreamTlsContext inFilterTlsContext = inFilter.getDownstreamTlsContext(); DownstreamTlsContext inFilterTlsContext = inFilter.getDownstreamTlsContext();
assertThat(inFilterTlsContext).isNotNull(); assertThat(inFilterTlsContext.hasCommonTlsContext()).isTrue();
CommonTlsContext commonTlsContext = inFilterTlsContext.getCommonTlsContext(); CommonTlsContext commonTlsContext = inFilterTlsContext.getCommonTlsContext();
assertThat(commonTlsContext).isNotNull();
List<SdsSecretConfig> tlsCertSdsConfigs = commonTlsContext List<SdsSecretConfig> tlsCertSdsConfigs = commonTlsContext
.getTlsCertificateSdsSecretConfigsList(); .getTlsCertificateSdsSecretConfigsList();
assertThat(tlsCertSdsConfigs).isNotNull();
assertThat(tlsCertSdsConfigs).hasSize(1); assertThat(tlsCertSdsConfigs).hasSize(1);
assertThat(tlsCertSdsConfigs.get(0).getName()).isEqualTo("google-sds-config-default"); assertThat(tlsCertSdsConfigs.get(0).getName()).isEqualTo("google-sds-config-default");
} }
@ -98,12 +95,10 @@ public class EnvoyServerProtoDataTest {
// TODO(sanjaypujare): remove when we move to envoy protos v3 // TODO(sanjaypujare): remove when we move to envoy protos v3
@Test @Test
public void listener_convertFromDeprecatedListenerProto() throws InvalidProtocolBufferException { public void listener_convertFromDeprecatedListenerProto() throws InvalidProtocolBufferException {
io.envoyproxy.envoy.api.v2.core.Address address = Address address =
io.envoyproxy.envoy.api.v2.core.Address.newBuilder() Address.newBuilder()
.setSocketAddress(SocketAddress.newBuilder() .setSocketAddress(
.setPortValue(8000) SocketAddress.newBuilder().setPortValue(8000).setAddress("10.2.1.34").build())
.setAddress("10.2.1.34")
.build())
.build(); .build();
io.envoyproxy.envoy.api.v2.Listener listener = io.envoyproxy.envoy.api.v2.Listener listener =
io.envoyproxy.envoy.api.v2.Listener.newBuilder() io.envoyproxy.envoy.api.v2.Listener.newBuilder()
@ -116,9 +111,8 @@ public class EnvoyServerProtoDataTest {
assertThat(filterChains).hasSize(1); assertThat(filterChains).hasSize(1);
EnvoyServerProtoData.FilterChain inFilter = filterChains.get(0); EnvoyServerProtoData.FilterChain inFilter = filterChains.get(0);
DownstreamTlsContext inFilterTlsContext = inFilter.getDownstreamTlsContext(); DownstreamTlsContext inFilterTlsContext = inFilter.getDownstreamTlsContext();
assertThat(inFilterTlsContext).isNotNull(); assertThat(inFilterTlsContext.hasCommonTlsContext()).isTrue();
CommonTlsContext commonTlsContext = inFilterTlsContext.getCommonTlsContext(); CommonTlsContext commonTlsContext = inFilterTlsContext.getCommonTlsContext();
assertThat(commonTlsContext).isNotNull();
List<SdsSecretConfig> tlsCertSdsConfigs = commonTlsContext List<SdsSecretConfig> tlsCertSdsConfigs = commonTlsContext
.getTlsCertificateSdsSecretConfigsList(); .getTlsCertificateSdsSecretConfigsList();
assertThat(tlsCertSdsConfigs).hasSize(1); assertThat(tlsCertSdsConfigs).hasSize(1);
@ -130,7 +124,7 @@ public class EnvoyServerProtoDataTest {
FilterChain.newBuilder() FilterChain.newBuilder()
.setFilterChainMatch( .setFilterChainMatch(
FilterChainMatch.newBuilder() FilterChainMatch.newBuilder()
.setDestinationPort(UInt32Value.newBuilder().setValue(8000).build()) .setDestinationPort(UInt32Value.of(8000))
.build()) .build())
.addFilters(Filter.newBuilder() .addFilters(Filter.newBuilder()
.setName("envoy.http_connection_manager") .setName("envoy.http_connection_manager")
@ -144,12 +138,11 @@ public class EnvoyServerProtoDataTest {
FilterChain.newBuilder() FilterChain.newBuilder()
.setFilterChainMatch( .setFilterChainMatch(
FilterChainMatch.newBuilder() FilterChainMatch.newBuilder()
.setDestinationPort(UInt32Value.newBuilder().setValue(8000) .setDestinationPort(UInt32Value.of(8000))
.build())
.addPrefixRanges(CidrRange.newBuilder() .addPrefixRanges(CidrRange.newBuilder()
.setAddressPrefix("10.20.0.15") .setAddressPrefix("10.20.0.15")
.setPrefixLen(UInt32Value.newBuilder().setValue(32) .setPrefixLen(UInt32Value.of(32))
.build()).build()) .build())
.addApplicationProtocols("managed-mtls") .addApplicationProtocols("managed-mtls")
.build()) .build())
.setTransportSocket(TransportSocket.newBuilder().setName("tls") .setTransportSocket(TransportSocket.newBuilder().setName("tls")
@ -173,12 +166,10 @@ public class EnvoyServerProtoDataTest {
FilterChain.newBuilder() FilterChain.newBuilder()
.setFilterChainMatch( .setFilterChainMatch(
FilterChainMatch.newBuilder() FilterChainMatch.newBuilder()
.setDestinationPort(UInt32Value.newBuilder().setValue(8000) .setDestinationPort(UInt32Value.of(8000))
.build())
.addPrefixRanges(CidrRange.newBuilder() .addPrefixRanges(CidrRange.newBuilder()
.setAddressPrefix("10.20.0.15") .setAddressPrefix("10.20.0.15")
.setPrefixLen(UInt32Value.newBuilder().setValue(32) .setPrefixLen(UInt32Value.of(32)).build())
.build()).build())
.addApplicationProtocols("managed-mtls") .addApplicationProtocols("managed-mtls")
.build()) .build())
.setTlsContext(CommonTlsContextTestsUtil.buildTestDownstreamTlsContext()) .setTlsContext(CommonTlsContextTestsUtil.buildTestDownstreamTlsContext())

View File

@ -688,10 +688,10 @@ public class XdsClientImplTest {
.setRoute(RouteAction.newBuilder().setWeightedClusters( .setRoute(RouteAction.newBuilder().setWeightedClusters(
WeightedCluster.newBuilder() WeightedCluster.newBuilder()
.addClusters(WeightedCluster.ClusterWeight.newBuilder() .addClusters(WeightedCluster.ClusterWeight.newBuilder()
.setWeight(UInt32Value.newBuilder().setValue(30)) .setWeight(UInt32Value.of(30))
.setName("cl21.googleapis.com")) .setName("cl21.googleapis.com"))
.addClusters(WeightedCluster.ClusterWeight.newBuilder() .addClusters(WeightedCluster.ClusterWeight.newBuilder()
.setWeight(UInt32Value.newBuilder().setValue(70)) .setWeight(UInt32Value.of(70))
.setName("cl22.googleapis.com")))) .setName("cl22.googleapis.com"))))
.setMatch(RouteMatch.newBuilder().setPath("/service2/method2"))) .setMatch(RouteMatch.newBuilder().setPath("/service2/method2")))
.addRoutes(Route.newBuilder() .addRoutes(Route.newBuilder()

View File

@ -213,7 +213,7 @@ class XdsClientTestHelper {
.setZone(zone) .setZone(zone)
.setSubZone(subZone)) .setSubZone(subZone))
.addAllLbEndpoints(lbEndpoints) .addAllLbEndpoints(lbEndpoints)
.setLoadBalancingWeight(UInt32Value.newBuilder().setValue(loadBalancingWeight)) .setLoadBalancingWeight(UInt32Value.of(loadBalancingWeight))
.setPriority(priority) .setPriority(priority)
.build(); .build();
} }
@ -226,8 +226,8 @@ class XdsClientTestHelper {
io.envoyproxy.envoy.api.v2.endpoint.Endpoint.newBuilder().setAddress( io.envoyproxy.envoy.api.v2.endpoint.Endpoint.newBuilder().setAddress(
Address.newBuilder().setSocketAddress( Address.newBuilder().setSocketAddress(
SocketAddress.newBuilder().setAddress(address).setPortValue(port)))) SocketAddress.newBuilder().setAddress(address).setPortValue(port))))
.setHealthStatus(healthStatus).setLoadBalancingWeight( .setHealthStatus(healthStatus)
UInt32Value.newBuilder().setValue(loadbalancingWeight)) .setLoadBalancingWeight(UInt32Value.of(loadbalancingWeight))
.build(); .build();
} }

View File

@ -744,7 +744,7 @@ public class XdsNameResolverTest {
builder.addClusters( builder.addClusters(
ClusterWeight.newBuilder() ClusterWeight.newBuilder()
.setName(entry.getKey()) .setName(entry.getKey())
.setWeight(UInt32Value.newBuilder().setValue(entry.getValue()))); .setWeight(UInt32Value.of(entry.getValue())));
} }
return RouteAction.newBuilder() return RouteAction.newBuilder()
.setWeightedClusters(builder) .setWeightedClusters(builder)