From f40570402a9810aade2f736cdc00015ec0c39d56 Mon Sep 17 00:00:00 2001 From: Daniel Mikusa Date: Wed, 27 Jul 2022 12:06:15 -0400 Subject: [PATCH] Fixes issue where test was not waiting for the creation of service instance to complete 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 --- .idea/misc.xml | 2 +- .../client/v3/ServiceInstancesTest.java | 24 ++++++------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index b56f5aa0e7..fc9aaf441c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -14,7 +14,7 @@ - + \ No newline at end of file diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceInstancesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceInstancesTest.java index 38508a4cb4..4a6da53251 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceInstancesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceInstancesTest.java @@ -275,7 +275,9 @@ private static Mono updateServiceInstanceByName(CloudFoundryClient cloud .build()) .map(serviceInstances -> serviceInstances.getResources().get(0)) .flatMap(serviceInstance -> updateServiceInstanceById(cloudFoundryClient, serviceInstance.getId())) - .flatMap(serviceInstance -> waitForCompletionOnUpdate(cloudFoundryClient, serviceInstance, serviceInstanceName)); + .map(response -> response.getJobId().get()) + .flatMap(jobId -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), jobId)) + .then(getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName)); } private static Mono updateServiceInstanceById(CloudFoundryClient cloudFoundryClient, String serviceInstanceId) { @@ -287,26 +289,14 @@ private static Mono updateServiceInstanceById(Clo .build()); } - - private static Mono waitForCompletionOnUpdate(CloudFoundryClient cloudFoundryClient, UpdateServiceInstanceResponse updateServiceInstanceResponse, String serviceInstanceName) { - if (updateServiceInstanceResponse.getJobId().isPresent()) { - JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(1), updateServiceInstanceResponse.getJobId().get()); - } - return getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName); - } - private static Mono createManagedServiceInstanceId(CloudFoundryClient cloudFoundryClient, Mono serviceBrokerId, String serviceInstanceName, String serviceName, String spaceId) { return serviceBrokerId .flatMap(brokerId -> getPlanId(cloudFoundryClient, brokerId, serviceName)) .flatMap(planId -> requestCreateServiceInstance(cloudFoundryClient, planId, serviceInstanceName, spaceId)) - .flatMap(serviceInstance -> waitForCompletionOnCreate(cloudFoundryClient, serviceInstance, serviceInstanceName)); - } - - private static Mono waitForCompletionOnCreate(CloudFoundryClient cloudFoundryClient, CreateServiceInstanceResponse createServiceInstanceResponse, String serviceInstanceName) { - if (createServiceInstanceResponse.getJobId().isPresent()) { - JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(1), createServiceInstanceResponse.getJobId().get()); - } - return getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName); + .map(response -> response.getJobId() + .get()) + .flatMap(jobId -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), jobId)) + .then(getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName)); } private static Mono getServiceInstanceIdByName(CloudFoundryClient cloudFoundryClient, String serviceInstanceName) {