@Test public void non_method_joinpoints_cant_be_cached() throws Throwable { // Given ProceedingJoinPoint pjp = mock(ProceedingJoinPoint.class); when(pjp.getSignature()).thenReturn(mock(FieldSignature.class)); when(pjp.proceed()).thenReturn(new Result("foo"), new Result("foo")); // When Result firstResult = (Result) aspect.getMemoizedResultOrProceed(pjp); Result secondResult = (Result) aspect.getMemoizedResultOrProceed(pjp); // Then assertThat(firstResult != secondResult, is(true)); assertThat(firstResult, equalTo(secondResult)); verify(pjp, times(2)).proceed(); }
@Around("set(@com.lib.logthisannotations.annotation.LogThis * *) && args(newVal) && target(t)") public void weaveBeforeFieldLogThisJoinPoint(ProceedingJoinPoint joinPoint, Object t, Object newVal) throws Throwable { Logger logger = Logger.getInstance(); if(logger != null && logger.isLoggerEnabled()) { FieldSignature fs = (FieldSignature) joinPoint.getSignature(); String fieldName = fs.getName(); Field field = fs.getField(); field.setAccessible(true); Object oldVal = field.get(t); LogThis annotation = field.getAnnotation(com.lib.logthisannotations.annotation.LogThis.class); LoggerLevel loggerLevel = annotation.logger(); StringBuilder builder = Strings.getStringFieldBuilder(fieldName, String.valueOf(oldVal), String.valueOf(newVal)); logger.getLoggerInstance().log(t.getClass().getName(), "Field " + builder.toString(), loggerLevel, annotation.write()); joinPoint.proceed(); } }
private static Annotation getAnnotation(final Signature signature, final Class<? extends Annotation> annotationClass) { if (signature instanceof ConstructorSignature) { final Constructor<?> ctor = ConstructorSignature.class.cast(signature) .getConstructor(); return ctor.getAnnotation(annotationClass); } else if (signature instanceof MethodSignature) { return MethodSignature.class.cast(signature) .getMethod() .getAnnotation(annotationClass); } else if (signature instanceof FieldSignature) { return FieldSignature.class.cast(signature) .getField() .getAnnotation(annotationClass); } throw new RuntimeException( "Unsupported signature type " + signature.getClass().getName() ); }
@Around("args(newval) && set(@at.ac.tuwien.infosys.jcloudscale.annotations.CloudGlobal static * *.*)") public void writeStaticValueToClient(ProceedingJoinPoint pjp, Object newval) throws Throwable { if(!JCloudScaleConfiguration.isServerContext()) { pjp.proceed(); return; } try(IMQWrapper mq = JCloudScaleConfiguration.createMQWrapper()) { UUID corrId = UUID.randomUUID(); FieldSignature sig = (FieldSignature) pjp.getSignature(); Field field = sig.getField(); Object newValProcessed = JCloudScaleReferenceManager.getInstance().processField(field, newval); byte[] serialzed = SerializationUtil.serializeToByteArray(newValProcessed); SetStaticValueRequest req = new SetStaticValueRequest(); req.setField(field.getName()); req.setClassName(field.getDeclaringClass().getCanonicalName()); req.setValue(serialzed); mq.createQueueProducer(JCloudScaleConfiguration.getConfiguration().server().getStaticFieldWriteRequestQueueName()); mq.createTopicConsumer(JCloudScaleConfiguration.getConfiguration().server().getStaticFieldWriteResponseTopicName(), "JMSCorrelationID = '"+corrId.toString()+"'"); // we send request and wait for response to ensure that we in fact // changed the value before continuing. mq.requestResponse(req, corrId); } catch (JMSException | NamingException | IOException e) { e.printStackTrace(); log.severe("Could not write static field: "+e.getMessage()); } }
private Signature createFieldSignatureMock(String fieldName) { final FieldSignature fieldSignature = mock(FieldSignature.class); when(fieldSignature.getField()).thenReturn(resolveField(fieldName)); LOGGER.debug("FieldSignature Mock - getField() = {}", fieldSignature.getField()); return fieldSignature; }
@After("setValueToAnyField() && withParameterAnnotation()") public void parameterValueChanged(JoinPoint joinPoint) { try { FieldSignature fieldSignature = (FieldSignature) joinPoint.getSignature(); Parameter parameter = fieldSignature.getField().getAnnotation(Parameter.class); String name = parameter.value().isEmpty() ? fieldSignature.getName() : parameter.value(); Allure.LIFECYCLE.fire(new AddParameterEvent(name, joinPoint.getArgs()[0].toString())); } catch (Exception ignored) { } }
public FieldSetTest() { super("eval.org.aspectj.lang.FieldSetAspect", JoinPoint.FIELD_SET, FieldSignature.class); }
public FieldGetTest() { super("eval.org.aspectj.lang.FieldGetAspect", JoinPoint.FIELD_GET, FieldSignature.class); }
FieldJoinPointMatcher(AjJoinPointType joinPointType) { super(joinPointType, FieldSignature.class); }
@Override protected boolean doMatchSignature(FieldSignature signature, AjJoinPoint ajUnitJoinPoint) { return signature.getField().equals(ajUnitJoinPoint.getField()); }
/** * Aspect advice triggered on the access of all fields carrying an * {@link com.github.msoliter.iroh.container.annotations.Autowired} * annotation. If the field has been marked for lazy injection, and has not * been injected with an instance yet, this advice will properly initialize * that field. * * @param thisJoinPoint The join point carrying critical information about * which field is being accessed, as well as its current contents. */ @Before("external() && access()") public void lazilyInjectField(JoinPoint thisJoinPoint) { FieldSignature fs = (FieldSignature) thisJoinPoint.getSignature(); Field field = fs.getField(); Object target = thisJoinPoint.getTarget(); injector.lazilyInject(target, field); }