use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.
the class ZMSUtilsTest method testEmitMonmetricError.
@Test
public void testEmitMonmetricError() {
Metric savedMetric = ZMSImpl.metric;
assertFalse(ZMSUtils.emitMonmetricError(-1, "unittest"));
assertFalse(ZMSUtils.emitMonmetricError(400, null));
assertFalse(ZMSUtils.emitMonmetricError(400, ""));
ZMSImpl.metric = null;
assertFalse(ZMSUtils.emitMonmetricError(400, "unittest"));
ZMSImpl.metric = savedMetric;
}
use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.
the class MetricsTest method testMetricInterfaceNonDefaults.
@Test
public void testMetricInterfaceNonDefaults() {
Metric metric = new Metric() {
@Override
public void increment(String metric) {
}
@Override
public void increment(String metric, String requestDomainName) {
}
@Override
public void increment(String metric, String requestDomainName, int count) {
}
@Override
public Object startTiming(String metric, String requestDomainName) {
return null;
}
@Override
public void stopTiming(Object timerMetric) {
}
@Override
public void flush() {
}
@Override
public void quit() {
}
};
metric.increment("metric1");
metric.increment("metric1", "athenz", 3);
metric.increment("metric1", "athenz", "sports");
metric.increment("metric1", "athenz", "sports", 3);
metric.increment("apiRquestsMetric", "athenz", "sports", "POST", 200, "caller");
String[] attributes = new String[] { "tag1", "value1", "tag2", "value2", "tag3", "value3" };
metric.increment("metric1", attributes);
assertNull(metric.startTiming("metric1", "athenz", "sports"));
assertNull(metric.startTiming("apiRquestsMetric", "athenz", "sports", "POST", "caller"));
metric.stopTiming("metric1", "athenz", "sports");
metric.stopTiming("apiRquestsMetric", "athenz", "sports", "POST", 200, "caller");
metric.flush();
metric.quit();
}
use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.
the class MetricsTest method testFactoryNoOpMetric.
@Test
public void testFactoryNoOpMetric() throws Exception {
MetricFactory factory = new NoOpMetricFactory();
Metric metric = factory.create();
assertEquals(metric.getClass().getName(), Class.forName("com.yahoo.athenz.common.metrics.impl.NoOpMetric").getName());
metric.increment("metric1");
metric.increment("metric1", "athenz");
metric.increment("metric1", "athenz", 3);
metric.increment("metric1", "athenz", "sports");
metric.increment("metric1", "athenz", "sports", 3);
metric.increment("apiRquestsMetric", "athenz", "sports", "POST", 200, "caller");
String[] attributes = new String[] { "tag1", "value1", "tag2", "value2", "tag3", "value3" };
metric.increment("metric1", attributes);
assertNull(metric.startTiming("metric1", "athenz"));
assertNull(metric.startTiming("metric1", "athenz", "sports"));
assertNull(metric.startTiming("apiRquestsMetric", "athenz", "sports", "POST", "caller"));
metric.stopTiming("metric1");
metric.stopTiming("metric1", "athenz", "sports");
metric.stopTiming("apiRquestsMetric", "athenz", "sports", "POST", 200, "caller");
metric.flush();
metric.quit();
}
use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.
the class ZTSImplTest method testEmitMonmetricError.
@Test
public void testEmitMonmetricError() {
int errorCode = 403;
String caller = "forbiddenError";
boolean isEmitMonmetricError;
com.yahoo.athenz.common.metrics.Metric metric = getMetric();
// negative tests
isEmitMonmetricError = ZTSUtils.emitMonmetricError(errorCode, null, ZTSConsts.ZTS_UNKNOWN_DOMAIN, "principal-domain", metric);
assertFalse(isEmitMonmetricError);
isEmitMonmetricError = ZTSUtils.emitMonmetricError(errorCode, "", ZTSConsts.ZTS_UNKNOWN_DOMAIN, "principal-domain", metric);
assertFalse(isEmitMonmetricError);
isEmitMonmetricError = ZTSUtils.emitMonmetricError(errorCode, "", null, "principal-domain", metric);
assertFalse(isEmitMonmetricError);
isEmitMonmetricError = ZTSUtils.emitMonmetricError(0, caller, null, "principal-domain", metric);
assertFalse(isEmitMonmetricError);
isEmitMonmetricError = ZTSUtils.emitMonmetricError(-100, caller, null, "principal-domain", metric);
assertFalse(isEmitMonmetricError);
// positive tests
isEmitMonmetricError = ZTSUtils.emitMonmetricError(errorCode, caller, null, "principal-domain", metric);
assertTrue(isEmitMonmetricError);
isEmitMonmetricError = ZTSUtils.emitMonmetricError(errorCode, " " + caller + " ", null, "principal-domain", metric);
assertTrue(isEmitMonmetricError);
}
use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.
the class ZTSImplTest method getMetric.
private Metric getMetric() {
com.yahoo.athenz.common.metrics.MetricFactory metricFactory;
com.yahoo.athenz.common.metrics.Metric metric;
try {
metricFactory = (com.yahoo.athenz.common.metrics.MetricFactory) Class.forName(System.getProperty(ZTSConsts.ZTS_PROP_METRIC_FACTORY_CLASS)).newInstance();
metric = metricFactory.create();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException exc) {
System.out.println("Invalid MetricFactory class: " + METRIC_DEFAULT_FACTORY_CLASS + " error: " + exc.getMessage());
metric = new com.yahoo.athenz.common.metrics.impl.NoOpMetric();
}
return metric;
}
Aggregations