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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.proxy;
import com.yahoo.vespa.config.ConfigKey;
import com.yahoo.vespa.config.RawConfig;
import com.yahoo.vespa.config.protocol.JRTConfigRequestFactory;
import com.yahoo.vespa.config.protocol.JRTServerConfigRequestV3;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
/**
* @author hmusum
*/
public class ClientUpdaterTest {
private MockRpcServer rpcServer;
private ConfigProxyStatistics statistics;
private DelayedResponses delayedResponses;
private ClientUpdater clientUpdater;
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
@Before
public void setup() {
rpcServer = new MockRpcServer();
statistics = new ConfigProxyStatistics();
delayedResponses = new DelayedResponses(statistics);
clientUpdater = new ClientUpdater(rpcServer, statistics, delayedResponses);
}
@Test
public void basic() {
assertThat(rpcServer.responses, is(0L));
final RawConfig fooConfig = ProxyServerTest.fooConfig;
clientUpdater.updateSubscribers(fooConfig);
// No delayed response, so not returned
assertEquals(0, rpcServer.responses);
delayedResponses.add(new DelayedResponse(JRTServerConfigRequestV3.createFromRequest(JRTConfigRequestFactory.createFromRaw(fooConfig, -10L).getRequest())));
clientUpdater.updateSubscribers(fooConfig);
assertEquals(1, rpcServer.responses);
// Will not find bar config in delayed responses
RawConfig barConfig = new RawConfig(new ConfigKey<>("bar", "id", "namespace"), fooConfig.getDefMd5());
clientUpdater.updateSubscribers(barConfig);
assertEquals(1, rpcServer.responses);
}
@Test
public void errorResponse() {
assertThat(rpcServer.responses, is(0L));
clientUpdater.updateSubscribers(ProxyServerTest.errorConfig);
assertThat(rpcServer.responses, is(0L));
assertThat(statistics.errors(), is(1L));
}
}
|