use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.
the class DomConfigPayloadBuilderTest method assertPayload.
private void assertPayload(String expected, ConfigPayload payload) {
try {
ByteArrayOutputStream a = new ByteArrayOutputStream();
new JsonFormat(true).encode(a, payload.getSlime());
assertThat(a.toString(), is(expected));
} catch (Exception e) {
fail("Exception thrown when encoding slime: " + e.getMessage());
}
}
use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.
the class SlimeTraceSerializerTest method toJson.
private String toJson(TraceNode root) throws IOException {
Slime slime = new Slime();
SlimeTraceSerializer serializer = new SlimeTraceSerializer(slime.setObject());
root.accept(serializer);
JsonFormat format = new JsonFormat(true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
format.encode(baos, slime);
return Utf8.toString(baos.toByteArray());
}
use of com.yahoo.slime.JsonFormat 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\"]}"));
}
use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.
the class DeployHandlerLoggerTest method testLogging.
private void testLogging(boolean verbose, String expectedPattern) throws IOException {
Slime slime = new Slime();
Cursor array = slime.setArray();
DeployLogger logger = new DeployHandlerLogger(array, verbose, new ApplicationId.Builder().tenant("testtenant").applicationName("testapp").build());
logMessages(logger);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new JsonFormat(true).encode(baos, slime);
assertTrue(Pattern.matches(expectedPattern, baos.toString()));
}
use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.
the class UpgraderResponse method render.
@Override
public void render(OutputStream outputStream) throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
root.setDouble("upgradesPerMinute", upgrader.upgradesPerMinute());
Cursor array = root.setArray("confidenceOverrides");
upgrader.confidenceOverrides().forEach((version, confidence) -> {
Cursor object = array.addObject();
object.setString(version.toString(), confidence.name());
});
new JsonFormat(true).encode(outputStream, slime);
}
Aggregations