Search in sources :

Example 16 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class ConfigFileFormatterTest method require_that_basic_formatting_is_correct_with_types.

@Test
public void require_that_basic_formatting_is_correct_with_types() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("stringval", "foo");
    root.setLong("intval", 324234);
    root.setLong("longval", 324);
    root.setDouble("doubleval", 3.455);
    root.setString("enumval", "VAL2");
    root.setBool("boolval", true);
    assertConfigFormat(slime, expected_simpletypes);
}
Also used : Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Test(org.junit.Test)

Example 17 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class DeployHandlerLogger method log.

@Override
public void log(Level level, String message) {
    if ((level == LogLevel.FINE || level == LogLevel.DEBUG || level == LogLevel.SPAM) && !verbose) {
        return;
    }
    String fullMsg = Tenants.logPre(app) + message;
    Cursor entry = logroot.addObject();
    entry.setLong("time", System.currentTimeMillis());
    entry.setString("level", level.getName());
    entry.setString("message", fullMsg);
    // Also tee to a normal log, Vespa log for example, but use level fine
    log.log(LogLevel.FINE, fullMsg);
}
Also used : Cursor(com.yahoo.slime.Cursor)

Example 18 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class ConfigPayloadBuilderTest method createSlime.

private Cursor createSlime(ConfigPayloadBuilder builder) {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    builder.resolve(root);
    return root;
}
Also used : Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 19 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class ConfigPayloadBuilderTest method require_that_arrays_can_be_indexed_structs.

@Test
public void require_that_arrays_can_be_indexed_structs() {
    ConfigPayloadBuilder builder = new ConfigPayloadBuilder();
    ConfigPayloadBuilder.Array array = builder.getArray("foo");
    ConfigPayloadBuilder elem1 = array.set(4);
    elem1.setField("bar", "baz");
    ConfigPayloadBuilder elem2 = array.set(2);
    elem2.setField("foo", "bar");
    Cursor root = createSlime(builder);
    Cursor a = root.field("foo");
    assertEquals("baz", a.entry(0).field("bar").asString());
    assertEquals("bar", a.entry(1).field("foo").asString());
}
Also used : Cursor(com.yahoo.slime.Cursor) Test(org.junit.Test)

Example 20 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class ConfigPayloadBuilderTest method require_that_builder_can_be_created_from_payload.

@Test
public void require_that_builder_can_be_created_from_payload() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("foo", "bar");
    Cursor obj = root.setObject("foorio");
    obj.setString("bar", "bam");
    Cursor obj2 = obj.setObject("bario");
    obj2.setString("bim", "bul");
    Cursor a2 = obj.setArray("blim");
    Cursor arrayobj = a2.addObject();
    arrayobj.setString("fim", "fam");
    Cursor arrayobj2 = a2.addObject();
    arrayobj2.setString("blim", "blam");
    Cursor a1 = root.setArray("arrio");
    a1.addString("himbio");
    ConfigPayloadBuilder builder = new ConfigPayloadBuilder(new ConfigPayload(slime));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ConfigPayload.fromBuilder(builder).serialize(baos, new JsonFormat(true));
    assertThat(baos.toString(), is("{\"foo\":\"bar\",\"foorio\":{\"bar\":\"bam\",\"bario\":{\"bim\":\"bul\"},\"blim\":[{\"fim\":\"fam\"},{\"blim\":\"blam\"}]},\"arrio\":[\"himbio\"]}"));
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Test(org.junit.Test)

Aggregations

Cursor (com.yahoo.slime.Cursor)112 Slime (com.yahoo.slime.Slime)79 Test (org.junit.Test)33 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 DefParser (com.yahoo.config.codegen.DefParser)15 InnerCNode (com.yahoo.config.codegen.InnerCNode)15 StringReader (java.io.StringReader)15 IOException (java.io.IOException)9 ApplicationId (com.yahoo.config.provision.ApplicationId)8 JsonFormat (com.yahoo.slime.JsonFormat)8 Application (com.yahoo.vespa.hosted.controller.Application)6 List (java.util.List)6 Map (java.util.Map)6 Inspector (com.yahoo.slime.Inspector)5 SlimeUtils (com.yahoo.vespa.config.SlimeUtils)5 Ignore (org.junit.Ignore)5 Version (com.yahoo.component.Version)4 RegionName (com.yahoo.config.provision.RegionName)4 TenantName (com.yahoo.config.provision.TenantName)4