@@ -165,16 +165,24 @@ public void testDeletingFilesAfterShutdown() throws InterruptedException, Execut
165
165
}
166
166
}
167
167
168
+ @ DataProvider (name = "shouldThrowOnGetClientDataProvider" )
169
+ public Object [][] shouldThrowOnGetClientDataProvider ()
170
+ {
171
+ return new Object [][]
172
+ {{true }, {false }};
173
+ }
174
+
168
175
/**
169
176
* Since the list might from the fetcher might not be complete (update service, old data, etc.., and the user might
170
177
* require additional services at runtime, we have to check that those services are not cleared from the cache
171
- * otherwise it would incur in a penalty at the next deployment
178
+ * otherwise it would incur in a penalty at the next deployment.
179
+ * Note that regardless of whether getClient returns successfully or not (if it times out, for example),
180
+ * we should still record the service/s we tried to warm up.
172
181
*/
173
- @ Test (timeOut = 10000 , retryAnalyzer = ThreeRetries .class )
174
- public void testNotDeletingFilesGetClient () throws InterruptedException , ExecutionException , TimeoutException , ServiceUnavailableException
175
- {
182
+ @ Test (dataProvider = "shouldThrowOnGetClientDataProvider" , timeOut = 10000 , retryAnalyzer = ThreeRetries .class )
183
+ public void testNotDeletingFilesGetClient (boolean shouldThrowOnGetClient ) throws InterruptedException , ExecutionException , TimeoutException {
176
184
createDefaultServicesIniFiles ();
177
- TestLoadBalancer balancer = new TestLoadBalancer ();
185
+ TestLoadBalancer balancer = new TestLoadBalancer (shouldThrowOnGetClient );
178
186
179
187
List <String > allServicesBeforeShutdown = getAllDownstreamServices ();
180
188
DownstreamServicesFetcher returnNoDownstreams = callback -> callback .onSuccess (Collections .emptyList ());
@@ -190,14 +198,19 @@ public void testNotDeletingFilesGetClient() throws InterruptedException, Executi
190
198
warmUpLoadBalancer .start (callback );
191
199
callback .get (5000 , TimeUnit .MILLISECONDS );
192
200
193
- warmUpLoadBalancer .getClient (new URIRequest ("d2://" + pickOneService ), new RequestContext ());
201
+ try {
202
+ warmUpLoadBalancer .getClient (new URIRequest ("d2://" + pickOneService ), new RequestContext ());
203
+ } catch (Exception e ) {
204
+ Assert .assertTrue (shouldThrowOnGetClient );
205
+ }
194
206
195
207
FutureCallback <None > shutdownCallback = new FutureCallback <>();
196
208
warmUpLoadBalancer .shutdown (() -> shutdownCallback .onSuccess (None .none ()));
197
209
shutdownCallback .get (5000 , TimeUnit .MILLISECONDS );
198
210
199
211
List <String > allServicesAfterShutdown = getAllDownstreamServices ();
200
212
213
+ // regardless of whether getClient returned successfully or threw an Exception, we should still record the service we tried to warm up
201
214
Assert .assertEquals (1 , allServicesAfterShutdown .size (), "After shutdown there should be just one service, the one that we 'get the client' on" );
202
215
}
203
216
0 commit comments