aboutsummaryrefslogtreecommitdiffstats
path: root/standalone-container/src/test/java/com/yahoo/container/standalone/CloudConfigInstallVariablesTest.java
blob: 72f32ac04b863f9a7d1826db8725b77b3cfaebdb (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.standalone;

import com.yahoo.vespa.model.container.configserver.option.CloudConfigOptions;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static com.yahoo.container.standalone.CloudConfigInstallVariables.toConfigModelsPluginDir;
import static com.yahoo.container.standalone.CloudConfigInstallVariables.toConfigServer;
import static com.yahoo.container.standalone.CloudConfigInstallVariables.toConfigServers;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * @author Ulf Lilleengen
 * @author Tony Vaagenes
 */
public class CloudConfigInstallVariablesTest {

    @Test
    public void test_configserver_parsing() {
        CloudConfigOptions.ConfigServer[] parsed = toConfigServers("myhost.mydomain.com");
        assertEquals(1, parsed.length);
    }

    @Test
    public void port_can_be_configured() {
        CloudConfigOptions.ConfigServer[] parsed = toConfigServers("myhost:123");
        int port = parsed[0].port.get();
        assertEquals(123, port);
    }

    @Test
    public void multiple_spaces_are_supported() {
        CloudConfigOptions.ConfigServer[] parsed = toConfigServers("test1     test2");
        assertEquals(2, parsed.length);

        List<String> hostNames = Arrays.stream(parsed).map(cs -> cs.hostName).toList();
        assertTrue(hostNames.containsAll(Arrays.asList("test1", "test2")));
    }

    @Test(expected = IllegalArgumentException.class)
    public void missing_port_gives_exception() {
        toConfigServer("myhost:");
    }

    @Test(expected = IllegalArgumentException.class)
    public void non_numeric_port_gives_exception() {
        toConfigServer("myhost:non-numeric");
    }

    @Test
    public void string_arrays_are_split_on_spaces() {
        String[] parsed = toConfigModelsPluginDir("/home/vespa/foo /home/vespa/bar ");
        assertEquals(2, parsed.length);
    }

    @Test
    public void string_arrays_are_split_on_comma() {
        String[] parsed = toConfigModelsPluginDir("/home/vespa/foo,/home/vespa/bar,");
        assertEquals(2, parsed.length);
    }
}