Skip to content

Commit e4e9c09

Browse files
committed
remove zen1 dependency from server/src/test/java/org/elasticsearch/cluster/coordination/PublicationTests.java
1 parent 4f8b70e commit e4e9c09

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

server/src/test/java/org/elasticsearch/cluster/coordination/PublicationTests.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
import org.elasticsearch.cluster.coordination.CoordinationMetaData.VotingConfiguration;
2626
import org.elasticsearch.cluster.node.DiscoveryNode;
2727
import org.elasticsearch.cluster.node.DiscoveryNodes;
28+
import org.elasticsearch.common.Nullable;
2829
import org.elasticsearch.common.collect.Tuple;
2930
import org.elasticsearch.common.settings.Settings;
31+
import org.elasticsearch.common.unit.TimeValue;
3032
import org.elasticsearch.common.util.set.Sets;
3133
import org.elasticsearch.discovery.Discovery;
32-
import org.elasticsearch.discovery.zen.PublishClusterStateActionTests.AssertingAckListener;
3334
import org.elasticsearch.test.ESTestCase;
3435
import org.elasticsearch.transport.TransportException;
3536
import org.elasticsearch.transport.TransportResponse;
@@ -45,6 +46,8 @@
4546
import java.util.Map;
4647
import java.util.Optional;
4748
import java.util.Set;
49+
import java.util.concurrent.CopyOnWriteArrayList;
50+
import java.util.concurrent.CountDownLatch;
4851
import java.util.concurrent.TimeUnit;
4952
import java.util.concurrent.atomic.AtomicBoolean;
5053
import java.util.concurrent.atomic.AtomicInteger;
@@ -57,6 +60,7 @@
5760
import static org.hamcrest.Matchers.containsInAnyOrder;
5861
import static org.hamcrest.Matchers.containsString;
5962
import static org.hamcrest.Matchers.empty;
63+
import static org.hamcrest.Matchers.emptyIterable;
6064
import static org.hamcrest.Matchers.equalTo;
6165

6266
public class PublicationTests extends ESTestCase {
@@ -478,4 +482,43 @@ private static DiscoveryNode newNode(int nodeId, Map<String, String> attributes,
478482
return ts.stream();
479483
});
480484
}
485+
486+
public static class AssertingAckListener implements Discovery.AckListener {
487+
private final List<Tuple<DiscoveryNode, Throwable>> errors = new CopyOnWriteArrayList<>();
488+
private final Set<DiscoveryNode> successfulAcks = Collections.synchronizedSet(new HashSet<>());
489+
private final CountDownLatch countDown;
490+
private final CountDownLatch commitCountDown;
491+
492+
public AssertingAckListener(int nodeCount) {
493+
countDown = new CountDownLatch(nodeCount);
494+
commitCountDown = new CountDownLatch(1);
495+
}
496+
497+
@Override
498+
public void onCommit(TimeValue commitTime) {
499+
commitCountDown.countDown();
500+
}
501+
502+
@Override
503+
public void onNodeAck(DiscoveryNode node, @Nullable Exception e) {
504+
if (e != null) {
505+
errors.add(new Tuple<>(node, e));
506+
} else {
507+
successfulAcks.add(node);
508+
}
509+
countDown.countDown();
510+
}
511+
512+
public Set<DiscoveryNode> await(long timeout, TimeUnit unit) throws InterruptedException {
513+
assertThat(awaitErrors(timeout, unit), emptyIterable());
514+
assertTrue(commitCountDown.await(timeout, unit));
515+
return new HashSet<>(successfulAcks);
516+
}
517+
518+
public List<Tuple<DiscoveryNode, Throwable>> awaitErrors(long timeout, TimeUnit unit) throws InterruptedException {
519+
countDown.await(timeout, unit);
520+
return errors;
521+
}
522+
523+
}
481524
}

0 commit comments

Comments
 (0)