Search in sources :

Example 16 with ConfigPayload

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

the class ConfigInstancePayloadTest method map_types_are_correctly_deserialized.

@Test
public void map_types_are_correctly_deserialized() {
    MaptypesConfig orig = createMapTypesConfig();
    List<String> lines = ConfigInstance.serialize(orig);
    ConfigPayload payload = new CfgConfigPayloadBuilder().deserialize(lines);
    System.out.println(payload.toString());
    MaptypesConfig config = ConfigInstanceUtil.getNewInstance(MaptypesConfig.class, "foo", payload);
    System.out.println(config);
    assertThat(config.intmap().size(), is(1));
    assertThat(config.intmap("foo"), is(1337));
    assertNotNull(config.innermap("bar"));
    assertThat(config.innermap("bar").foo(), is(93));
    assertThat(config.nestedmap().size(), is(1));
    assertNotNull(config.nestedmap("baz"));
    assertThat(config.nestedmap("baz").inner("foo"), is(1));
    assertThat(config.nestedmap("baz").inner("bar"), is(2));
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) MaptypesConfig(com.yahoo.foo.MaptypesConfig) Test(org.junit.Test)

Example 17 with ConfigPayload

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

the class ConfigInstancePayloadTest method function_test_payload_is_correctly_deserialized.

@Test
public void function_test_payload_is_correctly_deserialized() {
    FunctionTestConfig orig = createVariableAccessConfigWithBuilder();
    List<String> lines = ConfigInstance.serialize(orig);
    ConfigPayload payload = new CfgConfigPayloadBuilder().deserialize(lines);
    FunctionTestConfig config = ConfigInstanceUtil.getNewInstance(FunctionTestConfig.class, "foo", payload);
    FunctionTest.assertVariableAccessValues(config, "foo");
}
Also used : FunctionTestConfig(com.yahoo.foo.FunctionTestConfig) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Test(org.junit.Test)

Example 18 with ConfigPayload

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

the class SuperModelConfigProvider method getConfig.

public <CONFIGTYPE extends ConfigInstance> CONFIGTYPE getConfig(Class<CONFIGTYPE> configClass, ApplicationId applicationId, String configId) {
    TenantName tenant = applicationId.tenant();
    if (!superModel.getAllModels().containsKey(tenant)) {
        throw new IllegalArgumentException("Tenant " + tenant + " not found");
    }
    Map<ApplicationId, ApplicationInfo> applications = superModel.getAllModels().get(tenant);
    if (!applications.containsKey(applicationId)) {
        throw new IllegalArgumentException("Application id " + applicationId + " not found");
    }
    ApplicationInfo application = applications.get(applicationId);
    ConfigKey<CONFIGTYPE> key = new ConfigKey<>(configClass, configId);
    ConfigPayload payload = application.getModel().getConfig(key, null);
    return payload.toInstance(configClass, configId);
}
Also used : ConfigKey(com.yahoo.vespa.config.ConfigKey) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) TenantName(com.yahoo.config.provision.TenantName) ApplicationInfo(com.yahoo.config.model.api.ApplicationInfo) ApplicationId(com.yahoo.config.provision.ApplicationId)

Example 19 with ConfigPayload

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

the class HttpGetConfigHandlerTest method require_that_handler_can_be_created.

@Test
public void require_that_handler_can_be_created() throws IOException {
    // Define config response for mock handler
    final long generation = 1L;
    ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
    InnerCNode targetDef = getInnerCNode();
    mockRequestHandler.responses.put(new ApplicationId.Builder().tenant(tenant).applicationName("myapplication").build(), SlimeConfigResponse.fromConfigPayload(payload, targetDef, generation, "mymd5"));
    HttpResponse response = handler.handle(HttpRequest.createTestRequest(configUri, GET));
    assertThat(SessionHandlerTest.getRenderedString(response), is(EXPECTED_RENDERED_STRING));
}
Also used : SimpletypesConfig(com.yahoo.config.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) HttpResponse(com.yahoo.container.jdisc.HttpResponse) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) Test(org.junit.Test) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest)

Example 20 with ConfigPayload

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

the class HttpGetConfigHandlerTest method require_that_handler_can_be_created.

@Test
public void require_that_handler_can_be_created() throws IOException {
    // Define config response for mock handler
    final 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"));
    HttpResponse response = handler.handle(HttpRequest.createTestRequest(configUri, GET));
    assertThat(SessionHandlerTest.getRenderedString(response), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
Also used : 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)

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