xds: Improve code clarity by removing Unnecessary fully qualified names and using Immutable interface types. (#9025)

1. Unnecessary fully qualified names
Currently in XdsCredentialsRegistry, the child classes are referred by
their fully qualified names i.e.
'io.grpc.xds.internal.GoogleDefaultXdsCredentialsProvider' instead of
importing GoogleDefaultXdsCredentialsProvider and just using
GoogleDefaultXdsCredentialsProvider.class.

2. Use immutable interfaces instead of the generic collection interface
   i.e. ImmutableMap instead of just Map.

These improvements are related to #8924.
This commit is contained in:
Anirudh Ramachandra 2022-04-04 07:19:53 -07:00 committed by GitHub
parent 1ab7a6dd0f
commit 79f2562306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 7 deletions

View File

@ -25,6 +25,9 @@ import com.google.common.collect.ImmutableMap;
import io.grpc.ChannelCredentials;
import io.grpc.xds.XdsCredentialsProvider;
import io.grpc.xds.XdsCredentialsRegistry;
import io.grpc.xds.internal.GoogleDefaultXdsCredentialsProvider;
import io.grpc.xds.internal.InsecureXdsCredentialsProvider;
import io.grpc.xds.internal.TlsXdsCredentialsProvider;
import java.util.List;
import java.util.Map;
import org.junit.Test;
@ -95,7 +98,7 @@ public class XdsCredentialsRegistryTest {
}
});
Map<String, String> sampleConfig = ImmutableMap.of("a", "b");
ImmutableMap<String, String> sampleConfig = ImmutableMap.of("a", "b");
ChannelCredentials creds = registry.providers().get(credsName)
.newChannelCredentials(sampleConfig);
assertSame(SampleChannelCredentials.class, creds.getClass());
@ -135,20 +138,20 @@ public class XdsCredentialsRegistryTest {
XdsCredentialsRegistry.getDefaultRegistry().providers();
assertThat(providers).hasSize(3);
assertThat(providers.get("google_default").getClass())
.isEqualTo(io.grpc.xds.internal.GoogleDefaultXdsCredentialsProvider.class);
.isEqualTo(GoogleDefaultXdsCredentialsProvider.class);
assertThat(providers.get("insecure").getClass())
.isEqualTo(io.grpc.xds.internal.InsecureXdsCredentialsProvider.class);
.isEqualTo(InsecureXdsCredentialsProvider.class);
assertThat(providers.get("tls").getClass())
.isEqualTo(io.grpc.xds.internal.TlsXdsCredentialsProvider.class);
.isEqualTo(TlsXdsCredentialsProvider.class);
}
@Test
public void getClassesViaHardcoded_classesPresent() throws Exception {
List<Class<?>> classes = XdsCredentialsRegistry.getHardCodedClasses();
assertThat(classes).containsExactly(
io.grpc.xds.internal.GoogleDefaultXdsCredentialsProvider.class,
io.grpc.xds.internal.InsecureXdsCredentialsProvider.class,
io.grpc.xds.internal.TlsXdsCredentialsProvider.class);
GoogleDefaultXdsCredentialsProvider.class,
InsecureXdsCredentialsProvider.class,
TlsXdsCredentialsProvider.class);
}
@Test