aboutsummaryrefslogtreecommitdiffstats
path: root/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/NodeIndicesTest.java
blob: c93401c48cc4880440505ec7301a1c66693a47ff (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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision.provisioning;

import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * @author jonmv
 */
public class NodeIndicesTest {

    @Test
    public void testNodeIndices() {
        NodeIndices indices = new NodeIndices(List.of(1, 3, 4));
        assertEquals(0, indices.probeNext());
        assertEquals(2, indices.probeNext());
        assertEquals(5, indices.probeNext());
        assertEquals(6, indices.probeNext());

        indices.resetProbe();
        assertEquals(0, indices.probeNext());
        assertEquals(2, indices.probeNext());

        indices.commitProbe();
        assertEquals(5, indices.probeNext());
        assertEquals(6, indices.probeNext());

        indices.resetProbe();
        assertEquals(5, indices.next());
        assertEquals(6, indices.next());

        assertEquals(7, indices.probeNext());
        try {
            indices.next();
        }
        catch (IllegalStateException e) {
            assertEquals("Must commit ongoing probe before calling 'next'", e.getMessage());
        }
    }

}