Search in sources :

Example 21 with ConfigPayload

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\"}"));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) SimpletypesConfig(com.yahoo.config.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 22 with ConfigPayload

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());
}
Also used : ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) ConfigPayloadApplier(com.yahoo.vespa.config.ConfigPayloadApplier) File(java.io.File) ConfigInstance(com.yahoo.config.ConfigInstance) Test(org.junit.Test)

Example 23 with ConfigPayload

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);
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload)

Example 24 with ConfigPayload

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)));
}
Also used : FunctionTestConfig(com.yahoo.foo.FunctionTestConfig) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Test(org.junit.Test)

Example 25 with ConfigPayload

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);
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload)

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