summaryrefslogtreecommitdiffstats
path: root/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/DelayedResponseHandlerTest.java
blob: c01e236fa2ab7aeeab5d05e5d2a881fdee91ccbc (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
// 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 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.assertThat;

/**
 * @author hmusum
 */
public class DelayedResponseHandlerTest {

    private final MockConfigSource source = new MockConfigSource(new MockClientUpdater(new MemoryCache()));

    @Rule
    public TemporaryFolder temporaryFolder = new TemporaryFolder();

    @Before
    public void setup() {
        source.clear();
        source.put(ProxyServerTest.fooConfig.getKey(), ProxyServerTest.createConfigWithNextConfigGeneration(ProxyServerTest.fooConfig, 0));
    }

    @Test
    public void basic() {
        ConfigTester tester = new ConfigTester();
        ConfigProxyStatistics statistics = new ConfigProxyStatistics();
        DelayedResponses delayedResponses = new DelayedResponses(statistics);
        final MockRpcServer mockRpcServer = new MockRpcServer();
        final MemoryCache memoryCache = new MemoryCache();
        memoryCache.put(ProxyServerTest.fooConfig);
        final DelayedResponseHandler delayedResponseHandler = new DelayedResponseHandler(delayedResponses, memoryCache, mockRpcServer);
        delayedResponses.add(new DelayedResponse(tester.createRequest(ProxyServerTest.fooConfig, 0)));
        delayedResponses.add(new DelayedResponse(tester.createRequest(ProxyServerTest.fooConfig, 1200000))); // should not be returned yet
        delayedResponses.add(new DelayedResponse(tester.createRequest(ProxyServerTest.errorConfig, 0)));  // will not give a config when resolving
        delayedResponseHandler.checkDelayedResponses();

        assertThat(mockRpcServer.responses, is(1L));
    }

}