Search in sources :

Example 11 with ConfigPayload

use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.

the class ConfigUtilsTest method testGetMd5OfPayload.

@Test
public void testGetMd5OfPayload() {
    String expectedMd5 = "c9246ed8c8ab55b1c463c501c84075e6";
    String expectedChangedMd5 = "f6f81062ef5f024f1912798490ba7dfc";
    ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
    System.out.println(payload);
    assertThat(ConfigUtils.getMd5(payload), is(expectedMd5));
    payload.getSlime().get().setString("fabio", "bar");
    System.out.println(payload);
    assertThat(ConfigUtils.getMd5(payload), is(expectedChangedMd5));
}
Also used : SimpletypesConfig(com.yahoo.foo.SimpletypesConfig) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Test(org.junit.Test)

Example 12 with ConfigPayload

use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.

the class JRTConfigSubscription method toConfigInstance.

/**
 * This method should ideally throw new MissingConfig/Configuration exceptions and let the caller
 * catch them. However, this would make the code in JRT/File/RawSource uglier.
 * Alternatively, it could return a SetConfigStatus object with an int and an error message.
 *
 * @param jrtRequest a config request
 * @return an instance of a config class (subclass of ConfigInstance)
 */
private T toConfigInstance(JRTClientConfigRequest jrtRequest) {
    Payload payload = jrtRequest.getNewPayload();
    ConfigPayload configPayload = ConfigPayload.fromUtf8Array(payload.withCompression(CompressionType.UNCOMPRESSED).getData());
    T configInstance = configPayload.toInstance(configClass, jrtRequest.getConfigKey().getConfigId());
    configInstance.setConfigMd5(jrtRequest.getNewConfigMd5());
    return configInstance;
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Payload(com.yahoo.vespa.config.protocol.Payload) ConfigPayload(com.yahoo.vespa.config.ConfigPayload)

Example 13 with ConfigPayload

use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.

the class PayloadTest method testEquals.

@Test
public void testEquals() {
    final String foo1 = "foo 1";
    final String foo2 = "foo 2";
    Payload a = Payload.from(foo1);
    Payload b = Payload.from(foo1);
    Payload c = Payload.from(foo2);
    Slime slime = new Slime();
    slime.setString(foo1);
    Payload d = Payload.from(new ConfigPayload(slime));
    slime.setString(foo1);
    Payload e = Payload.from(new ConfigPayload(slime));
    slime.setString("foo 2");
    Payload f = Payload.from(new ConfigPayload(slime));
    Payload g = null;
    Payload h = null;
    Payload i = null;
    Payload j = null;
    try {
        g = Payload.from(new Utf8Array(foo1.getBytes("UTF-8")), CompressionInfo.uncompressed());
        h = Payload.from(new Utf8Array(foo1.getBytes("UTF-8")), CompressionInfo.uncompressed());
        LZ4PayloadCompressor compressor = new LZ4PayloadCompressor();
        CompressionInfo info = CompressionInfo.create(CompressionType.LZ4, foo2.length());
        Utf8Array compressed = new Utf8Array(compressor.compress(foo2.getBytes()));
        i = Payload.from(compressed, info);
        j = Payload.from(compressed, info);
    } catch (UnsupportedEncodingException e1) {
        fail();
    }
    new EqualsTester().addEqualityGroup(a, b, g, h).addEqualityGroup(c).addEqualityGroup(d, e).addEqualityGroup(f).addEqualityGroup(i, j).testEquals();
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) EqualsTester(com.google.common.testing.EqualsTester) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) LZ4PayloadCompressor(com.yahoo.vespa.config.LZ4PayloadCompressor) Slime(com.yahoo.slime.Slime) Utf8Array(com.yahoo.text.Utf8Array) Test(org.junit.Test)

Example 14 with ConfigPayload

use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.

the class PayloadTest method testUncompressedToCompressedWithoutCompressionInfo.

@Test
public void testUncompressedToCompressedWithoutCompressionInfo() {
    String json = "{\"foo\":13}";
    ConfigPayload configPayload = ConfigPayload.fromString(json);
    Payload payload = Payload.from(configPayload);
    assertThat(payload.getData().toString(), is(json));
    payload = Payload.from(payload.getData(), CompressionInfo.create(CompressionType.UNCOMPRESSED, 0));
    Payload compressed = payload.withCompression(CompressionType.LZ4);
    Payload uncompressed = compressed.withCompression(CompressionType.UNCOMPRESSED);
    assertThat(uncompressed.getData().toString(), is(json));
    assertThat(compressed.toString(), is(json));
    assertThat(uncompressed.toString(), is(json));
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Test(org.junit.Test)

Example 15 with ConfigPayload

use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.

the class ConfigInstancePayloadTest method config_builder_can_be_created_from_generic_payload.

@Test
public void config_builder_can_be_created_from_generic_payload() {
    FunctionTestConfig config = createVariableAccessConfigWithBuilder();
    ConfigPayload payload = new CfgConfigPayloadBuilder().deserialize(ConfigInstance.serialize(config));
    assertFunctionTestPayload(config, payload);
}
Also used : FunctionTestConfig(com.yahoo.foo.FunctionTestConfig) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Test(org.junit.Test)

Aggregations

ConfigPayload (com.yahoo.vespa.config.ConfigPayload)41 Test (org.junit.Test)29 InnerCNode (com.yahoo.config.codegen.InnerCNode)10 SimpletypesConfig (com.yahoo.config.SimpletypesConfig)6 Slime (com.yahoo.slime.Slime)6 Element (org.w3c.dom.Element)6 HttpResponse (com.yahoo.container.jdisc.HttpResponse)5 FunctionTestConfig (com.yahoo.foo.FunctionTestConfig)4 SimpletypesConfig (com.yahoo.foo.SimpletypesConfig)4 DefParser (com.yahoo.config.codegen.DefParser)3 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)3 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)3 StringReader (java.io.StringReader)3 ConfigurationRuntimeException (com.yahoo.config.ConfigurationRuntimeException)2 ApplicationId (com.yahoo.config.provision.ApplicationId)2 CfgConfigPayloadBuilder (com.yahoo.config.subscription.CfgConfigPayloadBuilder)2 ConfigInterruptedException (com.yahoo.config.subscription.ConfigInterruptedException)2 HttpRequest (com.yahoo.container.jdisc.HttpRequest)2 Utf8Array (com.yahoo.text.Utf8Array)2 ConfigCacheKey (com.yahoo.vespa.config.ConfigCacheKey)2