This is an automated email from the ASF dual-hosted git repository.
kezhuw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git
The following commit(s) were added to refs/heads/master by this push:
new 88dee99a8 Add test case to assert spurious wakeup in
DistributedDoubleBarrier
88dee99a8 is described below
commit 88dee99a85921bd0f20955e1d7efbaf896fc17f3
Author: Kezhu Wang <[email protected]>
AuthorDate: Mon Jul 20 01:25:07 2026 +0800
Add test case to assert spurious wakeup in DistributedDoubleBarrier
See #1291.
---
.../barriers/TestDistributedDoubleBarrier.java | 45 ++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git
a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/barriers/TestDistributedDoubleBarrier.java
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/barriers/TestDistributedDoubleBarrier.java
index 6739a3ce9..d206ff32a 100644
---
a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/barriers/TestDistributedDoubleBarrier.java
+++
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/barriers/TestDistributedDoubleBarrier.java
@@ -99,6 +99,51 @@ public class TestDistributedDoubleBarrier extends
BaseClassForTests {
assertEquals(max.get(), QTY);
}
+ @Test
+ public void testSpuriousWakeup() throws Exception {
+ final Timing timing = new Timing();
+ final CountDownLatch waitLatch = new CountDownLatch(1);
+
+ // given: client1 waiting on barrior
+ CuratorFramework client1 = CuratorFrameworkFactory.newClient(
+ server.getConnectString(), timing.session(),
timing.connection(), new RetryOneTime(1));
+ client1.start();
+ DistributedDoubleBarrier barrier1 = new
DistributedDoubleBarrier(client1, "/barrier", 2);
+
+ Thread thread = new Thread(() -> {
+ waitLatch.countDown();
+ try {
+ assertTrue(barrier1.enter(timing.seconds(), TimeUnit.SECONDS));
+ } catch (Exception ignored) {
+ } finally {
+ CloseableUtils.closeQuietly(client1);
+ }
+ });
+ thread.setDaemon(true);
+ thread.start();
+
+ waitLatch.await();
+ Thread.sleep(200);
+
+ // when: wakup spuriously
+ for (int i = 0; i < 10; i++) {
+ Thread.sleep(20);
+ synchronized (barrier1) {
+ barrier1.notifyAll();
+ }
+ }
+
+ // then: barrior should behave normally
+ try (CuratorFramework client2 = CuratorFrameworkFactory.newClient(
+ server.getConnectString(), timing.session(),
timing.connection(), new RetryOneTime(1))) {
+ client2.start();
+ DistributedDoubleBarrier barrier2 = new
DistributedDoubleBarrier(client2, "/barrier", 2);
+ assertTrue(barrier2.enter(timing.seconds(), TimeUnit.SECONDS));
+ }
+
+ thread.join();
+ }
+
@Test
public void testOverSubscribed() throws Exception {
final Timing timing = new Timing();