summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ContentClusterHtmlRendererTest.java
blob: ff1c5b0bb17d028b770869f39d52d3d95c9497fa (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core;

import com.google.common.collect.Sets;
import com.yahoo.vdslib.state.ClusterState;
import com.yahoo.vespa.clustercontroller.core.hostinfo.HostInfo;
import com.yahoo.vespa.clustercontroller.core.status.statuspage.VdsClusterHtmlRenderer;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONWriter;
import org.junit.Before;
import org.junit.Test;

import java.io.StringWriter;
import java.io.Writer;
import java.util.Collections;
import java.util.TreeMap;

import static org.hamcrest.core.Is.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;

public class ContentClusterHtmlRendererTest {
    private final VdsClusterHtmlRenderer renderer = new VdsClusterHtmlRenderer();
    private final static int slobrokGeneration = 34;
    private final static String clusterName = "clustername";
    private final TreeMap<Integer, NodeInfo> storageNodeInfoByIndex = new TreeMap<>();
    private final TreeMap<Integer, NodeInfo> distributorNodeInfoByIndex = new TreeMap<>();
    private String result;

    @Before
    public void before() throws JSONException {
        final ClusterStateBundle stateBundle = ClusterStateBundle.ofBaselineOnly(
                AnnotatedClusterState.withoutAnnotations(
                        ClusterState.stateFromString("version:34633 bits:24 distributor:211 storage:211")));
        final EventLog eventLog = new EventLog(new FakeTimer(), null);

        final VdsClusterHtmlRenderer.Table table = renderer.createNewClusterHtmlTable(clusterName, slobrokGeneration);

        final ContentCluster contentCluster = mock(ContentCluster.class);

        for (int x = 0; x < 10; x++) {
            NodeInfo nodeInfo = new DistributorNodeInfo(contentCluster, x, "dist " + x, null);
            final Writer writer = new StringWriter();
            new JSONWriter(writer)
                    .object().key("vtag")
                    // Let one node have a different release tag.
                    .object().key("version").value("release1" + (x == 2 ? "bad" : ""))
                    .endObject()
                    .endObject();
            nodeInfo.setHostInfo(HostInfo.createHostInfo(writer.toString()));
            distributorNodeInfoByIndex.put(x, nodeInfo);
        }
        storageNodeInfoByIndex.put(2, new StorageNodeInfo(contentCluster, 2, false, "storage" + 2, null));
        ClusterStatsAggregator statsAggregator = new ClusterStatsAggregator(Sets.newHashSet(2), Sets.newHashSet(2));

        table.renderNodes(
                storageNodeInfoByIndex,
                distributorNodeInfoByIndex,
                new FakeTimer(),
                stateBundle,
                statsAggregator,
                1.0,
                10,
                Collections.emptyMap(),
                eventLog,
                "pathPrefix",
                "name");
        final StringBuilder stringBuilder = new StringBuilder();
        table.addTable(stringBuilder, 34);
        result = stringBuilder.toString();
    }

    @Test
    public void testVtagRendering() {
        // 9 distribution nodes should have green tag on release1.
        assertThat(result.split("<td bgcolor=\"#c0ffc0\" align=\"right\"><nobr>release1</nobr></td>").length, is(10));
        // 1 distribution node should have warning on release1bad.
        assertThat(result.split("<td bgcolor=\"#ffffc0\" align=\"right\"><nobr>release1bad</nobr></td>").length, is(2));
        // 1 storage node should should have warning on release "not set".
        assertThat(result.split("<td bgcolor=\"#ffffc0\" align=\"right\"><nobr>not set</nobr></td>").length, is(2));
    }
}