/** * Wait for a particular collection state to appear in the cluster client's state reader * * This is a convenience method using the {@link #DEFAULT_TIMEOUT} * * @param message a message to report on failure * @param collection the collection to watch * @param predicate a predicate to match against the collection state */ protected static void waitForState(String message, String collection, CollectionStatePredicate predicate) { AtomicReference<DocCollection> state = new AtomicReference<>(); AtomicReference<Set<String>> liveNodesLastSeen = new AtomicReference<>(); try { cluster.getSolrClient().waitForState(collection, DEFAULT_TIMEOUT, TimeUnit.SECONDS, (n, c) -> { state.set(c); liveNodesLastSeen.set(n); return predicate.matches(n, c); }); } catch (Exception e) { fail(message + "\n" + e.getMessage() + "\nLive Nodes: " + Arrays.toString(liveNodesLastSeen.get().toArray()) + "\nLast available state: " + state.get()); } }
boolean matches = predicate.matches(n, c); if (matches) latch.countDown();