1+ /*
2+ * Copyright (c) 2016-2023 Michael Zhang <yidongnan@gmail.com>
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+
118package net .devh .boot .grpc .test .inject ;
219
320import 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 ;
1522import org .junit .jupiter .api .Test ;
1623import org .springframework .beans .factory .annotation .Autowired ;
1724import org .springframework .boot .actuate .autoconfigure .metrics .JvmMetricsAutoConfiguration ;
2431import org .springframework .test .annotation .DirtiesContext ;
2532import 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
3856public 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