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));
}
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;
}
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();
}
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));
}
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);
}
Aggregations