summaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/MockDispatcher.java
blob: 2b25b2a3796e4f1139a53b624eb1ceb4b070931d (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.fastsearch.test;

import com.yahoo.container.handler.VipStatus;
import com.yahoo.prelude.fastsearch.FS4ResourcePool;
import com.yahoo.search.Result;
import com.yahoo.search.dispatch.Dispatcher;
import com.yahoo.search.dispatch.SearchCluster;
import com.yahoo.vespa.config.search.DispatchConfig;

import java.util.Collections;
import java.util.List;

class MockDispatcher extends Dispatcher {

    public MockDispatcher(SearchCluster.Node node) {
        this(Collections.singletonList(node));
    }

    public MockDispatcher(List<SearchCluster.Node> nodes) {
        super(toDispatchConfig(nodes), new FS4ResourcePool(1), 1, new VipStatus());
    }

    public MockDispatcher(List<SearchCluster.Node> nodes, VipStatus vipStatus) {
        super(toDispatchConfig(nodes), new FS4ResourcePool(1), 1, vipStatus);
    }

    public MockDispatcher(List<SearchCluster.Node> nodes, FS4ResourcePool fs4ResourcePool, 
                          int containerClusterSize, VipStatus vipStatus) {
        super(toDispatchConfig(nodes), fs4ResourcePool, containerClusterSize, vipStatus);
    }

    private static DispatchConfig toDispatchConfig(List<SearchCluster.Node> nodes) {
        DispatchConfig.Builder dispatchConfigBuilder = new DispatchConfig.Builder();
        int key = 0;
        for (SearchCluster.Node node : nodes) {
            DispatchConfig.Node.Builder dispatchConfigNodeBuilder = new DispatchConfig.Node.Builder();
            dispatchConfigNodeBuilder.host(node.hostname());
            dispatchConfigNodeBuilder.fs4port(node.fs4port());
            dispatchConfigNodeBuilder.port(0); // Mandatory, but currently not used here
            dispatchConfigNodeBuilder.group(node.group());
            dispatchConfigNodeBuilder.key(key++); // not used
            dispatchConfigBuilder.node(dispatchConfigNodeBuilder);
        }
        return new DispatchConfig(dispatchConfigBuilder);
    }
    
    public void fill(Result result, String summaryClass) {
    }

}