Search in sources :

Example 46 with Slime

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

the class ServiceApiResponseTest method testServiceViewResponse.

@Test
public void testServiceViewResponse() throws URISyntaxException, IOException {
    ServiceApiResponse response = new ServiceApiResponse(ZoneId.from(Environment.prod, RegionName.from("us-west-1")), ApplicationId.from("tenant1", "application1", "default"), Collections.singletonList(new URI("config-server1")), new URI("http://server1:4080/request/path?foo=bar"));
    ApplicationView applicationView = new ApplicationView();
    ClusterView clusterView = new ClusterView();
    clusterView.type = "container";
    clusterView.name = "cluster1";
    clusterView.url = "cluster-url";
    ServiceView serviceView = new ServiceView();
    serviceView.url = null;
    serviceView.serviceType = "container";
    serviceView.serviceName = "service1";
    serviceView.configId = "configId1";
    serviceView.host = "host1";
    serviceView.legacyStatusPages = "legacyPages";
    clusterView.services = Collections.singletonList(serviceView);
    applicationView.clusters = Collections.singletonList(clusterView);
    response.setResponse(applicationView);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    response.render(stream);
    Slime responseSlime = SlimeUtils.jsonToSlime(stream.toByteArray());
    Slime expectedSlime = SlimeUtils.jsonToSlime(IOUtils.readFile(new File(responseFiles + "service-api-response.json")).getBytes(StandardCharsets.UTF_8));
    assertEquals("service-api-response.json", new String(SlimeUtils.toJsonBytes(expectedSlime), StandardCharsets.UTF_8), new String(SlimeUtils.toJsonBytes(responseSlime), StandardCharsets.UTF_8));
}
Also used : ClusterView(com.yahoo.vespa.serviceview.bindings.ClusterView) ServiceView(com.yahoo.vespa.serviceview.bindings.ServiceView) ApplicationView(com.yahoo.vespa.serviceview.bindings.ApplicationView) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Slime(com.yahoo.slime.Slime) URI(java.net.URI) File(java.io.File) Test(org.junit.Test)

Example 47 with Slime

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

the class NodeSerializer method toJson.

public byte[] toJson(Node node) {
    try {
        Slime slime = new Slime();
        toSlime(node, slime.setObject());
        return SlimeUtils.toJsonBytes(slime);
    } catch (IOException e) {
        throw new RuntimeException("Serialization of " + node + " to json failed", e);
    }
}
Also used : IOException(java.io.IOException) Slime(com.yahoo.slime.Slime)

Example 48 with Slime

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

the class DocsumDefinitionTestCase method makeDocsum.

public static byte[] makeDocsum() {
    Slime slime = new Slime();
    Cursor docsum = slime.setObject();
    docsum.setString("TOPIC", "Arts/Celebrities/Madonna");
    docsum.setString("TITLE", "StudyOfMadonna.com - Interviews, Articles, Reviews, Quotes, Essays and more..");
    docsum.setString("DYNTEASER", "dynamic teaser");
    docsum.setLong("EXTINFOSOURCE", 1);
    docsum.setLong("LANG1", 10);
    docsum.setLong("WORDS", 352);
    docsum.setLong("BYTES", 9190);
    byte[] tmp = BinaryFormat.encode(slime);
    ByteBuffer buf = ByteBuffer.allocate(tmp.length + 4);
    buf.order(ByteOrder.LITTLE_ENDIAN);
    buf.putInt(DocsumDefinitionSet.SLIME_MAGIC_ID);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.put(tmp);
    return buf.array();
}
Also used : Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) ByteBuffer(java.nio.ByteBuffer)

Example 49 with Slime

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

the class JsonRendererTestCase method testJsonObjects.

@Test
public void testJsonObjects() throws InterruptedException, ExecutionException, IOException, JSONException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"fields\": {\n" + "                    \"inspectable\": {\n" + "                        \"a\": \"b\"\n" + "                    },\n" + "                    \"jackson\": {\n" + "                        \"Nineteen-eighty-four\": 1984\n" + "                    },\n" + "                    \"json producer\": {\n" + "                        \"long in structured\": 7809531904\n" + "                    },\n" + "                    \"org.json array\": [\n" + "                        true,\n" + "                        true,\n" + "                        false\n" + "                    ],\n" + "                    \"org.json object\": {\n" + "                        \"forty-two\": 42\n" + "                    }\n" + "                },\n" + "                \"id\": \"json objects\",\n" + "                \"relevance\": 1.0\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 0\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}\n";
    Result r = newEmptyResult();
    Hit h = new Hit("json objects");
    JSONObject o = new JSONObject();
    JSONArray a = new JSONArray();
    ObjectMapper mapper = new ObjectMapper();
    JsonNode j = mapper.createObjectNode();
    JSONString s = new JSONString("{\"a\": \"b\"}");
    Slime slime = new Slime();
    Cursor c = slime.setObject();
    c.setLong("long in structured", 7809531904L);
    SlimeAdapter slimeInit = new SlimeAdapter(slime.get());
    StructuredData struct = new StructuredData(slimeInit);
    ((ObjectNode) j).put("Nineteen-eighty-four", 1984);
    o.put("forty-two", 42);
    a.put(true);
    a.put(true);
    a.put(false);
    h.setField("inspectable", s);
    h.setField("jackson", j);
    h.setField("json producer", struct);
    h.setField("org.json array", a);
    h.setField("org.json object", o);
    r.hits().add(h);
    String summary = render(r);
    assertEqualJson(expected, summary);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StructuredData(com.yahoo.search.result.StructuredData) JSONArray(org.json.JSONArray) JsonNode(com.fasterxml.jackson.databind.JsonNode) JSONString(com.yahoo.prelude.hitfield.JSONString) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Result(com.yahoo.search.Result) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) JSONObject(org.json.JSONObject) SlimeAdapter(com.yahoo.data.access.slime.SlimeAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JSONString(com.yahoo.prelude.hitfield.JSONString) Test(org.junit.Test)

Example 50 with Slime

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

the class BinaryFormat method decode.

public static Predicate decode(byte[] buf) {
    Objects.requireNonNull(buf, "buf");
    Slime slime = com.yahoo.slime.BinaryFormat.decode(buf);
    return decode(slime.get());
}
Also used : Slime(com.yahoo.slime.Slime)

Aggregations

Slime (com.yahoo.slime.Slime)131 Cursor (com.yahoo.slime.Cursor)76 Test (org.junit.Test)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)23 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)22 DefParser (com.yahoo.config.codegen.DefParser)14 InnerCNode (com.yahoo.config.codegen.InnerCNode)14 StringReader (java.io.StringReader)14 JsonFormat (com.yahoo.slime.JsonFormat)10 ApplicationId (com.yahoo.config.provision.ApplicationId)9 Inspector (com.yahoo.slime.Inspector)9 Application (com.yahoo.vespa.hosted.controller.Application)9 SlimeAdapter (com.yahoo.data.access.slime.SlimeAdapter)8 IOException (java.io.IOException)8 Version (com.yahoo.component.Version)7 JsonDecoder (com.yahoo.slime.JsonDecoder)6 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)6 HttpResponse (com.yahoo.container.jdisc.HttpResponse)5 DeployLogger (com.yahoo.config.application.api.DeployLogger)4 TenantName (com.yahoo.config.provision.TenantName)4