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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.xml;
import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
import com.yahoo.vespa.model.container.ContainerCluster;
import com.yahoo.vespa.model.container.component.Handler;
import com.yahoo.vespaclient.config.FeederConfig;
import org.junit.Test;
import org.w3c.dom.Element;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertThat;
/**
* @author Einar M R Rosenvinge
*/
public class ContainerDocumentApiBuilderTest extends ContainerModelBuilderTestBase {
private Map<String, Handler<?>> getHandlers(String clusterName) {
ContainerCluster cluster = (ContainerCluster) root.getChildren().get(clusterName);
Map<String, Handler<?>> handlerMap = new HashMap<>();
Collection<Handler<?>> handlers = cluster.getHandlers();
for (Handler<?> handler : handlers) {
assertThat(handlerMap.containsKey(handler.getComponentId().toString()), is(false)); //die on overwrites
handlerMap.put(handler.getComponentId().toString(), handler);
}
return handlerMap;
}
@Test
public void document_api_config_is_added_to_container_cluster() {
Element elem = DomBuilderTest.parse(
"<jdisc id='cluster1' version='1.0'>",
" <document-api>",
" <abortondocumenterror>false</abortondocumenterror>",
" <maxpendingdocs>4321</maxpendingdocs>",
" <retrydelay>12.34</retrydelay>",
" <route>non-default</route>",
" </document-api>",
nodesXml,
"</jdisc>");
createModel(root, elem);
ContainerCluster cluster = (ContainerCluster)root.getProducer("cluster1");
FeederConfig.Builder builder = new FeederConfig.Builder();
cluster.getDocumentApi().getConfig(builder);
FeederConfig config = new FeederConfig(builder);
assertThat(config.abortondocumenterror(), is(false));
assertThat(config.maxpendingdocs(), is(4321));
assertThat(config.retrydelay(), is(12.34));
assertThat(config.route(), is("non-default"));
}
@Test
public void custom_bindings_are_allowed() {
Element elem = DomBuilderTest.parse(
"<jdisc id='cluster1' version='1.0'>",
" <document-api>",
" <binding>https://*/document-api/</binding>",
" <binding>missing-trailing-slash</binding>",
" </document-api>",
nodesXml,
"</jdisc>");
createModel(root, elem);
verifyCustomBindings("com.yahoo.vespa.http.server.FeedHandler", ContainerCluster.RESERVED_URI_PREFIX + "/feedapi");
}
private void verifyCustomBindings(String id, String bindingSuffix) {
Handler<?> handler = getHandlers("cluster1").get(id);
assertThat(handler.getServerBindings(), hasItem("https://*/document-api/" + bindingSuffix));
assertThat(handler.getServerBindings(), hasItem("https://*/document-api/" + bindingSuffix + "/"));
assertThat(handler.getServerBindings(), hasItem("missing-trailing-slash/" + bindingSuffix));
assertThat(handler.getServerBindings(), hasItem("missing-trailing-slash/" + bindingSuffix + "/"));
assertThat(handler.getServerBindings().size(), is(4));
}
@Test
public void requireThatHandlersAreSetup() {
Element elem = DomBuilderTest.parse(
"<jdisc id='cluster1' version='1.0'>",
" <document-api />",
nodesXml,
"</jdisc>");
createModel(root, elem);
Map<String, Handler<?>> handlerMap = getHandlers("cluster1");
assertThat(handlerMap.get("com.yahoo.container.handler.VipStatusHandler"), not(nullValue()));
assertThat(handlerMap.get("com.yahoo.container.handler.observability.ApplicationStatusHandler"), not(nullValue()));
assertThat(handlerMap.get("com.yahoo.container.jdisc.state.StateHandler"), not(nullValue()));
assertThat(handlerMap.get("com.yahoo.vespa.http.server.FeedHandler"), not(nullValue()));
assertThat(handlerMap.get("com.yahoo.vespa.http.server.FeedHandler").getServerBindings().contains("http://*/" + ContainerCluster.RESERVED_URI_PREFIX + "/feedapi"), is(true));
assertThat(handlerMap.get("com.yahoo.vespa.http.server.FeedHandler").getServerBindings().contains("https://*/" + ContainerCluster.RESERVED_URI_PREFIX + "/feedapi"), is(true));
assertThat(handlerMap.get("com.yahoo.vespa.http.server.FeedHandler").getServerBindings().contains("http://*/" + ContainerCluster.RESERVED_URI_PREFIX + "/feedapi/"), is(true));
assertThat(handlerMap.get("com.yahoo.vespa.http.server.FeedHandler").getServerBindings().contains("https://*/" + ContainerCluster.RESERVED_URI_PREFIX + "/feedapi/"), is(true));
assertThat(handlerMap.get("com.yahoo.vespa.http.server.FeedHandler").getServerBindings().size(), equalTo(4));
}
}
|