mirror of https://github.com/grpc/grpc-java.git
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:
parent
1ab7a6dd0f
commit
79f2562306
|
|
@ -25,6 +25,9 @@ import com.google.common.collect.ImmutableMap;
|
||||||
import io.grpc.ChannelCredentials;
|
import io.grpc.ChannelCredentials;
|
||||||
import io.grpc.xds.XdsCredentialsProvider;
|
import io.grpc.xds.XdsCredentialsProvider;
|
||||||
import io.grpc.xds.XdsCredentialsRegistry;
|
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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.junit.Test;
|
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)
|
ChannelCredentials creds = registry.providers().get(credsName)
|
||||||
.newChannelCredentials(sampleConfig);
|
.newChannelCredentials(sampleConfig);
|
||||||
assertSame(SampleChannelCredentials.class, creds.getClass());
|
assertSame(SampleChannelCredentials.class, creds.getClass());
|
||||||
|
|
@ -135,20 +138,20 @@ public class XdsCredentialsRegistryTest {
|
||||||
XdsCredentialsRegistry.getDefaultRegistry().providers();
|
XdsCredentialsRegistry.getDefaultRegistry().providers();
|
||||||
assertThat(providers).hasSize(3);
|
assertThat(providers).hasSize(3);
|
||||||
assertThat(providers.get("google_default").getClass())
|
assertThat(providers.get("google_default").getClass())
|
||||||
.isEqualTo(io.grpc.xds.internal.GoogleDefaultXdsCredentialsProvider.class);
|
.isEqualTo(GoogleDefaultXdsCredentialsProvider.class);
|
||||||
assertThat(providers.get("insecure").getClass())
|
assertThat(providers.get("insecure").getClass())
|
||||||
.isEqualTo(io.grpc.xds.internal.InsecureXdsCredentialsProvider.class);
|
.isEqualTo(InsecureXdsCredentialsProvider.class);
|
||||||
assertThat(providers.get("tls").getClass())
|
assertThat(providers.get("tls").getClass())
|
||||||
.isEqualTo(io.grpc.xds.internal.TlsXdsCredentialsProvider.class);
|
.isEqualTo(TlsXdsCredentialsProvider.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getClassesViaHardcoded_classesPresent() throws Exception {
|
public void getClassesViaHardcoded_classesPresent() throws Exception {
|
||||||
List<Class<?>> classes = XdsCredentialsRegistry.getHardCodedClasses();
|
List<Class<?>> classes = XdsCredentialsRegistry.getHardCodedClasses();
|
||||||
assertThat(classes).containsExactly(
|
assertThat(classes).containsExactly(
|
||||||
io.grpc.xds.internal.GoogleDefaultXdsCredentialsProvider.class,
|
GoogleDefaultXdsCredentialsProvider.class,
|
||||||
io.grpc.xds.internal.InsecureXdsCredentialsProvider.class,
|
InsecureXdsCredentialsProvider.class,
|
||||||
io.grpc.xds.internal.TlsXdsCredentialsProvider.class);
|
TlsXdsCredentialsProvider.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue