1
1
/*
2
- * Copyright 2015-2019 the original author or authors.
2
+ * Copyright 2015-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
40
40
/**
41
41
* @author Dave Syer
42
42
* @author Gary Russell
43
+ * @author Artem Bilan
43
44
*
44
45
*/
45
46
public class CircuitBreakerTests {
@@ -81,6 +82,8 @@ public void vanilla() throws Exception {
81
82
assertEquals (3 , service .getCount ());
82
83
service .expressionService ();
83
84
assertEquals (4 , service .getCount ());
85
+ service .expressionService2 ();
86
+ assertEquals (5 , service .getCount ());
84
87
Advised advised = (Advised ) service ;
85
88
Advisor advisor = advised .getAdvisors ()[0 ];
86
89
Map <?, ?> delegates = (Map <?, ?>) new DirectFieldAccessor (advisor ).getPropertyValue ("advice.delegates" );
@@ -94,6 +97,12 @@ public void vanilla() throws Exception {
94
97
assertEquals (20000L , accessor .getPropertyValue ("retryOperations.retryPolicy.resetTimeout" ));
95
98
assertEquals ("#root instanceof RuntimeExpression" ,
96
99
accessor .getPropertyValue ("retryOperations.retryPolicy.delegate.expression.expression" ));
100
+
101
+ interceptor = (MethodInterceptor ) methodMap .get (Service .class .getDeclaredMethod ("expressionService2" ));
102
+ accessor = new DirectFieldAccessor (interceptor );
103
+ assertEquals (10 , accessor .getPropertyValue ("retryOperations.retryPolicy.delegate.maxAttempts" ));
104
+ assertEquals (10000L , accessor .getPropertyValue ("retryOperations.retryPolicy.openTimeout" ));
105
+ assertEquals (20000L , accessor .getPropertyValue ("retryOperations.retryPolicy.resetTimeout" ));
97
106
context .close ();
98
107
}
99
108
@@ -106,6 +115,21 @@ public Service service() {
106
115
return new ServiceImpl ();
107
116
}
108
117
118
+ @ Bean
119
+ Configs configs () {
120
+ return new Configs ();
121
+ }
122
+
123
+ }
124
+
125
+ public static class Configs {
126
+
127
+ public int maxAttempts = 10 ;
128
+
129
+ public long openTimeout = 10000 ;
130
+
131
+ public long resetTimeout = 20000 ;
132
+
109
133
}
110
134
111
135
interface Service {
@@ -114,6 +138,8 @@ interface Service {
114
138
115
139
void expressionService ();
116
140
141
+ void expressionService2 ();
142
+
117
143
int getCount ();
118
144
119
145
RetryContext getContext ();
@@ -143,6 +169,13 @@ public void expressionService() {
143
169
this .count ++;
144
170
}
145
171
172
+ @ Override
173
+ @ CircuitBreaker (maxAttemptsExpression = "@configs.maxAttempts" , openTimeoutExpression = "@configs.openTimeout" ,
174
+ resetTimeoutExpression = "@configs.resetTimeout" )
175
+ public void expressionService2 () {
176
+ this .count ++;
177
+ }
178
+
146
179
@ Override
147
180
public RetryContext getContext () {
148
181
return this .context ;
0 commit comments