@@ -87,6 +87,15 @@ public void afterFiber_timeoutStepScheduled() throws Exception {
87
87
assertTrue (schedule .containsStepAt (TIMEOUT_SECONDS , TimeUnit .SECONDS ));
88
88
}
89
89
90
+ @ Test
91
+ public void afterTimeout_newRequestSent () throws Exception {
92
+ callFactory .clearRequest ();
93
+
94
+ schedule .setTime (TIMEOUT_SECONDS , TimeUnit .SECONDS );
95
+
96
+ assertTrue (callFactory .invokedWith (requestParams ));
97
+ }
98
+
90
99
@ Test
91
100
public void afterSuccessfulCallback_nextStepAppliedWithValue () throws Exception {
92
101
callFactory .sendSuccessfulCallback (17 );
@@ -103,16 +112,31 @@ public void afterSuccessfulCallback_packetDoesNotContainsResponse() throws Excep
103
112
104
113
@ Test
105
114
public void afterFailedCallback_packetContainsRetryStrategy () throws Exception {
106
- schedule .execute (() ->
107
- callFactory .sendFailedCallback (new ApiException ("test failure" ), HttpURLConnection .HTTP_UNAVAILABLE ));
115
+ sendFailedCallback (HttpURLConnection .HTTP_UNAVAILABLE );
108
116
109
117
assertThat (packet .getComponents ().get (RESPONSE_COMPONENT_NAME ).getSPI (RetryStrategy .class ), notNullValue ());
110
118
}
111
119
120
+ private void sendFailedCallback (int statusCode ) {
121
+ schedule .execute (() -> callFactory .sendFailedCallback (new ApiException ("test failure" ), statusCode ));
122
+ }
123
+
124
+ @ Test
125
+ public void afterFailedCallback_retrySentAfterDelay () throws Exception {
126
+ sendFailedCallback (HttpURLConnection .HTTP_UNAVAILABLE );
127
+ callFactory .clearRequest ();
128
+
129
+ schedule .setTime (TIMEOUT_SECONDS -1 , TimeUnit .SECONDS );
130
+
131
+ assertTrue (callFactory .invokedWith (requestParams ));
132
+ }
133
+
112
134
// todo tests
113
- // after timeout, packet contains retry strategy
114
- // after either failure, setting time to before the timeout causes new request
115
- // after new request, success leads to invocation
135
+ // can new request clear timeout action?
136
+ // what is accessContinue?
137
+ // test CONFLICT (409) status
138
+ // no retry if status not handled
139
+ // test exceeded retry count
116
140
117
141
118
142
static class TestStep extends ResponseStep <Integer > {
@@ -135,15 +159,19 @@ static class CallFactoryStub implements CallFactory<Integer> {
135
159
private RequestParams requestParams ;
136
160
private ApiCallback <Integer > callback ;
137
161
138
- private boolean invokedWith (RequestParams requestParams ) {
162
+ void clearRequest () {
163
+ requestParams = null ;
164
+ }
165
+
166
+ boolean invokedWith (RequestParams requestParams ) {
139
167
return requestParams == this .requestParams ;
140
168
}
141
169
142
- private void sendSuccessfulCallback (Integer callbackValue ) {
170
+ void sendSuccessfulCallback (Integer callbackValue ) {
143
171
callback .onSuccess (callbackValue , HttpURLConnection .HTTP_OK , Collections .emptyMap ());
144
172
}
145
173
146
- private void sendFailedCallback (ApiException exception , int statusCode ) {
174
+ void sendFailedCallback (ApiException exception , int statusCode ) {
147
175
callback .onFailure (exception , statusCode , Collections .emptyMap ());
148
176
}
149
177
0 commit comments