aboutsummaryrefslogtreecommitdiffstats
path: root/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/OrchestratorContextTest.java
blob: 429ce81ea33e03f710ad366f4d4c49bdb52ff931 (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
43
44
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.orchestrator;

import com.yahoo.test.ManualClock;
import com.yahoo.vespa.applicationmodel.ApplicationInstanceId;
import com.yahoo.vespa.applicationmodel.ApplicationInstanceReference;
import com.yahoo.vespa.applicationmodel.TenantId;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * @author hakonhall
 */
public class OrchestratorContextTest {
    private final ApplicationInstanceReference application = new ApplicationInstanceReference(
            new TenantId("tenant"),
            new ApplicationInstanceId("app:dev:us-east-1:default"));

    @Test
    public void testLargeLocks() {
        var mutable = new Object() { boolean locked = true; };
        Runnable unlock = () -> mutable.locked = false;

        try (OrchestratorContext rootContext = OrchestratorContext.createContextForMultiAppOp(new ManualClock())) {
            try (OrchestratorContext probeContext = rootContext.createSubcontextForSingleAppOp(true)) {
                assertFalse(probeContext.hasLock(application));
                assertTrue(probeContext.registerLockAcquisition(application, unlock));

                assertTrue(probeContext.hasLock(application));
                assertTrue(mutable.locked);
            }

            try (OrchestratorContext nonProbeContext = rootContext.createSubcontextForSingleAppOp(false)) {
                assertTrue(nonProbeContext.hasLock(application));
                assertTrue(mutable.locked);
            }

            assertTrue(mutable.locked);
        }
        assertFalse(mutable.locked);
    }
}