HistogramConstructInterceptor implements InstanceConstructorInterceptor { @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { final MeterId meterId = (MeterId) allArguments[0]; final List<Double> steps = (List<Double>) allArguments[1]; final Histogram histogram = new Histogram(MeterIdConverter.convert(meterId), steps); if (METER_SERVICE == null) { METER_SERVICE = ServiceManager.INSTANCE.findService(MeterService.class); } objInst.setSkyWalkingDynamicField(METER_SERVICE.register(histogram)); }  @Override void onConstruct(EnhancedInstance objInst, Object[] allArguments);  }
@Test public void testConstruct() { histogramConstructInterceptor.onConstruct(enhancedInstance, new Object[] { new MeterId("test", MeterId.MeterType.HISTOGRAM, Arrays.asList(new MeterId.Tag("k1", "v1"))), Arrays.asList(1d, 5d, 10d) }); final MeterService service = ServiceManager.INSTANCE.findService(MeterService.class); final Map<MeterId, BaseMeter> meterMap = (Map<MeterId, BaseMeter>) Whitebox.getInternalState( service, "meterMap"); Assert.assertEquals(1, meterMap.size()); final Object field = meterMap.values().iterator().next(); Assert.assertNotNull(field); Assert.assertTrue(field instanceof Histogram); final Histogram histogramTransformer = (Histogram) field; Assert.assertNotNull(histogramTransformer.getId()); Assert.assertEquals("test", histogramTransformer.getId().getName()); Assert.assertEquals(MeterType.HISTOGRAM, histogramTransformer.getId().getType()); Assert.assertEquals(Arrays.asList(new MeterTag("k1", "v1")), histogramTransformer.getId().getTags()); }