Skip to content

Commit 0863721

Browse files
committed
Initialize stub factories always the same way
Fixes gh-217
1 parent 9cb2886 commit 0863721

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcClientFactory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ private StubFactory<?> findFactory(Class<?> factoryType, Class<?> type) {
8888
}
8989
AnnotationAwareOrderComparator.sort(factories);
9090
for (StubFactory<?> factory : factories) {
91-
if (supports(factory.getClass(), type)) {
92-
this.factories.put(factory.getClass(), factory);
93-
}
91+
this.factories.put(factory.getClass(), factory);
9492
}
9593
for (Class<?> factory : DEFAULT_FACTORIES) {
9694
if (this.factories.containsKey(factory)) {

spring-grpc-core/src/test/java/org/springframework/grpc/client/GrpcClientFactoryTests.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class GrpcClientFactoryTests {
4646

4747
GrpcClientFactoryTests() {
4848
Mockito.when(channelFactory.createChannel(Mockito.anyString(), Mockito.any()))
49-
.thenReturn(Mockito.mock(ManagedChannel.class));
49+
.thenReturn(Mockito.mock(ManagedChannel.class));
5050
context.registerBean(GrpcChannelFactory.class, () -> channelFactory);
5151
factory = new GrpcClientFactory();
5252
factory.setApplicationContext(context);
@@ -75,7 +75,7 @@ void testCustomStubFactory() {
7575
void testWithExplicitStubFactory() {
7676
context.registerBean(OtherStubFactory.class, () -> new OtherStubFactory());
7777
GrpcClientFactory.register(context, new GrpcClientRegistrationSpec("local", new Class[] { OtherStub.class })
78-
.factory(OtherStubFactory.class));
78+
.factory(OtherStubFactory.class));
7979
assertThat(factory.getClient("local", OtherStub.class, null)).isNotNull();
8080
}
8181

@@ -96,11 +96,25 @@ void testCoroutineStubFactory() {
9696
context.registerBean(CoroutineStubFactory.class, CoroutineStubFactory::new);
9797
GrpcClientFactory.register(context,
9898
GrpcClientRegistrationSpec.of("local")
99-
.factory(CoroutineStubFactory.class)
100-
.types(MyCoroutineStub.class));
99+
.factory(CoroutineStubFactory.class)
100+
.types(MyCoroutineStub.class));
101101
assertThat(factory.getClient("local", MyCoroutineStub.class, null)).isNotNull();
102102
}
103103

104+
@Test
105+
void testCoroutineStubFactoryAfterDefault() {
106+
context.registerBean(CoroutineStubFactory.class, CoroutineStubFactory::new);
107+
GrpcClientFactory.register(context,
108+
GrpcClientRegistrationSpec.of("local")
109+
.types(MyStub.class));
110+
GrpcClientFactory.register(context,
111+
GrpcClientRegistrationSpec.of("local")
112+
.factory(CoroutineStubFactory.class)
113+
.types(MyCoroutineStub.class));
114+
assertThat(factory.getClient("local", MyCoroutineStub.class, null)).isNotNull();
115+
assertThat(factory.getClient("local", MyStub.class, null)).isNotNull();
116+
}
117+
104118
static class OtherStubFactory implements StubFactory<OtherStub> {
105119

106120
@Override

0 commit comments

Comments
 (0)