aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/container/search/searchchain/SourceGroupTest.java
blob: 8c564f5cd6ff76c7e584264d92bfcb30d9ffab2e (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.search.searchchain;

import com.yahoo.component.ComponentId;
import com.yahoo.component.chain.model.ChainSpecification;
import com.yahoo.config.model.test.MockRoot;
import com.yahoo.search.searchchain.model.federation.FederationOptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @author Tony Vaagenes
 */
public class SourceGroupTest {
    private MockRoot root;
    private SearchChains searchChains;

    @BeforeEach
    public void setUp() {
        root = new MockRoot();
        searchChains = new SearchChains(root, "searchchains");
    }

    @Test
    void report_error_when_no_leader() {
        try {
            Provider provider = createProvider("p1");
            Source source = createSource("s1", Source.GroupOption.participant);
            provider.addSource(source);

            searchChains.add(provider);
            root.freezeModelTopology();

            searchChains.validate();
        } catch (Exception e) {
            assertTrue(e.getMessage().contains("Missing leader for the source s1."));
            return;
        }
        fail("Expected exception");
    }

    private Provider createProvider(String p1) {
        return new Provider(createSearchChainSpecification(p1), new FederationOptions());
    }

    private ChainSpecification createSearchChainSpecification(String id) {
        return new ChainSpecification(ComponentId.fromString(id),
                new ChainSpecification.Inheritance(null, null),
                List.of(),
                Set.of());
    }

    private Source createSource(String sourceId, Source.GroupOption groupOption) {
        return new Source(
                createSearchChainSpecification(sourceId),
                new FederationOptions(),
                groupOption);
    }

    @Test
    void require_that_source_and_provider_id_is_not_allowed_to_be_equal() {
        Provider provider = createProvider("sameId");
        Provider provider2 = createProvider("ignoredId");

        Source source = createSource("sameId", Source.GroupOption.leader);

        provider2.addSource(source);

        searchChains.add(provider);
        searchChains.add(provider2);
        root.freezeModelTopology();

        try {
            searchChains.validate();
            fail("Expected exception");
        } catch (Exception e) {
            assertEquals("Id 'sameId' is used both for a source and another search chain/provider",
                    e.getMessage());
        }
    }
}