use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class HttpGetConfigHandlerTest method require_that_nocache_property_works.
@Test
public void require_that_nocache_property_works() throws IOException {
long generation = 1L;
ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
InnerCNode targetDef = getInnerCNode();
mockRequestHandler.responses.put(ApplicationId.defaultId(), SlimeConfigResponse.fromConfigPayload(payload, targetDef, generation, "mymd5"));
final HttpRequest request = HttpRequest.createTestRequest(configUri, GET, null, Collections.singletonMap("nocache", "true"));
HttpResponse response = handler.handle(request);
assertThat(SessionHandlerTest.getRenderedString(response), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class ConfigBuilderGeneratorTest method require_that_custom_classes_can_be_generated.
@Test
public void require_that_custom_classes_can_be_generated() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
String[] schema = new String[] { "namespace=foo.bar", "intval int", "stringval string" };
File tempDir = Files.createTempDir();
ConfigDefinitionKey key = new ConfigDefinitionKey("quux", "foo.bar");
ConfigCompiler compiler = new LazyConfigCompiler(tempDir);
ConfigInstance.Builder builder = compiler.compile(new ConfigDefinition(key.getName(), schema).generateClass()).newInstance();
assertNotNull(builder);
ConfigPayloadApplier<?> payloadApplier = new ConfigPayloadApplier<>(builder);
Slime slime = new Slime();
Cursor root = slime.setObject();
root.setString("intval", "3");
root.setString("stringval", "Hello, world");
payloadApplier.applyPayload(new ConfigPayload(slime));
String className = createClassName(key.getName());
ConfigInstance instance = (ConfigInstance) builder.getClass().getClassLoader().loadClass("com.yahoo." + key.getNamespace() + "." + className).getConstructor(new Class<?>[] { builder.getClass() }).newInstance(builder);
assertNotNull(instance);
assertEquals("intval 3\nstringval \"Hello, world\"", instance.toString());
}
use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class CfgConfigPayloadBuilderTest method assertDeserializedConfigEqualsJson.
private static void assertDeserializedConfigEqualsJson(List<String> inputConfig, String expectedJson) {
ConfigPayload payload = new CfgConfigPayloadBuilder().deserialize(inputConfig);
assertJsonEquals(payload.toString(), expectedJson);
}
use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class ConfigInstanceSerializationTest method require_symmetrical_serialization_and_deserialization_with_builder.
@Test
public void require_symmetrical_serialization_and_deserialization_with_builder() {
FunctionTestConfig config = ConfigInstancePayloadTest.createVariableAccessConfigWithBuilder();
// NOTE: configId must be ':parent:' because the library replaces ReferenceNodes with that value with
// the instance's configId. (And the config used here contains such nodes.)
List<String> lines = ConfigInstance.serialize(config);
ConfigPayload payload = new CfgConfigPayloadBuilder().deserialize(lines);
FunctionTestConfig config2 = ConfigInstanceUtil.getNewInstance(FunctionTestConfig.class, ":parent:", payload);
assertThat(config, is(config2));
assertThat(ConfigInstance.serialize(config), is(ConfigInstance.serialize(config2)));
}
use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class SuperModelController method resolveConfig.
/**
* Resolves global config for given request.
*
* @param request The {@link com.yahoo.vespa.config.GetConfigRequest} to find config for.
* @return a {@link com.yahoo.vespa.config.protocol.ConfigResponse} containing the response for this request.
* @throws java.lang.IllegalArgumentException if no such config was found.
*/
public ConfigResponse resolveConfig(GetConfigRequest request) {
ConfigKey<?> configKey = request.getConfigKey();
InnerCNode targetDef = getConfigDefinition(request.getConfigKey(), request.getDefContent());
ConfigPayload payload = model.getConfig(configKey);
return responseFactory.createResponse(payload, targetDef, generation);
}
Aggregations