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
+
1
18
package net .devh .boot .grpc .test .inject ;
2
19
3
20
import static org .assertj .core .api .AssertionsForInterfaceTypes .assertThat ;
4
21
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 ;
15
22
import org .junit .jupiter .api .Test ;
16
23
import org .springframework .beans .factory .annotation .Autowired ;
17
24
import org .springframework .boot .actuate .autoconfigure .metrics .JvmMetricsAutoConfiguration ;
24
31
import org .springframework .test .annotation .DirtiesContext ;
25
32
import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
26
33
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
+
27
45
@ SpringBootTest
28
46
@ 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
+ })
37
55
@ DirtiesContext
38
56
public class GrpcClientMetricsTest {
39
57
@ Autowired
@@ -42,8 +60,8 @@ public class GrpcClientMetricsTest {
42
60
@ Test
43
61
void jvmMetricsTest () {
44
62
assertThat (registry .getMeters ())
45
- .filteredOn (meter -> meter .getId ().getName ().contains ("jvm" ))
46
- .isNotEmpty ();
63
+ .filteredOn (meter -> meter .getId ().getName ().contains ("jvm" ))
64
+ .isNotEmpty ();
47
65
}
48
66
49
67
@ Component
@@ -55,16 +73,16 @@ public static class GrpcClientConstructorInjectionBean {
55
73
public CustomGrpc .FactoryMethodAccessibleStub anotherServiceClientBean ;
56
74
57
75
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 ;
68
86
}
69
87
}
70
88
@@ -77,13 +95,13 @@ StubFactory customStubFactory() {
77
95
78
96
@ Override
79
97
public boolean isApplicable (final Class <? extends AbstractStub <?>> stubType ) {
80
- return CustomStub .class .isAssignableFrom (stubType );
81
- }
98
+ return CustomStub .class .isAssignableFrom (stubType );
99
+ }
82
100
83
101
@ Override
84
102
protected String getFactoryMethodName () {
85
- return "custom" ;
86
- }
103
+ return "custom" ;
104
+ }
87
105
88
106
};
89
107
}
0 commit comments