Simplify Testing using Fault Injection   Rob Grzywinski [email_address]
Motivation <ul><li>Writing and testing an IO-intensive application </li></ul><ul><ul><li>Robust, asynchronous event (messa...
Agenda <ul><li>Quick Introduction to Fault Injection </li></ul><ul><li>Why Use Fault Injection </li></ul><ul><li>Fault Inj...
Fault Injection 101 <ul><li>A fault is an  abnormal condition  or  defect  which may lead to a  failure   [10] </li></ul><...
Fault Injection 101  (cont) <ul><li>There are two primary steps to Fault Injection: </li></ul><ul><li>To identify the set ...
Example <ul><li>byte []   readFile()  throws  IOException { </li></ul><ul><li>...   </li></ul><ul><li>final  InputStream i...
Possible Techniques <ul><li>Force the situations at the OS level </li></ul><ul><ul><li>Quite hairy to reproduce reliably w...
Why Use Fault Injection <ul><li>Fault occurred in a production application and it is determined that that is a valid fault...
Why Use Fault Injection  (cont) <ul><li>You publish an API and you want to be tolerant of user input or response </li></ul...
Reminder <ul><li>You don’t have to recreate the conditions that caused the fault … </li></ul><ul><li>…  you only have to r...
Quick Aside <ul><li>Traditionally , Fault Injection is centers around faults derived from hardware: </li></ul><ul><li>Disk...
Quick Aside  (cont) <ul><li>Fault Injection comes in two favors:  </li></ul><ul><li>Hardware-based </li></ul><ul><ul><li>T...
Example <ul><li>Creating a directory and temporary file </li></ul>final  File directory =  new  File(…); final  boolean su...
Example  (cont) <ul><li>Great uses of Fault Injection that I can’t easily show in examples: </li></ul><ul><li>Deeply neste...
Intelligent Fault Injection <ul><li>Fault injection doesn’t have to be all on or all off </li></ul><ul><li>Logic can be co...
Beyond Fault Injection <ul><li>The techniques that I’m going to demonstrate aren’t specific to injecting faults  ( i.e.  c...
Summary <ul><li>Intercept operations  and inject code to: </li></ul><ul><li>Perform a custom function </li></ul><ul><li>Re...
Checkpoint <ul><li>Done: </li></ul><ul><li>Quick Introduction to Fault Injection </li></ul><ul><li>Why Use Fault Injection...
Checkpoint  (cont) <ul><li>Questions? </li></ul>
Aspect Oriented Programming 101 <ul><li>Join Point </li></ul><ul><li>a point in the flow of a running program  [14] </li><...
Aspect Oriented Programming 101  (cont) <ul><li>Join point examples </li></ul><ul><li>reading or writing a field </li></ul...
Aspect Oriented Programming 101  (cont) <ul><li>Pointcut </li></ul><ul><li>a set of join points  [6]   </li></ul><ul><li>E...
Aspect Oriented Programming 101  (cont) <ul><li>Advice </li></ul><ul><li>code that executes at each join point picked out ...
Aspect Oriented Programming 101  (cont) <ul><li>Aspect </li></ul><ul><li>a logical collection of advice </li></ul><ul><li>...
Aspect Oriented Programming 101  (cont) <ul><li>Introduction  (aka  Mixin  or  inter-type declaration )   </li></ul><ul><l...
Aspect Oriented Programming 101  (cont) <ul><li>Weaving </li></ul><ul><li>the process by which specific join points are id...
How AOP Works <ul><li>Compile-time </li></ul><ul><ul><li>a specialized compiler is used to weave the source code and advic...
Load-Time Weaving <ul><li>We’re going to focus on load-time weaving (LTW) </li></ul><ul><ul><li>Advantange (over compile-t...
Java AOP <ul><li>AspectJ ( http:// www.eclipse.org/aspectj / ):  Excellent all-around solution. </li></ul><ul><li>dynaop (...
Questions?
AspectJ <ul><li>AspectJ </li></ul><ul><ul><li>http://www.eclipse.org/aspectj/ </li></ul></ul><ul><li>Documentation </li></...
Load-Time Weaving AspectJ <ul><li>Load-time Weaving can be accomplished via  [13] : </li></ul><ul><li>-javaagent:pathto/as...
AspectJ Examples <ul><li>There are three primary classes in the example: </li></ul><ul><li>Main </li></ul><ul><ul><li>Crea...
AspectJ Pros <ul><li>Quite mature </li></ul><ul><li>Integration with IDEs ( e.g.  AJDT) </li></ul><ul><li>Responsive forum...
AspectJ Cons <ul><li>Expect to burn a  lot  of time figuring out the difference between  call  and  execute ,  within  and...
Javassist <ul><li>Javassist </li></ul><ul><ul><li>http://www.csg.is.titech.ac.jp/~chiba/javassist/ </li></ul></ul><ul><li>...
Javassist Example
Javassist Pros <ul><li>Provides a relatively simple interface to do fault injection at the level of the bytecode </li></ul...
Javassist Cons <ul><li>Limited compiler </li></ul><ul><li>There’s  much  that you need to roll in order to use it </li></u...
Future Work <ul><li>Simplify fault injection + JUnit </li></ul><ul><ul><li>e.g.   run a set of test cases with different f...
Questions?
References <ul><li>[1]  Harbulot, B. & Gurd, J. (2005).  A join point for loops in AspectJ.   </li></ul><ul><li>  http://w...
Thank You <ul><li>Rob Grzywinski </li></ul><ul><li>http://www.realityinteractive.com/rgrzywinski/ </li></ul><ul><li>[email...
Upcoming SlideShare
Loading in …5
×

香港六合彩 &raquo; SlideShare

1,830 views

Published on

白天有白天的感觉,白天有白天的味道。因为油麻地的雨多,油麻地香港六合彩家的床,白天都常常闲不着,摇晃着,吱吱呀呀地叫唤。这是雨中的乐章。油麻地的女香港六合彩似乎特别能生孩子,而这些孩子十有八九是在雨天怀上的。雨使油麻地的男香港六合彩一个个都形销骨立,雨也使油麻地香港六合彩丁兴旺。范烟户觉得在这样的天气里尤其寂寞,就坐在门口唱起来:晨(又鸟)初叫,昏鸦争噪,哪个不去红尘闹。路遥遥,水迢迢。功名尽在长安道,今日少年明日老。山,依旧好;香港六合彩,憔悴了……范烟户的曲儿,飘进了一条又一条巷子……朱荻洼去了一趟杜元潮家,只片刻工夫,又走进雨地里……[第70节]鬼雨/梨花雨8(1)随后,雨中,杜元潮、邱子东都在很诡秘地走动着,去了一趟朱小楼家,去了一趟小七子家……最后,杜元潮去了一趟废弃的仓房。仓房里住了一对卖唱的父女。香港六合彩是路过油麻地,没想到雨将香港六合彩困在了这儿。油麻地的香港六合彩自然想听唱,但,都想白听。父女俩岂肯白唱,就住到仓房里,蒙头睡觉去了。杜元潮掏出五元钱,请父女俩晚饭后到村子中央的祠堂里唱几个曲子。那父女俩自然很高兴,对杜元潮说:香港六合彩一定用力唱。杜元潮让小七子站在巷口,大喊了几声:今晚上,到祠堂听唱!这个消息很令香港六合彩振奋,一个个奔走相告。吃了晚饭,雨小了些,香港六合彩就三三两两往祠堂走,不时地听见香港六合彩说:走,听唱去!与以往的雨天不一样,今晚上的油麻地香港六合彩不是一吃了饭就熄了灯往床上爬,而是纷纷去了祠堂。当杜元潮看到满满一祠堂香港六合彩时,心里很高兴。今晚上不能让油麻地香港六合彩睡觉。油麻地香港六合彩睡觉死沉,性子又木,夜里房子倒了都不一定肯起床。今晚上,必须有成千上百醒着的油麻地香港六合彩。油麻地的历史需要香港六合彩今晚醒着。但也有不少香港六合彩未到祠堂里听唱,比如朱小楼、小七子等。这父女俩唱得很不错,又很卖力。女孩儿声音尖而亮,亮而纯,纯而甜。拉胡琴的父亲声音厚而沙,沙而沉,沉而有力。唱得木讷的油麻地香港六合彩一个个很兴奋,两眼发亮,眼珠儿也变得灵活起来,黑暗里,像无数的猫聚在一起。杜元潮与邱子东站在最后面的黑暗里。这谭月月家住在镇子西头,与镇里香港六合彩家相隔了一段路,显得很僻静。当祠堂里父女俩已唱了两三曲,一个个已渐入佳境时,李长望的身影在通往谭月月家的小路口犹疑不定地出现了。香港六合彩在路口站了站,沿着菜园中间的小路大步走向谭月月家的门口。这女香港六合彩似乎早在门口屏声听着外面的脚步走,当李长望刚刚走到门口时,门便慢慢地开了一条缝。李长望再次向四周观望了一下,闪进门里。门关上后不久,灯便灭了。一直埋伏在草丛里的朱小楼拍了拍与香港六合彩一般潮湿的小七子,急急地往祠堂去了。这女香港六合彩似乎等得很焦渴了,一熄了灯,就带着一股浓烈的雪花膏味,一头扑在李长望宽阔的怀里,并用小小的拳头不住地击打香港六合彩的胸膛,然后,就用双手揪住李长望的衣襟,一个劲地摇晃着香港六合彩,就像拴在树上的一头急了的牛摇晃着大树。嘴里不住地说:你个杀千刀的,死哪里去啦?死哪里去啦?莫不是又勾搭上另外的女香港六合彩了?你这到处吃腥的馋猫!你倒说呀?你倒说呀?你是在往死里折磨香港六合彩呢!

Published in: Technology
  • Be the first to comment

  • Be the first to like this

香港六合彩 &raquo; SlideShare

  1. 1. Simplify Testing using Fault Injection Rob Grzywinski [email_address]
  2. 2. Motivation <ul><li>Writing and testing an IO-intensive application </li></ul><ul><ul><li>Robust, asynchronous event (message) collector / router </li></ul></ul><ul><ul><li>NIO (early 1.4 days) </li></ul></ul><ul><li>How to best simulate and test various failure modes? </li></ul><ul><ul><li>NIO buggy as all get-out </li></ul></ul><ul><ul><li>Networks are inherently flaky and problematic </li></ul></ul><ul><li>Didn’t want to have to obfuscate or drastically change code in order to test it </li></ul>
  3. 3. Agenda <ul><li>Quick Introduction to Fault Injection </li></ul><ul><li>Why Use Fault Injection </li></ul><ul><li>Fault Injection Examples </li></ul><ul><li>Beyond Fault Injection </li></ul><ul><li>Quick Introduction to AOP </li></ul><ul><li>Fault Injection in Java </li></ul><ul><ul><li>AspectJ </li></ul></ul><ul><ul><li>Javassist </li></ul></ul><ul><li>Wrap Up </li></ul>
  4. 4. Fault Injection 101 <ul><li>A fault is an abnormal condition or defect which may lead to a failure [10] </li></ul><ul><li>Fault injection involves the deliberate insertion of faults or errors into a computer system in order to determine its response [9] </li></ul><ul><ul><li>The goal isn’t to recreate the conditions that produced the fault </li></ul></ul>
  5. 5. Fault Injection 101 (cont) <ul><li>There are two primary steps to Fault Injection: </li></ul><ul><li>To identify the set of faults that can occur within an application, module, class, method, etc. </li></ul><ul><ul><li>e.g. if the application does not use the network then there’s no point in injecting network faults </li></ul></ul><ul><ul><li>In practice this isn’t as easy as it sounds </li></ul></ul><ul><ul><ul><li>e.g. 3 rd party libs </li></ul></ul></ul><ul><li>To exercise those faults to evaluate how the application responds </li></ul><ul><ul><li>Does the application detect the fault, is it isolated and does the application recover from it? [8] </li></ul></ul>
  6. 6. Example <ul><li>byte [] readFile() throws IOException { </li></ul><ul><li>... </li></ul><ul><li>final InputStream is = new FileInputStream(…); </li></ul><ul><li>... </li></ul><ul><li>while ((offset < bytes.length) && </li></ul><ul><li>(numRead = is.read(bytes, offset, (bytes.length - offset))) >= 0) </li></ul><ul><li>offset += numRead; </li></ul><ul><li>... </li></ul><ul><li>is.close(); </li></ul><ul><li>return bytes; </li></ul><ul><li>} </li></ul><ul><li>(from http://javaalmanac.com/egs/java.io/File2ByteArray.html ) </li></ul><ul><li>What could go wrong with this code? </li></ul><ul><li>new FileInputStream() can throw FileNotFoundException </li></ul><ul><li>InputStream.read() can throw IOException and IndexOutOfBoundsException and can return -1 for end of file </li></ul><ul><li>is.close() can throw IOException </li></ul>How do we test how the application responds to one of these situations? Specifically, how do we inject these faults so that we can test how the application responds?
  7. 7. Possible Techniques <ul><li>Force the situations at the OS level </li></ul><ul><ul><li>Quite hairy to reproduce reliably when they’re needed </li></ul></ul><ul><li>Refactor the snot out of it </li></ul><ul><ul><li>Replace the call to InputStream.read() to some local instrumented method </li></ul></ul><ul><ul><li>Create our own instrumented InputStream subclass possibly using mock objects </li></ul></ul><ul><ul><ul><li>Inject the subclass via IoC (requires some framework such as PicoContainer or Spring) </li></ul></ul></ul><ul><li>Just comment out the code and replace with throw new IOException() </li></ul><ul><ul><li>Egad! </li></ul></ul><ul><li>We need a way to inject a fault without changing the code! </li></ul>
  8. 8. Why Use Fault Injection <ul><li>Fault occurred in a production application and it is determined that that is a valid fault ( i.e. it is expected to occur) </li></ul><ul><ul><li>Inject the fault in a testing environment without having to reproduce the conditions that actually caused the fault </li></ul></ul><ul><li>Any fault that is difficult or inconvenient to reproduce in testing: </li></ul><ul><ul><li>Out of memory </li></ul></ul><ul><ul><li>Disk full </li></ul></ul><ul><ul><li>Database crash </li></ul></ul><ul><ul><li>3 rd party library / Java bug </li></ul></ul><ul><ul><li>Deadlock </li></ul></ul><ul><ul><li>Resource contention </li></ul></ul><ul><ul><li>Dumb users </li></ul></ul><ul><ul><li>Invalid / stale sessions </li></ul></ul><ul><ul><li>Corner cases </li></ul></ul>
  9. 9. Why Use Fault Injection (cont) <ul><li>You publish an API and you want to be tolerant of user input or response </li></ul><ul><li>It is inconvenient or undesirable to refactor code to facilitate testing </li></ul><ul><ul><li>e.g. 3 rd party library </li></ul></ul><ul><li>You believe that testing code coverage is a good metric to measure for code quality [11] </li></ul><ul><ul><li>Injecting faults forces exception paths to be followed </li></ul></ul><ul><li>More to come … </li></ul>
  10. 10. Reminder <ul><li>You don’t have to recreate the conditions that caused the fault … </li></ul><ul><li>… you only have to recreate the fault </li></ul><ul><li>e.g. if an OhNoException crashed your application because some little old lady drove her 1966 Buick Skylark into your datacenter -- you don’t need the Skylark or the little old lady to fix the application </li></ul>
  11. 11. Quick Aside <ul><li>Traditionally , Fault Injection is centers around faults derived from hardware: </li></ul><ul><li>Disk faults such as file missing and corrupt file </li></ul><ul><li>Network faults such as host not found, host inaccessible, and high latency </li></ul><ul><li>Memory faults such as corrupt memory </li></ul><ul><li>Operating system faults such as unexpected hardware interrupts </li></ul><ul><li>Traditionally used in mission-critical fault tolerant environments </li></ul>
  12. 12. Quick Aside (cont) <ul><li>Fault Injection comes in two favors: </li></ul><ul><li>Hardware-based </li></ul><ul><ul><li>Typically requires specialized hardware </li></ul></ul><ul><li>Software-based </li></ul><ul><ul><li>Traditionally attempts to mimic hardware-based fault injection and typically involves direct interaction with the operating system </li></ul></ul><ul><ul><li>More recently expanded to include any fault that can occur in software such as: </li></ul></ul><ul><ul><ul><li>Mutated bytecode </li></ul></ul></ul><ul><ul><ul><li>Exceptions </li></ul></ul></ul><ul><ul><ul><li>Invalid or mutated input / output values </li></ul></ul></ul><ul><ul><ul><li>Deadlock / resource contention </li></ul></ul></ul><ul><ul><ul><li>Application Security </li></ul></ul></ul><ul><ul><ul><li>etc. </li></ul></ul></ul>
  13. 13. Example <ul><li>Creating a directory and temporary file </li></ul>final File directory = new File(…); final boolean success = directory.mkdirs(); if (success) { final File file = File.createTempFile(…, …, directory); ... } <ul><li>Faults: </li></ul><ul><li>Making the parent directory(s) fails (returns false ) </li></ul><ul><li>Temp file creation failure (throws IOException ) </li></ul><ul><ul><li>Permissions </li></ul></ul><ul><ul><li>Parent directory(s) deleted </li></ul></ul><ul><li>Injection of a specific temp file </li></ul>
  14. 14. Example (cont) <ul><li>Great uses of Fault Injection that I can’t easily show in examples: </li></ul><ul><li>Deeply nested exceptions </li></ul><ul><li>Effects of unchecked exceptions </li></ul><ul><li>Consequences of using catch (Exception e) </li></ul><ul><ul><li>i.e. NullPointerException s that go unnoticed </li></ul></ul><ul><li>Complex / real-world cases </li></ul>
  15. 15. Intelligent Fault Injection <ul><li>Fault injection doesn’t have to be all on or all off </li></ul><ul><li>Logic can be coded around injected faults </li></ul><ul><li>e.g. InputStream.read() </li></ul><ul><ul><li>Throw IOException after n bytes are read </li></ul></ul><ul><ul><li>Return -1 (EOF) one byte before the actual EOF </li></ul></ul><ul><ul><li>Sporadically mutate the read bytes </li></ul></ul>
  16. 16. Beyond Fault Injection <ul><li>The techniques that I’m going to demonstrate aren’t specific to injecting faults ( i.e. conditions that may lead to a failure ) </li></ul><ul><ul><li>“ What if” analysis </li></ul></ul><ul><ul><li>Test difficult corner cases </li></ul></ul><ul><ul><ul><li>e.g. some optimization routine runs when certain conditions are met </li></ul></ul></ul><ul><ul><li>Initialize application state to some desired value </li></ul></ul><ul><ul><li>etc. </li></ul></ul><ul><li>The techniques are similar to mock objects or IoC but much more granular </li></ul>
  17. 17. Summary <ul><li>Intercept operations and inject code to: </li></ul><ul><li>Perform a custom function </li></ul><ul><li>Return a custom value </li></ul><ul><li>Modify a input parameter </li></ul><ul><li>Throw an exception </li></ul><ul><li>Set the state of an object to a specific value </li></ul>
  18. 18. Checkpoint <ul><li>Done: </li></ul><ul><li>Quick Introduction to Fault Injection </li></ul><ul><li>Why Use Fault Injection </li></ul><ul><li>Fault Injection Examples </li></ul><ul><li>Beyond Fault Injection </li></ul><ul><li>Next: </li></ul><ul><li>Quick Introduction to AOP </li></ul><ul><li>Fault Injection in Java </li></ul><ul><ul><li>AspectJ </li></ul></ul><ul><ul><li>Javassist </li></ul></ul><ul><li>Wrap Up </li></ul>
  19. 19. Checkpoint (cont) <ul><li>Questions? </li></ul>
  20. 20. Aspect Oriented Programming 101 <ul><li>Join Point </li></ul><ul><li>a point in the flow of a running program [14] </li></ul><ul><li>It is the “where” in AOP </li></ul><ul><li>Not all AO environments support all join points </li></ul><ul><ul><li>e.g. Spring AOP only supports method-based join points </li></ul></ul>
  21. 21. Aspect Oriented Programming 101 (cont) <ul><li>Join point examples </li></ul><ul><li>reading or writing a field </li></ul><ul><li>calling or executing a method or constructor </li></ul><ul><li>catching or throwing an exception </li></ul><ul><li>A “join point shadow” is the location of a join point in the source code or bytecode of the program [5] </li></ul><ul><li>We will use “join point” and “join point shadow” interchangeably </li></ul>
  22. 22. Aspect Oriented Programming 101 (cont) <ul><li>Pointcut </li></ul><ul><li>a set of join points [6] </li></ul><ul><li>Effectively a query where the join points are the data that is being queried – the “which” </li></ul>
  23. 23. Aspect Oriented Programming 101 (cont) <ul><li>Advice </li></ul><ul><li>code that executes at each join point picked out by a pointcut [7] </li></ul><ul><li>Advice is the code that you’re injecting -- the “what” </li></ul>
  24. 24. Aspect Oriented Programming 101 (cont) <ul><li>Aspect </li></ul><ul><li>a logical collection of advice </li></ul><ul><li>An aspect is to AO what an object is to OO </li></ul>
  25. 25. Aspect Oriented Programming 101 (cont) <ul><li>Introduction (aka Mixin or inter-type declaration ) </li></ul><ul><li>advice that provides additional functionality to a class </li></ul><ul><li>e.g. methods or member variables can be added via an Introduction to the “interface” of a class </li></ul>
  26. 26. Aspect Oriented Programming 101 (cont) <ul><li>Weaving </li></ul><ul><li>the process by which specific join points are identified by pointcuts and advice is injected into bytecode </li></ul>
  27. 27. How AOP Works <ul><li>Compile-time </li></ul><ul><ul><li>a specialized compiler is used to weave the source code and advice together to produce bytecode </li></ul></ul><ul><li>Post-compile (aka binary weaving) </li></ul><ul><ul><li>weaves advice into existing class files modifying them as necessary </li></ul></ul><ul><li>Load-time </li></ul><ul><ul><li>a classloader performs binary weaving as the class files are loaded into the JVM or a Java agent is used via JVMTI (JVM Tool Interface) </li></ul></ul><ul><li>Run-time </li></ul><ul><ul><li>classes that are already loaded by the JVM are woven with aspects via JPDA (Java Platform Debugger Architecture) to replace method bodies. Dynamic proxies can also be used. </li></ul></ul>
  28. 28. Load-Time Weaving <ul><li>We’re going to focus on load-time weaving (LTW) </li></ul><ul><ul><li>Advantange (over compile-time or post-compile): does not modify classes on disk </li></ul></ul><ul><ul><li>Disadvantage: increases application startup time </li></ul></ul>
  29. 29. Java AOP <ul><li>AspectJ ( http:// www.eclipse.org/aspectj / ): Excellent all-around solution. </li></ul><ul><li>dynaop ( https:// dynaop.dev.java.net / ) Bob Lee’s stripped down AOP: Requires proxy creation in code (i.e. not 100% transparent). </li></ul><ul><li>CGLIB ( http:// cglib.sourceforge.net / ): a roll-your-own solution using proxies. Requires proxy creation in code (i.e. not 100% transparent). For load-time weaving a custom class loader would be needed. </li></ul><ul><li>BCEL ( http:// jakarta.apache.org/bcel / ): roll-your-own solution requiring knowledge of Java byte code to write advice. For load-time weaving a custom class loader would be needed. </li></ul><ul><li>Javassist ( http:// www.csg.is.titech.ac.jp/~chiba/javassist / ): A large step above CGLIB / BCEL in that it includes a stripped down compiler and modifies the advised class on the fly. Load-time weaving is supported. </li></ul><ul><li>Spring AOP ( http:// www.springframework.org/docs/reference/aop.html ): Limited to method-based joinpoints. If using the @AspectJ annotations then it effectively becomes AspectJ otherwise standard Spring-style XML configuration. JDK dynamic proxies or CGLIB for implementation. If you’re already using Spring and only need to advise coarse-grained objects (i.e. the objects that you’re IoC’ing) and method-based jointpoints are suitable then this is a good solution. </li></ul><ul><li>JMangler ( http://roots.iai.uni-bonn.de/research/jmangler / ): A step above BCEL / CGLIB but a step below Javassist. Requires knowledge of Java byte code (it uses the BCEL API for advice). Load-time weaving is supported. </li></ul><ul><li>JBoss-AOP ( http:// labs.jboss.com/portal/jbossaop / ): Effectively on par with AspectJ. If you’re using JBoss then this would be the best solution. Even has support in their IDE. </li></ul>
  30. 30. Questions?
  31. 31. AspectJ <ul><li>AspectJ </li></ul><ul><ul><li>http://www.eclipse.org/aspectj/ </li></ul></ul><ul><li>Documentation </li></ul><ul><ul><li>http://www.eclipse.org/aspectj/doc/released/ </li></ul></ul><ul><li>AspectJ FAQ </li></ul><ul><ul><li>http://www.eclipse.org/aspectj/doc/next/faq.html </li></ul></ul><ul><li>AspectJ Development Environment Guide </li></ul><ul><ul><li>http:// www.eclipse.org/aspectj/doc/next/devguide/index.html </li></ul></ul><ul><li>AspectJ Programming Guide </li></ul><ul><ul><li>http://www.eclipse.org/aspectj/doc/released/progguide/index.html </li></ul></ul><ul><li>AspectJ Quick Reference </li></ul><ul><ul><li>http://www.eclipse.org/aspectj/doc/released/quick5.pdf </li></ul></ul>
  32. 32. Load-Time Weaving AspectJ <ul><li>Load-time Weaving can be accomplished via [13] : </li></ul><ul><li>-javaagent:pathto/aspectjweaver.jar </li></ul><ul><li>aj.bat </li></ul><ul><li>Custom classloader ( WeavingURLClassLoader ) </li></ul><ul><li>Both require a META-INF/aop.xml to be located in the classpath </li></ul>
  33. 33. AspectJ Examples <ul><li>There are three primary classes in the example: </li></ul><ul><li>Main </li></ul><ul><ul><li>Creates and calls the other classes </li></ul></ul><ul><li>ReadFile </li></ul><ul><ul><li>Accepts a File on construction </li></ul></ul><ul><ul><li>displayExistence() displays if the file exists </li></ul></ul><ul><ul><li>byte[] getBytesFromFile() returns the contents of the file as a byte array </li></ul></ul><ul><li>TemporaryFile </li></ul><ul><ul><li>readWriteTemporaryFile() </li></ul></ul><ul><ul><ul><li>Creates a temp file </li></ul></ul></ul><ul><ul><ul><li>Writes data into it </li></ul></ul></ul><ul><ul><ul><li>Reads contents line-by-line </li></ul></ul></ul><ul><ul><ul><li>Reads contents byte-by-byte </li></ul></ul></ul><ul><ul><ul><li>Deletes the temp file </li></ul></ul></ul>
  34. 34. AspectJ Pros <ul><li>Quite mature </li></ul><ul><li>Integration with IDEs ( e.g. AJDT) </li></ul><ul><li>Responsive forums </li></ul><ul><li>Does 95% of what you need </li></ul>
  35. 35. AspectJ Cons <ul><li>Expect to burn a lot of time figuring out the difference between call and execute , within and withincode , etc. </li></ul><ul><li>Can add quite a bit of time to incremental compiles (Also see bugs #146071 and #145438) </li></ul><ul><li>It’s very easy to confuse the IDE </li></ul><ul><li>No access to local variables </li></ul><ul><li>You have to be careful about other errors in your application. A compile error in some completely unrelated file may cause errors in aspects. </li></ul><ul><li>Brittle with respect to refactoring especially in the case of load-time weaving. If using AJDT with compile-time weaving then refactorings apply across aspects. </li></ul>
  36. 36. Javassist <ul><li>Javassist </li></ul><ul><ul><li>http://www.csg.is.titech.ac.jp/~chiba/javassist/ </li></ul></ul><ul><li>Javadoc </li></ul><ul><ul><li>http://www.csg.is.titech.ac.jp/~chiba/javassist/html/index.html </li></ul></ul><ul><li>Tutorial </li></ul><ul><ul><li>http://www.csg.is.titech.ac.jp/~chiba/javassist/tutorial/tutorial.html </li></ul></ul>
  37. 37. Javassist Example
  38. 38. Javassist Pros <ul><li>Provides a relatively simple interface to do fault injection at the level of the bytecode </li></ul><ul><li>Provides a limited compiler to take away the need to work directly in bytecode ( e.g. BCEL) </li></ul>
  39. 39. Javassist Cons <ul><li>Limited compiler </li></ul><ul><li>There’s much that you need to roll in order to use it </li></ul><ul><li>Confusing code fragment language </li></ul>
  40. 40. Future Work <ul><li>Simplify fault injection + JUnit </li></ul><ul><ul><li>e.g. run a set of test cases with different faults </li></ul></ul><ul><li>Library of faults for java.* and javax.* </li></ul><ul><li>Profiler for java.* and javax.* faults </li></ul><ul><li>Encourage fault libraries and profilers for common 3 rd party libs </li></ul>
  41. 41. Questions?
  42. 42. References <ul><li>[1] Harbulot, B. & Gurd, J. (2005). A join point for loops in AspectJ. </li></ul><ul><li> http://www.cs.iastate.edu/~leavens/FOAL/papers-2005/harbulot-gurd.pdf </li></ul><ul><li>[2] http://www.eclipse.org/aspectj/doc/released/faq.html#q:joinpoints </li></ul><ul><li>[3] http://www.aspectprogrammer.org/blogs/adrian/2004/06/go_from_stateme.html </li></ul><ul><li>[4] Ossher, H. & Tarr, P. Operation-Level Composition: A Case in (Join) Point </li></ul><ul><li> http:// www.ccs.neu.edu/research/demeter/SOP/Tarr.pdf </li></ul><ul><li>[5] Hilsdale, E. & Hugunin, J. Advice Weaving in AspectJ </li></ul><ul><li> http://hugunin.net/papers/aosd-2004-cameraReady.pdf </li></ul><ul><li>[6] http:// en.wikipedia.org/wiki/Pointcut </li></ul><ul><li>[7] http:// www.eclipse.org/aspectj/doc/released/faq.html#q:advice </li></ul><ul><li>[8] Hsueh, M, Tasi, T, & Iyer, R. Fault InjectionTechniques and Tools. </li></ul><ul><li> IEEE CS Press, 1997, pp. 75-82 </li></ul><ul><li>[9] Clark, J. & Pradhan, D. Fault Injection. IEEE CS Press, 1995, pp. 47-56 </li></ul><ul><li>[10] http://en.wikipedia.org/wiki/Fault_%28technology%29 </li></ul><ul><li>[11] http://blogs.msdn.com/bwill/archive/2003/09/23/51169.aspx </li></ul><ul><li>[12] Espak, M. Improving Efficiency by Weaving at Run-time </li></ul><ul><li> http://www.old.netobjectdays.org/pdf/03/papers/ws-yrw/415.pdf </li></ul><ul><li>[13] http://www.eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html </li></ul><ul><li>[14] http:// en.wikipedia.org/wiki/Join_point </li></ul>
  43. 43. Thank You <ul><li>Rob Grzywinski </li></ul><ul><li>http://www.realityinteractive.com/rgrzywinski/ </li></ul><ul><li>[email_address] </li></ul>

×