use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class AllocatedHosts method toJson.
public byte[] toJson() throws IOException {
Slime slime = new Slime();
toSlime(slime.setObject());
return SlimeUtils.toJsonBytes(slime);
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class MemoryCacheTest method setup.
@Before
public void setup() {
ArrayList<String> defContent = new ArrayList<>();
defContent.add("bar string");
Slime slime = new Slime();
slime.setString("bar \"value\"");
payload = Payload.from(new ConfigPayload(slime));
slime = new Slime();
slime.setString("bar \"baz\"");
payload2 = Payload.from(new ConfigPayload(slime));
slime = new Slime();
slime.setString("bar \"value2\"");
payloadDifferentMd5 = Payload.from(new ConfigPayload(slime));
config = new RawConfig(configKey, defMd5, payload, configMd5, generation, defContent, Optional.empty());
config2 = new RawConfig(configKey2, defMd52, payload2, configMd5, generation, defContent, Optional.empty());
configDifferentMd5 = new RawConfig(configKey, differentDefMd5, payloadDifferentMd5, configMd5, generation, defContent, Optional.empty());
cacheKey = new ConfigCacheKey(configKey, config.getDefMd5());
cacheKey2 = new ConfigCacheKey(configKey2, config2.getDefMd5());
cacheKeyDifferentMd5 = new ConfigCacheKey(configKey, differentDefMd5);
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class ConfigFileFormatterTest method require_that_strings_are_properly_escaped.
@Test
public void require_that_strings_are_properly_escaped() throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
root.setString("stringval", "some\"quotes\\\"instring");
InnerCNode def = new DefParser("simpletypes", new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ConfigFileFormat(def).encode(baos, slime);
assertThat(baos.toString(), is("stringval \"some\\\"quotes\\\\\\\"instring\"\n"));
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class ConfigFileFormatterTest method require_that_array_formatting_is_correct.
@Test
public void require_that_array_formatting_is_correct() throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
Cursor boolarr = root.setArray("boolarr");
boolarr.addString("true");
boolarr.addString("false");
Cursor doublearr = root.setArray("doublearr");
doublearr.addString("3.14");
doublearr.addString("1.414");
Cursor enumarr = root.setArray("enumarr");
enumarr.addString("VAL1");
enumarr.addString("VAL2");
Cursor intarr = root.setArray("intarr");
intarr.addString("3");
intarr.addString("5");
Cursor longarr = root.setArray("longarr");
longarr.addString("55");
longarr.addString("66");
Cursor stringarr = root.setArray("stringarr");
stringarr.addString("foo");
stringarr.addString("bar");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InnerCNode def = new DefParser("arraytypes", new StringReader(StringUtilities.implode(ArraytypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
new ConfigFileFormat(def).encode(baos, slime);
assertThat(baos.toString(), is("boolarr[0] true\n" + "boolarr[1] false\n" + "doublearr[0] 3.14\n" + "doublearr[1] 1.414\n" + "enumarr[0] VAL1\n" + "enumarr[1] VAL2\n" + "intarr[0] 3\n" + "intarr[1] 5\n" + "longarr[0] 55\n" + "longarr[1] 66\n" + "stringarr[0] \"foo\"\n" + "stringarr[1] \"bar\"\n"));
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class ConfigFileFormatterTest method require_that_illegal_long_throws_exception.
// TODO: Reenable this when we can reenable typechecking.
@Ignore
@Test(expected = IllegalArgumentException.class)
public void require_that_illegal_long_throws_exception() throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
root.setString("longval", "invalid");
InnerCNode def = new DefParser("simpletypes", new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
new ConfigFileFormat(def).encode(new ByteArrayOutputStream(), slime);
}
Aggregations