use of com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager in project sofa-rpc by sofastack.
the class AbstractTracerBase method removeRpcDigestStatLogType.
protected void removeRpcDigestStatLogType() throws Exception {
AsyncCommonDigestAppenderManager asyncDigestManager = SofaTracerDigestReporterAsyncManager.getSofaTracerDigestReporterAsyncManager();
// stat
Map<Long, SofaTracerStatisticReporterManager> cycleTimesManager = SofaTracerStatisticReporterCycleTimesManager.getCycleTimesManager();
for (Map.Entry<Long, SofaTracerStatisticReporterManager> entry : cycleTimesManager.entrySet()) {
SofaTracerStatisticReporterManager manager = entry.getValue();
manager.getStatReporters().clear();
}
}
use of com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager in project sofa-boot by sofastack.
the class AbstractTestBase method reflectSpringMVCClear.
public static void reflectSpringMVCClear() throws NoSuchFieldException, IllegalAccessException {
Field field = SpringMvcTracer.class.getDeclaredField("springMvcTracer");
field.setAccessible(true);
field.set(null, null);
// clear digest
Field fieldAsync = SofaTracerDigestReporterAsyncManager.class.getDeclaredField("asyncCommonDigestAppenderManager");
fieldAsync.setAccessible(true);
fieldAsync.set(null, null);
// clear stat
SofaTracerStatisticReporterManager statReporterManager = SofaTracerStatisticReporterCycleTimesManager.getSofaTracerStatisticReporterManager(1L);
Field fieldStat = SofaTracerStatisticReporterManager.class.getDeclaredField("statReporters");
fieldStat.setAccessible(true);
fieldStat.set(statReporterManager, new ConcurrentHashMap<>());
}
use of com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager in project sofa-boot by sofastack.
the class SpringMvcFilterJsonOutputTest method testSofaRestGet.
@Test
@Ignore
public void testSofaRestGet() throws Exception {
String restUrl = urlHttpPrefix + "/greeting";
int countTimes = 5;
for (int i = 0; i < countTimes; i++) {
ResponseEntity<SampleRestController.Greeting> response = testRestTemplate.getForEntity(restUrl, SampleRestController.Greeting.class);
SampleRestController.Greeting greetingResponse = response.getBody();
assertTrue(greetingResponse.isSuccess());
// http://docs.spring.io/spring-boot/docs/1.4.2.RELEASE/reference/htmlsingle/#boot-features-testing
assertTrue(greetingResponse.getId() >= 0);
}
TestUtil.waitForAsyncLog();
// wait for async output
List<String> contents = FileUtils.readLines(customFileLog(SpringMvcLogEnum.SPRING_MVC_DIGEST.getDefaultLogName()));
assertTrue(contents.size() == countTimes);
for (int i = 0; i < contents.size(); i++) {
String logValue = contents.get(i);
Map<String, String> jsonMap = parseToMap(logValue, String.class, String.class);
assertTrue(jsonMap.size() > 0);
}
// wait another 500ms to reach a cycle of stat_internal_log
Thread.sleep(500);
for (int i = 0; i < countTimes; i++) {
ResponseEntity<SampleRestController.Greeting> response = testRestTemplate.getForEntity(restUrl, SampleRestController.Greeting.class);
SampleRestController.Greeting greetingResponse = response.getBody();
assertTrue(greetingResponse.isSuccess());
}
SofaTracerStatisticReporterManager s = SofaTracerStatisticReporterCycleTimesManager.getSofaTracerStatisticReporterManager(1L);
Assert.notNull(s.getStatReporters().get(SpringMvcLogEnum.SPRING_MVC_STAT.getDefaultLogName()));
// stat log : 设置了周期 1s 输出一次
Thread.sleep(1000);
// wait for async output
List<String> statContents = FileUtils.readLines(customFileLog(SpringMvcLogEnum.SPRING_MVC_STAT.getDefaultLogName()));
assertEquals(2, statContents.size());
}
use of com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager in project sofa-boot by alipay.
the class SpringMvcFilterJsonOutputTest method testSofaRestGet.
@Test
@Ignore
public void testSofaRestGet() throws Exception {
String restUrl = urlHttpPrefix + "/greeting";
int countTimes = 5;
for (int i = 0; i < countTimes; i++) {
ResponseEntity<SampleRestController.Greeting> response = testRestTemplate.getForEntity(restUrl, SampleRestController.Greeting.class);
SampleRestController.Greeting greetingResponse = response.getBody();
assertTrue(greetingResponse.isSuccess());
// http://docs.spring.io/spring-boot/docs/1.4.2.RELEASE/reference/htmlsingle/#boot-features-testing
assertTrue(greetingResponse.getId() >= 0);
}
TestUtil.waitForAsyncLog();
// wait for async output
List<String> contents = FileUtils.readLines(customFileLog(SpringMvcLogEnum.SPRING_MVC_DIGEST.getDefaultLogName()));
assertTrue(contents.size() == countTimes);
for (int i = 0; i < contents.size(); i++) {
String logValue = contents.get(i);
Map<String, String> jsonMap = parseToMap(logValue, String.class, String.class);
assertTrue(jsonMap.size() > 0);
}
// wait another 500ms to reach a cycle of stat_internal_log
Thread.sleep(500);
for (int i = 0; i < countTimes; i++) {
ResponseEntity<SampleRestController.Greeting> response = testRestTemplate.getForEntity(restUrl, SampleRestController.Greeting.class);
SampleRestController.Greeting greetingResponse = response.getBody();
assertTrue(greetingResponse.isSuccess());
}
SofaTracerStatisticReporterManager s = SofaTracerStatisticReporterCycleTimesManager.getSofaTracerStatisticReporterManager(1L);
Assert.notNull(s.getStatReporters().get(SpringMvcLogEnum.SPRING_MVC_STAT.getDefaultLogName()));
// stat log : 设置了周期 1s 输出一次
Thread.sleep(1000);
// wait for async output
List<String> statContents = FileUtils.readLines(customFileLog(SpringMvcLogEnum.SPRING_MVC_STAT.getDefaultLogName()));
assertEquals(2, statContents.size());
}
use of com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager in project sofa-boot by alipay.
the class AbstractTestBase method reflectSpringMVCClear.
public static void reflectSpringMVCClear() throws NoSuchFieldException, IllegalAccessException {
Field field = SpringMvcTracer.class.getDeclaredField("springMvcTracer");
field.setAccessible(true);
field.set(null, null);
// clear digest
Field fieldAsync = SofaTracerDigestReporterAsyncManager.class.getDeclaredField("asyncCommonDigestAppenderManager");
fieldAsync.setAccessible(true);
fieldAsync.set(null, null);
// clear stat
SofaTracerStatisticReporterManager statReporterManager = SofaTracerStatisticReporterCycleTimesManager.getSofaTracerStatisticReporterManager(1L);
Field fieldStat = SofaTracerStatisticReporterManager.class.getDeclaredField("statReporters");
fieldStat.setAccessible(true);
fieldStat.set(statReporterManager, new ConcurrentHashMap<>());
}
Aggregations