TransportServiceConInterceptor implements InstanceConstructorInterceptor { @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { Settings settings = (Settings) allArguments[0]; String clusterName = settings.get("cluster.name"); TransportClientEnhanceInfo transportClientEnhanceInfo = new TransportClientEnhanceInfo(); transportClientEnhanceInfo.setClusterName(clusterName); transportClientEnhanceInfo.setTransportAddressCache(new TransportAddressCache()); objInst.setSkyWalkingDynamicField(transportClientEnhanceInfo); }  @Override void onConstruct(EnhancedInstance objInst, Object[] allArguments);  }
@Test public void testConstruct() { final EnhancedInstance objInst = new EnhancedInstance() { private Object object = null; @Override public Object getSkyWalkingDynamicField() { return object; } @Override public void setSkyWalkingDynamicField(Object value) { this.object = value; } }; transportServiceConInterceptor = new TransportServiceConInterceptor(); transportServiceConInterceptor.onConstruct(objInst, allArguments); assertThat(objInst.getSkyWalkingDynamicField() instanceof TransportClientEnhanceInfo, is(true)); assertThat(((TransportClientEnhanceInfo) (objInst.getSkyWalkingDynamicField())).getClusterName(), is("my.es.cluster")); }