use of com.yahoo.bullet.result.Meta.Concept in project bullet-core by yahoo.
the class BulletConfigTest method testMetadataConversion.
@Test
public void testMetadataConversion() {
List<Map<String, String>> metadata = new ArrayList<>();
Map<String, String> expected = new HashMap<>();
for (Concept concept : Meta.KNOWN_CONCEPTS) {
Map<String, String> entry = new HashMap<>();
String name = concept.getName();
String key = concept.getName().substring(0, 3);
entry.put(BulletConfig.RESULT_METADATA_METRICS_CONCEPT_KEY, name);
entry.put(BulletConfig.RESULT_METADATA_METRICS_NAME_KEY, key);
metadata.add(entry);
expected.put(name, key);
}
BulletConfig config = new BulletConfig();
Assert.assertEquals(config.get(BulletConfig.RESULT_METADATA_METRICS), allMetadataAsMap());
config.set(BulletConfig.RESULT_METADATA_METRICS, metadata);
config.validate();
Assert.assertEquals(config.get(BulletConfig.RESULT_METADATA_METRICS), expected);
}
use of com.yahoo.bullet.result.Meta.Concept in project bullet-core by yahoo.
the class BulletConfigTest method testUnknownMetadata.
@Test
public void testUnknownMetadata() {
List<Map<String, String>> metadata = new ArrayList<>();
Map<String, String> expected = new HashMap<>();
for (Concept concept : Arrays.asList(Concept.QUERY_ID, Concept.SKETCH_ITEMS_SEEN)) {
Map<String, String> entry = new HashMap<>();
String name = concept.getName();
String key = concept.getName().substring(0, 3);
entry.put(BulletConfig.RESULT_METADATA_METRICS_CONCEPT_KEY, name);
entry.put(BulletConfig.RESULT_METADATA_METRICS_NAME_KEY, key);
metadata.add(entry);
expected.put(name, key);
}
BulletConfig config = new BulletConfig();
config.set(BulletConfig.RESULT_METADATA_METRICS, metadata);
config.validate();
Assert.assertEquals(config.get(BulletConfig.RESULT_METADATA_METRICS), expected);
// Add an unknown one
Map<String, String> entry = new HashMap<>();
entry.put("foo", "bar");
entry.put("baz", "qux");
metadata.add(entry);
config.set(BulletConfig.RESULT_METADATA_METRICS, metadata);
config.validate();
// Now it's all defaults
Assert.assertEquals(config.get(BulletConfig.RESULT_METADATA_METRICS), allMetadataAsMap());
}
use of com.yahoo.bullet.result.Meta.Concept in project bullet-core by yahoo.
the class BulletConfigTest method testIdempotencyOfMetadataValidate.
@Test
public void testIdempotencyOfMetadataValidate() {
Map<String, String> metadata = new HashMap<>();
for (Concept concept : Meta.KNOWN_CONCEPTS) {
String name = concept.getName();
String key = concept.getName().substring(0, 3);
metadata.put(name, key);
}
BulletConfig config = new BulletConfig();
config.set(BulletConfig.RESULT_METADATA_METRICS, metadata);
config.validate();
// It is the same object
Assert.assertTrue(config.get(BulletConfig.RESULT_METADATA_METRICS) == metadata);
// Even if we validate it again and again
config.validate();
config.validate();
Assert.assertTrue(config.get(BulletConfig.RESULT_METADATA_METRICS) == metadata);
}
use of com.yahoo.bullet.result.Meta.Concept in project bullet-core by yahoo.
the class BulletConfigTest method testMetadataGuard.
@Test
public void testMetadataGuard() {
BulletConfig config = new BulletConfig();
config.set(BulletConfig.RESULT_METADATA_METRICS, null);
config.validate();
Assert.assertEquals(config.get(BulletConfig.RESULT_METADATA_METRICS), allMetadataAsMap());
config.set(BulletConfig.RESULT_METADATA_METRICS, 1L);
config.validate();
Assert.assertEquals(config.get(BulletConfig.RESULT_METADATA_METRICS), allMetadataAsMap());
Map<Integer, Integer> bad = new HashMap<>();
bad.put(1, 2);
config.set(BulletConfig.RESULT_METADATA_METRICS, bad);
config.validate();
Assert.assertEquals(config.get(BulletConfig.RESULT_METADATA_METRICS), allMetadataAsMap());
Map<String, String> metadata = new HashMap<>();
for (Concept concept : Meta.KNOWN_CONCEPTS) {
String name = concept.getName();
String key = concept.getName().substring(0, 3);
metadata.put(name, key);
}
config.set(BulletConfig.RESULT_METADATA_METRICS, metadata);
config.validate();
Assert.assertTrue(config.get(BulletConfig.RESULT_METADATA_METRICS) == metadata);
}
use of com.yahoo.bullet.result.Meta.Concept in project bullet-core by yahoo.
the class BulletConfigTest method testBadMetadata.
@Test
public void testBadMetadata() {
List<Map<String, Object>> metadata = new ArrayList<>();
Map<String, String> expected = new HashMap<>();
for (Concept concept : Arrays.asList(Concept.QUERY_ID, Concept.SKETCH_ITEMS_SEEN)) {
Map<String, Object> entry = new HashMap<>();
String name = concept.getName();
String key = concept.getName().substring(0, 3);
entry.put(BulletConfig.RESULT_METADATA_METRICS_CONCEPT_KEY, name);
entry.put(BulletConfig.RESULT_METADATA_METRICS_NAME_KEY, key);
metadata.add(entry);
expected.put(name, key);
}
BulletConfig config = new BulletConfig();
config.set(BulletConfig.RESULT_METADATA_METRICS, metadata);
config.validate();
Assert.assertEquals(config.get(BulletConfig.RESULT_METADATA_METRICS), expected);
// Add a badly typed one
Map<String, Object> entry = new HashMap<>();
entry.put(BulletConfig.RESULT_METADATA_METRICS_CONCEPT_KEY, new ArrayList<>());
entry.put(BulletConfig.RESULT_METADATA_METRICS_NAME_KEY, new ArrayList<>());
metadata.add(entry);
config.set(BulletConfig.RESULT_METADATA_METRICS, metadata);
config.validate();
// Now it's all defaults
Assert.assertEquals(config.get(BulletConfig.RESULT_METADATA_METRICS), allMetadataAsMap());
}