aboutsummaryrefslogtreecommitdiffstats
path: root/hosted-zone-api/src/test/java/ai/vespa/cloud/SystemInfoTest.java
blob: 85e175271108a8f8e4b930d921755b1792d7ec2a (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.cloud;

import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

/**
 * @author bratseth
 */
public class SystemInfoTest {

    @Test
    public void testSystemInfo() {
        Zone zone = new Zone(Environment.dev, "us-west-1");
        Cluster cluster = new Cluster(1, List.of());
        Node node = new Node(0);

        SystemInfo info = new SystemInfo(zone, cluster, node);
        assertEquals(zone, info.zone());
        assertEquals(cluster, info.cluster());
        assertEquals(node, info.node());
    }

    @Test
    public void testZone() {
        Zone zone = Zone.from("dev.us-west-1");
        zone = Zone.from(zone.toString());
        assertEquals(Environment.dev, zone.environment());
        assertEquals("us-west-1", zone.region());
        Zone sameZone = Zone.from("dev.us-west-1");
        assertEquals(sameZone.hashCode(), zone.hashCode());
        assertEquals(sameZone, zone);

        try {
            Zone.from("invalid");
            fail("Expected exception");
        }
        catch (IllegalArgumentException e) {
            assertEquals("A zone string must be on the form [environment].[region], but was 'invalid'",
                         e.getMessage());
        }

        try {
            Zone.from("invalid.us-west-1");
            fail("Expected exception");
        }
        catch (IllegalArgumentException e) {
            assertEquals("Invalid zone 'invalid.us-west-1': No environment named 'invalid'", e.getMessage());
        }
    }

    @Test
    public void testCluster() {
        int size = 1;
        var indices = List.of(1);
        Cluster cluster = new Cluster(size, indices);
        assertEquals(size, cluster.size());
        assertEquals(indices, cluster.indices());
    }

    @Test
    public void testNode() {
        int index = 0;
        Node node = new Node(index);
        assertEquals(index, node.index());
    }

}