use of com.megaease.easeagent.mock.plugin.api.utils.TagVerifier in project easeagent by megaease.
the class RabbitMqConsumerMetricTest method metricAfter.
@Test
public void metricAfter() {
IPluginConfig config = TestUtils.getMqMetricConfig();
RabbitMqConsumerMetric metric = EaseAgent.getOrCreateServiceMetric(config, RabbitMqConsumerMetric.buildConsumerTags(), RabbitMqConsumerMetric.SERVICE_METRIC_SUPPLIER);
String key = "testMetricAfter";
metric.metricAfter(key, System.currentTimeMillis() - 101, true);
TagVerifier tagVerifier = TagVerifier.build(RabbitMqConsumerMetric.buildConsumerTags(), key);
LastJsonReporter lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(tagVerifier::verifyAnd);
Map<String, Object> metrics = lastJsonReporter.flushAndOnlyOne();
assertTrue((int) (double) metrics.get(MetricField.MIN_EXECUTION_TIME.getField()) > 100);
Meter meter = metric.meter(key, MetricSubType.CONSUMER);
Meter meterError = metric.meter(key, MetricSubType.CONSUMER_ERROR);
assertEquals(1, meter.getCount());
assertEquals(0, meterError.getCount());
metric.metricAfter(key, System.currentTimeMillis() - 100, false);
assertEquals(2, meter.getCount());
assertEquals(1, meterError.getCount());
}
use of com.megaease.easeagent.mock.plugin.api.utils.TagVerifier in project easeagent by megaease.
the class MD5SQLCompressionTest method compress.
@Test
public void compress() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
MD5SQLCompression md5SQLCompression = MD5SQLCompression.getInstance();
Cache<String, String> dictionary = AgentFieldReflectAccessor.getFieldValue(md5SQLCompression, "dictionary");
Cache<String, String> md5Cache = AgentFieldReflectAccessor.getFieldValue(md5SQLCompression, "md5Cache");
dictionary.cleanUp();
md5Cache.cleanUp();
String sql = "select * from data";
String md5 = DigestUtils.md5Hex(sql);
String result = md5SQLCompression.compress(sql);
assertEquals(md5, result);
assertEquals(result, md5SQLCompression.compress(sql));
assertEquals(md5, md5Cache.getIfPresent(sql));
assertEquals(sql, dictionary.getIfPresent(md5));
TagVerifier tagVerifier = new TagVerifier().add("category", "application").add("type", "md5-dictionary");
LastJsonReporter lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(tagVerifier::verifyAnd);
pushItems();
Map<String, Object> report = lastJsonReporter.getLastOnlyOne();
assertEquals(md5, report.get("md5"));
assertEquals(sql, report.get("sql"));
dictionary.cleanUp();
md5Cache.cleanUp();
}
use of com.megaease.easeagent.mock.plugin.api.utils.TagVerifier in project easeagent by megaease.
the class JdbcDataSourceMetricInterceptorTest method doAfter.
@Test
public void doAfter() throws SQLException {
JdbcDataSourceMetricInterceptor interceptor = new JdbcDataSourceMetricInterceptor();
InterceptorTestUtils.init(interceptor, new JdbcConnectionMetricPlugin());
Context context = EaseAgent.getContext();
ContextUtils.setBeginTime(context);
MethodInfo methodInfo = MethodInfo.builder().build();
interceptor.doAfter(methodInfo, context);
TagVerifier errorTagVerifier = TagVerifier.build(JdbcMetric.newConnectionTags(), JdbcDataSourceMetricInterceptor.ERR_CON_METRIC_KEY);
LastJsonReporter lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(errorTagVerifier::verifyAnd);
Map<String, Object> metrics = lastJsonReporter.flushAndOnlyOne();
assertEquals(1, metrics.get(MetricField.EXECUTION_COUNT.getField()));
assertEquals(1, metrics.get(MetricField.EXECUTION_ERROR_COUNT.getField()));
Connection connection = TestUtils.mockConnection();
methodInfo = MethodInfo.builder().retValue(connection).throwable(new RuntimeException("test error")).build();
interceptor.doAfter(methodInfo, context);
metrics = lastJsonReporter.flushAndOnlyOne();
assertEquals(2, metrics.get(MetricField.EXECUTION_COUNT.getField()));
assertEquals(2, metrics.get(MetricField.EXECUTION_ERROR_COUNT.getField()));
methodInfo = MethodInfo.builder().retValue(connection).build();
interceptor.doAfter(methodInfo, context);
metrics = lastJsonReporter.flushAndOnlyOne();
assertEquals(2, metrics.get(MetricField.EXECUTION_COUNT.getField()));
assertEquals(2, metrics.get(MetricField.EXECUTION_ERROR_COUNT.getField()));
TagVerifier urlTagVerifier = TagVerifier.build(JdbcMetric.newConnectionTags(), TestUtils.URI);
lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(urlTagVerifier::verifyAnd);
metrics = lastJsonReporter.flushAndOnlyOne();
assertEquals(1, metrics.get(MetricField.EXECUTION_COUNT.getField()));
assertNull(metrics.get(MetricField.EXECUTION_ERROR_COUNT.getField()));
}
use of com.megaease.easeagent.mock.plugin.api.utils.TagVerifier in project easeagent by megaease.
the class JdbcMetricTest method onRemoval.
@Test
public void onRemoval() {
JdbcMetric jdbcMetric = get();
Context context = EaseAgent.getContext();
ContextUtils.setBeginTime(context);
jdbcMetric.collectMetric(TestUtils.URI, true, context);
TagVerifier tagVerifier = TagVerifier.build(JdbcMetric.newConnectionTags(), TestUtils.URI);
LastJsonReporter lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(tagVerifier::verifyAnd);
Map<String, Object> metrics = lastJsonReporter.flushAndOnlyOne();
assertNotNull(metrics);
jdbcMetric.collectMetric(TestUtils.URI, false, context);
metrics = lastJsonReporter.flushAndOnlyOne();
assertNotNull(metrics);
RemovalNotification<String, String> removalNotification = RemovalNotification.create(TestUtils.URI, "", RemovalCause.SIZE);
jdbcMetric.onRemoval(removalNotification);
try {
lastJsonReporter.flushAndOnlyOne();
fail("must be throw error");
} catch (Exception e) {
// must be error
}
}
use of com.megaease.easeagent.mock.plugin.api.utils.TagVerifier in project easeagent by megaease.
the class GatewayAccessLogInterceptorTest method after.
@Test
public void after() throws InterruptedException {
GatewayAccessLogInterceptor interceptor = new GatewayAccessLogInterceptor();
InterceptorTestUtils.init(interceptor, new AccessPlugin());
Context context = EaseAgent.getContext();
MockServerWebExchange mockServerWebExchange = TestServerWebExchangeUtils.mockServerWebExchange();
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { mockServerWebExchange }).build();
interceptor.before(methodInfo, context);
Long start = context.get(startTime);
assertNotNull(start);
interceptor.after(methodInfo, context);
assertNull(context.get(startTime));
assertTrue(methodInfo.getRetValue() instanceof AgentMono);
AgentMono agentMono = (AgentMono) methodInfo.getRetValue();
TagVerifier tagVerifier = new TagVerifier().add("type", "access-log").add("system", "test-gateway-system");
LastJsonReporter lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(tagVerifier::verifyAnd);
Thread thread = new Thread(() -> agentMono.getFinish().accept(agentMono.getMethodInfo(), agentMono.getAsyncContext()));
thread.start();
thread.join();
RequestInfo requestInfo = getRequestInfo(lastJsonReporter);
verify(requestInfo, start);
}
Aggregations