Skip to content

Commit 974a8b5

Browse files
author
Daniel Mikusa
authored
Fixes issue where test was not waiting for the creation of service instance to complete (#1161)
The update test does two things: 1.) it creates a managed service instance and 2.) it updates the managed service instance. The second part was failing because CloudController will refuse to update a service that's still being created. The update job was calling a method `waitForCompletionOnCreate` which was looking at the CreateServiceInstanceResponse object to see if it had an job id, if it did, then it would call `JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(1), createServiceInstanceResponse.getJobId().get())` and then return `getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName)`. The problem is that the call to `JobUtils.waitForCompletion` was creating a flow but nothing was subscribing to it, so it never actually ran and the test would not pause until the creation finished. The test has been modified such that it assumes the creation request will be asynch and return a job id. If it does not for some reason, the test would fail as wel call `.get()` on an optional object and calling that if the optional is empty will generate a NoSuchElementException. Then with the jobId, we call `JobUtils.waitForCompletion` wrapped in a flatMap, which ensures it's part of the overall flow which is being subscribed to. The same change was made after the update request, which also returns an asynch response and needs to be polled. Signed-off-by: Daniel Mikusa <[email protected]>
1 parent a9b80c9 commit 974a8b5

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceInstancesTest.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ private static Mono<String> updateServiceInstanceByName(CloudFoundryClient cloud
275275
.build())
276276
.map(serviceInstances -> serviceInstances.getResources().get(0))
277277
.flatMap(serviceInstance -> updateServiceInstanceById(cloudFoundryClient, serviceInstance.getId()))
278-
.flatMap(serviceInstance -> waitForCompletionOnUpdate(cloudFoundryClient, serviceInstance, serviceInstanceName));
278+
.map(response -> response.getJobId().get())
279+
.flatMap(jobId -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), jobId))
280+
.then(getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName));
279281
}
280282

281283
private static Mono<UpdateServiceInstanceResponse> updateServiceInstanceById(CloudFoundryClient cloudFoundryClient, String serviceInstanceId) {
@@ -287,26 +289,14 @@ private static Mono<UpdateServiceInstanceResponse> updateServiceInstanceById(Clo
287289
.build());
288290
}
289291

290-
291-
private static Mono<String> waitForCompletionOnUpdate(CloudFoundryClient cloudFoundryClient, UpdateServiceInstanceResponse updateServiceInstanceResponse, String serviceInstanceName) {
292-
if (updateServiceInstanceResponse.getJobId().isPresent()) {
293-
JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(1), updateServiceInstanceResponse.getJobId().get());
294-
}
295-
return getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName);
296-
}
297-
298292
private static Mono<String> createManagedServiceInstanceId(CloudFoundryClient cloudFoundryClient, Mono<String> serviceBrokerId, String serviceInstanceName, String serviceName, String spaceId) {
299293
return serviceBrokerId
300294
.flatMap(brokerId -> getPlanId(cloudFoundryClient, brokerId, serviceName))
301295
.flatMap(planId -> requestCreateServiceInstance(cloudFoundryClient, planId, serviceInstanceName, spaceId))
302-
.flatMap(serviceInstance -> waitForCompletionOnCreate(cloudFoundryClient, serviceInstance, serviceInstanceName));
303-
}
304-
305-
private static Mono<String> waitForCompletionOnCreate(CloudFoundryClient cloudFoundryClient, CreateServiceInstanceResponse createServiceInstanceResponse, String serviceInstanceName) {
306-
if (createServiceInstanceResponse.getJobId().isPresent()) {
307-
JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(1), createServiceInstanceResponse.getJobId().get());
308-
}
309-
return getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName);
296+
.map(response -> response.getJobId()
297+
.get())
298+
.flatMap(jobId -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), jobId))
299+
.then(getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName));
310300
}
311301

312302
private static Mono<String> getServiceInstanceIdByName(CloudFoundryClient cloudFoundryClient, String serviceInstanceName) {

0 commit comments

Comments
 (0)