}
@Nullable
protected String collectTrait(Resource resource, String traitName) throws Exception {
System.out.println("=== Collecting trait [" + traitName + "] for " + resource + "...");
MeasurementReport report = collectMetric(resource, traitName);
String value;
if (report.getTraitData().isEmpty()) {
assertEquals(
report.getNumericData().size(),
0,
"Metric [" + traitName + "] for Resource type " + resource.getResourceType()
+ " is defined as a trait, but the plugin returned one or more numeric metrics!: "
+ report.getNumericData());
assertEquals(
report.getCallTimeData().size(),
0,
"Metric [" + traitName + "] for Resource type " + resource.getResourceType()
+ " is defined as a trait, but the plugin returned one or more call-time metrics!: "
+ report.getCallTimeData());
value = null;
} else {
assertEquals(report.getTraitData().size(), 1,
"Requested a single trait, but plugin returned more than one datum: " + report.getTraitData());
MeasurementDataTrait datum = report.getTraitData().iterator().next();
assertEquals(datum.getName(), traitName,
"Trait [" + traitName + "] for Resource type " + resource.getResourceType()
+ " was requested, but the plugin returned a trait with name [" + datum.getName() + "] and value ["
+ datum.getValue() + "]!");
value = datum.getValue();