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

import com.yahoo.config.subscription.ConfigSourceSet;
import com.yahoo.config.subscription.ConfigSubscriber;
import com.yahoo.config.subscription.impl.JRTConfigSubscription;
import com.yahoo.foo.FunctionTestConfig;
import com.yahoo.vespa.config.ConfigKey;
import com.yahoo.vespa.config.RawConfig;
import com.yahoo.vespa.config.TimingValues;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

/**
 * @author hmusum
 */
public class JRTConfigRequestFactoryTest {
    private static final VespaVersion defaultVespaVersion = JRTConfigRequestFactory.getCompiledVespaVersion();

    @Test
    public void testCompressionType() {
        assertThat(JRTConfigRequestFactory.getCompressionType("", ""), is(CompressionType.LZ4));
        assertThat(JRTConfigRequestFactory.getCompressionType("UNCOMPRESSED", ""), is(CompressionType.UNCOMPRESSED));
        assertThat(JRTConfigRequestFactory.getCompressionType("", "UNCOMPRESSED"), is(CompressionType.UNCOMPRESSED));
        assertThat(JRTConfigRequestFactory.getCompressionType("UNCOMPRESSED", "UNCOMPRESSED"), is(CompressionType.UNCOMPRESSED));

        assertThat(JRTConfigRequestFactory.getCompressionType("", ""), is(CompressionType.LZ4));
        assertThat(JRTConfigRequestFactory.getCompressionType("LZ4", ""), is(CompressionType.LZ4));
        assertThat(JRTConfigRequestFactory.getCompressionType("", "LZ4"), is(CompressionType.LZ4));
        assertThat(JRTConfigRequestFactory.getCompressionType("LZ4", "LZ4"), is(CompressionType.LZ4));

        assertThat(JRTConfigRequestFactory.getCompressionType("UNCOMPRESSED", "LZ4"), is(CompressionType.UNCOMPRESSED));
        assertThat(JRTConfigRequestFactory.getCompressionType("LZ4", "UNCOMPRESSED"), is(CompressionType.LZ4));
    }

    @Test
    public void testVespaVersion() {
        assertThat(JRTConfigRequestFactory.getVespaVersion().get(), is(defaultVespaVersion));
    }

    @Test
    public void testCreateFromSub() {
        ConfigSubscriber subscriber = new ConfigSubscriber();
        Class<FunctionTestConfig> clazz = FunctionTestConfig.class;
        final String configId = "foo";
        JRTConfigSubscription<FunctionTestConfig> sub = new JRTConfigSubscription<>(
                new ConfigKey<>(clazz, configId), subscriber, new ConfigSourceSet(), new TimingValues());

        JRTClientConfigRequest request = JRTConfigRequestFactory.createFromSub(sub);
        assertThat(request.getVespaVersion().get(), is(defaultVespaVersion));
    }

    @Test
    public void testCreateFromRaw() {
        Class<FunctionTestConfig> clazz = FunctionTestConfig.class;
        final String configId = "foo";
        RawConfig config = new RawConfig(new ConfigKey<>(clazz, configId), "595f44fec1e92a71d3e9e77456ba80d1");

        JRTClientConfigRequest request = JRTConfigRequestFactory.createFromRaw(config, 1000);
        assertThat(request.getVespaVersion().get(), is(defaultVespaVersion));
    }

}