use of com.yahoo.config.codegen.DefParser in project vespa by vespa-engine.
the class ConfigFileFormatterTest method require_that_illegal_double_throws_exception.
// TODO: Reenable this when we can reenable typechecking.
@Ignore
@Test(expected = IllegalArgumentException.class)
public void require_that_illegal_double_throws_exception() throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
root.setString("doubleval", "invalid");
InnerCNode def = new DefParser("simpletypes", new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
new ConfigFileFormat(def).encode(new ByteArrayOutputStream(), slime);
}
use of com.yahoo.config.codegen.DefParser in project vespa by vespa-engine.
the class ConfigFileFormatterTest method require_that_utf8_works.
@Test
@Ignore
public void require_that_utf8_works() throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
final String input = "Hei \u00E6\u00F8\u00E5 \n \uBC14\uB451 \u00C6\u00D8\u00C5 hallo";
root.setString("stringval", input);
System.out.println(bytesToHexString(Utf8.toBytes(input)));
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);
System.out.println(bytesToHexString(baos.toByteArray()));
assertThat(Utf8.toString(baos.toByteArray()), is("stringval \"" + input + "\"\n"));
}
use of com.yahoo.config.codegen.DefParser in project vespa by vespa-engine.
the class ConfigPayloadTest method test_applying_extra_default_values.
@Test
public void test_applying_extra_default_values() {
InnerCNode clientDef = new DefParser(SimpletypesConfig.CONFIG_DEF_NAME, new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n") + "\nnewfield int default=3\n")).getTree();
ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
payload = payload.applyDefaultsFromDef(clientDef);
assertThat(payload.toString(true), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\",\"newfield\":\"3\"}"));
}
use of com.yahoo.config.codegen.DefParser in project vespa by vespa-engine.
the class ConfigResponseTest method require_that_slime_response_is_initialized.
@Test
public void require_that_slime_response_is_initialized() throws IOException {
ConfigPayload configPayload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
DefParser dParser = new DefParser(SimpletypesConfig.getDefName(), new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n")));
InnerCNode targetDef = dParser.getTree();
ConfigResponse response = SlimeConfigResponse.fromConfigPayload(configPayload, targetDef, 3, "mymd5");
List<String> payload = response.getLegacyPayload();
assertNotNull(payload);
assertThat(payload.size(), is(6));
assertThat(payload.get(0), is("boolval false"));
assertThat(response.getGeneration(), is(3L));
assertThat(response.getConfigMd5(), is("mymd5"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.serialize(baos, CompressionType.UNCOMPRESSED);
assertThat(baos.toString(), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
use of com.yahoo.config.codegen.DefParser in project vespa by vespa-engine.
the class ConfigResponseTest method require_that_slime_response_decompresses_on_serialize.
@Test
public void require_that_slime_response_decompresses_on_serialize() throws IOException {
ConfigPayload configPayload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
DefParser dParser = new DefParser(SimpletypesConfig.getDefName(), new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n")));
InnerCNode targetDef = dParser.getTree();
Utf8Array data = configPayload.toUtf8Array(true);
Utf8Array bytes = new Utf8Array(new LZ4PayloadCompressor().compress(data.getBytes()));
ConfigResponse response = new SlimeConfigResponse(bytes, targetDef, 3, "mymd5", CompressionInfo.create(CompressionType.LZ4, data.getByteLength()));
List<String> payload = response.getLegacyPayload();
assertNotNull(payload);
assertThat(payload.size(), is(6));
assertThat(payload.get(0), is("boolval false"));
assertThat(response.getGeneration(), is(3L));
assertThat(response.getConfigMd5(), is("mymd5"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.serialize(baos, CompressionType.UNCOMPRESSED);
assertThat(baos.toString(), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
Aggregations