use of com.yahoo.foo.FunctionTestConfig in project vespa by vespa-engine.
the class CfgConfigPayloadBuilderTest method createConfigPayload.
@Test
public void createConfigPayload() {
final FunctionTestConfig config = ConfigInstancePayloadTest.createVariableAccessConfigWithBuilder();
final String expectedJson = inputJson("{", " 'double_val': '41.23',", " 'refarr': [", " ':parent:',", " ':parent',", " 'parent:'", " ],", " 'pathVal': 'src/test/resources/configs/def-files/function-test.def',", " 'string_val': 'foo',", " 'myStructMap': {", " 'one': {", " 'myString': 'bull',", " 'anotherMap': {", " 'anotherOne': {", " 'anInt': '3',", " 'anIntDef': '4'", " }", " },", " 'myInt': '1',", " 'myStringDef': 'bear',", " 'myIntDef': '2'", " }", " },", " 'boolarr': [", " 'false'", " ],", " 'intMap': {", " 'dotted.key': '3',", " 'spaced key': '4',", " 'two': '2',", " 'one': '1'", " },", " 'int_val': '5',", " 'stringarr': [", " 'bar'", " ],", " 'enum_val': 'FOOBAR',", " 'myarray': [", " {", " 'anotherarray': [", " {", " 'foo': '7'", " }", " ],", " 'intval': '-5',", " 'fileVal': 'file0',", " 'refval': ':parent:',", " 'myStruct': {", " 'a': '1',", " 'b': '2'", " },", " 'stringval': [", " 'baah',", " 'yikes'", " ],", " 'enumval': 'INNER'", " },", " {", " 'anotherarray': [", " {", " 'foo': '2'", " }", " ],", " 'intval': '5',", " 'fileVal': 'file1',", " 'refval': ':parent:',", " 'myStruct': {", " 'a': '-1',", " 'b': '-2'", " },", " 'enumval': 'INNER'", " }", " ],", " 'fileArr': [", " 'bin'", " ],", " 'enumwithdef': 'BAR2',", " 'bool_with_def': 'true',", " 'enumarr': [", " 'VALUES'", " ],", " 'pathMap': {", " 'one': 'pom.xml'", " },", " 'long_with_def': '-9876543210',", " 'double_with_def': '-12.0',", " 'stringMap': {", " 'double spaced key': 'third',", " 'double.dotted.key': 'second',", " 'one': 'first'", " },", " 'refwithdef': ':parent:',", " 'stringwithdef': 'bar and foo',", " 'doublearr': [", " '2344.0',", " '123.0'", " ],", " 'int_with_def': '-14',", " 'pathArr': [", " 'pom.xml'", " ],", " 'rootStruct': {", " 'innerArr': [", " {", " 'stringVal': 'deep',", " 'boolVal': 'true'", " },", " {", " 'stringVal': 'blue a=\\\'escaped\\\'',", " 'boolVal': 'false'", " }", " ],", " 'inner0': {", " 'index': '11',", " 'name': 'inner0'", " },", " 'inner1': {", " 'index': '12',", " 'name': 'inner1'", " }", " },", " 'fileVal': 'etc',", " 'refval': ':parent:',", " 'onechoice': 'ONLYFOO',", " 'bool_val': 'false',", " 'longarr': [", " '9223372036854775807',", " '-9223372036854775808'", " ],", " 'basicStruct': {", " 'intArr': [", " '310',", " '311'", " ],", " 'foo': 'basicFoo',", " 'bar': '3'", " },", " 'long_val': '12345678901'", "}");
CfgConfigPayloadBuilderTest.assertDeserializedConfigEqualsJson(config, expectedJson);
}
use of com.yahoo.foo.FunctionTestConfig in project vespa by vespa-engine.
the class FunctionTest method attemptLacking.
private void attemptLacking(String param, boolean isArray) throws IOException {
BufferedReader in = new BufferedReader(new FileReader(new File(PATH + "defaultvalues.txt")));
StringBuilder config = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
if ((line.length() > param.length()) && param.equals(line.substring(0, param.length())) && (line.charAt(param.length()) == ' ' || line.charAt(param.length()) == '[')) {
// Ignore values matched
} else {
config.append(line).append("\n");
}
}
// System.out.println("Config lacking " + param + "-> " + config + "\n");
try {
ConfigGetter<FunctionTestConfig> getter = new ConfigGetter<FunctionTestConfig>(FunctionTestConfig.class);
getter.getConfig("raw:\n" + config);
if (isArray) {
// Arrays are empty by default
return;
}
fail("Expected to fail when not specifying value " + param + " without default");
} catch (IllegalArgumentException expected) {
if (isArray) {
fail("Arrays should be empty by default.");
}
}
}
use of com.yahoo.foo.FunctionTestConfig in project vespa by vespa-engine.
the class FunctionTest method testDefaultValues.
@Test
public void testDefaultValues() {
assertNull(config);
String configId = "file:" + PATH + "defaultvalues.txt";
ConfigGetter<FunctionTestConfig> getter = new ConfigGetter<>(FunctionTestConfig.class);
FunctionTestConfig config = getter.getConfig(configId);
assertFalse(config.bool_val());
assertFalse(config.bool_with_def());
assertEquals(5, config.int_val());
assertEquals(-545, config.int_with_def());
assertEquals(1234567890123L, config.long_val());
assertEquals(-50000000000L, config.long_with_def());
assertEquals(41.23, config.double_val(), 0.000001);
assertEquals(-6.43, config.double_with_def(), 0.000001);
assertEquals("foo", config.string_val());
assertEquals("foobar", config.stringwithdef());
assertEquals(FunctionTestConfig.Enum_val.FOOBAR, config.enum_val());
assertEquals(FunctionTestConfig.Enumwithdef.BAR2, config.enumwithdef());
assertEquals(configId, config.refval());
assertEquals(configId, config.refwithdef());
assertEquals("vespa.log", config.fileVal().value());
assertEquals(1, config.boolarr().size());
assertEquals(0, config.intarr().size());
assertEquals(0, config.longarr().size());
assertEquals(2, config.doublearr().size());
assertEquals(1, config.stringarr().size());
assertEquals(1, config.enumarr().size());
assertEquals(0, config.refarr().size());
assertEquals(0, config.fileArr().size());
assertEquals(3, config.basicStruct().bar());
assertEquals(1, config.basicStruct().intArr().size());
assertEquals(10, config.basicStruct().intArr(0));
assertEquals(11, config.rootStruct().inner0().index());
assertEquals(12, config.rootStruct().inner1().index());
assertEquals(2, config.myarray().size());
assertEquals(1, config.myarray(0).myStruct().a());
assertEquals(-1, config.myarray(1).myStruct().a());
assertEquals("command.com", config.myarray(0).fileVal().value());
assertEquals("display.sys", config.myarray(1).fileVal().value());
}
use of com.yahoo.foo.FunctionTestConfig in project vespa by vespa-engine.
the class ConfigInstanceUtilTest method test_require_private_getter.
@Test
public void test_require_private_getter() {
FunctionTestConfig.Builder builder = createVariableAccessBuilder();
assertEquals(ConfigInstanceUtil.getField(builder, "int_val"), 5);
FunctionTestConfig conf = new FunctionTestConfig(builder);
assertEquals(conf.int_val(), 5);
}
use of com.yahoo.foo.FunctionTestConfig in project vespa by vespa-engine.
the class JRTConfigRequestFactoryTest method testCreateFromSub.
@Test
public void testCreateFromSub() {
ConfigSubscriber subscriber = new ConfigSubscriber();
Class<FunctionTestConfig> clazz = FunctionTestConfig.class;
final String configId = "foo";
JRTConfigSubscription<FunctionTestConfig> sub = new JRTConfigSubscription<>(new ConfigKey<>(clazz, configId), subscriber, new ConfigSet(), new TimingValues());
// Default vespa version
JRTClientConfigRequest request = JRTConfigRequestFactory.createFromSub(sub);
assertThat(request.getProtocolVersion(), is(3L));
assertThat(request.getVespaVersion().get(), is(defaultVespaVersion));
// Create with vespa version set
String version = "5.37.38";
System.setProperty(JRTConfigRequestFactory.VESPA_VERSION, version);
request = JRTConfigRequestFactory.createFromSub(sub);
assertThat(request.getProtocolVersion(), is(3L));
assertThat(request.getVespaVersion().get(), is(VespaVersion.fromString(version)));
System.clearProperty(JRTConfigRequestFactory.VESPA_VERSION);
}
Aggregations