Source:
private void createBuckets() { logger().debug("Creating " + buckets.size() + " buckets (and corresponding indexes)."); for (BucketDefinition bucket : buckets) { logger().debug("Creating bucket \"" + bucket.getName() + "\""); Response response = doHttpRequest(MGMT_PORT, "/pools/default/buckets", "POST", new FormBody.Builder() .add("name", bucket.getName()) .add("ramQuotaMB", Integer.toString(bucket.getQuota())) .build(), true); checkSuccessfulResponse(response, "Could not create bucket " + bucket.getName()); new HttpWaitStrategy() .forPath("/pools/default/buckets/" + bucket.getName()) .forPort(MGMT_PORT) .withBasicCredentials(username, password) .forStatusCode(200) .waitUntilReady(this); if (enabledServices.contains(CouchbaseService.QUERY)) { Unreliables.retryUntilTrue(1, TimeUnit.MINUTES, () -> { Response queryResponse = doHttpRequest(QUERY_PORT, "/query/service", "POST", new FormBody.Builder() .add("statement", "SELECT COUNT(*) > 0 as present FROM system:keyspaces WHERE name = \"" + bucket.getName() + "\"") .build(), true); String body = queryResponse.body() != null ? queryResponse.body().string() : null; checkSuccessfulResponse(queryResponse, "Could not poll query service state for bucket: " + bucket.getName()); return Optional.of(MAPPER.readTree(body)) .map(n -> n.at("/results/0/present")) .map(JsonNode::asBoolean) .orElse(false); }); } if (bucket.hasPrimaryIndex()) { if (enabledServices.contains(CouchbaseService.QUERY)) { Response queryResponse = doHttpRequest(QUERY_PORT, "/query/service", "POST", new FormBody.Builder() .add("statement", "CREATE PRIMARY INDEX on `" + bucket.getName() + "`") .build(), true); checkSuccessfulResponse(queryResponse, "Could not create primary index for bucket " + bucket.getName()); } else { logger().info("Primary index creation for bucket " + bucket.getName() + " ignored, since QUERY service is not present."); } } } }

Target:
private void createBuckets() { logger().debug("Creating " + buckets.size() + " buckets (and corresponding indexes)."); for (BucketDefinition bucket : buckets) { logger().debug("Creating bucket \"" + bucket.getName() + "\""); @Cleanup Response response = doHttpRequest(MGMT_PORT, "/pools/default/buckets", "POST", new FormBody.Builder() .add("name", bucket.getName()) .add("ramQuotaMB", Integer.toString(bucket.getQuota())) .build(), true); checkSuccessfulResponse(response, "Could not create bucket " + bucket.getName()); new HttpWaitStrategy() .forPath("/pools/default/buckets/" + bucket.getName()) .forPort(MGMT_PORT) .withBasicCredentials(username, password) .forStatusCode(200) .waitUntilReady(this); if (enabledServices.contains(CouchbaseService.QUERY)) { Unreliables.retryUntilTrue(1, TimeUnit.MINUTES, () -> { @Cleanup Response queryResponse = doHttpRequest(QUERY_PORT, "/query/service", "POST", new FormBody.Builder() .add("statement", "SELECT COUNT(*) > 0 as present FROM system:keyspaces WHERE name = \"" + bucket.getName() + "\"") .build(), true); String body = queryResponse.body() != null ? queryResponse.body().string() : null; checkSuccessfulResponse(queryResponse, "Could not poll query service state for bucket: " + bucket.getName()); return Optional.of(MAPPER.readTree(body)) .map(n -> n.at("/results/0/present")) .map(JsonNode::asBoolean) .orElse(false); }); } if (bucket.hasPrimaryIndex()) { if (enabledServices.contains(CouchbaseService.QUERY)) { @Cleanup Response queryResponse = doHttpRequest(QUERY_PORT, "/query/service", "POST", new FormBody.Builder() .add("statement", "CREATE PRIMARY INDEX on `" + bucket.getName() + "`") .build(), true); checkSuccessfulResponse(queryResponse, "Could not create primary index for bucket " + bucket.getName()); } else { logger().info("Primary index creation for bucket " + bucket.getName() + " ignored, since QUERY service is not present."); } } } }