Skip to content

Commit eb84d2c

Browse files
committed
Code Formatting
1 parent 4c26935 commit eb84d2c

File tree

3 files changed

+73
-58
lines changed

3 files changed

+73
-58
lines changed

grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/autoconfigure/GrpcClientAutoConfiguration.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222

2323
import javax.annotation.PostConstruct;
24+
2425
import org.springframework.beans.factory.annotation.Autowired;
2526
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2627
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -31,6 +32,8 @@
3132
import org.springframework.context.annotation.Bean;
3233
import org.springframework.context.annotation.Configuration;
3334
import org.springframework.context.annotation.Lazy;
35+
import org.springframework.context.weaving.LoadTimeWeaverAware;
36+
import org.springframework.instrument.classloading.LoadTimeWeaver;
3437

3538
import io.grpc.CompressorRegistry;
3639
import io.grpc.DecompressorRegistry;
@@ -53,8 +56,6 @@
5356
import net.devh.boot.grpc.client.stubfactory.BlockingStubFactory;
5457
import net.devh.boot.grpc.client.stubfactory.FutureStubFactory;
5558
import net.devh.boot.grpc.common.autoconfigure.GrpcCommonCodecAutoConfiguration;
56-
import org.springframework.context.weaving.LoadTimeWeaverAware;
57-
import org.springframework.instrument.classloading.LoadTimeWeaver;
5859

5960
/**
6061
* The auto configuration used by Spring-Boot that contains all beans to create and inject grpc clients into beans.
@@ -153,8 +154,7 @@ List<GrpcChannelConfigurer> defaultChannelConfigurers() {
153154
"io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder"})
154155
@Bean
155156
@Lazy
156-
GrpcChannelFactory shadedNettyGrpcChannelFactory(
157-
final GrpcChannelsProperties properties,
157+
GrpcChannelFactory shadedNettyGrpcChannelFactory(final GrpcChannelsProperties properties,
158158
final GlobalClientInterceptorRegistry globalClientInterceptorRegistry,
159159
final List<GrpcChannelConfigurer> channelConfigurers) {
160160

@@ -171,8 +171,7 @@ GrpcChannelFactory shadedNettyGrpcChannelFactory(
171171
@ConditionalOnClass(name = {"io.netty.channel.Channel", "io.grpc.netty.NettyChannelBuilder"})
172172
@Bean
173173
@Lazy
174-
GrpcChannelFactory nettyGrpcChannelFactory(
175-
final GrpcChannelsProperties properties,
174+
GrpcChannelFactory nettyGrpcChannelFactory(final GrpcChannelsProperties properties,
176175
final GlobalClientInterceptorRegistry globalClientInterceptorRegistry,
177176
final List<GrpcChannelConfigurer> channelConfigurers) {
178177

@@ -188,8 +187,7 @@ GrpcChannelFactory nettyGrpcChannelFactory(
188187
@ConditionalOnMissingBean(GrpcChannelFactory.class)
189188
@Bean
190189
@Lazy
191-
GrpcChannelFactory inProcessGrpcChannelFactory(
192-
final GrpcChannelsProperties properties,
190+
GrpcChannelFactory inProcessGrpcChannelFactory(final GrpcChannelsProperties properties,
193191
final GlobalClientInterceptorRegistry globalClientInterceptorRegistry,
194192
final List<GrpcChannelConfigurer> channelConfigurers) {
195193

@@ -208,7 +206,6 @@ public void init() {
208206
}
209207

210208
@Override
211-
public void setLoadTimeWeaver(LoadTimeWeaver ltw) {
212-
}
209+
public void setLoadTimeWeaver(LoadTimeWeaver ltw) {}
213210
}
214211
}

grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/inject/GrpcClientBeanPostProcessor.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Collection;
3131
import java.util.LinkedHashSet;
3232
import java.util.List;
33-
3433
import java.util.Map;
3534
import java.util.Set;
3635
import java.util.concurrent.ConcurrentHashMap;
@@ -59,6 +58,7 @@
5958
import org.springframework.lang.Nullable;
6059
import org.springframework.util.ClassUtils;
6160
import org.springframework.util.ReflectionUtils;
61+
import org.springframework.util.StringUtils;
6262

6363
import com.google.common.collect.Lists;
6464

@@ -69,7 +69,6 @@
6969
import net.devh.boot.grpc.client.nameresolver.NameResolverRegistration;
7070
import net.devh.boot.grpc.client.stubfactory.FallbackStubFactory;
7171
import net.devh.boot.grpc.client.stubfactory.StubFactory;
72-
import org.springframework.util.StringUtils;
7372

7473
/**
7574
* This {@link BeanPostProcessor} searches for fields and methods in beans that are annotated with {@link GrpcClient}
@@ -78,7 +77,8 @@
7877
* @author Michael ([email protected])
7978
* @author Daniel Theuke ([email protected])
8079
*/
81-
public class GrpcClientBeanPostProcessor implements InstantiationAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor {
80+
public class GrpcClientBeanPostProcessor
81+
implements InstantiationAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor {
8282

8383
private final ApplicationContext applicationContext;
8484

@@ -96,8 +96,8 @@ public class GrpcClientBeanPostProcessor implements InstantiationAwareBeanPostPr
9696
private final Map<String, InjectionMetadata> injectionMetadataCache = new ConcurrentHashMap<>(256);
9797

9898
/**
99-
* Creates a new GrpcClientBeanPostProcessor with the given ApplicationContext
100-
* for GrpcClient standard {@link GrpcClient @GrpcClient} annotation.
99+
* Creates a new GrpcClientBeanPostProcessor with the given ApplicationContext for GrpcClient standard
100+
* {@link GrpcClient @GrpcClient} annotation.
101101
*
102102
* @param applicationContext The application context that will be used to get lazy access to the
103103
* {@link GrpcChannelFactory} and {@link StubTransformer}s.
@@ -156,11 +156,9 @@ public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, Str
156156
InjectionMetadata metadata = findGrpcClientMetadata(beanName, bean.getClass(), pvs);
157157
try {
158158
metadata.inject(bean, beanName, pvs);
159-
}
160-
catch (BeanCreationException ex) {
159+
} catch (BeanCreationException ex) {
161160
throw ex;
162-
}
163-
catch (Throwable ex) {
161+
} catch (Throwable ex) {
164162
throw new BeanCreationException(beanName, "Injection of gRPC client stub failed", ex);
165163
}
166164
return pvs;
@@ -473,7 +471,8 @@ private InjectionMetadata buildGrpcClientMetadata(Class<?> clazz) {
473471
MergedAnnotation<?> ann = findGrpcClientAnnotation(field);
474472
if (ann != null) {
475473
if (Modifier.isStatic(field.getModifiers())) {
476-
throw new IllegalStateException("GrpcClient annotation is not supported on static fields: " + field);
474+
throw new IllegalStateException(
475+
"GrpcClient annotation is not supported on static fields: " + field);
477476
}
478477
currElements.add(new GrpcClientMemberElement(field, null));
479478
}
@@ -487,10 +486,12 @@ private InjectionMetadata buildGrpcClientMetadata(Class<?> clazz) {
487486
MergedAnnotation<?> ann = findGrpcClientAnnotation(bridgedMethod);
488487
if (ann != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
489488
if (Modifier.isStatic(method.getModifiers())) {
490-
throw new IllegalStateException("GrpcClient annotation is not supported on static method: " + method);
489+
throw new IllegalStateException(
490+
"GrpcClient annotation is not supported on static method: " + method);
491491
}
492492
if (method.getParameterCount() == 0) {
493-
throw new IllegalStateException("GrpcClient annotation should only be used on methods with parameters: " + method);
493+
throw new IllegalStateException(
494+
"GrpcClient annotation should only be used on methods with parameters: " + method);
494495
}
495496
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
496497
currElements.add(new GrpcClientMemberElement(method, pd));
@@ -499,8 +500,7 @@ private InjectionMetadata buildGrpcClientMetadata(Class<?> clazz) {
499500

500501
elements.addAll(0, currElements);
501502
targetClass = targetClass.getSuperclass();
502-
}
503-
while (targetClass != null && targetClass != Object.class);
503+
} while (targetClass != null && targetClass != Object.class);
504504

505505
return InjectionMetadata.forElements(elements, clazz);
506506
}

tests/src/test/java/net/devh/boot/grpc/test/inject/GrpcClientMetricsTest.java

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1+
/*
2+
* Copyright (c) 2016-2023 Michael Zhang <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
118
package net.devh.boot.grpc.test.inject;
219

320
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
421

5-
import io.grpc.stub.AbstractStub;
6-
import io.micrometer.core.instrument.MeterRegistry;
7-
import net.devh.boot.grpc.client.inject.GrpcClient;
8-
import net.devh.boot.grpc.client.stubfactory.StandardJavaGrpcStubFactory;
9-
import net.devh.boot.grpc.client.stubfactory.StubFactory;
10-
import net.devh.boot.grpc.test.config.BaseAutoConfiguration;
11-
import net.devh.boot.grpc.test.config.InProcessConfiguration;
12-
import net.devh.boot.grpc.test.config.MetricConfiguration;
13-
import net.devh.boot.grpc.test.config.ServiceConfiguration;
14-
import net.devh.boot.grpc.test.proto.TestServiceGrpc;
1522
import org.junit.jupiter.api.Test;
1623
import org.springframework.beans.factory.annotation.Autowired;
1724
import org.springframework.boot.actuate.autoconfigure.metrics.JvmMetricsAutoConfiguration;
@@ -24,16 +31,27 @@
2431
import org.springframework.test.annotation.DirtiesContext;
2532
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2633

34+
import io.grpc.stub.AbstractStub;
35+
import io.micrometer.core.instrument.MeterRegistry;
36+
import net.devh.boot.grpc.client.inject.GrpcClient;
37+
import net.devh.boot.grpc.client.stubfactory.StandardJavaGrpcStubFactory;
38+
import net.devh.boot.grpc.client.stubfactory.StubFactory;
39+
import net.devh.boot.grpc.test.config.BaseAutoConfiguration;
40+
import net.devh.boot.grpc.test.config.InProcessConfiguration;
41+
import net.devh.boot.grpc.test.config.MetricConfiguration;
42+
import net.devh.boot.grpc.test.config.ServiceConfiguration;
43+
import net.devh.boot.grpc.test.proto.TestServiceGrpc;
44+
2745
@SpringBootTest
2846
@SpringJUnitConfig(
29-
classes = {
30-
GrpcClientMetricsTest.TestConfig.class,
31-
GrpcClientMetricsTest.GrpcClientConstructorInjectionBean.class,
32-
InProcessConfiguration.class,
33-
ServiceConfiguration.class,
34-
BaseAutoConfiguration.class,
35-
MetricConfiguration.class
36-
})
47+
classes = {
48+
GrpcClientMetricsTest.TestConfig.class,
49+
GrpcClientMetricsTest.GrpcClientConstructorInjectionBean.class,
50+
InProcessConfiguration.class,
51+
ServiceConfiguration.class,
52+
BaseAutoConfiguration.class,
53+
MetricConfiguration.class
54+
})
3755
@DirtiesContext
3856
public class GrpcClientMetricsTest {
3957
@Autowired
@@ -42,8 +60,8 @@ public class GrpcClientMetricsTest {
4260
@Test
4361
void jvmMetricsTest() {
4462
assertThat(registry.getMeters())
45-
.filteredOn(meter -> meter.getId().getName().contains("jvm"))
46-
.isNotEmpty();
63+
.filteredOn(meter -> meter.getId().getName().contains("jvm"))
64+
.isNotEmpty();
4765
}
4866

4967
@Component
@@ -55,16 +73,16 @@ public static class GrpcClientConstructorInjectionBean {
5573
public CustomGrpc.FactoryMethodAccessibleStub anotherServiceClientBean;
5674

5775
public GrpcClientConstructorInjectionBean(
58-
@GrpcClient("test") TestServiceGrpc.TestServiceBlockingStub blockingStub,
59-
@GrpcClient("test") TestServiceGrpc.TestServiceFutureStub futureStubForClientTest,
60-
@GrpcClient("anotherTest") TestServiceGrpc.TestServiceBlockingStub anotherBlockingStub,
61-
@GrpcClient("unnamed") TestServiceGrpc.TestServiceBlockingStub unnamedTestServiceBlockingStub,
62-
@GrpcClient("test") CustomGrpc.FactoryMethodAccessibleStub anotherServiceClientBean) {
63-
this.blockingStub = blockingStub;
64-
this.futureStubForClientTest = futureStubForClientTest;
65-
this.anotherBlockingStub = anotherBlockingStub;
66-
this.unnamedTestServiceBlockingStub = unnamedTestServiceBlockingStub;
67-
this.anotherServiceClientBean = anotherServiceClientBean;
76+
@GrpcClient("test") TestServiceGrpc.TestServiceBlockingStub blockingStub,
77+
@GrpcClient("test") TestServiceGrpc.TestServiceFutureStub futureStubForClientTest,
78+
@GrpcClient("anotherTest") TestServiceGrpc.TestServiceBlockingStub anotherBlockingStub,
79+
@GrpcClient("unnamed") TestServiceGrpc.TestServiceBlockingStub unnamedTestServiceBlockingStub,
80+
@GrpcClient("test") CustomGrpc.FactoryMethodAccessibleStub anotherServiceClientBean) {
81+
this.blockingStub = blockingStub;
82+
this.futureStubForClientTest = futureStubForClientTest;
83+
this.anotherBlockingStub = anotherBlockingStub;
84+
this.unnamedTestServiceBlockingStub = unnamedTestServiceBlockingStub;
85+
this.anotherServiceClientBean = anotherServiceClientBean;
6886
}
6987
}
7088

@@ -77,13 +95,13 @@ StubFactory customStubFactory() {
7795

7896
@Override
7997
public boolean isApplicable(final Class<? extends AbstractStub<?>> stubType) {
80-
return CustomStub.class.isAssignableFrom(stubType);
81-
}
98+
return CustomStub.class.isAssignableFrom(stubType);
99+
}
82100

83101
@Override
84102
protected String getFactoryMethodName() {
85-
return "custom";
86-
}
103+
return "custom";
104+
}
87105

88106
};
89107
}

0 commit comments

Comments
 (0)