aboutsummaryrefslogtreecommitdiffstats
path: root/zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorCompletionWaiterTest.java
blob: 17ec7fb65e9d84c70c6d689120c3440836a7e79c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.curator;

import com.yahoo.path.Path;
import com.yahoo.vespa.curator.mock.MockCurator;
import org.junit.Test;

import java.time.Duration;

import static org.junit.Assert.fail;

/**
 * @author Ulf Lilleengen
 */
public class CuratorCompletionWaiterTest {

    private static final Duration waitForAll = Duration.ofSeconds(1);

    @Test
    public void testCompletionWaiter() throws InterruptedException {
        Curator curator = new MockCurator();
        Curator.CompletionWaiter waiter = CuratorCompletionWaiter.createAndInitialize(curator, Path.createRoot().append("foo"), "foo", waitForAll);
        Curator.CompletionWaiter notifier = CuratorCompletionWaiter.create(curator, Path.fromString("/foo"), "bar", waitForAll);
        Thread t1 = new Thread(() -> {
            try {
                waiter.awaitCompletion(Duration.ofSeconds(120));
            } catch (CompletionTimeoutException e) {
                fail("Waiting failed due to timeout");
            }
        });
        t1.start();
        notifier.notifyCompletion();
        t1.join();
    }

    @Test(expected = CompletionTimeoutException.class)
    public void testCompletionWaiterFailure() {
        Curator curator = new MockCurator();
        Curator.CompletionWaiter waiter = CuratorCompletionWaiter.createAndInitialize(curator, Path.createRoot().append("foo"), "foo", waitForAll);
        waiter.awaitCompletion(Duration.ofMillis(100));
    }
}