From 4e365f9f93453dbeaabefd9926ae70bf36c96317 Mon Sep 17 00:00:00 2001 From: Nicholas Yip Date: Wed, 12 May 2021 08:50:10 +0900 Subject: [PATCH] Revert "couchbase: wait until all services are part of the config (#3003)" This reverts commit ed8386c4cc2e38cc766eea30de68f3d559639a8a. --- .../couchbase/CouchbaseContainer.java | 54 ++++--------------- .../couchbase/CouchbaseService.java | 17 ++---- 2 files changed, 15 insertions(+), 56 deletions(-) diff --git a/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java b/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java index 3671608d324..11960304ee6 100644 --- a/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java +++ b/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java @@ -36,12 +36,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.EnumSet; -import java.util.Iterator; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.concurrent.TimeUnit; -import java.util.function.Predicate; import java.util.stream.Collectors; /** @@ -183,7 +181,7 @@ protected void configure() { .map("healthy"::equals) .orElse(false); } catch (IOException e) { - logger().error("Unable to parse response: {}", response, e); + logger().error("Unable to parse response {}", response, e); return false; } }) @@ -256,10 +254,15 @@ private void renameNode() { private void initializeServices() { logger().debug("Initializing couchbase services on host: {}", enabledServices); - final String services = enabledServices - .stream() - .map(CouchbaseService::getIdentifier) - .collect(Collectors.joining(",")); + final String services = enabledServices.stream().map(s -> { + switch (s) { + case KV: return "kv"; + case QUERY: return "n1ql"; + case INDEX: return "index"; + case SEARCH: return "fts"; + default: throw new IllegalStateException("Unknown service!"); + } + }).collect(Collectors.joining(",")); @Cleanup Response response = doHttpRequest(MGMT_PORT, "/node/controller/setupServices", "POST", new FormBody.Builder() .add("services", services) @@ -360,11 +363,10 @@ private void createBuckets() { checkSuccessfulResponse(response, "Could not create bucket " + bucket.getName()); new HttpWaitStrategy() - .forPath("/pools/default/b/" + bucket.getName()) + .forPath("/pools/default/buckets/" + bucket.getName()) .forPort(MGMT_PORT) .withBasicCredentials(username, password) .forStatusCode(200) - .forResponsePredicate(new AllServicesEnabledPredicate()) .waitUntilReady(this); if (enabledServices.contains(CouchbaseService.QUERY)) { @@ -470,38 +472,4 @@ private Response doHttpRequest(final int port, final String path, final String m throw new RuntimeException("Could not perform request against couchbase HTTP endpoint ", ex); } } - - /** - * In addition to getting a 200, we need to make sure that all services we need are enabled and available on - * the bucket. - *

- * Fixes the issue observed in https://github.com/testcontainers/testcontainers-java/issues/2993 - */ - private class AllServicesEnabledPredicate implements Predicate { - - @Override - public boolean test(final String rawConfig) { - try { - for (JsonNode node : MAPPER.readTree(rawConfig).at("/nodesExt")) { - for (CouchbaseService enabledService : enabledServices) { - boolean found = false; - Iterator fieldNames = node.get("services").fieldNames(); - while (fieldNames.hasNext()) { - if (fieldNames.next().startsWith(enabledService.getIdentifier())) { - found = true; - } - } - if (!found) { - logger().trace("Service {} not yet part of config, retrying.", enabledService); - return false; - } - } - } - return true; - } catch (IOException ex) { - logger().error("Unable to parse response: {}", rawConfig, ex); - return false; - } - } - } } diff --git a/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseService.java b/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseService.java index c60fc6b71d0..d284c660709 100644 --- a/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseService.java +++ b/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseService.java @@ -24,30 +24,21 @@ public enum CouchbaseService { /** * Key-Value service. */ - KV("kv"), + KV, /** * Query (N1QL) service. */ - QUERY("n1ql"), + QUERY, /** * Search (FTS) service. */ - SEARCH("fts"), + SEARCH, /** * Indexing service (needed if QUERY is also used!). */ - INDEX("index"); + INDEX - private final String identifier; - - CouchbaseService(String identifier) { - this.identifier = identifier; - } - - String getIdentifier() { - return identifier; - } }