Github user dragonsinth commented on the pull request:
https://github.com/apache/lucene-solr/pull/32#issuecomment-216351404
BTW, here's an implementation of waitForState() that does the work on the
calling thread. This passes your tests:
```
public void waitForState(final String collection, long wait, TimeUnit
unit, CollectionStatePredicate predicate)
throws InterruptedException, TimeoutException {
long stop = System.nanoTime() + unit.toNanos(wait);
if (predicate.matches(this.liveNodes,
clusterState.getCollectionOrNull(collection))) {
return;
}
LinkedBlockingQueue<Pair<Set<String>, DocCollection>> queue = new
LinkedBlockingQueue<>();
CollectionStateWatcher watcher = new CollectionStateWatcher() {
@Override
public void onStateChanged(Set<String> liveNodes, DocCollection
collectionState) {
queue.add(new Pair<>(liveNodes, collectionState));
registerCollectionStateWatcher(collection, this);
}
};
registerCollectionStateWatcher(collection, watcher);
try {
while (true) {
Pair<Set<String>, DocCollection> pair = queue.poll(stop -
System.nanoTime(), TimeUnit.NANOSECONDS);
if (pair == null) {
throw new TimeoutException();
}
if (predicate.matches(pair.getKey(), pair.getValue())) {
return;
}
}
} finally {
removeCollectionStateWatcher(collection, watcher);
}
}
```
One thing I noticed in writing this is that it's uncertain whether you'll
miss any states or not. I kind of like the idea that you could have your
watcher return true or false to decide whether to keep watching, as it would
ensure we could get all updates without missing any.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]