How to test complex pointcut patterns?

View: New views
3 Messages — Rating Filter:   Alert me  

How to test complex pointcut patterns?

by maly.velky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello, are there please some tools for testing complex pointcut expressions, like the following one (taken from aop.xml):

---
(portletEntryMethods() AND !cflowbelow(portletEntryMethods())) || (call(* javax.xml.soap.SOAPConnection.call(..)) AND within(com.tonbeller.jpivot.xmla.XMLA_SOAP)) || (within(com.tonbeller..*) AND (execution(* XMLA_SOAP.discover(..)) || execution(* XMLA_SOAP.executeQuery(..)) || execution(* XMLA_Model.lookup*(..)) || execution(* XMLA_Model.initCubeMetaData(..)) || execution(* XMLA_Model.getResult(..)) || execution(* XMLA_Result.handle*(..)) || execution(* XMLA_QueryAdapter.afterExecute(..)) || execution(* RendererTag.doEndTag(..)) || execution(* TableComponent.render(..)) || execution(* *.doEndTag(..)) ))
---
(The pointcut is so complex because it's a specification of an abstract pointcut in aop.xml, in an aspect class I'd split it into multiple poincuts.)

The problem with such a complex pattern is that when it fails to match some expected join point then you have no idea which part of it is wrong. There is of course the laborious manual process of splitting it into individual, simple pointcuts and testing them then trying their combinations... . But it's just too time-consuming.

I wonder if there is:
A) either an interactive pattern-testing tool like the jEdit plugin 'RE Tester' for testing regular expression (checking the pattern against classes on the classpath)
B) or a tool that would again check the pattern against a set of classes and provided detailed information about the matching process with useful reports like "the subpatern ... didn't match due to the condition 'within(com.tonbeller..*)' for there is no sub-package of 'com.tonbeller' and there is also no package 'com.tonbeller'". Such a tool would make writing correct expressions much easier.

What do you use for getting your pointcut patterns right?

Thank you very much!

Best Regards, Jakub Holy
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Re: How to test complex pointcut patterns?

by Ichthyostega :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

maly.velky@... schrieb:
> What do you use for getting your pointcut patterns right?

Hi Jakub,

indeed, using AspectJ now since several years, I've found there is the
possibility to get astray. Some of my observations/guidelines:

- - the moment you're going to target individual methods or (worse) specific
  parameter patterns, you should be alarmed.
  Such tends to be unstable and cause endless maintenance problems.

- - try fist to create specific interfaces, which capture a concept precisely.
  And then write your pointcuts against those interfaces.

- - use annotations instead of method/class names to direct the match

- - try to be *declarative*
  That means: a set of pointcuts should describe a *logical* relationship,
  and *not* a specific execution situation.

- - and by all means: *name* your pointcuts!
  Never create such a "train wreck" sequence of && and || with dozens of
  individual patterns. Instead, create small logical groups (1..3 clauses)
  and *try to give them a descriptive and precise name*
  Naming is not just avoidable bla bla. It's the key of getting things right.
  If you aren't able to give a pointcut a proper name, you should consider
  it broken!

If you adhere to this rules, testing is rather simple. Write a test/dummy
before advice for each separately named pointcut, and verify (either with
the AJDT cross reference view or by log messages) that it matches the
right targets.

Regarding the example you quoted, I'd propose the following:

> (portletEntryMethods() AND !cflowbelow(portletEntryMethods()))
> || (call(* javax.xml.soap.SOAPConnection.call(..))
>    AND within(com.tonbeller.jpivot.xmla.XMLA_SOAP))
> || (within(com.tonbeller..*)
>    AND (execution(* XMLA_SOAP.discover(..))
> || execution....

- - the final "top level" pointcut, which you are addressing in your advice
  should be just a disjunction of named pointcuts
- - the parts in turn should be the conjugation of named sub-pointcuts
- - the within() pointcuts should be declared abstract and the specific
  packages pushed down into the concrete aspect.
- - you can use *one* aspect just to place annotations on specific methods;
  which then can be targeted by other aspects!
  Couldn't you utilise this technique to simplify your pointcut? for example
  all the various execution pointcuts could be replaced by a pointcut targeting
  the execution of a method with a custom annotation. And another aspect would
  place this annotation at the right places.

Hope this helps
Cheers,
Hermann Vosseler



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkq8wMwACgkQZbZrB6HelLKTZQCbBKRsEbliPTlgxSIgXQEkVEqN
uhMAn3+ee+/1KFnbxmz0WKNyH8vVgSqy
=DIxE
-----END PGP SIGNATURE-----
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Re: Re: How to test complex pointcut patterns?

by maly.velky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Hermann,
thank you very much for your elaborate answer. Your guidelines are very good by I'm afraid that in my case they're applicable only to a limited degree for two reasons: First, I cannot change the classes (source codes) to which I apply the aspect. Second, I need the set of intercepted methods to be highly configurable via aop.xml and thus cannot split it into simple named pointcuts because I can't know in advance what pointcuts will be needed. But you're right that I could extract some parts of that complex expression into abstract pointcuts of their own. I'll think about your suggestions of matching against an annotation injected by another aspect, perhaps that something that could really simplify the thing.

Thank you very much, Jakub

> ------------ Původní zpráva ------------
> Od: Ichthyostega <prg@...>
> Předmět: Re: [aspectj-users] How to test complex pointcut patterns?
> Datum: 25.9.2009 15:09:18
> ----------------------------------------
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> maly.velky@... schrieb:
> > What do you use for getting your pointcut patterns right?
>
> Hi Jakub,
>
> indeed, using AspectJ now since several years, I've found there is the
> possibility to get astray. Some of my observations/guidelines:
>
> - - the moment you're going to target individual methods or (worse) specific
>   parameter patterns, you should be alarmed.
>   Such tends to be unstable and cause endless maintenance problems.
>
> - - try fist to create specific interfaces, which capture a concept precisely.
>   And then write your pointcuts against those interfaces.
>
> - - use annotations instead of method/class names to direct the match
>
> - - try to be *declarative*
>   That means: a set of pointcuts should describe a *logical* relationship,
>   and *not* a specific execution situation.
>
> - - and by all means: *name* your pointcuts!
>   Never create such a "train wreck" sequence of && and || with dozens of
>   individual patterns. Instead, create small logical groups (1..3 clauses)
>   and *try to give them a descriptive and precise name*
>   Naming is not just avoidable bla bla. It's the key of getting things right.
>   If you aren't able to give a pointcut a proper name, you should consider
>   it broken!
>
> If you adhere to this rules, testing is rather simple. Write a test/dummy
> before advice for each separately named pointcut, and verify (either with
> the AJDT cross reference view or by log messages) that it matches the
> right targets.
>
> Regarding the example you quoted, I'd propose the following:
>
> > (portletEntryMethods() AND !cflowbelow(portletEntryMethods()))
> > || (call(* javax.xml.soap.SOAPConnection.call(..))
> >    AND within(com.tonbeller.jpivot.xmla.XMLA_SOAP))
> > || (within(com.tonbeller..*)
> >    AND (execution(* XMLA_SOAP.discover(..))
> > || execution....
>
> - - the final "top level" pointcut, which you are addressing in your advice
>   should be just a disjunction of named pointcuts
> - - the parts in turn should be the conjugation of named sub-pointcuts
> - - the within() pointcuts should be declared abstract and the specific
>   packages pushed down into the concrete aspect.
> - - you can use *one* aspect just to place annotations on specific methods;
>   which then can be targeted by other aspects!
>   Couldn't you utilise this technique to simplify your pointcut? for example
>   all the various execution pointcuts could be replaced by a pointcut targeting
>   the execution of a method with a custom annotation. And another aspect would
>   place this annotation at the right places.
>
> Hope this helps
> Cheers,
> Hermann Vosseler
>
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkq8wMwACgkQZbZrB6HelLKTZQCbBKRsEbliPTlgxSIgXQEkVEqN
> uhMAn3+ee+/1KFnbxmz0WKNyH8vVgSqy
> =DIxE
> -----END PGP SIGNATURE-----
>
>
>

Jakub Holy
maly.velky@...
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users