aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ConfigChangeActionsSlimeConverterTest.java
blob: b6b24544888bb9f73b901327c26aeef6f1466612 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.configchange;

import com.yahoo.slime.Cursor;
import com.yahoo.slime.JsonFormat;
import com.yahoo.slime.Slime;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static com.yahoo.vespa.config.server.configchange.Utils.*;

/**
 * @author geirst
 * @since 5.44
 */
public class ConfigChangeActionsSlimeConverterTest {

    private static String toJson(ConfigChangeActions actions) throws IOException {
        Slime slime = new Slime();
        Cursor root = slime.setObject();
        new ConfigChangeActionsSlimeConverter(actions).toSlime(root);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        new JsonFormat(false).encode(outputStream, slime);
        return outputStream.toString();
    }

    @Test
    public void json_representation_of_empty_actions() throws IOException {
        ConfigChangeActions actions = new ConfigChangeActionsBuilder().build();
        assertEquals("{\n"
                     + "  \"configChangeActions\": {\n"
                     + "    \"restart\": [ ],\n"
                     + "    \"refeed\": [ ],\n"
                     + "    \"reindex\": [ ]\n"
                     + "  }\n"
                     + "}\n",
                     toJson(actions));
    }

    @Test
    public void json_representation_of_restart_actions() throws IOException {
        ConfigChangeActions actions = new ConfigChangeActionsBuilder().
                restart(CHANGE_MSG, CLUSTER, CLUSTER_TYPE, SERVICE_TYPE, SERVICE_NAME).
                restart(CHANGE_MSG, CLUSTER, CLUSTER_TYPE, SERVICE_TYPE, SERVICE_NAME_2).
                restart(CHANGE_MSG_2, CLUSTER, CLUSTER_TYPE, SERVICE_TYPE, SERVICE_NAME).
                restart(CHANGE_MSG_2, CLUSTER, CLUSTER_TYPE, SERVICE_TYPE, SERVICE_NAME_2).build();
        assertEquals("{\n"
                     + "  \"configChangeActions\": {\n"
                     + "    \"restart\": [\n"
                     + "      {\n"
                     + "        \"clusterName\": \"foo\",\n"
                     + "        \"clusterType\": \"search\",\n"
                     + "        \"serviceType\": \"searchnode\",\n"
                     + "        \"messages\": [\n"
                     + "          \"change\",\n"
                     + "          \"other change\"\n"
                     + "        ],\n"
                     + "        \"services\": [\n"
                     + "          {\n"
                     + "            \"serviceName\": \"baz\",\n"
                     + "            \"serviceType\": \"searchnode\",\n"
                     + "            \"configId\": \"searchnode/baz\",\n"
                     + "            \"hostName\": \"hostname\"\n"
                     + "          },\n"
                     + "          {\n"
                     + "            \"serviceName\": \"qux\",\n"
                     + "            \"serviceType\": \"searchnode\",\n"
                     + "            \"configId\": \"searchnode/qux\",\n"
                     + "            \"hostName\": \"hostname\"\n"
                     + "          }\n"
                     + "        ]\n"
                     + "      }\n"
                     + "    ],\n"
                     + "    \"refeed\": [ ],\n"
                     + "    \"reindex\": [ ]\n"
                     + "  }\n"
                     + "}\n",
                     toJson(actions));
    }

    @Test
    public void json_representation_of_refeed_actions() throws IOException {
        ConfigChangeActions actions = new ConfigChangeActionsBuilder().
                refeed(CHANGE_ID, CHANGE_MSG, DOC_TYPE, CLUSTER, SERVICE_TYPE).
                refeed(CHANGE_ID_2, CHANGE_MSG, DOC_TYPE_2, CLUSTER, SERVICE_TYPE).build();
        assertEquals("{\n"
                     + "  \"configChangeActions\": {\n"
                     + "    \"restart\": [ ],\n"
                     + "    \"refeed\": [\n"
                     + "      {\n"
                     + "        \"name\": \"field-type-change\",\n"
                     + "        \"documentType\": \"music\",\n"
                     + "        \"clusterName\": \"foo\",\n"
                     + "        \"messages\": [\n"
                     + "          \"change\"\n"
                     + "        ],\n"
                     + "        \"services\": [\n"
                     + "          {\n"
                     + "            \"serviceName\": \"searchnode\",\n"
                     + "            \"serviceType\": \"myservicetype\",\n"
                     + "            \"configId\": \"myservicetype/searchnode\",\n"
                     + "            \"hostName\": \"hostname\"\n"
                     + "          }\n"
                     + "        ]\n"
                     + "      },\n"
                     + "      {\n"
                     + "        \"name\": \"indexing-change\",\n"
                     + "        \"documentType\": \"book\",\n"
                     + "        \"clusterName\": \"foo\",\n"
                     + "        \"messages\": [\n"
                     + "          \"change\"\n"
                     + "        ],\n"
                     + "        \"services\": [\n"
                     + "          {\n"
                     + "            \"serviceName\": \"searchnode\",\n"
                     + "            \"serviceType\": \"myservicetype\",\n"
                     + "            \"configId\": \"myservicetype/searchnode\",\n"
                     + "            \"hostName\": \"hostname\"\n"
                     + "          }\n"
                     + "        ]\n"
                     + "      }\n"
                     + "    ],\n"
                     + "    \"reindex\": [ ]\n"
                     + "  }\n"
                     + "}\n",
                toJson(actions));
    }

        @Test
        public void json_representation_of_reindex_actions() throws IOException {
            ConfigChangeActions actions = new ConfigChangeActionsBuilder().
                    reindex(CHANGE_ID, CHANGE_MSG, DOC_TYPE, CLUSTER, SERVICE_TYPE).build();
            assertEquals("{\n"
                         + "  \"configChangeActions\": {\n"
                         + "    \"restart\": [ ],\n"
                         + "    \"refeed\": [ ],\n"
                         + "    \"reindex\": [\n"
                         + "      {\n"
                         + "        \"name\": \"field-type-change\",\n"
                         + "        \"documentType\": \"music\",\n"
                         + "        \"clusterName\": \"foo\",\n"
                         + "        \"messages\": [\n"
                         + "          \"change\"\n"
                         + "        ],\n"
                         + "        \"services\": [\n"
                         + "          {\n"
                         + "            \"serviceName\": \"searchnode\",\n"
                         + "            \"serviceType\": \"myservicetype\",\n"
                         + "            \"configId\": \"myservicetype/searchnode\",\n"
                         + "            \"hostName\": \"hostname\"\n"
                         + "          }\n"
                         + "        ]\n"
                         + "      }\n"
                         + "    ]\n"
                         + "  }\n"
                         + "}\n",
                         toJson(actions));
    }

}